Search in sources :

Example 1 with Bpmn2JsonUnmarshaller

use of org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller 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)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Definitions (org.eclipse.bpmn2.Definitions)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)1 Bpmn2JsonUnmarshaller (org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller)1 JBPMBpmn2ResourceImpl (org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl)1