use of org.flowable.engine.repository.ProcessDefinition in project plumdo-work by wengwh.
the class ProcessDefinitionToModelResource method processDefinitionToModel.
@RequestMapping(value = "/process-definition/{processDefinitionId}/toModel", method = RequestMethod.PUT, produces = "application/json", name = "流程定义转换模型")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public ModelResponse processDefinitionToModel(@PathVariable String processDefinitionId) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
try {
InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
XMLInputFactory xif = XMLInputFactory.newInstance();
InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
XMLStreamReader xtr = xif.createXMLStreamReader(in);
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
BpmnJsonConverter converter = new BpmnJsonConverter();
ObjectNode modelNode = converter.convertToJson(bpmnModel);
Model modelData = repositoryService.newModel();
modelData.setKey(processDefinition.getKey());
modelData.setName(processDefinition.getName());
modelData.setCategory(processDefinition.getCategory());
ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName());
modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription());
modelData.setMetaInfo(modelObjectNode.toString());
repositoryService.saveModel(modelData);
repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));
repositoryService.addModelEditorSourceExtra(modelData.getId(), IOUtils.toByteArray(repositoryService.getProcessDiagram(processDefinition.getId())));
return restResponseFactory.createModelResponse(modelData);
} catch (Exception e) {
throw new FlowableException("Error converting process-definition to model", e);
}
}
use of org.flowable.engine.repository.ProcessDefinition in project plumdo-work by wengwh.
the class ProcessInstanceImageResource method getProcessInstanceImage.
@RequestMapping(value = "/process-instance/{processInstanceId}/image", method = RequestMethod.GET, name = "流程实例流程图")
public ResponseEntity<byte[]> getProcessInstanceImage(@PathVariable String processInstanceId) {
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);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.IMAGE_PNG);
try {
return new ResponseEntity<byte[]>(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.");
}
}
Aggregations