Search in sources :

Example 6 with Artifact

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

the class DefaultProcessDiagramGenerator method initProcessDiagramCanvas.

protected static DefaultProcessDiagramCanvas initProcessDiagramCanvas(BpmnModel bpmnModel, String imageType, String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader) {
    // We need to calculate maximum values to know how big the image will be in its entirety
    double minX = Double.MAX_VALUE;
    double maxX = 0;
    double minY = Double.MAX_VALUE;
    double maxY = 0;
    for (Pool pool : bpmnModel.getPools()) {
        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
        minX = graphicInfo.getX();
        maxX = graphicInfo.getX() + graphicInfo.getWidth();
        minY = graphicInfo.getY();
        maxY = graphicInfo.getY() + graphicInfo.getHeight();
    }
    List<FlowNode> flowNodes = gatherAllFlowNodes(bpmnModel);
    for (FlowNode flowNode : flowNodes) {
        GraphicInfo flowNodeGraphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
        // width
        if (flowNodeGraphicInfo.getX() + flowNodeGraphicInfo.getWidth() > maxX) {
            maxX = flowNodeGraphicInfo.getX() + flowNodeGraphicInfo.getWidth();
        }
        if (flowNodeGraphicInfo.getX() < minX) {
            minX = flowNodeGraphicInfo.getX();
        }
        // height
        if (flowNodeGraphicInfo.getY() + flowNodeGraphicInfo.getHeight() > maxY) {
            maxY = flowNodeGraphicInfo.getY() + flowNodeGraphicInfo.getHeight();
        }
        if (flowNodeGraphicInfo.getY() < minY) {
            minY = flowNodeGraphicInfo.getY();
        }
        for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
            List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(sequenceFlow.getId());
            if (graphicInfoList != null) {
                for (GraphicInfo graphicInfo : graphicInfoList) {
                    // width
                    if (graphicInfo.getX() > maxX) {
                        maxX = graphicInfo.getX();
                    }
                    if (graphicInfo.getX() < minX) {
                        minX = graphicInfo.getX();
                    }
                    // height
                    if (graphicInfo.getY() > maxY) {
                        maxY = graphicInfo.getY();
                    }
                    if (graphicInfo.getY() < minY) {
                        minY = graphicInfo.getY();
                    }
                }
            }
        }
    }
    List<Artifact> artifacts = gatherAllArtifacts(bpmnModel);
    for (Artifact artifact : artifacts) {
        GraphicInfo artifactGraphicInfo = bpmnModel.getGraphicInfo(artifact.getId());
        if (artifactGraphicInfo != null) {
            // width
            if (artifactGraphicInfo.getX() + artifactGraphicInfo.getWidth() > maxX) {
                maxX = artifactGraphicInfo.getX() + artifactGraphicInfo.getWidth();
            }
            if (artifactGraphicInfo.getX() < minX) {
                minX = artifactGraphicInfo.getX();
            }
            // height
            if (artifactGraphicInfo.getY() + artifactGraphicInfo.getHeight() > maxY) {
                maxY = artifactGraphicInfo.getY() + artifactGraphicInfo.getHeight();
            }
            if (artifactGraphicInfo.getY() < minY) {
                minY = artifactGraphicInfo.getY();
            }
        }
        List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(artifact.getId());
        if (graphicInfoList != null) {
            for (GraphicInfo graphicInfo : graphicInfoList) {
                // width
                if (graphicInfo.getX() > maxX) {
                    maxX = graphicInfo.getX();
                }
                if (graphicInfo.getX() < minX) {
                    minX = graphicInfo.getX();
                }
                // height
                if (graphicInfo.getY() > maxY) {
                    maxY = graphicInfo.getY();
                }
                if (graphicInfo.getY() < minY) {
                    minY = graphicInfo.getY();
                }
            }
        }
    }
    int nrOfLanes = 0;
    for (Process process : bpmnModel.getProcesses()) {
        for (Lane l : process.getLanes()) {
            nrOfLanes++;
            GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(l.getId());
            // // width
            if (graphicInfo.getX() + graphicInfo.getWidth() > maxX) {
                maxX = graphicInfo.getX() + graphicInfo.getWidth();
            }
            if (graphicInfo.getX() < minX) {
                minX = graphicInfo.getX();
            }
            // height
            if (graphicInfo.getY() + graphicInfo.getHeight() > maxY) {
                maxY = graphicInfo.getY() + graphicInfo.getHeight();
            }
            if (graphicInfo.getY() < minY) {
                minY = graphicInfo.getY();
            }
        }
    }
    // Special case, see https://activiti.atlassian.net/browse/ACT-1431
    if (flowNodes.isEmpty() && bpmnModel.getPools().isEmpty() && nrOfLanes == 0) {
        // Nothing to show
        minX = 0;
        minY = 0;
    }
    return new DefaultProcessDiagramCanvas((int) maxX + 10, (int) maxY + 10, (int) minX, (int) minY, imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);
}
Also used : SequenceFlow(org.activiti.bpmn.model.SequenceFlow) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Lane(org.activiti.bpmn.model.Lane) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) Artifact(org.activiti.bpmn.model.Artifact) Pool(org.activiti.bpmn.model.Pool) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 7 with Artifact

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

the class BaseBpmnJsonConverter method convertToBpmnModel.

