Search in sources :

Example 1 with BPMNDiagram

use of org.eclipse.bpmn2.di.BPMNDiagram 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 2 with BPMNDiagram

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

the class Bpmn2JsonMarshaller method marshallDefinitions.

protected void marshallDefinitions(Definitions def, JsonGenerator generator, String preProcessingData) throws JsonGenerationException, IOException {
    try {
        generator.writeStartObject();
        generator.writeObjectField("resourceId", def.getId());
        /**
         * "properties":{"name":"",
         * "documentation":"",
         * "auditing":"",
         * "monitoring":"",
         * "executable":"true",
         * "package":"com.sample",
         * "vardefs":"a,b,c,d",
         * "lanes" : "a,b,c",
         * "id":"",
         * "version":"",
         * "author":"",
         * "language":"",
         * "namespaces":"",
         * "targetnamespace":"",
         * "expressionlanguage":"",
         * "typelanguage":"",
         * "creationdate":"",
         * "modificationdate":""
         * }
         */
        Map<String, Object> props = new LinkedHashMap<String, Object>();
        props.put(NAMESPACES, "");
        // props.put("targetnamespace", def.getTargetNamespace());
        props.put(TARGETNAMESPACE, "http://www.omg.org/bpmn20");
        props.put(TYPELANGUAGE, def.getTypeLanguage());
        props.put(NAME, StringEscapeUtils.unescapeXml(def.getName()));
        props.put(ID, def.getId());
        props.put(EXPRESSIONLANGUAGE, def.getExpressionLanguage());
        // backwards compat for BZ 1048191
        putDocumentationProperty(def, props);
        for (RootElement rootElement : def.getRootElements()) {
            if (rootElement instanceof Process) {
                // have to wait for process node to finish properties and stencil marshalling
                props.put(EXECUTABLE, ((Process) rootElement).isIsExecutable() + "");
                props.put(ID, rootElement.getId());
                if (rootElement.getDocumentation() != null && rootElement.getDocumentation().size() > 0) {
                    props.put(DOCUMENTATION, rootElement.getDocumentation().get(0).getText());
                }
                Process pr = (Process) rootElement;
                if (pr.getName() != null && pr.getName().length() > 0) {
                    props.put(PROCESSN, StringEscapeUtils.unescapeXml(((Process) rootElement).getName()));
                }
                List<Property> processProperties = ((Process) rootElement).getProperties();
                if (processProperties != null && processProperties.size() > 0) {
                    String propVal = "";
                    for (int i = 0; i < processProperties.size(); i++) {
                        Property p = processProperties.get(i);
                        String pKPI = Utils.getMetaDataValue(p.getExtensionValues(), "customKPI");
                        propVal += p.getId();
                        // check the structureRef value
                        if (p.getItemSubjectRef() != null && p.getItemSubjectRef().getStructureRef() != null) {
                            propVal += ":" + p.getItemSubjectRef().getStructureRef();
                        }
                        if (pKPI != null && pKPI.length() > 0) {
                            propVal += ":" + pKPI;
                        }
                        if (i != processProperties.size() - 1) {
                            propVal += ",";
                        }
                    }
                    props.put("vardefs", propVal);
                }
                // packageName and version and adHoc are jbpm-specific extension attribute
                Iterator<FeatureMap.Entry> iter = ((Process) rootElement).getAnyAttribute().iterator();
                while (iter.hasNext()) {
                    FeatureMap.Entry entry = iter.next();
                    if (entry.getEStructuralFeature().getName().equals("packageName")) {
                        props.put(PACKAGE, entry.getValue());
                    }
                    if (entry.getEStructuralFeature().getName().equals("version")) {
                        props.put(VERSION, entry.getValue());
                    }
                    if (entry.getEStructuralFeature().getName().equals("adHoc")) {
                        props.put(ADHOCPROCESS, entry.getValue());
                    }
                }
                // process imports, custom description and globals extension elements
                String allImports = "";
                if ((rootElement).getExtensionValues() != null && (rootElement).getExtensionValues().size() > 0) {
                    String importsStr = "";
                    String globalsStr = "";
                    for (ExtensionAttributeValue extattrval : rootElement.getExtensionValues()) {
                        FeatureMap extensionElements = extattrval.getValue();
                        @SuppressWarnings("unchecked") List<ImportType> importExtensions = (List<ImportType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, true);
                        @SuppressWarnings("unchecked") List<GlobalType> globalExtensions = (List<GlobalType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, true);
                        List<MetaDataType> metadataExtensions = (List<MetaDataType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, true);
                        for (ImportType importType : importExtensions) {
                            importsStr += importType.getName();
                            importsStr += "|default,";
                        }
                        for (GlobalType globalType : globalExtensions) {
                            globalsStr += (globalType.getIdentifier() + ":" + globalType.getType());
                            globalsStr += ",";
                        }
                        for (MetaDataType metaType : metadataExtensions) {
                            props.put("customdescription", metaType.getMetaValue());
                        }
                    }
                    allImports += importsStr;
                    if (globalsStr.length() > 0) {
                        if (globalsStr.endsWith(",")) {
                            globalsStr = globalsStr.substring(0, globalsStr.length() - 1);
                        }
                        props.put(GLOBALS, globalsStr);
                    }
                }
                // definitions imports (wsdl)
                List<org.eclipse.bpmn2.Import> wsdlImports = def.getImports();
                if (wsdlImports != null) {
                    for (org.eclipse.bpmn2.Import imp : wsdlImports) {
                        allImports += imp.getLocation() + "|" + imp.getNamespace() + "|wsdl,";
                    }
                }
                if (allImports.endsWith(",")) {
                    allImports = allImports.substring(0, allImports.length() - 1);
                }
                props.put(IMPORTS, allImports);
                // simulation
                if (_simulationScenario != null && _simulationScenario.getScenarioParameters() != null) {
                    props.put(CURRENCY, _simulationScenario.getScenarioParameters().getBaseCurrencyUnit() == null ? "" : _simulationScenario.getScenarioParameters().getBaseCurrencyUnit());
                    props.put(TIMEUNIT, _simulationScenario.getScenarioParameters().getBaseTimeUnit().getName());
                }
                marshallProperties(props, generator);
                marshallStencil("BPMNDiagram", generator);
                linkSequenceFlows(((Process) rootElement).getFlowElements());
                marshallProcess((Process) rootElement, def, generator, preProcessingData);
            } else if (rootElement instanceof Interface) {
            // TODO
            } else if (rootElement instanceof ItemDefinition) {
            // TODO
            } else if (rootElement instanceof Resource) {
            // TODO
            } else if (rootElement instanceof Error) {
            // TODO
            } else if (rootElement instanceof Message) {
            // TODO
            } else if (rootElement instanceof Signal) {
            // TODO
            } else if (rootElement instanceof Escalation) {
            // TODO
            } else if (rootElement instanceof Collaboration) {
            } else {
                _logger.warn("Unknown root element " + rootElement + ". This element will not be parsed.");
            }
        }
        generator.writeObjectFieldStart("stencilset");
        generator.writeObjectField("url", this.profile.getStencilSetURL());
        generator.writeObjectField("namespace", this.profile.getStencilSetNamespaceURL());
        generator.writeEndObject();
        generator.writeArrayFieldStart("ssextensions");
        generator.writeObject(this.profile.getStencilSetExtensionURL());
        generator.writeEndArray();
        generator.writeEndObject();
    } finally {
        _diagramElements.clear();
    }
}
Also used : Message(org.eclipse.bpmn2.Message) Escalation(org.eclipse.bpmn2.Escalation) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) Signal(org.eclipse.bpmn2.Signal) MetaDataType(org.jboss.drools.MetaDataType) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) Property(org.eclipse.bpmn2.Property) ImportType(org.jboss.drools.ImportType) Resource(org.eclipse.bpmn2.Resource) Error(org.eclipse.bpmn2.Error) Point(org.eclipse.dd.dc.Point) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) RootElement(org.eclipse.bpmn2.RootElement) Collaboration(org.eclipse.bpmn2.Collaboration) DataObject(org.eclipse.bpmn2.DataObject) Interface(org.eclipse.bpmn2.Interface) GlobalType(org.jboss.drools.GlobalType)

