Search in sources :

Example 1 with Artifact

use of org.eclipse.bpmn2.Artifact in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method findOutgoingAssociation.

protected Association findOutgoingAssociation(BPMNPlane plane, BaseElement baseElement) {
    Association result = _diagramAssociations.get(baseElement.getId());
    if (result != null) {
        return result;
    }
    if (!(plane.getBpmnElement() instanceof Process)) {
        throw new IllegalArgumentException("Don't know how to get associations from a non-Process Diagram");
    }
    Process process = (Process) plane.getBpmnElement();
    for (Artifact artifact : process.getArtifacts()) {
        if (artifact instanceof Association) {
            Association association = (Association) artifact;
            if (association.getSourceRef() == baseElement) {
                _diagramAssociations.put(baseElement.getId(), association);
                return association;
            }
        }
    }
    return null;
}
Also used : Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) Artifact(org.eclipse.bpmn2.Artifact)

Example 2 with Artifact

use of org.eclipse.bpmn2.Artifact in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallDataObject.

protected void marshallDataObject(DataObject dataObject, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
    Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties);
    putDocumentationProperty(dataObject, properties);
    if (dataObject.getName() != null && dataObject.getName().length() > 0) {
        properties.put(NAME, StringEscapeUtils.unescapeXml(dataObject.getName()));
    } else {
        // we need a name, use id instead
        properties.put(NAME, dataObject.getId());
    }
    // overwrite name if elementname extension element is present
    String elementName = Utils.getMetaDataValue(dataObject.getExtensionValues(), "elementname");
    if (elementName != null) {
        properties.put(NAME, elementName);
    }
    if (dataObject.getItemSubjectRef().getStructureRef() != null && dataObject.getItemSubjectRef().getStructureRef().length() > 0) {
        if (defaultTypesList.contains(dataObject.getItemSubjectRef().getStructureRef())) {
            properties.put(STANDARDTYPE, dataObject.getItemSubjectRef().getStructureRef());
        } else {
            properties.put(CUSTOMTYPE, dataObject.getItemSubjectRef().getStructureRef());
        }
    }
    Association outgoingAssociaton = findOutgoingAssociation(plane, dataObject);
    Association incomingAssociation = null;
    Process process = (Process) plane.getBpmnElement();
    for (Artifact artifact : process.getArtifacts()) {
        if (artifact instanceof Association) {
            Association association = (Association) artifact;
            if (association.getTargetRef() == dataObject) {
                incomingAssociation = association;
            }
        }
    }
    if (outgoingAssociaton != null && incomingAssociation == null) {
        properties.put(INPUT_OUTPUT, "Input");
    }
    if (outgoingAssociaton == null && incomingAssociation != null) {
        properties.put(INPUT_OUTPUT, "Output");
    }
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    generator.writeObjectField("id", "DataObject");
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    List<Association> associations = findOutgoingAssociations(plane, dataObject);
    if (associations != null) {
        for (Association as : associations) {
            generator.writeStartObject();
            generator.writeObjectField("resourceId", as.getId());
            generator.writeEndObject();
        }
    }
    generator.writeEndArray();
    Bounds bounds = ((BPMNShape) findDiagramElement(plane, dataObject)).getBounds();
    generator.writeObjectFieldStart("bounds");
    generator.writeObjectFieldStart("lowerRight");
    generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
    generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
    generator.writeEndObject();
    generator.writeObjectFieldStart("upperLeft");
    generator.writeObjectField("x", bounds.getX() - xOffset);
    generator.writeObjectField("y", bounds.getY() - yOffset);
    generator.writeEndObject();
    generator.writeEndObject();
}
Also used : Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) Bounds(org.eclipse.dd.dc.Bounds) DataObject(org.eclipse.bpmn2.DataObject) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Artifact(org.eclipse.bpmn2.Artifact) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with Artifact

use of org.eclipse.bpmn2.Artifact in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallProcess.

