Search in sources :

Example 21 with Resource

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

the class BaseDirectDiagramMarshaller 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
    PropertyWriterFactory propertyWriterFactory = new PropertyWriterFactory();
    DefinitionsConverter definitionsConverter = new DefinitionsConverter(new ConverterFactory(new DefinitionsBuildingContext(diagram.getGraph(), getDiagramClass()), propertyWriterFactory), propertyWriterFactory);
    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 : JBPMBpmn2Resource(org.kie.workbench.common.stunner.bpmn.backend.resource.JBPMBpmn2Resource) Bpmn2Resource(org.eclipse.bpmn2.util.Bpmn2Resource) Definitions(org.eclipse.bpmn2.Definitions) DefinitionsBuildingContext(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsBuildingContext) ConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.ConverterFactory) BaseConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BaseConverterFactory) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) PropertyWriterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.PropertyWriterFactory)

Example 22 with Resource

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

the class BaseDirectDiagramMarshaller method parseDefinitions.

private static DefinitionsHandler parseDefinitions(final InputStream inputStream) throws IOException {
    DroolsPackageImpl.init();
    BpsimPackageImpl.init();
    final ResourceSet resourceSet = new ResourceSetImpl();
    Resource.Factory.Registry resourceFactoryRegistry = resourceSet.getResourceFactoryRegistry();
    resourceFactoryRegistry.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new JBPMBpmn2ResourceFactory());
    EPackage.Registry packageRegistry = resourceSet.getPackageRegistry();
    packageRegistry.put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
    packageRegistry.put("http://www.jboss.org/drools", DroolsPackage.eINSTANCE);
    final JBPMBpmn2Resource resource = (JBPMBpmn2Resource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    resource.getDefaultLoadOptions().put(JBPMBpmn2Resource.OPTION_ENCODING, "UTF-8");
    resource.setEncoding("UTF-8");
    final Map<String, Object> options = new HashMap<>();
    options.put(JBPMBpmn2Resource.OPTION_ENCODING, "UTF-8");
    options.put(JBPMBpmn2Resource.OPTION_DEFER_IDREF_RESOLUTION, true);
    options.put(JBPMBpmn2Resource.OPTION_DISABLE_NOTIFY, true);
    options.put(JBPMBpmn2Resource.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2Resource.OPTION_PROCESS_DANGLING_HREF_RECORD);
    try {
        resource.load(inputStream, options);
    } finally {
        inputStream.close();
    }
    final DocumentRoot root = (DocumentRoot) resource.getContents().get(0);
    return new DefinitionsHandler(root);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) HashMap(java.util.HashMap) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) LoggerFactory(org.slf4j.LoggerFactory) ConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.ConverterFactory) PropertyWriterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.PropertyWriterFactory) BaseConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BaseConverterFactory) JBPMBpmn2ResourceFactory(org.kie.workbench.common.stunner.bpmn.backend.resource.JBPMBpmn2ResourceFactory) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EPackage(org.eclipse.emf.ecore.EPackage) JBPMBpmn2Resource(org.kie.workbench.common.stunner.bpmn.backend.resource.JBPMBpmn2Resource) JBPMBpmn2ResourceFactory(org.kie.workbench.common.stunner.bpmn.backend.resource.JBPMBpmn2ResourceFactory)

Example 23 with Resource

use of org.eclipse.bpmn2.Resource 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)

Aggregations

Definitions (org.eclipse.bpmn2.Definitions)9 DocumentRoot (org.eclipse.bpmn2.DocumentRoot)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)6 Test (org.junit.Test)6 JBPMBpmn2ResourceImpl (org.kie.workbench.common.stunner.bpmn.backend.legacy.resource.JBPMBpmn2ResourceImpl)6 Process (org.eclipse.bpmn2.Process)5 HashMap (java.util.HashMap)4 Bpmn2Resource (org.eclipse.bpmn2.util.Bpmn2Resource)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)4 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)4 Graph (org.kie.workbench.common.stunner.core.graph.Graph)4 Resource (io.opencensus.proto.resource.v1.Resource)3 ArrayList (java.util.ArrayList)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IOException (java.io.IOException)2 URI (java.net.URI)2 LinkedHashMap (java.util.LinkedHashMap)2 DefaultValue (javax.ws.rs.DefaultValue)2