Search in sources :

Example 6 with Association

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

the class BpmnAutoLayout method handleAssociations.

protected void handleAssociations() {
    Hashtable<String, Object> edgeStyle = new Hashtable<String, Object>();
    edgeStyle.put(mxConstants.STYLE_ORTHOGONAL, true);
    edgeStyle.put(mxConstants.STYLE_EDGE, mxEdgeStyle.ElbowConnector);
    edgeStyle.put(mxConstants.STYLE_ENTRY_X, 0.0);
    edgeStyle.put(mxConstants.STYLE_ENTRY_Y, 0.5);
    graph.getStylesheet().putCellStyle(STYLE_SEQUENCEFLOW, edgeStyle);
    Hashtable<String, Object> boundaryEdgeStyle = new Hashtable<String, Object>();
    boundaryEdgeStyle.put(mxConstants.STYLE_EXIT_X, 0.5);
    boundaryEdgeStyle.put(mxConstants.STYLE_EXIT_Y, 1.0);
    boundaryEdgeStyle.put(mxConstants.STYLE_ENTRY_X, 0.5);
    boundaryEdgeStyle.put(mxConstants.STYLE_ENTRY_Y, 1.0);
    boundaryEdgeStyle.put(mxConstants.STYLE_EDGE, mxEdgeStyle.OrthConnector);
    graph.getStylesheet().putCellStyle(STYLE_BOUNDARY_SEQUENCEFLOW, boundaryEdgeStyle);
    for (Association association : associations.values()) {
        Object sourceVertex = generatedVertices.get(association.getSourceRef());
        Object targetVertex = generatedVertices.get(association.getTargetRef());
        String style = null;
        if (handledFlowElements.get(association.getSourceRef()) instanceof BoundaryEvent) {
            // Sequence flow out of boundary events are handled in a different way,
            // to make them visually appealing for the eye of the dear end user.
            style = STYLE_BOUNDARY_SEQUENCEFLOW;
        } else {
            style = STYLE_SEQUENCEFLOW;
        }
        Object associationEdge = graph.insertEdge(cellParent, association.getId(), "", sourceVertex, targetVertex, style);
        generatedAssociationEdges.put(association.getId(), associationEdge);
    }
}
Also used : Association(org.activiti.bpmn.model.Association) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) Hashtable(java.util.Hashtable) DataObject(org.activiti.bpmn.model.DataObject)

Example 7 with Association

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

the class BaseBpmnJsonConverter method convertToJson.

