Search in sources :

Example 1 with ProcessDiagramGenerator

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);
    }
}
Also used : FlowableException(org.flowable.engine.common.api.FlowableException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) Model(org.flowable.engine.repository.Model) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FlowableException(org.flowable.engine.common.api.FlowableException) BpmnModel(org.flowable.bpmn.model.BpmnModel) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ProcessDiagramGenerator

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.");
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) BpmnModel(org.flowable.bpmn.model.BpmnModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

InputStream (java.io.InputStream)2 BpmnModel (org.flowable.bpmn.model.BpmnModel)2 ProcessDiagramGenerator (org.flowable.image.ProcessDiagramGenerator)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 BpmnJsonConverter (org.flowable.editor.language.json.converter.BpmnJsonConverter)1 FlowableException (org.flowable.engine.common.api.FlowableException)1 FlowableIllegalArgumentException (org.flowable.engine.common.api.FlowableIllegalArgumentException)1 Model (org.flowable.engine.repository.Model)1 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)1 ProcessInstance (org.flowable.engine.runtime.ProcessInstance)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1