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

The following examples show how to use org.flowable.bpmn.model.Process#findFlowElementsOfType() . 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: SubprocessValidator.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<SubProcess> subProcesses = process.findFlowElementsOfType(SubProcess.class);
    for (SubProcess subProcess : subProcesses) {

        if (!(subProcess instanceof EventSubProcess)) {

            // Verify start events
            List<StartEvent> startEvents = process.findFlowElementsInSubProcessOfType(subProcess, StartEvent.class, false);
            if (startEvents.size() > 1) {
                addError(errors, Problems.SUBPROCESS_MULTIPLE_START_EVENTS, process, subProcess, "Multiple start events not supported for subprocess");
            }

            for (StartEvent startEvent : startEvents) {
                if (!startEvent.getEventDefinitions().isEmpty()) {
                    addError(errors, Problems.SUBPROCESS_START_EVENT_EVENT_DEFINITION_NOT_ALLOWED, process, startEvent, "event definitions only allowed on start event if subprocess is an event subprocess");
                }
            }

        }

    }

}
 
Example 3
Source File: EventValidator.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<Event> events = process.findFlowElementsOfType(Event.class);
    for (Event event : events) {
        if (event.getEventDefinitions() != null) {
            for (EventDefinition eventDefinition : event.getEventDefinitions()) {

                if (eventDefinition instanceof MessageEventDefinition) {
                    handleMessageEventDefinition(bpmnModel, process, event, eventDefinition, errors);
                } else if (eventDefinition instanceof SignalEventDefinition) {
                    handleSignalEventDefinition(bpmnModel, process, event, eventDefinition, errors);
                } else if (eventDefinition instanceof TimerEventDefinition) {
                    handleTimerEventDefinition(process, event, eventDefinition, errors);
                } else if (eventDefinition instanceof CompensateEventDefinition) {
                    handleCompensationEventDefinition(bpmnModel, process, event, eventDefinition, errors);
                }

            }
        }
    }
}
 
Example 4
Source File: DataObjectValidator.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {

    // Gather data objects
    List<ValuedDataObject> allDataObjects = new ArrayList<>(process.getDataObjects());
    List<SubProcess> subProcesses = process.findFlowElementsOfType(SubProcess.class, true);
    for (SubProcess subProcess : subProcesses) {
        allDataObjects.addAll(subProcess.getDataObjects());
    }

    // Validate
    for (ValuedDataObject dataObject : allDataObjects) {
        if (StringUtils.isEmpty(dataObject.getName())) {
            addError(errors, Problems.DATA_OBJECT_MISSING_NAME, process, dataObject, "Name is mandatory for a data object");
        }
    }

}
 
Example 5
Source File: IntermediateThrowEventValidator.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<ThrowEvent> throwEvents = process.findFlowElementsOfType(ThrowEvent.class);
    for (ThrowEvent throwEvent : throwEvents) {
        EventDefinition eventDefinition = null;
        if (!throwEvent.getEventDefinitions().isEmpty()) {
            eventDefinition = throwEvent.getEventDefinitions().get(0);
        }

        if (eventDefinition != null && !(eventDefinition instanceof SignalEventDefinition) && 
                        !(eventDefinition instanceof EscalationEventDefinition) && !(eventDefinition instanceof CompensateEventDefinition)) {
            
            addError(errors, Problems.THROW_EVENT_INVALID_EVENTDEFINITION, process, throwEvent, "Unsupported intermediate throw event type");
        }
    }
}
 
Example 6
Source File: AbstractBpmnActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected Collection<BoundaryEvent> findBoundaryEventsForFlowNode(final String processDefinitionId, final FlowElement flowElement) {
    Process process = getProcessDefinition(processDefinitionId);

    // This could be cached or could be done at parsing time
    List<BoundaryEvent> results = new ArrayList<>(1);
    Collection<BoundaryEvent> boundaryEvents = process.findFlowElementsOfType(BoundaryEvent.class, true);
    for (BoundaryEvent boundaryEvent : boundaryEvents) {
        if (boundaryEvent.getAttachedToRefId() != null && boundaryEvent.getAttachedToRefId().equals(flowElement.getId())) {
            results.add(boundaryEvent);
        }
    }
    return results;
}
 
Example 7
Source File: ExclusiveGatewayValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<ExclusiveGateway> gateways = process.findFlowElementsOfType(ExclusiveGateway.class);
    for (ExclusiveGateway gateway : gateways) {
        validateExclusiveGateway(process, gateway, errors);
    }
}
 
