Search in sources :

Example 1 with DelegateExecution

use of org.activiti.engine.delegate.DelegateExecution in project midpoint by Evolveum.

the class DumpVariables method dumpExecutionVariables.

private void dumpExecutionVariables(String executionId, DelegateExecution delegateExecution, Execution execution, Set<String> variablesSeen, RuntimeService runtimeService) {
    Map<String, Object> variablesLocal = runtimeService.getVariablesLocal(executionId);
    LOGGER.trace("Execution id={} ({} variables); class={}/{}", executionId, variablesLocal.size(), delegateExecution != null ? delegateExecution.getClass().getName() : null, execution != null ? execution.getClass().getName() : null);
    TreeSet<String> names = new TreeSet<>(variablesLocal.keySet());
    names.forEach(n -> LOGGER.trace(" - {} = {} {}", n, variablesLocal.get(n), variablesSeen.contains(n) ? "(dup)" : ""));
    variablesSeen.addAll(variablesLocal.keySet());
    if (delegateExecution instanceof ExecutionEntity) {
        ExecutionEntity executionEntity = (ExecutionEntity) delegateExecution;
        if (executionEntity.getParent() != null) {
            dumpExecutionVariables(executionEntity.getParentId(), executionEntity.getParent(), null, variablesSeen, runtimeService);
        }
    } else if (delegateExecution instanceof ExecutionImpl) {
        ExecutionImpl executionImpl = (ExecutionImpl) delegateExecution;
        if (executionImpl.getParent() != null) {
            dumpExecutionVariables(executionImpl.getParentId(), executionImpl.getParent(), null, variablesSeen, runtimeService);
        }
    } else {
        Execution execution1 = runtimeService.createExecutionQuery().executionId(executionId).singleResult();
        if (execution1 == null) {
            LOGGER.trace("Execution with id {} was not found.", executionId);
        } else if (execution1.getParentId() != null) {
            Execution execution2 = runtimeService.createExecutionQuery().executionId(execution1.getParentId()).singleResult();
            dumpExecutionVariables(execution.getParentId(), null, execution2, variablesSeen, runtimeService);
        }
    }
}
Also used : DelegateExecution(org.activiti.engine.delegate.DelegateExecution) Execution(org.activiti.engine.runtime.Execution) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ExecutionImpl(org.activiti.engine.impl.pvm.runtime.ExecutionImpl)

Example 2 with DelegateExecution

use of org.activiti.engine.delegate.DelegateExecution in project Activiti by Activiti.

the class ActivitiEventBuilder method populateEventWithCurrentContext.

protected static void populateEventWithCurrentContext(ActivitiEventImpl event) {
    boolean extractedFromContext = false;
    if (Context.isExecutionContextActive()) {
        ExecutionContext executionContext = Context.getExecutionContext();
        if (executionContext != null) {
            extractedFromContext = true;
            event.setExecutionId(executionContext.getExecution().getId());
            event.setProcessInstanceId(executionContext.getExecution().getProcessInstanceId());
            event.setProcessDefinitionId(executionContext.getExecution().getProcessDefinitionId());
        }
    }
    // Fallback to fetching context from the object itself
    if (!extractedFromContext) {
        if (event instanceof ActivitiEntityEvent) {
            Object persistendObject = ((ActivitiEntityEvent) event).getEntity();
            if (persistendObject instanceof Job) {
                event.setExecutionId(((Job) persistendObject).getExecutionId());
                event.setProcessInstanceId(((Job) persistendObject).getProcessInstanceId());
                event.setProcessDefinitionId(((Job) persistendObject).getProcessDefinitionId());
            } else if (persistendObject instanceof DelegateExecution) {
                event.setExecutionId(((DelegateExecution) persistendObject).getId());
                event.setProcessInstanceId(((DelegateExecution) persistendObject).getProcessInstanceId());
                event.setProcessDefinitionId(((DelegateExecution) persistendObject).getProcessDefinitionId());
            } else if (persistendObject instanceof IdentityLinkEntity) {
                IdentityLinkEntity idLink = (IdentityLinkEntity) persistendObject;
                if (idLink.getProcessDefinitionId() != null) {
                    event.setProcessDefinitionId(idLink.getProcessDefId());
                } else if (idLink.getProcessInstance() != null) {
                    event.setProcessDefinitionId(idLink.getProcessInstance().getProcessDefinitionId());
                    event.setProcessInstanceId(idLink.getProcessInstanceId());
                    event.setExecutionId(idLink.getProcessInstanceId());
                } else if (idLink.getTask() != null) {
                    event.setProcessDefinitionId(idLink.getTask().getProcessDefinitionId());
                    event.setProcessInstanceId(idLink.getTask().getProcessInstanceId());
                    event.setExecutionId(idLink.getTask().getExecutionId());
                }
            } else if (persistendObject instanceof Task) {
                event.setProcessInstanceId(((Task) persistendObject).getProcessInstanceId());
                event.setExecutionId(((Task) persistendObject).getExecutionId());
                event.setProcessDefinitionId(((Task) persistendObject).getProcessDefinitionId());
            } else if (persistendObject instanceof ProcessDefinition) {
                event.setProcessDefinitionId(((ProcessDefinition) persistendObject).getId());
            }
        }
    }
}
Also used : IdentityLinkEntity(org.activiti.engine.impl.persistence.entity.IdentityLinkEntity) Task(org.activiti.engine.task.Task) ExecutionContext(org.activiti.engine.impl.context.ExecutionContext) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Job(org.activiti.engine.runtime.Job)

Example 3 with DelegateExecution

use of org.activiti.engine.delegate.DelegateExecution in project Activiti by Activiti.

the class AssigneeOverwriteFromVariable method notify.

