@Override public boolean apply(Step step) { return step.getId() == previousStepId; } }, null);
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 ""; } }
try currentSteps = store.findCurrentSteps(entry.getId()); Integer stepId = new Integer(step.getStepId()); if (stepIds.contains(stepId))
List currentSteps = store.findCurrentSteps(wfid); SimpleStep currentStep = null; WorkflowEntry newEntry = store.createEntry(newWorkflow.getName()); 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.moveToHistory(currentStep); store.createCurrentStep(newEntry.getId(), stepInNewWorkflow.getId(), null, startDate, null, newStatus.getString("id"), null); issue.set("workflowId", newEntry.getId()); issue.store();
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(); }
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); }
/** * 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; } }
private String getToStatus(WorkflowDescriptor workflowDescriptor, Step createdStep) { return option(workflowDescriptor.getStep(createdStep.getStepId())).map(new Function<StepDescriptor, String>() { @Override public String apply(final StepDescriptor input) { return input.getName(); } }).getOrElse(""); } }
private void createStep(final boolean correct, final Long workflowEntryId, final int stepInWorkflowId, final GenericValue issue, final List<CheckAmendment> results) throws StoreException { final String message; if (correct) { final WorkflowStore store = workflowManager.getStore(); store.createCurrentStep(workflowEntryId, stepInWorkflowId, null, issue.getTimestamp("created"), null, issue.getString("status"), null); // Record the message message = getI18NBean().getText("admin.integrity.check.workflow.current.step.correct.message", issue.getString("key"), workflowEntryId.toString()); results.add(new CheckAmendment(Amendment.ERROR, message, "JRA-4539")); } else { // Record the message message = getI18NBean().getText("admin.integrity.check.workflow.current.step.correct.preview", issue.getString("key"), workflowEntryId.toString()); results.add(new CheckAmendment(Amendment.ERROR, message, "JRA-4539")); } }
final Collection workflowSteps = store.findCurrentSteps(originalWfIdString.longValue());
issue.setWorkflowId(entry.getId()); Step step = (Step) ((WorkflowStore) transientVars.get("store")).findCurrentSteps(entry.getId()).get(0); WorkflowDescriptor descriptor = (WorkflowDescriptor) transientVars.get("descriptor"); StepDescriptor stepDescriptor = descriptor.getStep(step.getStepId()); issue.setStatusId((String) stepDescriptor.getMetaAttributes().get("jira.status.id"));