Example 8
Source File: UserTaskValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<UserTask> userTasks = process.findFlowElementsOfType(UserTask.class);
    for (UserTask userTask : userTasks) {
        if (userTask.getTaskListeners() != null) {
            for (FlowableListener listener : userTask.getTaskListeners()) {
                if (listener.getImplementation() == null || listener.getImplementationType() == null) {
                    addError(errors, Problems.USER_TASK_LISTENER_IMPLEMENTATION_MISSING, process, userTask, "Element 'class' or 'expression' is mandatory on executionListener");
                }
            }
        }
    }
}
 
Example 9
Source File: EventSubprocessValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<EventSubProcess> eventSubprocesses = process.findFlowElementsOfType(EventSubProcess.class);
    for (EventSubProcess eventSubprocess : eventSubprocesses) {

        List<StartEvent> startEvents = process.findFlowElementsInSubProcessOfType(eventSubprocess, StartEvent.class);
        for (StartEvent startEvent : startEvents) {
            if (startEvent.getEventDefinitions() != null && !startEvent.getEventDefinitions().isEmpty()) {
                EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
                if (!(eventDefinition instanceof ConditionalEventDefinition) &&
                        !(eventDefinition instanceof ErrorEventDefinition) &&
                        !(eventDefinition instanceof EscalationEventDefinition) &&
                        !(eventDefinition instanceof MessageEventDefinition) &&
                        !(eventDefinition instanceof SignalEventDefinition) &&
                        !(eventDefinition instanceof TimerEventDefinition)) {

                    addError(errors, Problems.EVENT_SUBPROCESS_INVALID_START_EVENT_DEFINITION, process, eventSubprocess,
                            "start event of event subprocess must be of type 'error', 'timer', 'message' or 'signal'");
                }
            }
        }

        List<BoundaryEvent> boundaryEvents = eventSubprocess.getBoundaryEvents();
        if (boundaryEvents != null && !boundaryEvents.isEmpty()) {
            addWarning(errors, Problems.EVENT_SUBPROCESS_BOUNDARY_EVENT, process, eventSubprocess, "event sub process cannot have attached boundary events");
        }

    }
}
 
Example 10
Source File: IntermediateCatchEventValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<IntermediateCatchEvent> intermediateCatchEvents = process.findFlowElementsOfType(IntermediateCatchEvent.class);
    for (IntermediateCatchEvent intermediateCatchEvent : intermediateCatchEvents) {
        EventDefinition eventDefinition = null;
        if (!intermediateCatchEvent.getEventDefinitions().isEmpty()) {
            eventDefinition = intermediateCatchEvent.getEventDefinitions().get(0);
        }

        if (eventDefinition == null) {

            Map<String, List<ExtensionElement>> extensionElements = intermediateCatchEvent.getExtensionElements();
            if (!extensionElements.isEmpty()) {
                List<ExtensionElement> eventTypeExtensionElements = intermediateCatchEvent.getExtensionElements().get("eventType");
                if (eventTypeExtensionElements != null && !eventTypeExtensionElements.isEmpty()) {
                    return;
                }
            }

            addError(errors, Problems.INTERMEDIATE_CATCH_EVENT_NO_EVENTDEFINITION, process, intermediateCatchEvent, "No event definition for intermediate catch event ");
            
        } else {
            if (!(eventDefinition instanceof TimerEventDefinition) && !(eventDefinition instanceof SignalEventDefinition) && 
                            !(eventDefinition instanceof MessageEventDefinition) && !(eventDefinition instanceof ConditionalEventDefinition)) {
                
                addError(errors, Problems.INTERMEDIATE_CATCH_EVENT_INVALID_EVENTDEFINITION, process, intermediateCatchEvent, "Unsupported intermediate catch event type");
            }
        }
    }
}
 
Example 11
Source File: ScriptTaskValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<ScriptTask> scriptTasks = process.findFlowElementsOfType(ScriptTask.class);
    for (ScriptTask scriptTask : scriptTasks) {
        if (StringUtils.isEmpty(scriptTask.getScript())) {
            addError(errors, Problems.SCRIPT_TASK_MISSING_SCRIPT, process, scriptTask, "No script provided for script task");
        }
    }
}
 
