Search in sources :

Example 6 with Process

use of org.activiti.bpmn.model.Process in project Activiti by Activiti.

the class WorkflowDefinitionConversionTest method testGeneratedWorkflowDefinitionId.

/**
	 * Check if all required artifacts are created when converting an empty workflow-definition.
	 */
@Test
public void testGeneratedWorkflowDefinitionId() {
    WorkflowDefinition definition = new WorkflowDefinition();
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    BpmnModel bpmnModel = conversion.getBpmnModel();
    assertNotNull(bpmnModel);
    Process process = bpmnModel.getMainProcess();
    assertNotNull(process);
    String generatedProcessId = process.getId();
    assertNotNull(generatedProcessId);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Process(org.activiti.bpmn.model.Process) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 7 with Process

use of org.activiti.bpmn.model.Process in project Activiti by Activiti.

the class DefaultWorkflowDefinitionConversionListener method afterStepsConversion.

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);
        }
    }
}
Also used : SequenceFlow(org.activiti.bpmn.model.SequenceFlow) EndEvent(org.activiti.bpmn.model.EndEvent) Process(org.activiti.bpmn.model.Process) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 8 with Process

use of org.activiti.bpmn.model.Process in project Activiti by Activiti.

the class DefaultWorkflowDefinitionConversionListener method initializeProcess.

protected void initializeProcess(WorkflowDefinitionConversion conversion) {
    WorkflowDefinition workflowDefinition = conversion.getWorkflowDefinition();
    // Create new process
    Process process = conversion.getProcess();
    process.setId(generateProcessId(workflowDefinition));
    process.setName(workflowDefinition.getName());
    process.setDocumentation(workflowDefinition.getDescription());
    if (workflowDefinition.getCategory() != null) {
        conversion.getBpmnModel().setTargetNamespace(workflowDefinition.getCategory());
    }
    conversion.setProcess(process);
    // Add start-event
    StartEvent startEvent = new StartEvent();
    startEvent.setId(START_EVENT_ID);
    if (workflowDefinition.getStartFormDefinition() != null && workflowDefinition.getStartFormDefinition().getFormKey() != null) {
        startEvent.setFormKey(workflowDefinition.getStartFormDefinition().getFormKey());
    }
    process.addFlowElement(startEvent);
    conversion.setLastActivityId(startEvent.getId());
}
Also used : StartEvent(org.activiti.bpmn.model.StartEvent) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Process(org.activiti.bpmn.model.Process)

Example 9 with Process

use of org.activiti.bpmn.model.Process in project Activiti by Activiti.

