public static boolean isReachable(Process process, FlowNode sourceElement, FlowNode targetElement, Set<String> visitedElements) { if (sourceElement.getOutgoingFlows().size() == 0) { visitedElements.add(sourceElement.getId()); if (sourceElement.getId().equals(targetElement.getId())) { return true; visitedElements.add(sourceElement.getId()); List<SequenceFlow> sequenceFlows = sourceElement.getOutgoingFlows(); if (sequenceFlows != null && sequenceFlows.size() > 0) { for (SequenceFlow sequenceFlow : sequenceFlows) { String targetRef = sequenceFlow.getTargetRef(); FlowNode sequenceFlowTarget = (FlowNode) process.getFlowElement(targetRef, true); if (sequenceFlowTarget != null && !visitedElements.contains(sequenceFlowTarget.getId())) { boolean reachable = isReachable(process, sequenceFlowTarget, targetElement, visitedElements);
protected void continueThroughFlowNode(FlowNode flowNode) { // Check if it's the initial flow element. If so, we must fire the execution listeners for the process too if (flowNode.getIncomingFlows() != null && flowNode.getIncomingFlows().size() == 0 && flowNode.getSubProcess() == null) { executeProcessStartExecutionListeners(); } // For a subprocess, a new child execution is created that will visit the steps of the subprocess // The original execution that arrived here will wait until the subprocess is finished // and will then be used to continue the process instance. if (flowNode instanceof SubProcess) { createChildExecutionForSubProcess((SubProcess) flowNode); } if (flowNode instanceof Activity && ((Activity) flowNode).hasMultiInstanceLoopCharacteristics()) { // the multi instance execution will look at async executeMultiInstanceSynchronous(flowNode); } else if (forceSynchronousOperation || !flowNode.isAsynchronous()) { executeSynchronous(flowNode); } else { executeAsynchronous(flowNode); } }
FlowNode sourceNode = getFlowNodeFromScope(sequenceFlow.getSourceRef(), parentScope); if (sourceNode != null) { sourceNode.getOutgoingFlows().add(sequenceFlow); sequenceFlow.setSourceFlowElement(sourceNode); targetNode.getIncomingFlows().add(sequenceFlow); sequenceFlow.setTargetFlowElement(targetNode);
protected void executeMultiInstanceSynchronous(FlowNode flowNode) { // Execution listener: event 'start' if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) { executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START); } // Execute any boundary events, sub process boundary events will be executed from the activity behavior if (!inCompensation && flowNode instanceof Activity) { // Only activities can have boundary events List<BoundaryEvent> boundaryEvents = ((Activity) flowNode).getBoundaryEvents(); if (CollectionUtil.isNotEmpty(boundaryEvents)) { executeBoundaryEvents(boundaryEvents, execution); } } // Execute the multi instance behavior ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior(); if (activityBehavior != null) { executeActivityBehavior(activityBehavior, flowNode); } else { throw new ActivitiException("Expected an activity behavior in flow node " + flowNode.getId()); } }
protected void executeSynchronous(FlowNode flowNode) { if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) { executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START); ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior(); if (activityBehavior != null) { logger.debug("Executing activityBehavior {} on activity '{}' with execution {}", activityBehavior.getClass(), flowNode.getId(), execution.getId()); ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_STARTED, flowNode.getId(), flowNode.getName(), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode)); logger.debug("No activityBehavior on activity '{}' with execution {}", flowNode.getId(), execution.getId());
protected void handleActivityEnd(FlowNode flowNode) { // a process instance execution can never leave a flow node, but it can pass here whilst cleaning up // hence the check for NOT being a process instance if (!execution.isProcessInstanceType()) { if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) { executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_END); } commandContext.getHistoryManager().recordActivityEnd(execution, null); if (!(execution.getCurrentFlowElement() instanceof SubProcess)) { Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, flowNode.getId(), flowNode.getName(), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode)); } } }
public void afterStepsConversion(WorkflowDefinitionConversion conversion) { // Add end-event to process Process process = conversion.getProcess(); EndEvent endEvent = new EndEvent(); endEvent.setId(END_EVENT_ID); process.addFlowElement(endEvent); // Sequence flow from last created activity to end SequenceFlow sequenceFlow = new SequenceFlow(); sequenceFlow.setId(conversion.getUniqueNumberedId(ConversionConstants.DEFAULT_SEQUENCEFLOW_PREFIX)); sequenceFlow.setSourceRef(conversion.getLastActivityId()); sequenceFlow.setTargetRef(END_EVENT_ID); process.addFlowElement(sequenceFlow); // To make the generated workflow compatible with some tools (eg the // Modeler, but also others), // We must add the ingoing and outgoing sequence flow to each of the flow // nodes SequenceFlowMapping sequenceFlowMapping = generateSequenceflowMappings(process); for (FlowNode flowNode : process.findFlowElementsOfType(FlowNode.class)) { List<SequenceFlow> incomingSequenceFlow = sequenceFlowMapping.getIncomingSequenceFlowMapping().get(flowNode.getId()); if (incomingSequenceFlow != null) { flowNode.setIncomingFlows(incomingSequenceFlow); } List<SequenceFlow> outgoingSequenceFlow = sequenceFlowMapping.getOutgoingSequenceFlowMapping().get(flowNode.getId()); if (outgoingSequenceFlow != null) { flowNode.setOutgoingFlows(outgoingSequenceFlow); } } }
Collection<String> flowNodeIdsWithInactivatedBehavior = new ArrayList<String>(); for (FlowNode flowNode : process.findFlowElementsOfType(FlowNode.class)) { if (flowNode.getBehavior() instanceof InactiveActivityBehavior) { flowNodeIdsWithInactivatedBehavior.add(flowNode.getId()); InactiveActivityBehavior inactiveActivityBehavior = ((InactiveActivityBehavior) flowNode.getBehavior()); logger.debug("Found InactiveActivityBehavior instance of class {} that can be executed on activity '{}'", inactiveActivityBehavior.getClass(), flowNode.getId()); inactiveActivityBehavior.executeInactive(inactiveExecution);
protected void handleAdhocSubProcess(FlowNode flowNode) { boolean completeAdhocSubProcess = false; AdhocSubProcess adhocSubProcess = (AdhocSubProcess) flowNode.getParentContainer(); if (adhocSubProcess.getCompletionCondition() != null) { Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(adhocSubProcess.getCompletionCondition()); if (flowNode.getOutgoingFlows().size() > 0) { leaveFlowNode(flowNode); } else {
if (flowElement instanceof FlowNode) { FlowNode flowNode = (FlowNode) flowElement; if (flowNode.getIncomingFlows().size() == 0) { enabledFlowNodes.add(flowNode);
if (flowNode.isAsynchronous()) { writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw); if (flowNode.isNotExclusive()) { writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
protected void continueThroughMultiInstanceFlowNode(FlowNode flowNode) { if (!flowNode.isAsynchronous()) { executeSynchronous(flowNode); } else { executeAsynchronous(flowNode); } }
@Override public void parse(BpmnParse bpmnParse, BaseElement element) { super.parse(bpmnParse, element); createExecutionListenersOnScope(bpmnParse, ((FlowNode) element).getExecutionListeners(), findActivity(bpmnParse, element.getId())); }
((FlowNode) sourceFlowElement).getOutgoingFlows().add(sequenceFlow); JsonNode edgeNode = edgeMap.get(sequenceFlow.getId()); if (edgeNode != null) { ((FlowNode) targetFlowElement).getIncomingFlows().add(sequenceFlow);
protected void executeSynchronous(FlowNode flowNode) { commandContext.getHistoryManager().recordActivityStart(execution); // Execution listener: event 'start' if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) { executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START); } // Execute any boundary events, sub process boundary events will be executed from the activity behavior if (!inCompensation && flowNode instanceof Activity) { // Only activities can have boundary events List<BoundaryEvent> boundaryEvents = ((Activity) flowNode).getBoundaryEvents(); if (CollectionUtil.isNotEmpty(boundaryEvents)) { executeBoundaryEvents(boundaryEvents, execution); } } // Execute actual behavior ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior(); if (activityBehavior != null) { executeActivityBehavior(activityBehavior, flowNode); } else { logger.debug("No activityBehavior on activity '{}' with execution {}", flowNode.getId(), execution.getId()); Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(execution, true); } }
protected void executeSynchronous(FlowNode flowNode) { if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) { executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START); ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior(); if (activityBehavior != null) { logger.debug("Executing activityBehavior {} on activity '{}' with execution {}", activityBehavior.getClass(), flowNode.getId(), execution.getId()); ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_STARTED, flowNode.getId(), flowNode.getName(), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode)); logger.debug("No activityBehavior on activity '{}' with execution {}", flowNode.getId(), execution.getId());
protected void handleActivityEnd(FlowNode flowNode) { // a process instance execution can never leave a flow node, but it can pass here whilst cleaning up // hence the check for NOT being a process instance if (!execution.isProcessInstanceType()) { if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) { executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_END); } commandContext.getHistoryManager().recordActivityEnd(execution, null); if (!(execution.getCurrentFlowElement() instanceof SubProcess)) { Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, flowNode.getId(), flowNode.getName(), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode)); } } }