Search in sources :

Example 1 with DelegateTask

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) DelegateTask(org.activiti.engine.delegate.DelegateTask) ApprovalStageDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalStageDefinitionType) TaskService(org.activiti.engine.TaskService) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 2 with 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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) DelegateTask(org.activiti.engine.delegate.DelegateTask) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) SpringApplicationContextHolder.getPrismContext(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext) PrismContext(com.evolveum.midpoint.prism.PrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NotNull(org.jetbrains.annotations.NotNull) SystemException(com.evolveum.midpoint.util.exception.SystemException) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 DelegateTask (org.activiti.engine.delegate.DelegateTask)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 SpringApplicationContextHolder.getPrismContext (com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext)1 ApprovalStageDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalStageDefinitionType)1 TaskService (org.activiti.engine.TaskService)1 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)1 NotNull (org.jetbrains.annotations.NotNull)1