Example 3 with BPMNDiagram

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

the class Bpmn2JsonUnmarshaller method orderDiagramElements.

private void orderDiagramElements(Definitions def) {
    if (zOrderEnabled) {
        if (def.getDiagrams() != null) {
            for (BPMNDiagram diagram : def.getDiagrams()) {
                if (diagram != null) {
                    _logger.debug("Sorting diagram elements using DIZorderComparator");
                    BPMNPlane plane = diagram.getPlane();
                    List<DiagramElement> unsortedElements = new ArrayList<DiagramElement>(plane.getPlaneElement());
                    plane.getPlaneElement().clear();
                    Collections.sort(unsortedElements, new DIZorderComparator());
                    plane.getPlaneElement().addAll(unsortedElements);
                    diagram.setPlane(plane);
                }
            }
        }
    }
}
Also used : DiagramElement(org.eclipse.dd.di.DiagramElement) BPMNDiagram(org.eclipse.bpmn2.di.BPMNDiagram) ArrayList(java.util.ArrayList) BPMNPlane(org.eclipse.bpmn2.di.BPMNPlane)

Example 4 with BPMNDiagram

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

the class DefinitionResolverTest method testCalculateResolutionFactor.

@Test
public void testCalculateResolutionFactor() {
    BPMNDiagram diagram = mock(BPMNDiagram.class);
    when(diagram.getResolution()).thenReturn(0f);
    double factor = DefinitionResolver.calculateResolutionFactor(diagram);
    assertEquals(1d, factor, 0d);
    when(diagram.getResolution()).thenReturn(250f);
    factor = DefinitionResolver.calculateResolutionFactor(diagram);
    assertEquals(0.45d, factor, 0d);
}
Also used : BPMNDiagram(org.eclipse.bpmn2.di.BPMNDiagram) Test(org.junit.Test)

