Search in sources :

Example 6 with JBPMBpmn2ResourceImpl

use of org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl 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 7 with JBPMBpmn2ResourceImpl

use of org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl 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 8 with JBPMBpmn2ResourceImpl

use of org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl in project kie-wb-common by kiegroup.

the class BaseDiagramMarshaller method parseDefinitions.

private Definitions parseDefinitions(final InputStream inputStream) throws IOException {
    try {
        DroolsPackageImpl.init();
        BpsimPackageImpl.init();
        final ResourceSet resourceSet = new ResourceSetImpl();
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new JBPMBpmn2ResourceFactoryImpl());
        resourceSet.getPackageRegistry().put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
        resourceSet.getPackageRegistry().put("http://www.jboss.org/drools", DroolsPackage.eINSTANCE);
        final JBPMBpmn2ResourceImpl resource = (JBPMBpmn2ResourceImpl) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
        resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
        resource.setEncoding("UTF-8");
        final Map<String, Object> options = new HashMap<String, Object>();
        options.put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
        options.put(JBPMBpmn2ResourceImpl.OPTION_DEFER_IDREF_RESOLUTION, true);
        options.put(JBPMBpmn2ResourceImpl.OPTION_DISABLE_NOTIFY, true);
        options.put(JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF_RECORD);
        resource.load(inputStream, options);
        final DocumentRoot root = (DocumentRoot) resource.getContents().get(0);
        return root.getDefinitions();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
    }
    return null;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) JBPMBpmn2ResourceImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl) HashMap(java.util.HashMap) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JBPMBpmn2ResourceFactoryImpl(org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl) IOException(java.io.IOException)

Aggregations

JBPMBpmn2ResourceImpl (org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl)8 Definitions (org.eclipse.bpmn2.Definitions)4 HashMap (java.util.HashMap)3 Process (org.eclipse.bpmn2.Process)3 Test (org.junit.Test)3 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)3 Graph (org.kie.workbench.common.stunner.core.graph.Graph)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 DocumentRoot (org.eclipse.bpmn2.DocumentRoot)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 JBPMBpmn2ResourceFactoryImpl (org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceFactoryImpl)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 DataInput (org.eclipse.bpmn2.DataInput)1 DataOutput (org.eclipse.bpmn2.DataOutput)1 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)1