the class BpmnXMLConverter method convertToXML.

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);
        for (Process process : model.getProcesses()) {
            if (process.getFlowElements().isEmpty() && process.getLanes().isEmpty()) {
                // empty process, ignore it 
                continue;
            }
            ProcessExport.writeProcess(process, 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);
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) XMLException(org.activiti.bpmn.exceptions.XMLException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) FlowElement(org.activiti.bpmn.model.FlowElement) OutputStreamWriter(java.io.OutputStreamWriter) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Artifact(org.activiti.bpmn.model.Artifact) XMLStreamException(javax.xml.stream.XMLStreamException) XMLException(org.activiti.bpmn.exceptions.XMLException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 10 with Process

use of org.activiti.bpmn.model.Process in project Activiti by Activiti.

the class BpmnXMLConverter method convertToBpmnModel.

public BpmnModel convertToBpmnModel(XMLStreamReader xtr) {
    BpmnModel model = new BpmnModel();
    model.setStartEventFormTypes(startEventFormTypes);
    model.setUserTaskFormTypes(userTaskFormTypes);
    try {
        Process activeProcess = null;
        List<SubProcess> activeSubProcessList = new ArrayList<SubProcess>();
        while (xtr.hasNext()) {
            try {
                xtr.next();
            } catch (Exception e) {
                LOGGER.debug("Error reading XML document", e);
                throw new XMLException("Error reading XML", e);
            }
            if (xtr.isEndElement() && ELEMENT_SUBPROCESS.equals(xtr.getLocalName())) {
                activeSubProcessList.remove(activeSubProcessList.size() - 1);
            }
            if (xtr.isEndElement() && ELEMENT_TRANSACTION.equals(xtr.getLocalName())) {
                activeSubProcessList.remove(activeSubProcessList.size() - 1);
            }
            if (xtr.isStartElement() == false) {
                continue;
            }
            if (ELEMENT_DEFINITIONS.equals(xtr.getLocalName())) {
                definitionsParser.parse(xtr, model);
            } else if (ELEMENT_RESOURCE.equals(xtr.getLocalName())) {
                resourceParser.parse(xtr, model);
            } else if (ELEMENT_SIGNAL.equals(xtr.getLocalName())) {
                signalParser.parse(xtr, model);
            } else if (ELEMENT_MESSAGE.equals(xtr.getLocalName())) {
                messageParser.parse(xtr, model);
            } else if (ELEMENT_ERROR.equals(xtr.getLocalName())) {
                if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
                    model.addError(xtr.getAttributeValue(null, ATTRIBUTE_ID), xtr.getAttributeValue(null, ATTRIBUTE_ERROR_CODE));
                }
            } else if (ELEMENT_IMPORT.equals(xtr.getLocalName())) {
                importParser.parse(xtr, model);
            } else if (ELEMENT_ITEM_DEFINITION.equals(xtr.getLocalName())) {
                itemDefinitionParser.parse(xtr, model);
            } else if (ELEMENT_DATA_STORE.equals(xtr.getLocalName())) {
                dataStoreParser.parse(xtr, model);
            } else if (ELEMENT_INTERFACE.equals(xtr.getLocalName())) {
                interfaceParser.parse(xtr, model);
            } else if (ELEMENT_IOSPECIFICATION.equals(xtr.getLocalName())) {
                ioSpecificationParser.parseChildElement(xtr, activeProcess, model);
            } else if (ELEMENT_PARTICIPANT.equals(xtr.getLocalName())) {
                participantParser.parse(xtr, model);
            } else if (ELEMENT_MESSAGE_FLOW.equals(xtr.getLocalName())) {
                messageFlowParser.parse(xtr, model);
            } else if (ELEMENT_PROCESS.equals(xtr.getLocalName())) {
                Process process = processParser.parse(xtr, model);
                if (process != null) {
                    activeProcess = process;
                }
            } else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) {
                potentialStarterParser.parse(xtr, activeProcess);
            } else if (ELEMENT_LANE.equals(xtr.getLocalName())) {
                laneParser.parse(xtr, activeProcess, model);
            } else if (ELEMENT_DOCUMENTATION.equals(xtr.getLocalName())) {
                BaseElement parentElement = null;
                if (!activeSubProcessList.isEmpty()) {
                    parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);
                } else if (activeProcess != null) {
                    parentElement = activeProcess;
                }
                documentationParser.parseChildElement(xtr, parentElement, model);
            } else if (activeProcess == null && ELEMENT_TEXT_ANNOTATION.equals(xtr.getLocalName())) {
                String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
                TextAnnotation textAnnotation = (TextAnnotation) new TextAnnotationXMLConverter().convertXMLToElement(xtr, model);
                textAnnotation.setId(elementId);
                model.getGlobalArtifacts().add(textAnnotation);
            } else if (activeProcess == null && ELEMENT_ASSOCIATION.equals(xtr.getLocalName())) {
                String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
                Association association = (Association) new AssociationXMLConverter().convertXMLToElement(xtr, model);
                association.setId(elementId);
                model.getGlobalArtifacts().add(association);
            } else if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                extensionElementsParser.parse(xtr, activeSubProcessList, activeProcess, model);
            } else if (ELEMENT_SUBPROCESS.equals(xtr.getLocalName())) {
                subProcessParser.parse(xtr, activeSubProcessList, activeProcess);
            } else if (ELEMENT_TRANSACTION.equals(xtr.getLocalName())) {
                subProcessParser.parse(xtr, activeSubProcessList, activeProcess);
            } else if (ELEMENT_DI_SHAPE.equals(xtr.getLocalName())) {
                bpmnShapeParser.parse(xtr, model);
            } else if (ELEMENT_DI_EDGE.equals(xtr.getLocalName())) {
                bpmnEdgeParser.parse(xtr, model);
            } else {
                if (!activeSubProcessList.isEmpty() && ELEMENT_MULTIINSTANCE.equalsIgnoreCase(xtr.getLocalName())) {
                    multiInstanceParser.parseChildElement(xtr, activeSubProcessList.get(activeSubProcessList.size() - 1), model);
                } else if (convertersToBpmnMap.containsKey(xtr.getLocalName())) {
                    if (activeProcess != null) {
                        BaseBpmnXMLConverter converter = convertersToBpmnMap.get(xtr.getLocalName());
                        converter.convertToBpmnModel(xtr, model, activeProcess, activeSubProcessList);
                    }
                }
            }
        }
        for (Process process : model.getProcesses()) {
            for (Pool pool : model.getPools()) {
                if (process.getId().equals(pool.getProcessRef())) {
                    pool.setExecutable(process.isExecutable());
                }
            }
            processFlowElements(process.getFlowElements(), process);
        }
    } catch (XMLException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.error("Error processing BPMN document", e);
        throw new XMLException("Error processing BPMN document", e);
    }
    return model;
}
Also used : EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) ArrayList(java.util.ArrayList) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) XMLStreamException(javax.xml.stream.XMLStreamException) XMLException(org.activiti.bpmn.exceptions.XMLException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BpmnModel(org.activiti.bpmn.model.BpmnModel) BaseElement(org.activiti.bpmn.model.BaseElement) XMLException(org.activiti.bpmn.exceptions.XMLException) Association(org.activiti.bpmn.model.Association) Pool(org.activiti.bpmn.model.Pool) TextAnnotation(org.activiti.bpmn.model.TextAnnotation)

Aggregations

Process (org.activiti.bpmn.model.Process)32 FlowElement (org.activiti.bpmn.model.FlowElement)13 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)9 SubProcess (org.activiti.bpmn.model.SubProcess)9 BpmnModel (org.activiti.bpmn.model.BpmnModel)8 Lane (org.activiti.bpmn.model.Lane)8 Pool (org.activiti.bpmn.model.Pool)8 UserTask (org.activiti.bpmn.model.UserTask)6 Artifact (org.activiti.bpmn.model.Artifact)5 List (java.util.List)4 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)4 FlowNode (org.activiti.bpmn.model.FlowNode)4 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)4 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)4 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)4 Test (org.junit.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ArrayList (java.util.ArrayList)3 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)3