Search in sources :

Example 41 with Definitions

use of org.kie.dmn.model.v1_1.Definitions in project kie-wb-common by kiegroup.

the class DefaultProfileImpl method createMarshaller.

public IDiagramMarshaller createMarshaller() {
    return new IDiagramMarshaller() {

        public String parseModel(String jsonModel, String preProcessingData) {
            Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
            // Definitions def;
            Resource res;
            try {
                res = unmarshaller.unmarshall(jsonModel, preProcessingData);
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                Map saveMap = new HashMap();
                saveMap.put(XMLResource.OPTION_ENCODING, "UTF-8");
                saveMap.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
                saveMap.put(XMLResource.OPTION_DISABLE_NOTIFY, true);
                saveMap.put(XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
                res.save(outputStream, saveMap);
                return outputStream.toString();
            } catch (JsonParseException e) {
                _logger.error(e.getMessage(), e);
            } catch (IOException e) {
                _logger.error(e.getMessage(), e);
            }
            return "";
        }

        public Definitions getDefinitions(String jsonModel, String preProcessingData) {
            try {
                Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
                JBPMBpmn2ResourceImpl res = (JBPMBpmn2ResourceImpl) unmarshaller.unmarshall(jsonModel, preProcessingData);
                return (Definitions) res.getContents().get(0);
            } catch (JsonParseException e) {
                _logger.error(e.getMessage(), e);
            } catch (IOException e) {
                _logger.error(e.getMessage(), e);
            }
            return null;
        }

        public Resource getResource(String jsonModel, String preProcessingData) {
            try {
                Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
                return (JBPMBpmn2ResourceImpl) unmarshaller.unmarshall(jsonModel, preProcessingData);
            } catch (JsonParseException e) {
                _logger.error(e.getMessage(), e);
            } catch (IOException e) {
                _logger.error(e.getMessage(), e);
            }
            return null;
        }
    };
}
Also used : Bpmn2JsonUnmarshaller(org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JBPMBpmn2ResourceImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl) Definitions(org.eclipse.bpmn2.Definitions) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 42 with Definitions

use of org.kie.dmn.model.v1_1.Definitions in project kie-wb-common by kiegroup.

the class JBPMXMLSaveImpl method traverse.

@Override
public void traverse(List<? extends EObject> contents) {
    for (EObject e : contents) {
        if (e instanceof Definitions) {
            List<RootElement> roots = ((Definitions) e).getRootElements();
            Process p = null;
            for (RootElement root : roots) {
                if (root instanceof Process) {
                    p = (Process) root;
                }
            }
            if (p != null) {
                ((Definitions) e).getRootElements().remove(p);
                ((Definitions) e).getRootElements().add(p);
            }
        }
    }
    super.traverse(contents);
}
Also used : RootElement(org.eclipse.bpmn2.RootElement) EObject(org.eclipse.emf.ecore.EObject) Definitions(org.eclipse.bpmn2.Definitions) Process(org.eclipse.bpmn2.Process)

Example 43 with Definitions

use of org.kie.dmn.model.v1_1.Definitions in project kie-wb-common by kiegroup.

the class Bpmn2UnMarshaller method unmarshall.

public Graph unmarshall(final String content) throws IOException {
    final XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://" + UUID.uuid() + ".xml"));
    outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    outResource.setEncoding("UTF-8");
    final Map<String, Object> options = new HashMap<String, Object>();
    options.put(XMLResource.OPTION_ENCODING, "UTF-8");
    outResource.load(new BufferedInputStream(new ByteArrayInputStream(content.getBytes("UTF-8"))), options);
    final DocumentRoot root = (DocumentRoot) outResource.getContents().get(0);
    final Definitions definitions = root.getDefinitions();
    return unmarshall(definitions, null);
}
Also used : HashMap(java.util.HashMap) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) Definitions(org.eclipse.bpmn2.Definitions) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 44 with Definitions

use of org.kie.dmn.model.v1_1.Definitions in project kie-wb-common by kiegroup.

the class BPMNDiagramMarshallerTest method testMarshallProcessProperties.

@Test
public void testMarshallProcessProperties() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_PROCESSPROPERTIES);
    JBPMBpmn2ResourceImpl resource = tested.marshallToBpmn2Resource(diagram);
    String result = tested.marshall(diagram);
    assertDiagram(result, 1, 3, 2);
    Definitions definitions = (Definitions) resource.getContents().get(0);
    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"));
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) JBPMBpmn2ResourceImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl) Definitions(org.eclipse.bpmn2.Definitions) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Process(org.eclipse.bpmn2.Process) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 45 with Definitions

use of org.kie.dmn.model.v1_1.Definitions in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method test_diamond.

