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.");
}
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());
}
}
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);
}
}
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);
}
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;
}
Aggregations