protected void marshallProcess(Process process, Definitions def, JsonGenerator generator, String preProcessingData) throws JsonGenerationException, IOException {
    BPMNPlane plane = null;
    for (BPMNDiagram d : def.getDiagrams()) {
        if (d != null) {
            BPMNPlane p = d.getPlane();
            if (p != null) {
                if (p.getBpmnElement() == process) {
                    plane = p;
                    break;
                }
            }
        }
    }
    if (plane == null) {
        throw new IllegalArgumentException("Could not find BPMNDI information");
    }
    generator.writeArrayFieldStart("childShapes");
    List<String> laneFlowElementsIds = new ArrayList<String>();
    for (LaneSet laneSet : process.getLaneSets()) {
        for (Lane lane : laneSet.getLanes()) {
            // we only want to marshall lanes if we have the bpmndi info for them!
            if (findDiagramElement(plane, lane) != null) {
                laneFlowElementsIds.addAll(marshallLanes(lane, plane, generator, 0, 0, preProcessingData, def));
            }
        }
    }
    for (FlowElement flowElement : process.getFlowElements()) {
        if (!laneFlowElementsIds.contains(flowElement.getId())) {
            marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def);
        }
    }
    for (Artifact artifact : process.getArtifacts()) {
        marshallArtifact(artifact, plane, generator, 0, 0, preProcessingData, def);
    }
    generator.writeEndArray();
}
Also used : BPMNDiagram(org.eclipse.bpmn2.di.BPMNDiagram) FlowElement(org.eclipse.bpmn2.FlowElement) ArrayList(java.util.ArrayList) Lane(org.eclipse.bpmn2.Lane) LaneSet(org.eclipse.bpmn2.LaneSet) BPMNPlane(org.eclipse.bpmn2.di.BPMNPlane) Artifact(org.eclipse.bpmn2.Artifact)

Example 4 with Artifact

use of org.eclipse.bpmn2.Artifact in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method findOutgoingAssociations.

protected List<Association> findOutgoingAssociations(BPMNPlane plane, BaseElement baseElement) {
    List<Association> retList = new ArrayList<Association>();
    if (!(plane.getBpmnElement() instanceof Process)) {
        throw new IllegalArgumentException("Don't know how to get associations from a non-Process Diagram");
    }
    Process process = (Process) plane.getBpmnElement();
    for (Artifact artifact : process.getArtifacts()) {
        if (artifact instanceof Association) {
            Association association = (Association) artifact;
            if (association.getSourceRef() == baseElement) {
                retList.add(association);
            }
        }
    }
    return retList;
}
Also used : Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) ArrayList(java.util.ArrayList) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) Artifact(org.eclipse.bpmn2.Artifact)

Example 5 with Artifact

use of org.eclipse.bpmn2.Artifact in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method createSubProcessDiagram.

private void createSubProcessDiagram(BPMNPlane plane, FlowElement flowElement, BpmnDiFactory factory) {
    SubProcess sp = (SubProcess) flowElement;
    for (FlowElement subProcessFlowElement : sp.getFlowElements()) {
        if (subProcessFlowElement instanceof SubProcess) {
            createBpmnShapeForElement(factory, plane, subProcessFlowElement);
            createSubProcessDiagram(plane, subProcessFlowElement, factory);
        } else if (subProcessFlowElement instanceof FlowNode) {
            createBpmnShapeForElement(factory, plane, subProcessFlowElement);
            if (subProcessFlowElement instanceof BoundaryEvent) {
                createDockersForBoundaryEvent((BoundaryEvent) subProcessFlowElement);
            }
        } else if (subProcessFlowElement instanceof SequenceFlow) {
            createBpmnEdgeForSequenceFlow(factory, plane, (SequenceFlow) subProcessFlowElement);
        }
    }
    if (sp.getArtifacts() != null) {
        List<Association> incompleteAssociations = new ArrayList<Association>();
        for (Artifact artifact : sp.getArtifacts()) {
            // if (artifact instanceof TextAnnotation || artifact instanceof Group) {
            if (artifact instanceof Group) {
                createBpmnShapeForElement(factory, plane, artifact);
            }
            if (artifact instanceof Association) {
                Association association = (Association) artifact;
                if (association.getSourceRef() != null && association.getTargetRef() != null) {
                    createBpmnEdgeForAssociation(factory, plane, association);
                } else {
                    incompleteAssociations.add(association);
                }
            }
        }
        if (!incompleteAssociations.isEmpty()) {
            for (Association incompleteAssociation : incompleteAssociations) {
                sp.getArtifacts().remove(incompleteAssociation);
            }
        }
    }
}
Also used : AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Group(org.eclipse.bpmn2.Group) Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) FlowElement(org.eclipse.bpmn2.FlowElement) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) Artifact(org.eclipse.bpmn2.Artifact) FlowNode(org.eclipse.bpmn2.FlowNode)

Aggregations

Artifact (org.eclipse.bpmn2.Artifact)12 SubProcess (org.eclipse.bpmn2.SubProcess)10 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)9 Process (org.eclipse.bpmn2.Process)9 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)8 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)8 ArrayList (java.util.ArrayList)7 Association (org.eclipse.bpmn2.Association)7 FlowElement (org.eclipse.bpmn2.FlowElement)7 DataObject (org.eclipse.bpmn2.DataObject)5 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)5 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)4 RootElement (org.eclipse.bpmn2.RootElement)4 FlowNode (org.eclipse.bpmn2.FlowNode)3 Group (org.eclipse.bpmn2.Group)3 Lane (org.eclipse.bpmn2.Lane)3 Bounds (org.eclipse.dd.dc.Bounds)3 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2