/** * Verifies if the element with the given source identifier can reach the element with the target identifier through following sequence flow. */ public static boolean isReachable(String processDefinitionId, String sourceElementId, String targetElementId) { // Fetch source and target elements Process process = ProcessDefinitionUtil.getProcess(processDefinitionId); FlowElement sourceFlowElement = process.getFlowElement(sourceElementId, true); FlowNode sourceElement = null; if (sourceFlowElement instanceof FlowNode) { sourceElement = (FlowNode) sourceFlowElement; } else if (sourceFlowElement instanceof SequenceFlow) { sourceElement = (FlowNode) ((SequenceFlow) sourceFlowElement).getTargetFlowElement(); } FlowElement targetFlowElement = process.getFlowElement(targetElementId, true); FlowNode targetElement = null; if (targetFlowElement instanceof FlowNode) { targetElement = (FlowNode) targetFlowElement; } else if (targetFlowElement instanceof SequenceFlow) { targetElement = (FlowNode) ((SequenceFlow) targetFlowElement).getTargetFlowElement(); } if (sourceElement == null) { throw new ActivitiException("Invalid sourceElementId '" + sourceElementId + "': no element found for this id n process definition '" + processDefinitionId + "'"); } if (targetElement == null) { throw new ActivitiException("Invalid targetElementId '" + targetElementId + "': no element found for this id n process definition '" + processDefinitionId + "'"); } Set<String> visitedElements = new HashSet<String>(); return isReachable(process, sourceElement, targetElement, visitedElements); }
Set<String> eventActivityIds = new HashSet<String>(outgoingSequenceFlows.size() - 1); // -1, the event being triggered does not need to be deleted for (SequenceFlow outgoingSequenceFlow : outgoingSequenceFlows) { if (outgoingSequenceFlow.getTargetFlowElement() != null && !outgoingSequenceFlow.getTargetFlowElement().getId().equals(execution.getCurrentActivityId())) { eventActivityIds.add(outgoingSequenceFlow.getTargetFlowElement().getId());
FlowElement targetFlowElement = sequenceFlow.getTargetFlowElement(); Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createSequenceFlowTakenEvent( FlowElement targetFlowElement = sequenceFlow.getTargetFlowElement(); execution.setCurrentFlowElement(targetFlowElement);
/** * Verifies if the element with the given source identifier can reach the element with the target identifier through following sequence flow. */ public static boolean isReachable(String processDefinitionId, String sourceElementId, String targetElementId) { // Fetch source and target elements Process process = ProcessDefinitionUtil.getProcess(processDefinitionId); FlowElement sourceFlowElement = process.getFlowElement(sourceElementId, true); FlowNode sourceElement = null; if (sourceFlowElement instanceof FlowNode) { sourceElement = (FlowNode) sourceFlowElement; } else if (sourceFlowElement instanceof SequenceFlow) { sourceElement = (FlowNode) ((SequenceFlow) sourceFlowElement).getTargetFlowElement(); } FlowElement targetFlowElement = process.getFlowElement(targetElementId, true); FlowNode targetElement = null; if (targetFlowElement instanceof FlowNode) { targetElement = (FlowNode) targetFlowElement; } else if (targetFlowElement instanceof SequenceFlow) { targetElement = (FlowNode) ((SequenceFlow) targetFlowElement).getTargetFlowElement(); } if (sourceElement == null) { throw new ActivitiException("Invalid sourceElementId '" + sourceElementId + "': no element found for this id n process definition '" + processDefinitionId + "'"); } if (targetElement == null) { throw new ActivitiException("Invalid targetElementId '" + targetElementId + "': no element found for this id n process definition '" + processDefinitionId + "'"); } Set<String> visitedElements = new HashSet<String>(); return isReachable(process, sourceElement, targetElement, visitedElements); }
Set<String> eventActivityIds = new HashSet<String>(outgoingSequenceFlows.size() - 1); // -1, the event being triggered does not need to be deleted for (SequenceFlow outgoingSequenceFlow : outgoingSequenceFlows) { if (outgoingSequenceFlow.getTargetFlowElement() != null && !outgoingSequenceFlow.getTargetFlowElement().getId().equals(execution.getCurrentActivityId())) { eventActivityIds.add(outgoingSequenceFlow.getTargetFlowElement().getId());
protected void continueThroughSequenceFlow(SequenceFlow sequenceFlow) { // Execution listener. Sequenceflow only 'take' makes sense ... but we've supported all three since the beginning if (CollectionUtil.isNotEmpty(sequenceFlow.getExecutionListeners())) { executeExecutionListeners(sequenceFlow, ExecutionListener.EVENTNAME_START); executeExecutionListeners(sequenceFlow, ExecutionListener.EVENTNAME_TAKE); executeExecutionListeners(sequenceFlow, ExecutionListener.EVENTNAME_END); } // Firing event that transition is being taken if(Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { FlowElement sourceFlowElement = sequenceFlow.getSourceFlowElement(); FlowElement targetFlowElement = sequenceFlow.getTargetFlowElement(); Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createSequenceFlowTakenEvent( (ExecutionEntity) execution, ActivitiEventType.SEQUENCEFLOW_TAKEN, sequenceFlow.getId(), sourceFlowElement != null ? sourceFlowElement.getId() : null, sourceFlowElement != null ? (String) sourceFlowElement.getName() : null, sourceFlowElement != null ? sourceFlowElement.getClass().getName() : null, sourceFlowElement != null ? ((FlowNode) sourceFlowElement).getBehavior(): null, targetFlowElement != null ? targetFlowElement.getId() : null, targetFlowElement != null ? targetFlowElement.getName() : null, targetFlowElement != null ? targetFlowElement.getClass().getName() : null, targetFlowElement != null ? ((FlowNode) targetFlowElement).getBehavior(): null)); } FlowElement targetFlowElement = sequenceFlow.getTargetFlowElement(); execution.setCurrentFlowElement(targetFlowElement); logger.debug("Sequence flow '{}' encountered. Continuing process by following it using execution {}", sequenceFlow.getId(), execution.getId()); Context.getAgenda().planContinueProcessOperation(execution); }