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);
}
}
}
Aggregations