public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
    this.model = model;
    this.processor = processor;
    this.subProcessX = subProcessX;
    this.subProcessY = subProcessY;
    this.shapesArrayNode = shapesArrayNode;
    GraphicInfo graphicInfo = model.getGraphicInfo(baseElement.getId());
    String stencilId = null;
    if (baseElement instanceof ServiceTask) {
        ServiceTask serviceTask = (ServiceTask) baseElement;
        if ("mail".equalsIgnoreCase(serviceTask.getType())) {
            stencilId = STENCIL_TASK_MAIL;
        } else if ("camel".equalsIgnoreCase(serviceTask.getType())) {
            stencilId = STENCIL_TASK_CAMEL;
        } else if ("mule".equalsIgnoreCase(serviceTask.getType())) {
            stencilId = STENCIL_TASK_MULE;
        } else if ("dmn".equalsIgnoreCase(serviceTask.getType())) {
            stencilId = STENCIL_TASK_DECISION;
        } else {
            stencilId = getStencilId(baseElement);
        }
    } else {
        stencilId = getStencilId(baseElement);
    }
    flowElementNode = BpmnJsonConverterUtil.createChildShape(baseElement.getId(), stencilId, graphicInfo.getX() - subProcessX + graphicInfo.getWidth(), graphicInfo.getY() - subProcessY + graphicInfo.getHeight(), graphicInfo.getX() - subProcessX, graphicInfo.getY() - subProcessY);
    shapesArrayNode.add(flowElementNode);
    ObjectNode propertiesNode = objectMapper.createObjectNode();
    propertiesNode.put(PROPERTY_OVERRIDE_ID, baseElement.getId());
    if (baseElement instanceof FlowElement) {
        FlowElement flowElement = (FlowElement) baseElement;
        if (StringUtils.isNotEmpty(flowElement.getName())) {
            propertiesNode.put(PROPERTY_NAME, flowElement.getName());
        }
        if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
            propertiesNode.put(PROPERTY_DOCUMENTATION, flowElement.getDocumentation());
        }
    }
    convertElementToJson(propertiesNode, baseElement);
    flowElementNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);
    ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
    if (baseElement instanceof FlowNode) {
        FlowNode flowNode = (FlowNode) baseElement;
        for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
            outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getId()));
        }
        for (MessageFlow messageFlow : model.getMessageFlows().values()) {
            if (messageFlow.getSourceRef().equals(flowNode.getId())) {
                outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
            }
        }
    }
    if (baseElement instanceof Activity) {
        Activity activity = (Activity) baseElement;
        for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) {
            outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(boundaryEvent.getId()));
        }
        propertiesNode.put(PROPERTY_ASYNCHRONOUS, activity.isAsynchronous());
        propertiesNode.put(PROPERTY_EXCLUSIVE, !activity.isNotExclusive());
        if (activity.getLoopCharacteristics() != null) {
            MultiInstanceLoopCharacteristics loopDef = activity.getLoopCharacteristics();
            if (StringUtils.isNotEmpty(loopDef.getLoopCardinality()) || StringUtils.isNotEmpty(loopDef.getInputDataItem()) || StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
                if (!loopDef.isSequential()) {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Parallel");
                } else {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Sequential");
                }
                if (StringUtils.isNotEmpty(loopDef.getLoopCardinality())) {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_CARDINALITY, loopDef.getLoopCardinality());
                }
                if (StringUtils.isNotEmpty(loopDef.getInputDataItem())) {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_COLLECTION, loopDef.getInputDataItem());
                }
                if (StringUtils.isNotEmpty(loopDef.getElementVariable())) {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_VARIABLE, loopDef.getElementVariable());
                }
                if (StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_CONDITION, loopDef.getCompletionCondition());
                }
            }
        }
        if (activity instanceof UserTask) {
            BpmnJsonConverterUtil.convertListenersToJson(((UserTask) activity).getTaskListeners(), false, propertiesNode);
        }
        if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
            for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
                if (model.getFlowElement(dataAssociation.getSourceRef()) != null) {
                    createDataAssociation(dataAssociation, true, activity);
                }
            }
        }
        if (CollectionUtils.isNotEmpty(activity.getDataOutputAssociations())) {
            for (DataAssociation dataAssociation : activity.getDataOutputAssociations()) {
                if (model.getFlowElement(dataAssociation.getTargetRef()) != null) {
                    createDataAssociation(dataAssociation, false, activity);
                    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
                }
            }
        }
    }
    if (baseElement instanceof FlowElement) {
        BpmnJsonConverterUtil.convertListenersToJson(((FlowElement) baseElement).getExecutionListeners(), true, propertiesNode);
    }
    for (Artifact artifact : container.getArtifacts()) {
        if (artifact instanceof Association) {
            Association association = (Association) artifact;
            if (StringUtils.isNotEmpty(association.getSourceRef()) && association.getSourceRef().equals(baseElement.getId())) {
                outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getId()));
            }
        }
    }
    if (baseElement instanceof DataStoreReference) {
        for (Process process : model.getProcesses()) {
            processDataStoreReferences(process, baseElement.getId(), outgoingArrayNode);
        }
    }
    flowElementNode.set("outgoing", outgoingArrayNode);
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) DataAssociation(org.activiti.bpmn.model.DataAssociation) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) UserTask(org.activiti.bpmn.model.UserTask) Activity(org.activiti.bpmn.model.Activity) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) MessageFlow(org.activiti.bpmn.model.MessageFlow) Artifact(org.activiti.bpmn.model.Artifact) DataStoreReference(org.activiti.bpmn.model.DataStoreReference) DataAssociation(org.activiti.bpmn.model.DataAssociation) Association(org.activiti.bpmn.model.Association) MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 8 with Association

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