Example 12
Source File: SendTaskValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<SendTask> sendTasks = process.findFlowElementsOfType(SendTask.class);
    for (SendTask sendTask : sendTasks) {

        // Verify implementation
        if (StringUtils.isEmpty(sendTask.getType()) && !ImplementationType.IMPLEMENTATION_TYPE_WEBSERVICE.equalsIgnoreCase(sendTask.getImplementationType())) {
            addError(errors, Problems.SEND_TASK_INVALID_IMPLEMENTATION, process, sendTask, "One of the attributes 'type' or 'operation' is mandatory on sendTask");
        }

        // Verify type
        if (StringUtils.isNotEmpty(sendTask.getType())) {

            if (!sendTask.getType().equalsIgnoreCase("mail") && !sendTask.getType().equalsIgnoreCase("mule") && !sendTask.getType().equalsIgnoreCase("camel")) {
                addError(errors, Problems.SEND_TASK_INVALID_TYPE, process, sendTask, "Invalid or unsupported type for send task");
            }

            if (sendTask.getType().equalsIgnoreCase("mail")) {
                validateFieldDeclarationsForEmail(process, sendTask, sendTask.getFieldExtensions(), errors);
            }

        }

        // Web service
        verifyWebservice(bpmnModel, process, sendTask, errors);
    }
}
 
Example 13
Source File: EventGatewayValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<EventGateway> eventGateways = process.findFlowElementsOfType(EventGateway.class);
    for (EventGateway eventGateway : eventGateways) {
        for (SequenceFlow sequenceFlow : eventGateway.getOutgoingFlows()) {
            FlowElement flowElement = process.getFlowElement(sequenceFlow.getTargetRef(), true);
            if (flowElement != null && !(flowElement instanceof IntermediateCatchEvent)) {
                addError(errors, Problems.EVENT_GATEWAY_ONLY_CONNECTED_TO_INTERMEDIATE_EVENTS, process, eventGateway, "Event based gateway can only be connected to elements of type intermediateCatchEvent");
            }
        }
    }
}
 
Example 14
Source File: ServiceTaskValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<ServiceTask> serviceTasks = process.findFlowElementsOfType(ServiceTask.class);
    for (ServiceTask serviceTask : serviceTasks) {
        verifyImplementation(process, serviceTask, errors);
        verifyType(process, serviceTask, errors);
        verifyResultVariableName(process, serviceTask, errors);
        verifyWebservice(bpmnModel, process, serviceTask, errors);
    }
}
 
Example 15
Source File: MultiInstanceActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected Collection<BoundaryEvent> findBoundaryEventsForFlowNode(final String processDefinitionId, final FlowElement flowElement) {
    Process process = getProcessDefinition(processDefinitionId);

    // This could be cached or could be done at parsing time
    List<BoundaryEvent> results = new ArrayList<>(1);
    Collection<BoundaryEvent> boundaryEvents = process.findFlowElementsOfType(BoundaryEvent.class, true);
    for (BoundaryEvent boundaryEvent : boundaryEvents) {
        if (boundaryEvent.getAttachedToRefId() != null && boundaryEvent.getAttachedToRefId().equals(flowElement.getId())) {
            results.add(boundaryEvent);
        }
    }
    return results;
}
 
Example 16
Source File: StartEventValidator.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<StartEvent> startEvents = process.findFlowElementsOfType(StartEvent.class, false);
    validateEventDefinitionTypes(startEvents, process, errors);
    validateMultipleStartEvents(startEvents, process, errors);
}
 
Example 17
Source File: SequenceflowValidator.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<SequenceFlow> sequenceFlows = process.findFlowElementsOfType(SequenceFlow.class);
    for (SequenceFlow sequenceFlow : sequenceFlows) {

        String sourceRef = sequenceFlow.getSourceRef();
        String targetRef = sequenceFlow.getTargetRef();

        if (StringUtils.isEmpty(sourceRef)) {
            addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
        }
        if (StringUtils.isEmpty(targetRef)) {
            addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
        }

        // Implicit check: sequence flow cannot cross (sub) process boundaries, hence we check the parent and not the process
        // (could be subprocess for example)
        FlowElement source = process.getFlowElement(sourceRef, true);
        FlowElement target = process.getFlowElement(targetRef, true);
        
        // Src and target validation
        if (source == null) {
            addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
        }
        
        if (target == null) {
            addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
        }

        if (source != null && target != null) {
            FlowElementsContainer sourceContainer = process.getFlowElementsContainer(source.getId());
            FlowElementsContainer targetContainer = process.getFlowElementsContainer(target.getId());
            
            if (sourceContainer == null) {
                addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
            }
            
            if (targetContainer == null) {
                addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
            }
            
            if (sourceContainer != null && targetContainer != null && !sourceContainer.equals(targetContainer)) {
                addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow, the target isn't defined in the same scope as the source");
            }
        }
    }
}