Search in sources :

Example 6 with WfContextType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType in project midpoint by Evolveum.

the class WfTaskUtil method getPrimaryChangeAspect.

@NotNull
public PrimaryChangeAspect getPrimaryChangeAspect(Task task, Collection<PrimaryChangeAspect> aspects) {
    WfContextType wfc = getWorkflowContextChecked(task);
    WfProcessorSpecificStateType pss = wfc.getProcessorSpecificState();
    if (!(pss instanceof WfPrimaryChangeProcessorStateType)) {
        throw new IllegalStateException("Expected " + WfPrimaryChangeProcessorStateType.class + " but got " + pss + " in task " + task);
    }
    WfPrimaryChangeProcessorStateType pcps = ((WfPrimaryChangeProcessorStateType) pss);
    String aspectClassName = pcps.getChangeAspect();
    if (aspectClassName == null) {
        throw new IllegalStateException("No wf primary change aspect defined in task " + task);
    }
    for (PrimaryChangeAspect a : aspects) {
        if (aspectClassName.equals(a.getClass().getName())) {
            return a;
        }
    }
    throw new IllegalStateException("Primary change aspect " + aspectClassName + " is not registered.");
}
Also used : PrimaryChangeAspect(com.evolveum.midpoint.wf.impl.processors.primary.aspect.PrimaryChangeAspect) WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with WfContextType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType in project midpoint by Evolveum.

the class TestUserChangeApprovalLegacy method assertWfContextAfterRootTaskFinishes.

protected void assertWfContextAfterRootTaskFinishes(Task rootTask, List<Task> subtasks, OperationResult result, String... processNames) throws Exception {
    final Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM), createRetrieve());
    Task opTask = taskManager.createTaskInstance();
    TaskType rootTaskType = modelService.getObject(TaskType.class, rootTask.getOid(), options, opTask, result).asObjectable();
    assertTrue("unexpected process instance id in root task", rootTaskType.getWorkflowContext() == null || rootTaskType.getWorkflowContext().getProcessInstanceId() == null);
    assertEquals("Wrong # of wf subtasks w.r.t processNames (" + Arrays.asList(processNames) + ")", processNames.length, subtasks.size());
    int i = 0;
    for (Task subtask : subtasks) {
        TaskType subtaskType = modelService.getObject(TaskType.class, subtask.getOid(), options, opTask, result).asObjectable();
        display("Subtask #" + (i + 1) + ": ", subtaskType);
        assertNull("Unexpected fetch result in wf subtask: " + subtask, subtaskType.getFetchResult());
        WfContextType wfc = subtaskType.getWorkflowContext();
        assertNotNull("Missing workflow context in wf subtask: " + subtask, wfc);
        assertNotNull("No process ID in wf subtask: " + subtask, wfc.getProcessInstanceId());
        assertEquals("Wrong process ID name in subtask: " + subtask, processNames[i++], wfc.getProcessInstanceName());
        assertNotNull("Missing process start time in subtask: " + subtask, wfc.getStartTimestamp());
        assertNotNull("Missing process end time in subtask: " + subtask, wfc.getEndTimestamp());
        assertEquals("Wrong outcome", SchemaConstants.MODEL_APPROVAL_OUTCOME_APPROVE, wfc.getOutcome());
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 8 with WfContextType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType in project midpoint by Evolveum.

the class ProcessInstanceManager method onTaskDelete.

public void onTaskDelete(Task task, OperationResult result) {
    try {
        WfContextType wfc = task.getWorkflowContext();
        if (wfc == null || wfc.getProcessInstanceId() == null) {
            return;
        }
        String instanceId = wfc.getProcessInstanceId();
        if (wfc.getEndTimestamp() == null) {
            try {
                stopProcessInstance(instanceId, "task delete action", result);
            } catch (RuntimeException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't stop workflow process instance {} while processing task deletion event for task {}", e, instanceId, task);
            }
        }
        deleteProcessInstance(instanceId, result);
    } catch (RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't process task deletion event for task {}", e, task);
    }
}
Also used : WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType)

Example 9 with WfContextType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType 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 10 with WfContextType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType in project midpoint by Evolveum.

the class ProcessInstanceManager method getMidpointToActiviti.

private Map<String, String> getMidpointToActiviti(OperationResult result) throws SchemaException {
    final Map<String, String> rv = new HashMap<>();
    final List<PrismObject<TaskType>> tasks = taskManager.searchObjects(TaskType.class, null, null, result);
    int tasksWithProcessId = 0;
    for (PrismObject<TaskType> taskObject : tasks) {
        final TaskType task = taskObject.asObjectable();
        final WfContextType wfc = task.getWorkflowContext();
        final String pid = wfc != null ? wfc.getProcessInstanceId() : null;
        rv.put(task.getOid(), pid);
        if (pid != null) {
            tasksWithProcessId++;
        }
    }
    LOGGER.info("Found {} tasks; among these, {} have a pointer to process instance id", rv.size(), tasksWithProcessId);
    return rv;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType)

Aggregations

WfContextType (com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType)9 Task (com.evolveum.midpoint.task.api.Task)2 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)1 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 WfContextUtil (com.evolveum.midpoint.schema.util.WfContextUtil)1 QNameUtil (com.evolveum.midpoint.util.QNameUtil)1 Trace (com.evolveum.midpoint.util.logging.Trace)1 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)1 DecisionsPanel (com.evolveum.midpoint.web.component.wf.DecisionsPanel)1 DecisionDto (com.evolveum.midpoint.web.page.admin.workflow.dto.DecisionDto)1 ActivitiUtil (com.evolveum.midpoint.wf.impl.processes.common.ActivitiUtil)1 CommonProcessVariableNames (com.evolveum.midpoint.wf.impl.processes.common.CommonProcessVariableNames)1 SpringApplicationContextHolder.getPrismContext (com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getPrismContext)1 PrimaryChangeAspect (com.evolveum.midpoint.wf.impl.processors.primary.aspect.PrimaryChangeAspect)1 ApprovalUtils (com.evolveum.midpoint.wf.util.ApprovalUtils)1