Search in sources :

Example 1 with MessageFlow

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

the class CollaborationExport method writePools.

public static void writePools(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    if (!model.getPools().isEmpty()) {
        xtw.writeStartElement(ELEMENT_COLLABORATION);
        xtw.writeAttribute(ATTRIBUTE_ID, "Collaboration");
        for (Pool pool : model.getPools()) {
            xtw.writeStartElement(ELEMENT_PARTICIPANT);
            xtw.writeAttribute(ATTRIBUTE_ID, pool.getId());
            if (StringUtils.isNotEmpty(pool.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, pool.getName());
            }
            if (StringUtils.isNotEmpty(pool.getProcessRef())) {
                xtw.writeAttribute(ATTRIBUTE_PROCESS_REF, pool.getProcessRef());
            }
            xtw.writeEndElement();
        }
        for (MessageFlow messageFlow : model.getMessageFlows().values()) {
            xtw.writeStartElement(ELEMENT_MESSAGE_FLOW);
            xtw.writeAttribute(ATTRIBUTE_ID, messageFlow.getId());
            if (StringUtils.isNotEmpty(messageFlow.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, messageFlow.getName());
            }
            if (StringUtils.isNotEmpty(messageFlow.getSourceRef())) {
                xtw.writeAttribute(ATTRIBUTE_FLOW_SOURCE_REF, messageFlow.getSourceRef());
            }
            if (StringUtils.isNotEmpty(messageFlow.getTargetRef())) {
                xtw.writeAttribute(ATTRIBUTE_FLOW_TARGET_REF, messageFlow.getTargetRef());
            }
            if (StringUtils.isNotEmpty(messageFlow.getMessageRef())) {
                xtw.writeAttribute(ATTRIBUTE_MESSAGE_REF, messageFlow.getMessageRef());
            }
            xtw.writeEndElement();
        }
        xtw.writeEndElement();
    }
}
Also used : Pool(org.activiti.bpmn.model.Pool) MessageFlow(org.activiti.bpmn.model.MessageFlow)

Example 2 with MessageFlow

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

the class MessageFlowConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    assertEquals(1, model.getDataStores().size());
    DataStore dataStore = model.getDataStore("DATASTORE_1");
    assertNotNull(dataStore);
    assertEquals("DATASTORE_1", dataStore.getId());
    assertEquals("test", dataStore.getName());
    assertEquals("ITEM_1", dataStore.getItemSubjectRef());
    MessageFlow messageFlow = model.getMessageFlow("MESSAGEFLOW_1");
    assertNotNull(messageFlow);
    assertEquals("test 1", messageFlow.getName());
    assertEquals("task1", messageFlow.getSourceRef());
    assertEquals("task2", messageFlow.getTargetRef());
    messageFlow = model.getMessageFlow("MESSAGEFLOW_2");
    assertNotNull(messageFlow);
    assertEquals("test 2", messageFlow.getName());
    assertEquals("task2", messageFlow.getSourceRef());
    assertEquals("task3", messageFlow.getTargetRef());
    assertEquals(2, model.getPools().size());
    Pool pool = model.getPools().get(0);
    assertEquals("participant1", pool.getId());
    assertEquals("Participant 1", pool.getName());
    assertEquals("PROCESS_1", pool.getProcessRef());
    pool = model.getPools().get(1);
    assertEquals("participant2", pool.getId());
    assertEquals("Participant 2", pool.getName());
    assertEquals("PROCESS_2", pool.getProcessRef());
}
Also used : DataStore(org.activiti.bpmn.model.DataStore) Pool(org.activiti.bpmn.model.Pool) MessageFlow(org.activiti.bpmn.model.MessageFlow)

Example 3 with MessageFlow

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

the class BpmnJsonConverter method processMessageFlows.

protected void processMessageFlows(BpmnModel model, ArrayNode shapesArrayNode) {
    for (MessageFlow messageFlow : model.getMessageFlows().values()) {
        MessageFlowJsonConverter jsonConverter = new MessageFlowJsonConverter();
        jsonConverter.convertToJson(messageFlow, this, model, null, shapesArrayNode, 0.0, 0.0);
    }
}
Also used : MessageFlow(org.activiti.bpmn.model.MessageFlow)

