protected void fireSentries(List<String> satisfiedSentries) { if (satisfiedSentries != null && !satisfiedSentries.isEmpty()) { // if there are satisfied sentries, trigger the associated // case executions // 1. propagate to all child case executions /////////////////////////////////////////// // collect the execution tree. ArrayList<CmmnExecution> children = new ArrayList<CmmnExecution>(); collectCaseExecutionsInExecutionTree(children); for (CmmnExecution currentChild : children) { // check and fire first exitCriteria currentChild.checkAndFireExitCriteria(satisfiedSentries); // then trigger entryCriteria currentChild.checkAndFireEntryCriteria(satisfiedSentries); } // 2. check exit criteria of the case instance ////////////////////////////////////////// if (isCaseInstanceExecution() && isActive()) { checkAndFireExitCriteria(satisfiedSentries); } } }
protected Map<String, List<CmmnSentryPart>> collectAllSentries() { Map<String, List<CmmnSentryPart>> sentries = new HashMap<String, List<CmmnSentryPart>>(); List<? extends CmmnExecution> caseExecutions = getCaseExecutions(); for (CmmnExecution caseExecution : caseExecutions) { sentries.putAll(caseExecution.collectAllSentries()); } sentries.putAll(getSentries()); return sentries; }
public CmmnExecution findCaseExecution(String activityId) { if ((getActivity() != null) && (getActivity().getId().equals(activityId))) { return this; } for (CmmnExecution nestedExecution : getCaseExecutions()) { CmmnExecution result = nestedExecution.findCaseExecution(activityId); if (result != null) { return result; } } return null; }
protected boolean containsIfPartAndExecutionActive( String sentryId, Map<String, List<CmmnSentryPart>> sentries) { List<? extends CmmnSentryPart> sentryParts = sentries.get(sentryId); for (CmmnSentryPart part : sentryParts) { CmmnExecution caseExecution = part.getCaseExecution(); if (IF_PART.equals(part.getType()) && caseExecution != null && caseExecution.isActive()) { return true; } } return false; }
protected boolean hasVariableWithSameNameInParent(CmmnExecution execution, String variableName) { while (execution != null) { if (execution.getId().equals(getId())) { return false; } TypedValue variableTypedValue = execution.getVariableLocalTyped(variableName); if (variableTypedValue != null) { return true; } execution = execution.getParent(); } return false; }
public void triggerChildExecutionsLifecycle(List<CmmnExecution> children) { // then notify create listener for each created // child case execution for (CmmnExecution child : children) { if (isActive()) { if (child.isNew()) { child.performOperation(CASE_EXECUTION_CREATE); } } else { // if this case execution is not active anymore, // then stop notifying create listener and executing // of each child case execution break; } } }
protected List<String> collectAffectedSentries(CmmnExecution child, String transition) { List<? extends CmmnSentryPart> sentryParts = getCaseSentryParts(); List<String> affectedSentries = new ArrayList<String>(); for (CmmnSentryPart sentryPart : sentryParts) { // necessary for backward compatibility String sourceCaseExecutionId = sentryPart.getSourceCaseExecutionId(); String sourceRef = sentryPart.getSource(); if (child.getActivityId().equals(sourceRef) || child.getId().equals(sourceCaseExecutionId)) { String standardEvent = sentryPart.getStandardEvent(); if (transition.equals(standardEvent)) { addIdIfNotSatisfied(affectedSentries, sentryPart); } } } return affectedSentries; }
public void createChildExecutions(List<CmmnActivity> activities) { List<CmmnExecution> children = new ArrayList<CmmnExecution>(); // first create new child case executions for (CmmnActivity currentActivity : activities) { CmmnExecution child = createCaseExecution(currentActivity); children.add(child); } // then notify create listener for each created // child case execution for (CmmnExecution child : children) { if (isActive()) { child.performOperation(CASE_EXECUTION_CREATE); } else { // if this case execution is not active anymore, // then stop notifying create listener and executing // of each child case execution break; } } }
protected void invokeVariableListeners(boolean includeCustomerListeners) { Queue<VariableEvent> variableEventsQueue = getVariableEventQueue(); while (!variableEventsQueue.isEmpty()) { // do not remove the event yet, as otherwise new events will immediately be dispatched VariableEvent nextEvent = variableEventsQueue.peek(); CmmnExecution sourceExecution = (CmmnExecution) nextEvent.getSourceScope(); DelegateCaseVariableInstanceImpl delegateVariable = DelegateCaseVariableInstanceImpl.fromVariableInstance(nextEvent.getVariableInstance()); delegateVariable.setEventName(nextEvent.getEventName()); delegateVariable.setSourceExecution(sourceExecution); Map<String, List<VariableListener<?>>> listenersByActivity = sourceExecution .getActivity() .getVariableListeners(delegateVariable.getEventName(), includeCustomerListeners); CmmnExecution currentExecution = sourceExecution; while (currentExecution != null) { if (currentExecution.getActivityId() != null) { List<VariableListener<?>> listeners = listenersByActivity.get(currentExecution.getActivityId()); if (listeners != null) { delegateVariable.setScopeExecution(currentExecution); for (VariableListener<?> listener : listeners) { try { CaseVariableListener caseVariableListener = (CaseVariableListener) listener; CaseVariableListenerInvocation invocation = new CaseVariableListenerInvocation( caseVariableListener, delegateVariable, currentExecution); Context.getProcessEngineConfiguration() .getDelegateInterceptor() .handleInvocation(invocation); } catch (Exception e) { throw LOG.invokeVariableListenerException(e); } } } } currentExecution = currentExecution.getParent(); } // finally remove the event from the queue variableEventsQueue.remove(); } }
public void remove() { CmmnExecution parent = getParent(); if (parent != null) { parent.getCaseExecutionsInternal().remove(this); } }
protected void collectCaseExecutionsInExecutionTree(List<CmmnExecution> children) { for (CmmnExecution child : getCaseExecutions()) { child.collectCaseExecutionsInExecutionTree(children); } children.addAll(getCaseExecutions()); }