Search in sources :

Example 1 with Artifact

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

the class DefaultProcessDiagramGenerator method generateProcessDiagram.

protected DefaultProcessDiagramCanvas generateProcessDiagram(BpmnModel bpmnModel, String imageType, List<String> highLightedActivities, List<String> highLightedFlows, String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader, double scaleFactor) {
    prepareBpmnModel(bpmnModel);
    DefaultProcessDiagramCanvas processDiagramCanvas = initProcessDiagramCanvas(bpmnModel, imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);
    // Draw pool shape, if process is participant in collaboration
    for (Pool pool : bpmnModel.getPools()) {
        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
        processDiagramCanvas.drawPoolOrLane(pool.getName(), graphicInfo);
    }
    // Draw lanes
    for (Process process : bpmnModel.getProcesses()) {
        for (Lane lane : process.getLanes()) {
            GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(lane.getId());
            processDiagramCanvas.drawPoolOrLane(lane.getName(), graphicInfo);
        }
    }
    // Draw activities and their sequence-flows
    for (Process process : bpmnModel.getProcesses()) {
        for (FlowNode flowNode : process.findFlowElementsOfType(FlowNode.class)) {
            drawActivity(processDiagramCanvas, bpmnModel, flowNode, highLightedActivities, highLightedFlows, scaleFactor);
        }
    }
    // Draw artifacts
    for (Process process : bpmnModel.getProcesses()) {
        for (Artifact artifact : process.getArtifacts()) {
            drawArtifact(processDiagramCanvas, bpmnModel, artifact);
        }
        List<SubProcess> subProcesses = process.findFlowElementsOfType(SubProcess.class, true);
        if (subProcesses != null) {
            for (SubProcess subProcess : subProcesses) {
                for (Artifact subProcessArtifact : subProcess.getArtifacts()) {
                    drawArtifact(processDiagramCanvas, bpmnModel, subProcessArtifact);
                }
            }
        }
    }
    return processDiagramCanvas;
}
Also used : EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Lane(org.activiti.bpmn.model.Lane) Pool(org.activiti.bpmn.model.Pool) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) Artifact(org.activiti.bpmn.model.Artifact) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 2 with Artifact

use of org.activiti.bpmn.model.Artifact 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();
        }
        ErrorExport.writeError(model, xtw);
        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) AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) 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 3 with Artifact

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

the class BpmnAutoLayout method layout.

protected void layout(FlowElementsContainer flowElementsContainer) {
    graph = new mxGraph();
    cellParent = graph.getDefaultParent();
    graph.getModel().beginUpdate();
    // Subprocesses are handled in a new instance of BpmnAutoLayout, hence they instantiations of new maps here.
    handledFlowElements = new HashMap<String, FlowElement>();
    handledArtifacts = new HashMap<String, Artifact>();
    generatedVertices = new HashMap<String, Object>();
    generatedSequenceFlowEdges = new HashMap<String, Object>();
    generatedAssociationEdges = new HashMap<String, Object>();
    // Associations are gathered and processed afterwards, because we must be sure we already found source and target
    associations = new HashMap<String, Association>();
    // Text Annotations are gathered and processed afterwards, because we must be sure we already found the parent.
    textAnnotations = new HashMap<String, TextAnnotation>();
    // Sequence flow are gathered and processed afterwards,because we mustbe sure we already found source and target
    sequenceFlows = new HashMap<String, SequenceFlow>();
    // Boundary events are gathered and processed afterwards, because we must be sure we have its parent
    boundaryEvents = new ArrayList<BoundaryEvent>();
    // Process all elements
    for (FlowElement flowElement : flowElementsContainer.getFlowElements()) {
        if (flowElement instanceof SequenceFlow) {
            handleSequenceFlow((SequenceFlow) flowElement);
        } else if (flowElement instanceof Event) {
            handleEvent(flowElement);
        } else if (flowElement instanceof Gateway) {
            createGatewayVertex(flowElement);
        } else if (flowElement instanceof Task || flowElement instanceof CallActivity) {
            handleActivity(flowElement);
        } else if (flowElement instanceof SubProcess) {
            handleSubProcess(flowElement);
        }
        handledFlowElements.put(flowElement.getId(), flowElement);
    }
    // process artifacts
    for (Artifact artifact : flowElementsContainer.getArtifacts()) {
        if (artifact instanceof Association) {
            handleAssociation((Association) artifact);
        } else if (artifact instanceof TextAnnotation) {
            handleTextAnnotation((TextAnnotation) artifact);
        }
        handledArtifacts.put(artifact.getId(), artifact);
    }
    // Process gathered elements
    handleBoundaryEvents();
    handleSequenceFlow();
    handleAssociations();
    // All elements are now put in the graph. Let's layout them!
    CustomLayout layout = new CustomLayout(graph, SwingConstants.WEST);
    layout.setIntraCellSpacing(100.0);
    layout.setResizeParent(true);
    layout.setFineTuning(true);
    layout.setParentBorder(20);
    layout.setMoveParent(true);
    layout.setDisableEdgeStyle(false);
    layout.setUseBoundingBox(true);
    layout.execute(graph.getDefaultParent());
    graph.getModel().endUpdate();
    generateDiagramInterchangeElements();
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) Task(org.activiti.bpmn.model.Task) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) com.mxgraph.view.mxGraph(com.mxgraph.view.mxGraph) CallActivity(org.activiti.bpmn.model.CallActivity) Artifact(org.activiti.bpmn.model.Artifact) Association(org.activiti.bpmn.model.Association) FlowElement(org.activiti.bpmn.model.FlowElement) Gateway(org.activiti.bpmn.model.Gateway) Event(org.activiti.bpmn.model.Event) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) DataObject(org.activiti.bpmn.model.DataObject) TextAnnotation(org.activiti.bpmn.model.TextAnnotation)