Example 4 with MessageFlow

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

the class BpmnJsonConverter method convertToJson.

public ObjectNode convertToJson(BpmnModel model) {
    ObjectNode modelNode = objectMapper.createObjectNode();
    double maxX = 0.0;
    double maxY = 0.0;
    for (GraphicInfo flowInfo : model.getLocationMap().values()) {
        if ((flowInfo.getX() + flowInfo.getWidth()) > maxX) {
            maxX = flowInfo.getX() + flowInfo.getWidth();
        }
        if ((flowInfo.getY() + flowInfo.getHeight()) > maxY) {
            maxY = flowInfo.getY() + flowInfo.getHeight();
        }
    }
    maxX += 50;
    maxY += 50;
    if (maxX < 1485) {
        maxX = 1485;
    }
    if (maxY < 700) {
        maxY = 700;
    }
    modelNode.put("bounds", BpmnJsonConverterUtil.createBoundsNode(maxX, maxY, 0, 0));
    modelNode.put("resourceId", "canvas");
    ObjectNode stencilNode = objectMapper.createObjectNode();
    stencilNode.put("id", "BPMNDiagram");
    modelNode.put("stencil", stencilNode);
    ObjectNode stencilsetNode = objectMapper.createObjectNode();
    stencilsetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
    stencilsetNode.put("url", "../editor/stencilsets/bpmn2.0/bpmn2.0.json");
    modelNode.put("stencilset", stencilsetNode);
    ArrayNode shapesArrayNode = objectMapper.createArrayNode();
    Process mainProcess = null;
    if (model.getPools().size() > 0) {
        mainProcess = model.getProcess(model.getPools().get(0).getId());
    } else {
        mainProcess = model.getMainProcess();
    }
    ObjectNode propertiesNode = objectMapper.createObjectNode();
    if (StringUtils.isNotEmpty(mainProcess.getId())) {
        propertiesNode.put(PROPERTY_PROCESS_ID, mainProcess.getId());
    }
    if (StringUtils.isNotEmpty(mainProcess.getName())) {
        propertiesNode.put(PROPERTY_NAME, mainProcess.getName());
    }
    if (StringUtils.isNotEmpty(mainProcess.getDocumentation())) {
        propertiesNode.put(PROPERTY_DOCUMENTATION, mainProcess.getDocumentation());
    }
    if (mainProcess.isExecutable() == false) {
        propertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, "No");
    }
    if (StringUtils.isNoneEmpty(model.getTargetNamespace())) {
        propertiesNode.put(PROPERTY_PROCESS_NAMESPACE, model.getTargetNamespace());
    }
    BpmnJsonConverterUtil.convertMessagesToJson(model.getMessages(), propertiesNode);
    BpmnJsonConverterUtil.convertListenersToJson(mainProcess.getExecutionListeners(), true, propertiesNode);
    BpmnJsonConverterUtil.convertEventListenersToJson(mainProcess.getEventListeners(), propertiesNode);
    BpmnJsonConverterUtil.convertSignalDefinitionsToJson(model, propertiesNode);
    BpmnJsonConverterUtil.convertMessagesToJson(model, propertiesNode);
    if (CollectionUtils.isNotEmpty(mainProcess.getDataObjects())) {
        BpmnJsonConverterUtil.convertDataPropertiesToJson(mainProcess.getDataObjects(), propertiesNode);
    }
    modelNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
    boolean poolHasDI = false;
    if (model.getPools().size() > 0) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
            if (graphicInfo != null) {
                poolHasDI = true;
                break;
            }
        }
    }
    if (model.getPools().size() > 0 && poolHasDI) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
            if (graphicInfo == null)
                continue;
            ObjectNode poolNode = BpmnJsonConverterUtil.createChildShape(pool.getId(), STENCIL_POOL, graphicInfo.getX() + graphicInfo.getWidth(), graphicInfo.getY() + graphicInfo.getHeight(), graphicInfo.getX(), graphicInfo.getY());
            shapesArrayNode.add(poolNode);
            ObjectNode poolPropertiesNode = objectMapper.createObjectNode();
            poolPropertiesNode.put(PROPERTY_OVERRIDE_ID, pool.getId());
            poolPropertiesNode.put(PROPERTY_PROCESS_ID, pool.getProcessRef());
            if (pool.isExecutable() == false) {
                poolPropertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, PROPERTY_VALUE_NO);
            }
            if (StringUtils.isNotEmpty(pool.getName())) {
                poolPropertiesNode.put(PROPERTY_NAME, pool.getName());
            }
            poolNode.put(EDITOR_SHAPE_PROPERTIES, poolPropertiesNode);
            ArrayNode laneShapesArrayNode = objectMapper.createArrayNode();
            poolNode.put(EDITOR_CHILD_SHAPES, laneShapesArrayNode);
            ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
            poolNode.put("outgoing", outgoingArrayNode);
            Process process = model.getProcess(pool.getId());
            if (process != null) {
                Map<String, ArrayNode> laneMap = new HashMap<String, ArrayNode>();
                for (Lane lane : process.getLanes()) {
                    GraphicInfo laneGraphicInfo = model.getGraphicInfo(lane.getId());
                    if (laneGraphicInfo == null)
                        continue;
                    ObjectNode laneNode = BpmnJsonConverterUtil.createChildShape(lane.getId(), STENCIL_LANE, laneGraphicInfo.getX() + laneGraphicInfo.getWidth(), laneGraphicInfo.getY() + laneGraphicInfo.getHeight(), laneGraphicInfo.getX(), laneGraphicInfo.getY());
                    laneShapesArrayNode.add(laneNode);
                    ObjectNode lanePropertiesNode = objectMapper.createObjectNode();
                    lanePropertiesNode.put(PROPERTY_OVERRIDE_ID, lane.getId());
                    if (StringUtils.isNotEmpty(lane.getName())) {
                        lanePropertiesNode.put(PROPERTY_NAME, lane.getName());
                    }
                    laneNode.put(EDITOR_SHAPE_PROPERTIES, lanePropertiesNode);
                    ArrayNode elementShapesArrayNode = objectMapper.createArrayNode();
                    laneNode.put(EDITOR_CHILD_SHAPES, elementShapesArrayNode);
                    laneNode.put("outgoing", objectMapper.createArrayNode());
                    laneMap.put(lane.getId(), elementShapesArrayNode);
                }
                for (FlowElement flowElement : process.getFlowElements()) {
                    Lane laneForElement = null;
                    GraphicInfo laneGraphicInfo = null;
                    FlowElement lookForElement = null;
                    if (flowElement instanceof SequenceFlow) {
                        SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
                        lookForElement = model.getFlowElement(sequenceFlow.getSourceRef());
                    } else {
                        lookForElement = flowElement;
                    }
                    for (Lane lane : process.getLanes()) {
                        if (lane.getFlowReferences().contains(lookForElement.getId())) {
                            laneGraphicInfo = model.getGraphicInfo(lane.getId());
                            if (laneGraphicInfo != null) {
                                laneForElement = lane;
                            }
                            break;
                        }
                    }
                    if (flowElement instanceof SequenceFlow || laneForElement != null) {
                        processFlowElement(flowElement, process, model, laneMap.get(laneForElement.getId()), laneGraphicInfo.getX(), laneGraphicInfo.getY());
                    }
                }
                processArtifacts(process, model, shapesArrayNode, 0.0, 0.0);
            }
            for (MessageFlow messageFlow : model.getMessageFlows().values()) {
                if (messageFlow.getSourceRef().equals(pool.getId())) {
                    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
                }
            }
        }
        processMessageFlows(model, shapesArrayNode);
    } else {
        processFlowElements(model.getMainProcess(), model, shapesArrayNode, 0.0, 0.0);
        processMessageFlows(model, shapesArrayNode);
    }
    modelNode.put(EDITOR_CHILD_SHAPES, shapesArrayNode);
    return modelNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Lane(org.activiti.bpmn.model.Lane) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) MessageFlow(org.activiti.bpmn.model.MessageFlow) FlowElement(org.activiti.bpmn.model.FlowElement) Pool(org.activiti.bpmn.model.Pool) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 5 with MessageFlow

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