public void convertToBpmnModel(JsonNode elementNode, JsonNode modelNode, ActivityProcessor processor, BaseElement parentElement, Map<String, JsonNode> shapeMap, BpmnModel bpmnModel) {
    this.processor = processor;
    this.model = bpmnModel;
    BaseElement baseElement = convertJsonToElement(elementNode, modelNode, shapeMap);
    baseElement.setId(BpmnJsonConverterUtil.getElementId(elementNode));
    if (baseElement instanceof FlowElement) {
        FlowElement flowElement = (FlowElement) baseElement;
        flowElement.setName(getPropertyValueAsString(PROPERTY_NAME, elementNode));
        flowElement.setDocumentation(getPropertyValueAsString(PROPERTY_DOCUMENTATION, elementNode));
        BpmnJsonConverterUtil.convertJsonToListeners(elementNode, flowElement);
        if (baseElement instanceof Activity) {
            Activity activity = (Activity) baseElement;
            activity.setAsynchronous(getPropertyValueAsBoolean(PROPERTY_ASYNCHRONOUS, elementNode));
            activity.setNotExclusive(!getPropertyValueAsBoolean(PROPERTY_EXCLUSIVE, elementNode));
            String multiInstanceType = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_TYPE, elementNode);
            String multiInstanceCardinality = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CARDINALITY, elementNode);
            String multiInstanceCollection = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_COLLECTION, elementNode);
            String multiInstanceCondition = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CONDITION, elementNode);
            if (StringUtils.isNotEmpty(multiInstanceType) && "none".equalsIgnoreCase(multiInstanceType) == false) {
                String multiInstanceVariable = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_VARIABLE, elementNode);
                MultiInstanceLoopCharacteristics multiInstanceObject = new MultiInstanceLoopCharacteristics();
                if ("sequential".equalsIgnoreCase(multiInstanceType)) {
                    multiInstanceObject.setSequential(true);
                } else {
                    multiInstanceObject.setSequential(false);
                }
                multiInstanceObject.setLoopCardinality(multiInstanceCardinality);
                multiInstanceObject.setInputDataItem(multiInstanceCollection);
                multiInstanceObject.setElementVariable(multiInstanceVariable);
                multiInstanceObject.setCompletionCondition(multiInstanceCondition);
                activity.setLoopCharacteristics(multiInstanceObject);
            }
        } else if (baseElement instanceof Gateway) {
            JsonNode flowOrderNode = getProperty(PROPERTY_SEQUENCEFLOW_ORDER, elementNode);
            if (flowOrderNode != null) {
                flowOrderNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(flowOrderNode);
                JsonNode orderArray = flowOrderNode.get("sequenceFlowOrder");
                if (orderArray != null && orderArray.size() > 0) {
                    for (JsonNode orderNode : orderArray) {
                        ExtensionElement orderElement = new ExtensionElement();
                        orderElement.setName("EDITOR_FLOW_ORDER");
                        orderElement.setElementText(orderNode.asText());
                        flowElement.addExtensionElement(orderElement);
                    }
                }
            }
        }
    }
    if (baseElement instanceof FlowElement) {
        FlowElement flowElement = (FlowElement) baseElement;
        if (flowElement instanceof SequenceFlow) {
            ExtensionElement idExtensionElement = new ExtensionElement();
            idExtensionElement.setName("EDITOR_RESOURCEID");
            idExtensionElement.setElementText(elementNode.get(EDITOR_SHAPE_ID).asText());
            flowElement.addExtensionElement(idExtensionElement);
        }
        if (parentElement instanceof Process) {
            ((Process) parentElement).addFlowElement(flowElement);
        } else if (parentElement instanceof SubProcess) {
            ((SubProcess) parentElement).addFlowElement(flowElement);
        } else if (parentElement instanceof Lane) {
            Lane lane = (Lane) parentElement;
            lane.getFlowReferences().add(flowElement.getId());
            lane.getParentProcess().addFlowElement(flowElement);
        }
    } else if (baseElement instanceof Artifact) {
        Artifact artifact = (Artifact) baseElement;
        if (parentElement instanceof Process) {
            ((Process) parentElement).addArtifact(artifact);
        } else if (parentElement instanceof SubProcess) {
            ((SubProcess) parentElement).addArtifact(artifact);
        } else if (parentElement instanceof Lane) {
            Lane lane = (Lane) parentElement;
            lane.getFlowReferences().add(artifact.getId());
            lane.getParentProcess().addArtifact(artifact);
        }
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) Lane(org.activiti.bpmn.model.Lane) Activity(org.activiti.bpmn.model.Activity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) Artifact(org.activiti.bpmn.model.Artifact) BaseElement(org.activiti.bpmn.model.BaseElement) MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) FlowElement(org.activiti.bpmn.model.FlowElement) Gateway(org.activiti.bpmn.model.Gateway)

Example 8 with Artifact

use of org.activiti.bpmn.model.Artifact 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 {
            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.put(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() == false) {
                    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);
        }
        BpmnJsonConverterUtil.convertListenersToJson(activity.getExecutionListeners(), true, 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()));
                }
            }
        }
    }
    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.put("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)

Aggregations

Artifact (org.activiti.bpmn.model.Artifact)8 SubProcess (org.activiti.bpmn.model.SubProcess)7 FlowElement (org.activiti.bpmn.model.FlowElement)6 Process (org.activiti.bpmn.model.Process)5 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)4 FlowNode (org.activiti.bpmn.model.FlowNode)4 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)4 Activity (org.activiti.bpmn.model.Activity)3 Gateway (org.activiti.bpmn.model.Gateway)3 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)3 Lane (org.activiti.bpmn.model.Lane)3 XMLException (org.activiti.bpmn.exceptions.XMLException)2 Association (org.activiti.bpmn.model.Association)2 BaseElement (org.activiti.bpmn.model.BaseElement)2 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)2 DataObject (org.activiti.bpmn.model.DataObject)2 MultiInstanceLoopCharacteristics (org.activiti.bpmn.model.MultiInstanceLoopCharacteristics)2 Pool (org.activiti.bpmn.model.Pool)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1