Example 4 with Artifact

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

the class DefaultProcessDiagramGenerator method generateProcessDiagram.

protected DefaultProcessDiagramCanvas generateProcessDiagram(BpmnModel bpmnModel, List<String> highLightedActivities, List<String> highLightedFlows, String activityFontName, String labelFontName, String annotationFontName) {
    prepareBpmnModel(bpmnModel);
    DefaultProcessDiagramCanvas processDiagramCanvas = initProcessDiagramCanvas(bpmnModel, activityFontName, labelFontName, annotationFontName);
    // Draw pool shape, if process is participant in collaboration
    for (Pool pool : bpmnModel.getPools()) {
        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
        processDiagramCanvas.drawPoolOrLane(pool.getId(), pool.getName(), graphicInfo);
    }
    // Draw lanes
    for (Process process : bpmnModel.getProcesses()) {
        for (Lane lane : process.getLanes()) {
            GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(lane.getId());
            processDiagramCanvas.drawPoolOrLane(lane.getId(), lane.getName(), graphicInfo);
        }
    }
    // Draw activities and their sequence-flows
    for (Process process : bpmnModel.getProcesses()) {
        for (FlowNode flowNode : process.findFlowElementsOfType(FlowNode.class)) {
            drawActivity(processDiagramCanvas, bpmnModel, flowNode, highLightedActivities, highLightedFlows);
        }
    }
    // Draw artifacts
    for (Process process : bpmnModel.getProcesses()) {
        for (Artifact artifact : process.getArtifacts()) {
            drawArtifact(processDiagramCanvas, bpmnModel, artifact);
        }
        List<SubProcess> subProcesses = process.findFlowElementsOfType(SubProcess.class, true);
        if (subProcesses != null) {
            for (SubProcess subProcess : subProcesses) {
                for (Artifact subProcessArtifact : subProcess.getArtifacts()) {
                    drawArtifact(processDiagramCanvas, bpmnModel, subProcessArtifact);
                }
            }
        }
    }
    return processDiagramCanvas;
}
Also used : EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Lane(org.activiti.bpmn.model.Lane) Pool(org.activiti.bpmn.model.Pool) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) Artifact(org.activiti.bpmn.model.Artifact) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 5 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 activityFontName, String labelFontName, String annotationFontName) {
    // 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());
        if (flowNodeGraphicInfo == null) {
            continue;
        }
        // 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());
            if (graphicInfo != null) {
                // 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, activityFontName, labelFontName, annotationFontName);
}
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)

Aggregations

Artifact (org.activiti.bpmn.model.Artifact)11 SubProcess (org.activiti.bpmn.model.SubProcess)11 Process (org.activiti.bpmn.model.Process)8 FlowElement (org.activiti.bpmn.model.FlowElement)7 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)6 FlowNode (org.activiti.bpmn.model.FlowNode)6 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)5 Lane (org.activiti.bpmn.model.Lane)5 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)5 Pool (org.activiti.bpmn.model.Pool)4 XMLException (org.activiti.bpmn.exceptions.XMLException)3 Activity (org.activiti.bpmn.model.Activity)3 Gateway (org.activiti.bpmn.model.Gateway)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 AdhocSubProcess (org.activiti.bpmn.model.AdhocSubProcess)2 Association (org.activiti.bpmn.model.Association)2 BaseElement (org.activiti.bpmn.model.BaseElement)2