Java Code Examples for org.flowable.bpmn.model.Process#findParent()

The following examples show how to use org.flowable.bpmn.model.Process#findParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EndEventValidator.java    From flowable-engine with Apache License 2.0 8 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<EndEvent> endEvents = process.findFlowElementsOfType(EndEvent.class);
    for (EndEvent endEvent : endEvents) {
        if (endEvent.getEventDefinitions() != null && !endEvent.getEventDefinitions().isEmpty()) {

            EventDefinition eventDefinition = endEvent.getEventDefinitions().get(0);

            // Error end event
            if (eventDefinition instanceof CancelEventDefinition) {

                FlowElementsContainer parent = process.findParent(endEvent);
                if (!(parent instanceof Transaction)) {
                    addError(errors, Problems.END_EVENT_CANCEL_ONLY_INSIDE_TRANSACTION, process, endEvent, "end event with cancelEventDefinition only supported inside transaction subprocess");
                }

            }

        }
    }
}
 
Example 2
Source File: ExecutionGraphUtil.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public static boolean isReachable(Process process, FlowNode sourceElement, FlowNode targetElement, Set<String> visitedElements) {
    
    // Special case: start events in an event subprocess might exist as an execution and are most likely be able to reach the target
    // when the target is in the event subprocess, but should be ignored as they are not 'real' runtime executions (but rather waiting for a trigger)
    if (sourceElement instanceof StartEvent && isInEventSubprocess(sourceElement)) {
        return false;
    }

    // No outgoing seq flow: could be the end of eg . the process or an embedded subprocess
    if (sourceElement.getOutgoingFlows().size() == 0) {
        visitedElements.add(sourceElement.getId());

        FlowElementsContainer parentElement = process.findParent(sourceElement);
        if (parentElement instanceof SubProcess) {
            sourceElement = (SubProcess) parentElement;
        } else {
            return false;
        }
    }

    if (sourceElement.getId().equals(targetElement.getId())) {
        return true;
    }

    // To avoid infinite looping, we must capture every node we visit
    // and check before going further in the graph if we have already
    // visited the node.
    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);

                if (reachable) {
                    return true;
                }
            }
        }
    }

    return false;
}