Source:
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 { 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); Result<BpmnNode> result = converterFactory.rootProcessConverter().convertProcess(); BpmnNode diagramRoot = result.value().get(); LOG.debug("Diagram unmarshalling completed successfully."); 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."); LOG.warn("Marshalling Messages " + result.messages() .stream() .filter(Objects::nonNull) .map(MarshallingMessage::getMessage) .filter(Objects::nonNull).map(String::valueOf) .collect(Collectors.joining("\n"))); 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(); } }

Target:
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 { 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); Result<BpmnNode> result = converterFactory.rootProcessConverter().convertProcess(); BpmnNode diagramRoot = result.value(); LOG.debug("Diagram unmarshalling completed successfully."); 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); } } }