Search in sources :

Example 1 with BaseConverterFactory

use of org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BaseConverterFactory 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

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 BpmnNode (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.BpmnNode)1 DefinitionResolver (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.DefinitionResolver)1 GraphBuilder (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.GraphBuilder)1 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)1 Graph (org.kie.workbench.common.stunner.core.graph.Graph)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)1