@Test
public void test_diamond() throws IOException {
    // round trip test
    roundTripUnmarshalThenMarshalUnmarshal(this.getClass().getResourceAsStream("/diamond.dmn"), this::checkDiamongGraph);
    // additionally, check the marshalled is still DMN executable as expected
    DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
    Graph<?, ?> g = m.unmarshall(null, this.getClass().getResourceAsStream("/diamond.dmn"));
    DiagramImpl diagram = new DiagramImpl("", null);
    diagram.setGraph(g);
    String mString = m.marshall(diagram);
    final KieServices ks = KieServices.Factory.get();
    final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test_diamond", "1.0"), ks.getResources().newByteArrayResource(mString.getBytes()).setTargetPath("src/main/resources/diamond.dmn"));
    final DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    DMNModel diamondModel = runtime.getModel("http://www.trisotech.com/definitions/_8afa6c24-55c8-43cf-8a02-fdde7fc5d1f2", "three decisions in a diamond shape");
    DMNContext dmnContext = runtime.newContext();
    dmnContext.set("My Name", "John Doe");
    DMNResult dmnResult = runtime.evaluateAll(diamondModel, dmnContext);
    assertFalse(dmnResult.getMessages().toString(), dmnResult.hasErrors());
    DMNContext result = dmnResult.getContext();
    assertEquals("Hello, John Doe.", result.get("My Decision"));
    // additionally, check DMN DD/DI for version 1.1
    org.kie.dmn.api.marshalling.v1_1.DMNMarshaller dmnMarshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new DDExtensionsRegister()));
    Definitions definitions = dmnMarshaller.unmarshal(mString);
    assertNotNull(definitions.getExtensionElements());
    assertNotNull(definitions.getExtensionElements().getAny());
    assertEquals(1, definitions.getExtensionElements().getAny().size());
    org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram ddRoot = (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram) definitions.getExtensionElements().getAny().get(0);
    DMNShape myname = findShapeByDMNI(ddRoot, "_4cd17e52-6253-41d6-820d-5824bf5197f3");
    assertBounds(500, 500, 100, 50, myname.getBounds());
    assertColor(255, 255, 255, myname.getBgColor());
    assertColor(0, 0, 0, myname.getBorderColor());
    assertEquals(0.5, myname.getBorderSize().getValue(), 0);
    assertDMNStyle("Open Sans", 24, 1, 255, 0, 0, myname.getFontStyle());
    DMNShape prefix = findShapeByDMNI(ddRoot, "_e920f38a-293c-41b8-adb3-69d0dc184fab");
    assertBounds(300, 400, 100, 50, prefix.getBounds());
    assertColor(0, 253, 25, prefix.getBgColor());
    assertColor(253, 0, 0, prefix.getBorderColor());
    assertEquals(1, prefix.getBorderSize().getValue(), 0);
    assertDMNStyle("Times New Roman", 8, 2.5, 70, 60, 50, prefix.getFontStyle());
    DMNShape postfix = findShapeByDMNI(ddRoot, "_f49f9c34-29d5-4e72-91d2-f4f92117c8da");
    assertBounds(700, 400, 100, 50, postfix.getBounds());
    assertColor(247, 255, 0, postfix.getBgColor());
    assertColor(0, 51, 255, postfix.getBorderColor());
    assertEquals(2, postfix.getBorderSize().getValue(), 0);
    assertDMNStyle("Arial", 10, 1.5, 50, 60, 70, postfix.getFontStyle());
    DMNShape mydecision = findShapeByDMNI(ddRoot, "_9b061fc3-8109-42e2-9fe4-fc39c90b654e");
    assertBounds(487.5, 275, 125, 75, mydecision.getBounds());
    assertColor(255, 255, 255, mydecision.getBgColor());
    assertColor(0, 0, 0, mydecision.getBorderColor());
    assertEquals(0.5, mydecision.getBorderSize().getValue(), 0);
    assertDMNStyle("Monospaced", 32, 3.5, 55, 66, 77, mydecision.getFontStyle());
}
Also used : KieServices(org.kie.api.KieServices) Matchers.anyString(org.mockito.Matchers.anyString) DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) DMNResult(org.kie.dmn.api.core.DMNResult) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) Definitions(org.kie.dmn.model.v1_1.Definitions) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DDExtensionsRegister(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DDExtensionsRegister) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)43 Definitions (org.eclipse.bpmn2.Definitions)42 Definitions (org.kie.dmn.model.api.Definitions)32 TDefinitions (org.kie.dmn.model.v1_1.TDefinitions)31 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)28 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)28 List (java.util.List)27 DMNResult (org.kie.dmn.api.core.DMNResult)27 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)27 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)23 Collectors (java.util.stream.Collectors)22 DMNModel (org.kie.dmn.api.core.DMNModel)22 Map (java.util.Map)21 Logger (org.slf4j.Logger)21 LoggerFactory (org.slf4j.LoggerFactory)21 Arrays (java.util.Arrays)20 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)20 Collection (java.util.Collection)19 Collections (java.util.Collections)19