use of org.activiti.engine.delegate.DelegateTask in project midpoint by Evolveum.
the class TaskCreateListener method notify.
@Override
public void notify(DelegateTask delegateTask) {
OperationResult result = new OperationResult(TaskCreateListener.class.getName() + ".notify");
Task wfTask = ActivitiUtil.getTask(delegateTask.getExecution(), result);
String taskId = delegateTask.getId();
// duration/deadline
ApprovalStageDefinitionType stageDef = WfContextUtil.getCurrentStageDefinition(wfTask.getWorkflowContext());
if (stageDef == null) {
throw new IllegalStateException("No approval stage information in " + delegateTask);
}
if (stageDef.getDuration() != null) {
MidpointUtil.setTaskDeadline(delegateTask, stageDef.getDuration());
}
// triggers
int escalationLevel = ActivitiUtil.getEscalationLevelNumber(delegateTask.getVariables());
MidpointUtil.createTriggersForTimedActions(taskId, escalationLevel, delegateTask.getCreateTime(), delegateTask.getDueDate(), wfTask, stageDef.getTimedActions(), result);
// originalAssignee
String assignee = delegateTask.getAssignee();
if (assignee != null) {
TaskService taskService = delegateTask.getExecution().getEngineServices().getTaskService();
taskService.setVariableLocal(taskId, CommonProcessVariableNames.VARIABLE_ORIGINAL_ASSIGNEE, assignee);
taskService.addUserIdentityLink(taskId, assignee, CommonProcessVariableNames.MIDPOINT_ASSIGNEE);
}
getActivitiInterface().notifyMidpointAboutTaskEvent(delegateTask);
}
use of org.activiti.engine.delegate.DelegateTask in project midpoint by Evolveum.
the class TaskCompleteListener method notify.
@Override
public void notify(DelegateTask delegateTask) {
DelegateExecution execution = delegateTask.getExecution();
PrismContext prismContext = getPrismContext();
OperationResult opResult = new OperationResult(TaskCompleteListener.class.getName() + ".notify");
Task wfTask = ActivitiUtil.getTask(execution, opResult);
ApprovalStageDefinitionType stageDef = ActivitiUtil.getAndVerifyCurrentStage(execution, wfTask, true, prismContext);
delegateTask.setVariableLocal(CommonProcessVariableNames.VARIABLE_WORK_ITEM_WAS_COMPLETED, Boolean.TRUE);
// System.out.println("%%% Task " + delegateTask + " has been completed.");
// LOGGER.info("%%% Task {} has been completed", delegateTask);
MidPointPrincipal user;
try {
user = SecurityUtil.getPrincipal();
} catch (SecurityViolationException e) {
throw new SystemException("Couldn't record a decision: " + e.getMessage(), e);
}
if (user != null && user.getOid() != null) {
delegateTask.setVariableLocal(CommonProcessVariableNames.VARIABLE_WORK_ITEM_COMPLETED_BY, user.getOid());
}
LOGGER.trace("======================================== Recording individual decision of {}", user);
@NotNull WorkItemResultType result1 = getItemApprovalProcessInterface().extractWorkItemResult(delegateTask.getVariables());
boolean isApproved = ApprovalUtils.isApproved(result1);
LevelEvaluationStrategyType levelEvaluationStrategyType = stageDef.getEvaluationStrategy();
Boolean setLoopApprovesInStageStop = null;
if (levelEvaluationStrategyType == LevelEvaluationStrategyType.FIRST_DECIDES) {
LOGGER.trace("Setting " + LOOP_APPROVERS_IN_STAGE_STOP + " to true, because the stage evaluation strategy is 'firstDecides'.");
setLoopApprovesInStageStop = true;
} else if ((levelEvaluationStrategyType == null || levelEvaluationStrategyType == LevelEvaluationStrategyType.ALL_MUST_AGREE) && !isApproved) {
LOGGER.trace("Setting " + LOOP_APPROVERS_IN_STAGE_STOP + " to true, because the stage eval strategy is 'allMustApprove' and the decision was 'reject'.");
setLoopApprovesInStageStop = true;
}
if (setLoopApprovesInStageStop != null) {
//noinspection ConstantConditions
execution.setVariable(LOOP_APPROVERS_IN_STAGE_STOP, setLoopApprovesInStageStop);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Approval process instance {} (id {}), stage {}: recording decision {}; stage stops now: {}", execution.getVariable(CommonProcessVariableNames.VARIABLE_PROCESS_INSTANCE_NAME), execution.getProcessInstanceId(), WfContextUtil.getStageDiagName(stageDef), result1.getOutcome(), setLoopApprovesInStageStop);
}
getActivitiInterface().notifyMidpointAboutTaskEvent(delegateTask);
getActivitiInterface().notifyMidpointAboutProcessEvent(execution);
}
Aggregations