Search in sources :

Example 51 with BpmnModel

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

the class StartEventConverterTest method doubleConversionValidation.

@Test
public void doubleConversionValidation() throws Exception {
    BpmnModel bpmnModel = readJsonFile();
    bpmnModel = convertToJsonAndBack(bpmnModel);
    validateModel(bpmnModel);
}
Also used : BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 52 with BpmnModel

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

the class SubProcessConverterTest method connvertJsonToModel.

@Test
public void connvertJsonToModel() throws Exception {
    BpmnModel bpmnModel = readJsonFile();
    validateModel(bpmnModel);
}
Also used : BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 53 with BpmnModel

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

the class UserTaskConverterTest method connvertJsonToModel.

@Test
public void connvertJsonToModel() throws Exception {
    BpmnModel bpmnModel = readJsonFile();
    validateModel(bpmnModel);
}
Also used : BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 54 with BpmnModel

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

the class UserTaskConverterTest method doubleConversionValidation.

@Test
public void doubleConversionValidation() throws Exception {
    BpmnModel bpmnModel = readJsonFile();
    bpmnModel = convertToJsonAndBack(bpmnModel);
    validateModel(bpmnModel);
}
Also used : BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 55 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel 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

BpmnModel (org.activiti.bpmn.model.BpmnModel)149 Test (org.junit.Test)101 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)15 InputStream (java.io.InputStream)13 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Deployment (org.activiti.engine.repository.Deployment)10 Process (org.activiti.bpmn.model.Process)8 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)8 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)8 StartEvent (org.activiti.bpmn.model.StartEvent)7 ActivitiException (org.activiti.engine.ActivitiException)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 ArrayList (java.util.ArrayList)6 XMLInputFactory (javax.xml.stream.XMLInputFactory)6 XMLStreamReader (javax.xml.stream.XMLStreamReader)6 UserTask (org.activiti.bpmn.model.UserTask)6 FlowElement (org.activiti.bpmn.model.FlowElement)5 BpmnJsonConverter (org.activiti.editor.language.json.converter.BpmnJsonConverter)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 StreamResource (com.vaadin.terminal.StreamResource)4