Search in sources :

Example 1 with DefinitionsConverter

use of org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshaller method marshall.

@Override
@SuppressWarnings("unchecked")
public String marshall(final Diagram<Graph, Metadata> diagram) throws IOException {
    LOG.debug("Starting diagram marshalling...");
    Bpmn2Resource resource = createBpmn2Resource();
    // we start converting from the root, then pull out the result
    DefinitionsConverter definitionsConverter = new DefinitionsConverter(diagram.getGraph());
    Definitions definitions = definitionsConverter.toDefinitions();
    resource.getContents().add(definitions);
    LOG.debug("Diagram marshalling completed successfully.");
    String outputString = renderToString(resource);
    LOG.trace(outputString);
    return outputString;
}
Also used : Bpmn2Resource(org.eclipse.bpmn2.util.Bpmn2Resource) Definitions(org.eclipse.bpmn2.Definitions) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter)

Example 2 with DefinitionsConverter

use of org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshallerTest method testMarshallProcessVariables.

@Test
public void testMarshallProcessVariables() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_PROCESSVARIABLES);
    String result = tested.marshall(diagram);
    assertDiagram(result, 1, 7, 7);
    Definitions definitions = new DefinitionsConverter(diagram.getGraph()).toDefinitions();
    assertNotNull(definitions);
    List<RootElement> rootElements = definitions.getRootElements();
    assertNotNull(rootElements);
    assertItemExists(rootElements, "_employeeItem", "java.lang.String");
    assertItemExists(rootElements, "_reasonItem", "java.lang.String");
    assertItemExists(rootElements, "_performanceItem", "java.lang.String");
    Process process = getProcess(definitions);
    assertNotNull(process);
    List<Property> properties = process.getProperties();
    assertNotNull(properties);
    assertNotNull(getProcessProperty(properties, "employee", "_employeeItem"));
    assertNotNull(getProcessProperty(properties, "reason", "_reasonItem"));
    assertNotNull(getProcessProperty(properties, "performance", "_performanceItem"));
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) RootElement(org.eclipse.bpmn2.RootElement) Definitions(org.eclipse.bpmn2.Definitions) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Process(org.eclipse.bpmn2.Process) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) Property(org.eclipse.bpmn2.Property) Test(org.junit.Test)

Example 3 with DefinitionsConverter

use of org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter in project kie-wb-common by kiegroup.

the class EmbeddedSubProcessTest method testMarshallEmbeddedCoords.

@Test
public void testMarshallEmbeddedCoords() throws Exception {
    final String BPMN_EMBEDDED_SUBPROCESS = "org/kie/workbench/common/stunner/bpmn/backend/service/diagram/embeddedSubprocess.bpmn";
    String END_EVENT = "shape__FF050977-4D13-47F1-8B9B-D68FDE208666";
    Diagram<Graph, Metadata> diagram = getSpecificDiagram(BPMN_EMBEDDED_SUBPROCESS);
    // we start converting from the root, then pull out the result
    DefinitionsConverter definitionsConverter = new DefinitionsConverter(diagram.getGraph());
    Definitions definitions = definitionsConverter.toDefinitions();
    List<DiagramElement> planeElement = definitions.getDiagrams().get(0).getPlane().getPlaneElement();
    BPMNShape diagramElement = planeElement.stream().filter(BPMNShape.class::isInstance).map(s -> (BPMNShape) s).filter(el -> el.getId().equals(END_EVENT)).findFirst().get();
    assertThat(diagramElement.getBounds().getX()).isEqualTo(885f);
    assertThat(diagramElement.getBounds().getY()).isEqualTo(143f);
}
Also used : DiagramElement(org.eclipse.dd.di.DiagramElement) ScriptTypeValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EmbeddedSubprocessExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.subProcess.execution.EmbeddedSubprocessExecutionSet) DiagramElement(org.eclipse.dd.di.DiagramElement) Test(org.junit.Test) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) EmbeddedSubprocess(org.kie.workbench.common.stunner.bpmn.definition.EmbeddedSubprocess) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Definitions(org.eclipse.bpmn2.Definitions) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Definitions(org.eclipse.bpmn2.Definitions) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) Test(org.junit.Test)

Example 4 with DefinitionsConverter

use of org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshallerTest method testMarshallUserTaskAssignments.

