use of org.flowable.image.ProcessDiagramGenerator in project plumdo-work by wengwh.
the class ModelEditorResource method saveModel.
@RequestMapping(value = "/models/{modelId}/editor", method = { RequestMethod.POST }, name = "模型设计器保存模型")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public void saveModel(@PathVariable String modelId, @RequestBody ModelEditorJsonRequest values) {
try {
Model model = getModelFromRequest(modelId);
ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
modelJson.put(MODEL_NAME, values.getName());
modelJson.put(MODEL_DESCRIPTION, values.getDescription());
model.setMetaInfo(modelJson.toString());
model.setName(values.getName());
if (model.getDeploymentId() != null) {
model.setDeploymentId(null);
}
if (values.isAddVersion()) {
model.setVersion(model.getVersion() + 1);
}
repositoryService.saveModel(model);
repositoryService.addModelEditorSource(model.getId(), values.getJson_xml().getBytes("utf-8"));
ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(values.getJson_xml().getBytes("utf-8"));
BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", Collections.<String>emptyList(), Collections.<String>emptyList(), processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader(), 1.0);
repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(resource));
} catch (Exception e) {
LOGGER.error("Error saving model", e);
throw new FlowableException("Error saving model", e);
}
}
use of org.flowable.image.ProcessDiagramGenerator 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