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