the class AssociationJsonConverter method convertToJson.

@Override
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
    Association association = (Association) baseElement;
    ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(association.getId(), STENCIL_ASSOCIATION, 172, 212, 128, 212);
    ArrayNode dockersArrayNode = objectMapper.createArrayNode();
    ObjectNode dockNode = objectMapper.createObjectNode();
    dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(association.getSourceRef()).getWidth() / 2.0);
    dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(association.getSourceRef()).getHeight() / 2.0);
    dockersArrayNode.add(dockNode);
    List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(association.getId());
    if (graphicInfoList.size() > 2) {
        for (int i = 1; i < graphicInfoList.size() - 1; i++) {
            GraphicInfo graphicInfo = graphicInfoList.get(i);
            dockNode = objectMapper.createObjectNode();
            dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
            dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
            dockersArrayNode.add(dockNode);
        }
    }
    GraphicInfo targetGraphicInfo = model.getGraphicInfo(association.getTargetRef());
    GraphicInfo flowGraphicInfo = graphicInfoList.get(graphicInfoList.size() - 1);
    double diffTopY = Math.abs(flowGraphicInfo.getY() - targetGraphicInfo.getY());
    double diffRightX = Math.abs(flowGraphicInfo.getX() - (targetGraphicInfo.getX() + targetGraphicInfo.getWidth()));
    double diffBottomY = Math.abs(flowGraphicInfo.getY() - (targetGraphicInfo.getY() + targetGraphicInfo.getHeight()));
    dockNode = objectMapper.createObjectNode();
    if (diffTopY < 5) {
        dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth() / 2.0);
        dockNode.put(EDITOR_BOUNDS_Y, 0.0);
    } else if (diffRightX < 5) {
        dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth());
        dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight() / 2.0);
    } else if (diffBottomY < 5) {
        dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth() / 2.0);
        dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight());
    } else {
        dockNode.put(EDITOR_BOUNDS_X, 0.0);
        dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight() / 2.0);
    }
    dockersArrayNode.add(dockNode);
    flowNode.set("dockers", dockersArrayNode);
    ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getTargetRef()));
    flowNode.set("outgoing", outgoingArrayNode);
    flowNode.set("target", BpmnJsonConverterUtil.createResourceNode(association.getTargetRef()));
    ObjectNode propertiesNode = objectMapper.createObjectNode();
    propertiesNode.put(PROPERTY_OVERRIDE_ID, association.getId());
    flowNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);
    shapesArrayNode.add(flowNode);
}
Also used : Association(org.activiti.bpmn.model.Association) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 9 with Association

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

the class AssociationJsonConverter method convertJsonToElement.

@Override
protected BaseElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) {
    Association association = new Association();
    String sourceRef = BpmnJsonConverterUtil.lookForSourceRef(elementNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES));
    if (sourceRef != null) {
        association.setSourceRef(sourceRef);
        String targetId = elementNode.get("target").get(EDITOR_SHAPE_ID).asText();
        association.setTargetRef(BpmnJsonConverterUtil.getElementId(shapeMap.get(targetId)));
    }
    return association;
}
Also used : Association(org.activiti.bpmn.model.Association)

Aggregations

Association (org.activiti.bpmn.model.Association)9 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)4 SubProcess (org.activiti.bpmn.model.SubProcess)4 FlowElement (org.activiti.bpmn.model.FlowElement)3 Process (org.activiti.bpmn.model.Process)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Activity (org.activiti.bpmn.model.Activity)2 Artifact (org.activiti.bpmn.model.Artifact)2 AssociationDirection (org.activiti.bpmn.model.AssociationDirection)2 DataObject (org.activiti.bpmn.model.DataObject)2 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)2 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)2 TextAnnotation (org.activiti.bpmn.model.TextAnnotation)2 com.mxgraph.view.mxGraph (com.mxgraph.view.mxGraph)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 XMLStreamException (javax.xml.stream.XMLStreamException)1