Example 5 with BPMNDiagram

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

the class GraphBuilderTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    when(diagram.getPlane()).thenReturn(plane);
    List<RootElement> rootElements = Collections.singletonList(process);
    List<BPMNDiagram> diagrams = Collections.singletonList(diagram);
    when(definitions.getId()).thenReturn(DIAGRAM_UUID);
    when(definitions.getRootElements()).thenReturn(rootElements);
    when(definitions.getDiagrams()).thenReturn(diagrams);
    when(definitions.getRelationships()).thenReturn(Collections.emptyList());
    definitionResolver = new DefinitionResolver(definitions, Collections.emptyList());
    StunnerTestingGraphBackendAPI api = StunnerTestingGraphBackendAPI.build(BPMNDefinitionSet.class, new BPMNTestDefinitionFactory());
    TypedFactoryManager typedFactoryManager = new TypedFactoryManager(api.getFactoryManager());
    Metadata metadata = new MetadataImpl.MetadataImplBuilder(BindableAdapterUtils.getDefinitionSetId(BPMNDefinitionSet.class)).build();
    Diagram<Graph<DefinitionSet, Node>, Metadata> diagram = api.getFactoryManager().newDiagram(definitionResolver.getDefinitions().getId(), BPMN_ID, metadata);
    graph = diagram.getGraph();
    graphBuilder = new GraphBuilder(graph, api.getDefinitionManager(), typedFactoryManager, api.getRuleManager(), api.commandFactory, api.commandManager);
}
Also used : TypedFactoryManager(org.kie.workbench.common.stunner.bpmn.backend.converters.TypedFactoryManager) BPMNTestDefinitionFactory(org.kie.workbench.common.stunner.bpmn.BPMNTestDefinitionFactory) StunnerTestingGraphBackendAPI(org.kie.workbench.common.stunner.core.backend.StunnerTestingGraphBackendAPI) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BPMNDiagram(org.eclipse.bpmn2.di.BPMNDiagram) RootElement(org.eclipse.bpmn2.RootElement) MetadataImpl(org.kie.workbench.common.stunner.core.diagram.MetadataImpl) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Before(org.junit.Before)

Aggregations

BPMNDiagram (org.eclipse.bpmn2.di.BPMNDiagram)16 Before (org.junit.Before)12 DefinitionResolver (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.DefinitionResolver)11 Definitions (org.eclipse.bpmn2.Definitions)8 RootElement (org.eclipse.bpmn2.RootElement)8 FlowElement (org.eclipse.bpmn2.FlowElement)6 BPMNDiagram (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram)6 Test (org.junit.Test)5 BPMNDiagramImpl (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl)5 ArrayList (java.util.ArrayList)4 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)4 TypedFactoryManager (org.kie.workbench.common.stunner.bpmn.backend.converters.TypedFactoryManager)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 Process (org.eclipse.bpmn2.Process)3 BPMNPlane (org.eclipse.bpmn2.di.BPMNPlane)3 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)3 Graph (org.kie.workbench.common.stunner.core.graph.Graph)3 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)2 Artifact (org.eclipse.bpmn2.Artifact)2