@Override public Map<String,StatusMapping> getStatusHolders(File xmlFile) throws Exception { Collection<Status> jiraStatuses = constantsManager.getStatusObjects(); Map<String,StatusMapping> holders = new HashMap<String, StatusMapping>(); String xml = FileUtils.readFileToString(xmlFile); WorkflowDescriptor descriptor = WorkflowUtil.convertXMLtoWorkflowDescriptor(xml); List<StepDescriptor> steps = descriptor.getSteps(); for(StepDescriptor step : steps) { if ((step.getMetaAttributes() != null) && step.getMetaAttributes().containsKey(JiraWorkflow.STEP_STATUS_KEY)) { String statusId = (String) step.getMetaAttributes().get(JiraWorkflow.STEP_STATUS_KEY); try { Status found = Iterables.find(jiraStatuses,new StatusNamePredicate(step.getName())); holders.put(statusId,new StatusMapping(statusId,step.getName(),found.getId(),getSuggestedName(jiraStatuses,found.getName()))); } catch (NoSuchElementException e) { holders.put(statusId, new StatusMapping(statusId, step.getName(), "-1", step.getName())); } } } return holders; }
private Integer getStepId(final JiraWorkflow workflow, final ActionDescriptor transition) { // Get the first step that feeds into this transition, and see if the step has a direct link to it. // If not, the transition is a global or initial transition, and we shouldn't provide a step ID. // See com.atlassian.jira.web.util.component.RequestComponentManager#injectWorkflow to understand why. final Collection<StepDescriptor> steps = workflow.getStepsForTransition(transition); if (!steps.isEmpty()) { final StepDescriptor step = steps.iterator().next(); if (step.getAction(transition.getId()) != null) { return step.getId(); } } return null; }
public Collection getTransitions() { // The actions list should contain all the common and ordinary actions. // (And no global actions, which cannot be deleted from here). return step.getActions(); }
@Override public String getLinkedStatusId(final StepDescriptor stepDescriptor) { if (stepDescriptor == null) { throw new IllegalArgumentException("Step cannot be null."); } if ((stepDescriptor.getMetaAttributes() != null) && stepDescriptor.getMetaAttributes().containsKey(STEP_STATUS_KEY)) { return (String) stepDescriptor.getMetaAttributes().get(JiraWorkflow.STEP_STATUS_KEY); } throw new IllegalStateException("Step with id '" + stepDescriptor.getId() + "' does not have a valid linked status."); }
public ConfigurableJiraWorkflow(final String name, final WorkflowManager workflowManager) { super(workflowManager, new WorkflowDescriptor()); this.name = name; // create the initial step - useful to have one of these :) final StepDescriptor step = DescriptorFactory.getFactory().createStepDescriptor(); step.setId(1); step.setName("Open"); step.getMetaAttributes().put(JiraWorkflow.STEP_STATUS_KEY, "1"); step.setParent(descriptor); descriptor.addStep(step); // create the initial action final ActionDescriptor initialAction = DescriptorFactory.getFactory().createActionDescriptor(); initialAction.setId(1); initialAction.setName("Create"); initialAction.setParent(descriptor); descriptor.addInitialAction(initialAction); // add create issue permission validator initialAction.getValidators().add(PermissionValidator.makeDescriptor("Create Issue")); // setup result to always be step 1 final ResultDescriptor resultDescriptor = DescriptorFactory.getFactory().createResultDescriptor(); resultDescriptor.setStep(1); resultDescriptor.setStatus("open"); initialAction.setUnconditionalResult(resultDescriptor); // setup post functions resultDescriptor.getPostFunctions().add(IssueCreateFunction.makeDescriptor()); resultDescriptor.getPostFunctions().add(IssueReindexFunction.makeDescriptor()); resultDescriptor.getPostFunctions().add(FireIssueEventFunction.makeDescriptor(EventType.ISSUE_CREATED_ID)); }
@Override public String apply(final StepDescriptor input) { return input.getName(); } }).getOrElse("");
@Override public Map<String, String> get() { return descriptor.getMetaAttributes(); }
public String getCancelUrl() { StringBuilder url = new StringBuilder("ViewWorkflowTransition.jspa") .append(getBasicWorkflowParameters()); if (getStep() != null) { url.append("&workflowStep=" + getStep().getId()); } url.append("&workflowTransition=" + action.getId()); return url.toString(); }
checkDuplicateTransitionName(getStep().getActions(), getTransitionName()); getStep().getId())) getStep().getName()));
@RequiresXsrfCheck protected String doExecute() throws Exception { StepDescriptor stepDescriptor = getWorkflow().getDescriptor().getStep(step.getId()); stepDescriptor.setName(getStepName()); //For a draft workflow, you can only changed the linked status for new steps. if (!isOldStepOnDraft(step)) { stepDescriptor.getMetaAttributes().put(JiraWorkflow.STEP_STATUS_KEY, getStepStatus()); } workflowService.updateWorkflow(getJiraServiceContext(), getWorkflow()); return getRedirect(getCancelUrl()); }
public String doDefault() throws Exception { if (workflowService.isStepOnDraftWithNoTransitionsOnParentWorkflow(getJiraServiceContext(), getWorkflow(), getStep().getId())) { addErrorMessage(getText("admin.workflowtransitions.error.add.transition.draft.step.without.transition", getStep().getName())); } return super.doDefault(); }
ActionDescriptor transition = step.getAction(transitionId); if (transition != null) step.getActions().remove(transition); step.getCommonActions().remove(new Integer(transition.getId())); if (step.getActions().isEmpty() && step.getCommonActions().isEmpty()) step.removeActions();
public void validateAddWorkflowTransitionToDraft(final JiraServiceContext jiraServiceContext, final JiraWorkflow newJiraWorkflow, final int stepId) { if (!hasAdminPermission(jiraServiceContext)) { jiraServiceContext.getErrorCollection().addErrorMessage(getI18nBean().getText("admin.workflows.service.error.no.admin.permission")); return; } if (isStepOnDraftWithNoTransitionsOnParentWorkflow(jiraServiceContext, newJiraWorkflow, stepId)) { //original step didn't have any actions. Lets check if the new step DOES have any actions. final StepDescriptor newStep = newJiraWorkflow.getDescriptor().getStep(stepId); final List<?> newActions = newStep.getActions(); if ((newActions != null) && !newActions.isEmpty()) { jiraServiceContext.getErrorCollection().addErrorMessage( getI18nBean().getText("admin.workflowtransitions.error.add.transition.draft.step.without.transition", newStep.getName())); } } }
final Map stepAttributes = stepDescriptor.getMetaAttributes(); final Collection actions = stepDescriptor.getActions();
final int stepInWorkflowId = stepInWorkflow.getId(); if (!stepInWorkflow.getActions().isEmpty())
public Collection getSelectedTransitions() { Collection transitions = new LinkedList(); if (transitionIds != null) { for (final int transitionId : transitionIds) { transitions.add(step.getAction(transitionId)); } } return transitions; }
for (StepDescriptor step: steps) postFunctions.addAll(step.getPostFunctions()); actions.addAll(step.getActions());
for (final Object o : stepDescriptor.getCommonActions()) for (final Object o : stepDescriptor.getActions())
for (StepDescriptor existingStep : existingSteps) if (getStepName().equalsIgnoreCase(existingStep.getName())) if (getStepStatus().equalsIgnoreCase((String) existingStep.getMetaAttributes().get(JiraWorkflow.STEP_STATUS_KEY))) newStep.setName(getStepName()); newStep.setId(WorkflowUtil.getNextId(getWorkflow().getDescriptor().getSteps())); newStep.getMetaAttributes().put(JiraWorkflow.STEP_STATUS_KEY, getStepStatus()); newStep.setParent(getWorkflow().getDescriptor()); getWorkflow().getDescriptor().addStep(newStep);
public String doDefault() throws Exception { setStepName(step.getName()); initStatuses(); return super.doDefault(); }