Java Code Examples for org.flowable.engine.repository.ProcessDefinition#hasGraphicalNotation()

The following examples show how to use org.flowable.engine.repository.ProcessDefinition#hasGraphicalNotation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProcessInstanceImageResource.java    From plumdo-work with Apache License 2.0 5 votes vote down vote up
@GetMapping(value = "/process-instances/{processInstanceId}/image", name = "流程实例流程图")
public ResponseEntity<byte[]> getProcessInstanceImage(@PathVariable String processInstanceId) {
    HistoricProcessInstance processInstance = getHistoricProcessInstanceFromRequest(processInstanceId);
    ProcessDefinition pde = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
    if (pde == null || !pde.hasGraphicalNotation()) {
        exceptionFactory.throwObjectNotFound(ErrorConstant.INSTANCE_IMAGE_NOT_FOUND, processInstance.getId());
    }

    List<String> highLightedActivities;
    if (processInstance.getEndTime() == null) {
        highLightedActivities = runtimeService.getActiveActivityIds(processInstance.getId());
    } else {
        highLightedActivities = Collections.emptyList();
    }

    BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
    ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();

    InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", highLightedActivities,
            Collections.emptyList(),
            processEngineConfiguration.getActivityFontName(),
            processEngineConfiguration.getLabelFontName(),
            processEngineConfiguration.getAnnotationFontName(),
            processEngineConfiguration.getClassLoader(), 1.0);

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.IMAGE_PNG);
    try {
        return new ResponseEntity<>(IOUtils.toByteArray(resource), responseHeaders, HttpStatus.OK);
    } catch (Exception e) {
        exceptionFactory.throwDefinedException(ErrorConstant.INSTANCE_IMAGE_READ_ERROR, e.getMessage());
    }

    return null;
}
 
Example 2
Source File: ProcessInstanceDiagramResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Get diagram for a process instance", tags = { "Process Instances" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the process instance was found and the diagram was returned."),
        @ApiResponse(code = 400, message = "Indicates the requested process instance was not found but the process does not contain any graphical information (BPMN:DI) and no diagram can be created."),
        @ApiResponse(code = 404, message = "Indicates the requested process instance was not found.")
})
@GetMapping(value = "/runtime/process-instances/{processInstanceId}/diagram")
public ResponseEntity<byte[]> getProcessInstanceDiagram(@ApiParam(name = "processInstanceId") @PathVariable String processInstanceId, HttpServletResponse response) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);

    ProcessDefinition pde = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());

    if (pde != null && pde.hasGraphicalNotation()) {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
        ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
        InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstance.getId()), Collections.<String>emptyList(),
                processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(),
                processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader(), 1.0,processEngineConfiguration.isDrawSequenceFlowNameWithNoLabelDI());

        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("Content-Type", "image/png");
        try {
            return new ResponseEntity<>(IOUtils.toByteArray(resource), responseHeaders, HttpStatus.OK);
        } catch (Exception e) {
            throw new FlowableIllegalArgumentException("Error exporting diagram", e);
        }

    } else {
        throw new FlowableIllegalArgumentException("Process instance with id '" + processInstance.getId() + "' has no graphical notation defined.");
    }
}