Search in sources :

Example 1 with GraphBuilder

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

the class BPMNDirectDiagramMarshaller method unmarshall.

@Override
public Graph<DefinitionSet, Node> unmarshall(final Metadata metadata, final InputStream inputStream) throws IOException {
    LOG.debug("Starting diagram unmarshalling...");
    // definition resolver provides utlities to access elements of the BPMN datamodel
    DefinitionResolver definitionResolver = new DefinitionResolver(parseDefinitions(inputStream));
    metadata.setCanvasRootUUID(definitionResolver.getDefinitions().getId());
    metadata.setTitle(definitionResolver.getProcess().getName());
    ConverterFactory converterFactory = new ConverterFactory(definitionResolver, typedFactoryManager);
    // perform actual conversion. Process is the root of the diagram
    BpmnNode diagramRoot = converterFactory.rootProcessConverter().convertProcess();
    LOG.debug("Diagram unmarshalling completed successfully.");
    // the root node contains all of the information
    // needed to build the entire graph (including parent/child relationships)
    // thus, we can now walk the graph to issue all the commands
    // to draw it on our canvas
    Diagram<Graph<DefinitionSet, Node>, Metadata> diagram = typedFactoryManager.newDiagram(definitionResolver.getDefinitions().getId(), BPMNDefinitionSet.class, metadata);
    GraphBuilder graphBuilder = new GraphBuilder(diagram.getGraph(), definitionManager, typedFactoryManager, ruleManager, commandFactory, commandManager);
    graphBuilder.render(diagramRoot);
    LOG.debug("Diagram drawing completed successfully.");
    return diagram.getGraph();
}
Also used : DefinitionResolver(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.DefinitionResolver) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) ConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.ConverterFactory) GraphBuilder(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.GraphBuilder) BpmnNode(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BpmnNode)

Example 2 with GraphBuilder

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

the class BaseDirectDiagramMarshaller method unmarshallWithValidation.

@Override
public MarshallingResponse<Graph> unmarshallWithValidation(MarshallingRequest<InputStream, Metadata> request) {
    final Metadata metadata = request.getMetadata();
    final InputStream inputStream = request.getInput();
    LOG.debug("Starting diagram unmarshalling...");
    DefinitionResolver definitionResolver;
    try {
        // definition resolver provides utlities to access elements of the BPMN datamodel
        final DefinitionsHandler definitionsHandler = parseDefinitions(inputStream);
        definitionResolver = new DefinitionResolver(definitionsHandler.getDefinitions(), workItemDefinitionService.execute(metadata), definitionsHandler.isJbpm(), request.getMode());
        metadata.setCanvasRootUUID(definitionResolver.getDefinitions().getId());
        metadata.setTitle(definitionResolver.getProcess().getName());
        BaseConverterFactory converterFactory = createToStunnerConverterFactory(definitionResolver, typedFactoryManager);
        // perform actual conversion. Process is the root of the diagram
        Result<BpmnNode> result = converterFactory.rootProcessConverter().convertProcess();
        BpmnNode diagramRoot = result.value();
        dataTypeCache.initCache(diagramRoot);
        LOG.debug("Diagram unmarshalling completed successfully.");
        // the root node contains all of the information
        // needed to build the entire graph (including parent/child relationships)
        // thus, we can now walk the graph to issue all the commands
        // to draw it on our canvas
        Diagram<Graph<DefinitionSet, Node>, Metadata> diagram = typedFactoryManager.newDiagram(definitionResolver.getDefinitions().getId(), getDefinitionSetClass(), metadata);
        Graph<DefinitionSet, Node> graph = diagram.getGraph();
        GraphBuilder graphBuilder = new GraphBuilder(graph, definitionManager, typedFactoryManager, ruleManager, commandFactory, commandManager);
        graphBuilder.render(diagramRoot);
        LOG.debug("Diagram drawing completed successfully for:" + request);
        return MarshallingResponse.builder().state(MarshallingResponse.State.SUCCESS).messages(result.messages()).result(graph).build();
    } catch (Exception e) {
        LOG.error("Marshalling error.", e);
        return MarshallingResponse.builder().state(MarshallingResponse.State.ERROR).addMessage(MarshallingMessage.builder().message(e.getMessage()).build()).build();
    } finally {
        try {
            inputStream.close();
        } catch (IOException e) {
            throw new RuntimeException("Error closing inputStream for: " + request, e);
        }
    }
}
Also used : DefinitionResolver(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.DefinitionResolver) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BpmnNode(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BpmnNode) Node(org.kie.workbench.common.stunner.core.graph.Node) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BpmnNode(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BpmnNode) IOException(java.io.IOException) BaseConverterFactory(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BaseConverterFactory) IOException(java.io.IOException) Graph(org.kie.workbench.common.stunner.core.graph.Graph) GraphBuilder(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.GraphBuilder) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)

Aggregations

BpmnNode (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BpmnNode)2 DefinitionResolver (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.DefinitionResolver)2 GraphBuilder (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.GraphBuilder)2 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)2 Graph (org.kie.workbench.common.stunner.core.graph.Graph)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BaseConverterFactory (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BaseConverterFactory)1 ConverterFactory (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.ConverterFactory)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)1