@ApiOperation(value="Retrieves process instance image", response=String.class, code=200) @ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process instance, image or Container Id not found") }) @GET @Path(PROCESS_INST_IMG_GET_URI) @Produces({MediaType.APPLICATION_SVG_XML}) public Response getProcessInstanceImage(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that process instance belongs to", required = true) @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of the process instance that image should be loaded for", required = true) @PathParam(PROCESS_INST_ID) Long procInstId) { Variant v = getVariant(headers); Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers); try { String svgString = imageServiceBase.getActiveProcessImage(containerId, procInstId); logger.debug("Returning OK response with content '{}'", svgString); return createResponse(svgString, v, Response.Status.OK, conversationIdHeader); } catch (ProcessInstanceNotFoundException e) { return notFound(MessageFormat.format("Not found", e.getMessage()), v, conversationIdHeader); } catch (IllegalArgumentException e) { return notFound("Image for process instance id " + procInstId + " not found", v, conversationIdHeader); } catch (Exception e) { logger.error("Unexpected error during processing {}", e.getMessage(), e); return internalServerError(MessageFormat.format("Unexpected error encountered", e.getMessage()), v, conversationIdHeader); } } }
public org.kie.server.api.model.instance.ProcessInstance getProcessInstanceById(long processInstanceId, boolean withVars) { ProcessInstanceDesc processInstanceDesc = runtimeDataService.getProcessInstanceById(processInstanceId); if (processInstanceDesc == null) { throw new ProcessInstanceNotFoundException("Could not find process instance with id " + processInstanceId); } org.kie.server.api.model.instance.ProcessInstance processInstance = convertToProcessInstance(processInstanceDesc); if (Boolean.TRUE.equals(withVars)) { Collection<VariableDesc> variableDescs = runtimeDataService.getVariablesCurrentState(processInstanceId); Map<String, Object> vars = new HashMap<String, Object>(); for (VariableDesc var : variableDescs) { vars.put(var.getVariableId(), var.getNewValue()); } processInstance.setVariables(vars); } return processInstance; }
public String getActiveProcessImage(String containerId, long procInstId) { ProcessInstanceDesc instance = dataService.getProcessInstanceById(procInstId); if (instance == null) { throw new ProcessInstanceNotFoundException("No instance found for process instance id " + procInstId); } String imageSVGString = null; // get SVG String byte[] imageSVG = getProcessImageAsBytes(instance.getDeploymentId(), instance.getProcessId()); if (imageSVG != null) { // find active nodes and modify image Map<String, String> subProcessLinks = new HashMap<>(); Collection<NodeInstanceDesc> activeLogs = dataService.getProcessInstanceHistoryActive(procInstId, new QueryContext(0, 1000)); Collection<NodeInstanceDesc> completedLogs = dataService.getProcessInstanceHistoryCompleted(procInstId, new QueryContext(0, 1000)); Map<Long, String> active = new HashMap<Long, String>(); List<String> completed = new ArrayList<String>(); for (NodeInstanceDesc activeNode : activeLogs) { active.put(activeNode.getId(), activeNode.getNodeId()); populateSubProcessLink(containerId, activeNode, subProcessLinks); } for (NodeInstanceDesc completeNode : completedLogs) { completed.add(completeNode.getNodeId()); active.remove(completeNode.getId()); populateSubProcessLink(containerId, completeNode, subProcessLinks); } ByteArrayInputStream svgStream = new ByteArrayInputStream(imageSVG); imageSVGString = SVGImageProcessor.transform(svgStream, completed, new ArrayList<String>(active.values()), subProcessLinks); return imageSVGString; } throw new IllegalArgumentException("No process found for " + instance.getProcessId() + " within container " + containerId); }