/** * This method retrieves the (potentially modified) issue object that is being transitioned through workflow. * * @param transientVars * @return the issue object representing the issue the functions shoudl modify * @throws com.atlassian.jira.exception.DataAccessException If for some reason the issue doesn't exist. */ protected MutableIssue getIssue(Map transientVars) throws DataAccessException { MutableIssue issue = (MutableIssue) transientVars.get("issue"); if (issue == null) { WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry"); try { issue = ComponentAccessor.getIssueManager().getIssueObjectByWorkflow(entry.getId()); } catch (GenericEntityException e) { throw new DataAccessException("Problem looking up issue with workflow entry id "+entry.getId()); } if (issue == null) throw new DataAccessException("No issue found with workflow entry id "+entry.getId()); } return issue; } }
public Map<String, Object> toMap(Map transientVars, ApplicationUser user, MutableIssue issue) { final WorkflowEntry entry = (WorkflowEntry) transientVars.get(ENTRY); final ImmutableMap.Builder<String, Object> transition = ImmutableMap.builder(); final Integer actionId = (Integer) transientVars.get(ACTION_ID); final WorkflowDescriptor workflowDescriptor = (WorkflowDescriptor) transientVars.get(WORKFLOW_DESCRIPTOR); final ActionDescriptor actionDescriptor = workflowDescriptor.getAction(actionId); final Step createdStep = (Step) transientVars.get(CREATED_STEP); final WorkflowStore workflowStore = (WorkflowStore) transientVars.get(WORKFLOW_STORE); transition.put(WORKFLOW_ID, entry.getId()) .put(WORKFLOW_NAME, entry.getWorkflowName()) .put(TRANSITION_ID, actionId) .put(TRANSITION_NAME, actionDescriptor.getName()) .put(FROM_STATUS, findPreviousStatus(createdStep, entry, workflowStore, workflowDescriptor)) .put(TO_STATUS, getToStatus(workflowDescriptor, createdStep)); final ImmutableMap.Builder<String, Object> transitionContext = ImmutableMap.builder(); transitionContext.put(TRANSITION_CONTEXT, transition.build()) .put(COMMENT, transientVars.get(COMMENT) != null ? transientVars.get(COMMENT) : "") .put(USER, user != null ? userBeanFactory.createBean(user) : ""); transitionContext.put(ISSUE, issueBeanFactory.createBean(issue)); transitionContext.put(TIMESTAMP, createdStep.getStartDate().getTime()); return transitionContext.build(); }
try currentSteps = store.findCurrentSteps(entry.getId());
public void execute(Map transientVars, Map args, PropertySet ps) throws StoreException { MutableIssue issue = (MutableIssue) transientVars.get("issue"); WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry"); SimpleStep step = (SimpleStep) ((WorkflowStore) transientVars.get("store")).findCurrentSteps(entry.getId()).get(0); WorkflowDescriptor descriptor = (WorkflowDescriptor) transientVars.get("descriptor"); StepDescriptor stepDescriptor = descriptor.getStep(step.getStepId()); Status oldStatus = issue.getStatus(); Status newStatus = ComponentAccessor.getConstantsManager().getStatus((String) stepDescriptor.getMetaAttributes().get("jira.status.id")); // Update issue issue.setStatusId(newStatus.getId()); // Generate status change item List changeItems = (List) transientVars.get("changeItems"); if (changeItems == null) { changeItems = new LinkedList(); } String from = null; String fromString = null; if (oldStatus != null) { from = oldStatus.getId(); fromString = oldStatus.getName(); } String to = newStatus.getId(); String toString = newStatus.getName(); changeItems.add(new ChangeItemBean(ChangeItemBean.STATIC_FIELD, IssueFieldConstants.STATUS, from, fromString, to, toString)); transientVars.put("changeItems", changeItems); }
private String findPreviousStatus(Step currentStep, WorkflowEntry entry, WorkflowStore workflowStore, WorkflowDescriptor workflowDescriptor) { if (currentStep.getPreviousStepIds().length == 0) { return ""; } final long previousStepId = currentStep.getPreviousStepIds()[0]; try { final List<Step> historySteps = workflowStore.findHistorySteps(entry.getId()); final Step previousStep = Iterables.find(historySteps, new Predicate<Step>() { @Override public boolean apply(Step step) { return step.getId() == previousStepId; } }, null); if (previousStep == null) { LOG.error("Transition from cannot be found. It seems that workflow data is inconsistent."); return ""; } return workflowDescriptor.getStep(previousStep.getStepId()).getName(); } catch (StoreException e) { return ""; } }
store.setEntryState(newEntry.getId(), WorkflowEntry.ACTIVATED); store.setEntryState(wfid, WorkflowEntry.KILLED); store.createCurrentStep(newEntry.getId(), stepInNewWorkflow.getId(), currentStep.getOwner(), currentStep.getStartDate(), currentStep.getDueDate(), currentStep.getStatus(), null); store.createCurrentStep(newEntry.getId(), stepInNewWorkflow.getId(), null, startDate, null, newStatus.getString("id"), null); issue.set("workflowId", newEntry.getId()); issue.store();