@Test
public void testMarshallUserTaskAssignments() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_USERTASKASSIGNMENTS);
    // JBPMBpmn2ResourceImpl resource = tested.marshallToBpmn2Resource(diagram);
    String result = tested.marshall(diagram);
    assertDiagram(result, 1, 7, 7);
    DefinitionsConverter definitionsConverter = new DefinitionsConverter(diagram.getGraph());
    Definitions definitions = definitionsConverter.toDefinitions();
    assertNotNull(definitions);
    Process process = getProcess(definitions);
    assertNotNull(process);
    org.eclipse.bpmn2.UserTask userTask = (org.eclipse.bpmn2.UserTask) getNamedFlowElement(process, org.eclipse.bpmn2.UserTask.class, "Self Evaluation");
    assertNotNull(userTask);
    DataInput dataInput = getDataInput(userTask, "reason");
    // this fails because of type
    validateDataInputOrOutput(dataInput, "_reasonInputX", "com.test.Reason", "_reasonInputXItem");
    DataOutput dataOutput = getDataOutput(userTask, "performance");
    validateDataInputOrOutput(dataOutput, "_performanceOutputX", "Object", "_performanceOutputXItem");
    ItemAwareElement sourceRef = getDataInputAssociationSourceRef(userTask, "reason");
    assertNotNull(sourceRef);
    ItemAwareElement targetRef = getDataInputAssociationTargetRef(userTask, "_reasonInputX");
    assertNotNull(targetRef);
    sourceRef = getDataOutputAssociationSourceRef(userTask, "_performanceOutputX");
    assertNotNull(sourceRef);
    targetRef = getDataOutputAssociationTargetRef(userTask, "performance");
    assertNotNull(targetRef);
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) Definitions(org.eclipse.bpmn2.Definitions) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) Process(org.eclipse.bpmn2.Process) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) DataInput(org.eclipse.bpmn2.DataInput) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Test(org.junit.Test)

Example 5 with DefinitionsConverter

use of org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshallerTest method testMarshallProcessProperties.

@Test
public void testMarshallProcessProperties() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_PROCESSPROPERTIES);
    String result = tested.marshall(diagram);
    assertDiagram(result, 1, 3, 2);
    Definitions definitions = new DefinitionsConverter(diagram.getGraph()).toDefinitions();
    assertNotNull(definitions);
    Process process = getProcess(definitions);
    assertNotNull(process);
    assertEquals("JDLProj.BPSimple", process.getId());
    assertEquals("BPSimple", process.getName());
    assertTrue(process.isIsExecutable());
    assertEquals("true", getProcessPropertyValue(process, "adHoc"));
    assertEquals("org.jbpm", getProcessPropertyValue(process, "packageName"));
    assertEquals("1.0", getProcessPropertyValue(process, "version"));
    assertNotNull(process.getDocumentation());
    assertFalse(process.getDocumentation().isEmpty());
    assertEquals("<![CDATA[This is a\nsimple\nprocess]]>", process.getDocumentation().get(0).getText());
    assertEquals("<![CDATA[This is the\nProcess\nInstance\nDescription]]>", getProcessExtensionValue(process, "customDescription"));
    assertEquals("<![CDATA[12/25/1983]]>", getProcessExtensionValue(process, "customSLADueDate"));
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Definitions(org.eclipse.bpmn2.Definitions) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Process(org.eclipse.bpmn2.Process) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) Test(org.junit.Test)

Aggregations

Definitions (org.eclipse.bpmn2.Definitions)8 DefinitionsConverter (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter)8 Test (org.junit.Test)6 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)6 Graph (org.kie.workbench.common.stunner.core.graph.Graph)6 Process (org.eclipse.bpmn2.Process)5 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)3 List (java.util.List)2 TestCase.assertEquals (junit.framework.TestCase.assertEquals)2 DataInput (org.eclipse.bpmn2.DataInput)2 Property (org.eclipse.bpmn2.Property)2 Bpmn2Resource (org.eclipse.bpmn2.util.Bpmn2Resource)2 BPMNDiagramMarshallerBaseTest (org.kie.workbench.common.stunner.bpmn.backend.service.diagram.marshalling.BPMNDiagramMarshallerBaseTest)2 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)2 HashSet (java.util.HashSet)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assignment (org.eclipse.bpmn2.Assignment)1 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)1 DataOutput (org.eclipse.bpmn2.DataOutput)1 FormalExpression (org.eclipse.bpmn2.FormalExpression)1