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

The following examples show how to use org.flowable.bpmn.model.Process#getFlowElements() . 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: ActivitiTestCaseProcessValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void executeParse(BpmnModel bpmnModel, Process element) {
    for (FlowElement flowElement : element.getFlowElements()) {
        if (!ServiceTask.class.isAssignableFrom(flowElement.getClass())) {
            continue;
        }
        ServiceTask serviceTask = (ServiceTask) flowElement;
        validateAsyncAttribute(serviceTask, bpmnModel, flowElement);
    }
}
 
Example 2
Source File: TimerManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected List<TimerJobEntity> getTimerDeclarations(ProcessDefinitionEntity processDefinition, Process process) {
    List<TimerJobEntity> timers = new ArrayList<>();
    if (CollectionUtil.isNotEmpty(process.getFlowElements())) {
        for (FlowElement element : process.getFlowElements()) {
            if (element instanceof StartEvent) {
                StartEvent startEvent = (StartEvent) element;
                if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) {
                    EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
                    if (eventDefinition instanceof TimerEventDefinition) {
                        TimerEventDefinition timerEventDefinition = (TimerEventDefinition) eventDefinition;
                        TimerJobEntity timerJob = TimerUtil.createTimerEntityForTimerEventDefinition(timerEventDefinition, startEvent,
                                false, null, TimerStartEventJobHandler.TYPE, TimerEventHandler.createConfiguration(startEvent.getId(), 
                                        timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName()));

                        if (timerJob != null) {
                            timerJob.setProcessDefinitionId(processDefinition.getId());

                            if (processDefinition.getTenantId() != null) {
                                timerJob.setTenantId(processDefinition.getTenantId());
                            }
                            timers.add(timerJob);
                        }

                    }
                }
            }
        }
    }

    return timers;
}
 
Example 3
Source File: DynamicProcessDefinitionSummary.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public ObjectNode getSummary() {
    ObjectNode summary = objectMapper.createObjectNode();

    for (Process process : bpmnModel.getProcesses()) {
        for (FlowElement flowElement : process.getFlowElements()) {
            summary.set(flowElement.getId(), getElement(flowElement.getId()));
        }
    }

    return summary;
}
 
Example 4
Source File: FlowableTestCaseProcessValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void executeParse(BpmnModel bpmnModel, Process element) {
    for (FlowElement flowElement : element.getFlowElements()) {
        if (!ServiceTask.class.isAssignableFrom(flowElement.getClass())) {
            continue;
        }
        ServiceTask serviceTask = (ServiceTask) flowElement;
        validateAsyncAttribute(serviceTask, bpmnModel, flowElement);
    }
}
 
Example 5
Source File: FlowElementValidator.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) {
    for (FlowElement flowElement : process.getFlowElements()) {

        if (flowElement instanceof Activity) {
            Activity activity = (Activity) flowElement;
            handleConstraints(process, activity, errors);
            handleMultiInstanceLoopCharacteristics(process, activity, errors);
            handleDataAssociations(process, activity, errors);
        }

    }

}
 
Example 6
Source File: ExecutionListenerValidator.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) {

    validateListeners(process, process, process.getExecutionListeners(), errors);

    for (FlowElement flowElement : process.getFlowElements()) {
        validateListeners(process, flowElement, flowElement.getExecutionListeners(), errors);
    }
}
 
Example 7
Source File: BpmnAutoLayout.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Since subprocesses are autolayouted independently (see {@link #handleSubProcess(FlowElement)}), the elements have x and y coordinates relative to the bounds of the subprocess (thinking the
 * subprocess is on (0,0). This however, does not work for nested subprocesses, as they need to take in account the x and y coordinates for each of the parent subproceses.
 * 
 * This method is to be called after fully layouting one process, since ALL elements need to have x and y.
 */
protected void translateNestedSubprocesses(Process process) {
    for (FlowElement flowElement : process.getFlowElements()) {
        if (flowElement instanceof SubProcess) {
            translateNestedSubprocessElements((SubProcess) flowElement);
        }
    }
}
 
Example 8
Source File: ProcessInstanceHelper.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public ProcessInstance createAndStartProcessInstanceByMessage(ProcessDefinition processDefinition, String messageName, String businessKey, 
        Map<String, Object> variables, Map<String, Object> transientVariables,
        String callbackId, String callbackType, String referenceId, String referenceType) {

    CommandContext commandContext = Context.getCommandContext();
    if (Flowable5Util.isFlowable5ProcessDefinition(processDefinition, commandContext)) {
        return CommandContextUtil.getProcessEngineConfiguration(commandContext).getFlowable5CompatibilityHandler().startProcessInstanceByMessage(
                messageName, variables, transientVariables, businessKey, processDefinition.getTenantId());
    }

    // Do not start process a process instance if the process definition is suspended
    if (ProcessDefinitionUtil.isProcessDefinitionSuspended(processDefinition.getId())) {
        throw new FlowableException("Cannot start process instance. Process definition " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
    }

    // Get model from cache
    Process process = ProcessDefinitionUtil.getProcess(processDefinition.getId());
    if (process == null) {
        throw new FlowableException("Cannot start process instance. Process model " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") could not be found");
    }

    FlowElement initialFlowElement = null;
    for (FlowElement flowElement : process.getFlowElements()) {
        if (flowElement instanceof StartEvent) {
            StartEvent startEvent = (StartEvent) flowElement;
            if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions()) && startEvent.getEventDefinitions().get(0) instanceof MessageEventDefinition) {

                MessageEventDefinition messageEventDefinition = (MessageEventDefinition) startEvent.getEventDefinitions().get(0);
                String actualMessageName = EventDefinitionExpressionUtil.determineMessageName(commandContext, messageEventDefinition, null);
                if (Objects.equals(actualMessageName, messageName)) {
                    initialFlowElement = flowElement;
                    break;
                }
            }
        }
    }
    if (initialFlowElement == null) {
        throw new FlowableException("No message start event found for process definition " + processDefinition.getId() + " and message name " + messageName);
    }

    return createAndStartProcessInstanceWithInitialFlowElement(processDefinition, businessKey, null, null, null, initialFlowElement, 
                    process, variables, transientVariables, callbackId, callbackType, referenceId, referenceType, null, true);
}
 
Example 9
Source File: BpmnXMLConverter.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public byte[] convertToXML(BpmnModel model, String encoding) {
    try {

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);

        XMLStreamWriter writer = xof.createXMLStreamWriter(out);
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);

        DefinitionsRootExport.writeRootElement(model, xtw, encoding);
        CollaborationExport.writePools(model, xtw);
        DataStoreExport.writeDataStores(model, xtw);
        SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);
        EscalationDefinitionExport.writeEscalations(model, xtw);

        for (Process process : model.getProcesses()) {

            if (process.getFlowElements().isEmpty() && process.getLanes().isEmpty()) {
                // empty process, ignore it
                continue;
            }

            ProcessExport.writeProcess(process, model, xtw);

            for (FlowElement flowElement : process.getFlowElements()) {
                createXML(flowElement, model, xtw);
            }

            for (Artifact artifact : process.getArtifacts()) {
                createXML(artifact, model, xtw);
            }

            // end process element
            xtw.writeEndElement();
        }

        BPMNDIExport.writeBPMNDI(model, xtw);

        // end definitions root element
        xtw.writeEndElement();
        xtw.writeEndDocument();

        xtw.flush();

        outputStream.close();

        xtw.close();

        return outputStream.toByteArray();

    } catch (Exception e) {
        LOGGER.error("Error writing BPMN XML", e);
        throw new XMLException("Error writing BPMN XML", e);
    }
}