@SuppressWarnings("unchecked")
public void notify(DelegateTask delegateTask) {
    // get mapping table from variable
    DelegateExecution execution = delegateTask.getExecution();
    Map<String, String> assigneeMappingTable = (Map<String, String>) execution.getVariable("assigneeMappingTable");
    // get assignee from process
    String assigneeFromProcessDefinition = delegateTask.getAssignee();
    // overwrite assignee if there is an entry in the mapping table
    if (assigneeMappingTable.containsKey(assigneeFromProcessDefinition)) {
        String assigneeFromMappingTable = assigneeMappingTable.get(assigneeFromProcessDefinition);
        delegateTask.setAssignee(assigneeFromMappingTable);
    }
}
Also used : DelegateExecution(org.activiti.engine.delegate.DelegateExecution) Map(java.util.Map)

Example 4 with DelegateExecution

use of org.activiti.engine.delegate.DelegateExecution in project midpoint by Evolveum.

the class SummarizeDecisionsInStage method execute.

public void execute(DelegateExecution execution) {
    PrismContext prismContext = getPrismContext();
    OperationResult result = new OperationResult(SummarizeDecisionsInStage.class.getName() + ".execute");
    Task wfTask = ActivitiUtil.getTask(execution, result);
    ApprovalStageDefinitionType stageDef = ActivitiUtil.getAndVerifyCurrentStage(execution, wfTask, true, prismContext);
    WfContextType wfc = ActivitiUtil.getWorkflowContext(wfTask);
    List<StageCompletionEventType> stageEvents = WfContextUtil.getEventsForCurrentStage(wfc, StageCompletionEventType.class);
    boolean approved;
    if (!stageEvents.isEmpty()) {
        String outcome = WfContextUtil.getCurrentStageOutcome(wfc, stageEvents);
        if (QNameUtil.matchUri(outcome, SchemaConstants.MODEL_APPROVAL_OUTCOME_APPROVE) || QNameUtil.matchUri(outcome, SchemaConstants.MODEL_APPROVAL_OUTCOME_SKIP)) {
            approved = true;
        } else if (QNameUtil.matchUri(outcome, SchemaConstants.MODEL_APPROVAL_OUTCOME_REJECT)) {
            approved = false;
        } else {
            // TODO less draconian handling
            throw new IllegalStateException("Unknown outcome: " + outcome);
        }
    } else {
        LOGGER.trace("****************************************** Summarizing decisions in stage {} (stage evaluation strategy = {}): ", stageDef.getName(), stageDef.getEvaluationStrategy());
        List<WorkItemCompletionEventType> itemEvents = WfContextUtil.getEventsForCurrentStage(wfc, WorkItemCompletionEventType.class);
        boolean allApproved = true;
        for (WorkItemCompletionEventType event : itemEvents) {
            LOGGER.trace(" - {}", event);
            allApproved &= ApprovalUtils.isApproved(event.getOutput());
        }
        approved = allApproved;
        if (stageDef.getEvaluationStrategy() == LevelEvaluationStrategyType.FIRST_DECIDES) {
            Set<String> outcomes = itemEvents.stream().map(e -> e.getOutput().getOutcome()).collect(Collectors.toSet());
            if (outcomes.size() > 1) {
                LOGGER.warn("Ambiguous outcome with firstDecides strategy in {}: {} response(s), providing outcomes of {}", WfContextUtil.getBriefDiagInfo(wfc), itemEvents.size(), outcomes);
            }
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Approval process instance {} (id {}), stage {}: result of this stage: {}", execution.getVariable(CommonProcessVariableNames.VARIABLE_PROCESS_INSTANCE_NAME), execution.getProcessInstanceId(), WfContextUtil.getStageDiagName(stageDef), approved);
    }
    execution.setVariable(ProcessVariableNames.LOOP_STAGES_STOP, !approved);
}
Also used : com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Set(java.util.Set) Trace(com.evolveum.midpoint.util.logging.Trace) ActivitiUtil(com.evolveum.midpoint.wf.impl.processes.common.ActivitiUtil) Task(com.evolveum.midpoint.task.api.Task) ApprovalUtils(com.evolveum.midpoint.wf.util.ApprovalUtils) Collectors(java.util.stream.Collectors) WfContextUtil(com.evolveum.midpoint.schema.util.WfContextUtil) QNameUtil(com.evolveum.midpoint.util.QNameUtil) JavaDelegate(org.activiti.engine.delegate.JavaDelegate) List(java.util.List) SpringApplicationContextHolder.getPrismContext(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext) PrismContext(com.evolveum.midpoint.prism.PrismContext) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) CommonProcessVariableNames(com.evolveum.midpoint.wf.impl.processes.common.CommonProcessVariableNames) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) SpringApplicationContextHolder.getPrismContext(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext) PrismContext(com.evolveum.midpoint.prism.PrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 5 with DelegateExecution

use of org.activiti.engine.delegate.DelegateExecution 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

DelegateExecution (org.activiti.engine.delegate.DelegateExecution)5 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 SpringApplicationContextHolder.getPrismContext (com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext)2 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)1 WfContextUtil (com.evolveum.midpoint.schema.util.WfContextUtil)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 QNameUtil (com.evolveum.midpoint.util.QNameUtil)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 Trace (com.evolveum.midpoint.util.logging.Trace)1 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)1 ActivitiUtil (com.evolveum.midpoint.wf.impl.processes.common.ActivitiUtil)1 CommonProcessVariableNames (com.evolveum.midpoint.wf.impl.processes.common.CommonProcessVariableNames)1 ApprovalUtils (com.evolveum.midpoint.wf.util.ApprovalUtils)1 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1