the class BPMNDIExport method writeBPMNDI.

public static void writeBPMNDI(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    // BPMN DI information
    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_DIAGRAM, BPMNDI_NAMESPACE);
    String processId = null;
    if (!model.getPools().isEmpty()) {
        processId = "Collaboration";
    } else {
        processId = model.getMainProcess().getId();
    }
    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNDiagram_" + processId);
    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_PLANE, BPMNDI_NAMESPACE);
    xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, processId);
    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNPlane_" + processId);
    for (String elementId : model.getLocationMap().keySet()) {
        if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null || model.getPool(elementId) != null || model.getLane(elementId) != null) {
            xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_SHAPE, BPMNDI_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
            xtw.writeAttribute(ATTRIBUTE_ID, "BPMNShape_" + elementId);
            GraphicInfo graphicInfo = model.getGraphicInfo(elementId);
            FlowElement flowElement = model.getFlowElement(elementId);
            if (flowElement instanceof SubProcess && graphicInfo.getExpanded() != null) {
                xtw.writeAttribute(ATTRIBUTE_DI_IS_EXPANDED, String.valueOf(graphicInfo.getExpanded()));
            }
            xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + graphicInfo.getHeight());
            xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + graphicInfo.getWidth());
            xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
            xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
            xtw.writeEndElement();
            xtw.writeEndElement();
        }
    }
    for (String elementId : model.getFlowLocationMap().keySet()) {
        if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null || model.getMessageFlow(elementId) != null) {
            xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_EDGE, BPMNDI_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
            xtw.writeAttribute(ATTRIBUTE_ID, "BPMNEdge_" + elementId);
            List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(elementId);
            for (GraphicInfo graphicInfo : graphicInfoList) {
                xtw.writeStartElement(OMGDI_PREFIX, ELEMENT_DI_WAYPOINT, OMGDI_NAMESPACE);
                xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
                xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
                xtw.writeEndElement();
            }
            GraphicInfo labelGraphicInfo = model.getLabelGraphicInfo(elementId);
            FlowElement flowElement = model.getFlowElement(elementId);
            MessageFlow messageFlow = null;
            if (flowElement == null) {
                messageFlow = model.getMessageFlow(elementId);
            }
            boolean hasName = false;
            if (flowElement != null && StringUtils.isNotEmpty(flowElement.getName())) {
                hasName = true;
            } else if (messageFlow != null && StringUtils.isNotEmpty(messageFlow.getName())) {
                hasName = true;
            }
            if (labelGraphicInfo != null && hasName) {
                xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_LABEL, BPMNDI_NAMESPACE);
                xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
                xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + labelGraphicInfo.getHeight());
                xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + labelGraphicInfo.getWidth());
                xtw.writeAttribute(ATTRIBUTE_DI_X, "" + labelGraphicInfo.getX());
                xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + labelGraphicInfo.getY());
                xtw.writeEndElement();
                xtw.writeEndElement();
            }
            xtw.writeEndElement();
        }
    }
    // end BPMN DI elements
    xtw.writeEndElement();
    xtw.writeEndElement();
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) FlowElement(org.activiti.bpmn.model.FlowElement) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) MessageFlow(org.activiti.bpmn.model.MessageFlow)

Aggregations

MessageFlow (org.activiti.bpmn.model.MessageFlow)9 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 FlowElement (org.activiti.bpmn.model.FlowElement)3 Pool (org.activiti.bpmn.model.Pool)3 SubProcess (org.activiti.bpmn.model.SubProcess)3 Process (org.activiti.bpmn.model.Process)2 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HashMap (java.util.HashMap)1 Activity (org.activiti.bpmn.model.Activity)1 Artifact (org.activiti.bpmn.model.Artifact)1 Association (org.activiti.bpmn.model.Association)1 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)1 DataAssociation (org.activiti.bpmn.model.DataAssociation)1 DataStore (org.activiti.bpmn.model.DataStore)1 DataStoreReference (org.activiti.bpmn.model.DataStoreReference)1 FlowNode (org.activiti.bpmn.model.FlowNode)1 Lane (org.activiti.bpmn.model.Lane)1