Search in sources :

Example 11 with BpmnModel

use of org.flowable.bpmn.model.BpmnModel in project plumdo-work by wengwh.

the class ModelValidationResource method validate.

@PostMapping(value = "/models/validate", name = "模型检查")
public List<ValidationError> validate(@RequestBody JsonNode body) {
    BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(body);
    ProcessValidator validator = new ProcessValidatorFactory().createDefaultProcessValidator();
    return validator.validate(bpmnModel);
}
Also used : ProcessValidatorFactory(org.flowable.validation.ProcessValidatorFactory) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) ProcessValidator(org.flowable.validation.ProcessValidator) BpmnModel(org.flowable.bpmn.model.BpmnModel) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 12 with BpmnModel

use of org.flowable.bpmn.model.BpmnModel in project plumdo-work by wengwh.

the class ProcessInstanceImageResource method getProcessInstanceImage.

@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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) BpmnModel(org.flowable.bpmn.model.BpmnModel) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

BpmnModel (org.flowable.bpmn.model.BpmnModel)12 BpmnJsonConverter (org.flowable.editor.language.json.converter.BpmnJsonConverter)9 BpmnXMLConverter (org.flowable.bpmn.converter.BpmnXMLConverter)8 FlowableException (org.flowable.engine.common.api.FlowableException)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 Model (org.flowable.engine.repository.Model)7 InputStream (java.io.InputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStreamReader (java.io.InputStreamReader)5 XMLStreamReader (javax.xml.stream.XMLStreamReader)5 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)5 XMLInputFactory (javax.xml.stream.XMLInputFactory)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 Deployment (org.flowable.engine.repository.Deployment)3 ProcessDiagramGenerator (org.flowable.image.ProcessDiagramGenerator)3 Transactional (org.springframework.transaction.annotation.Transactional)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 WorkflowException (org.apache.syncope.core.workflow.api.WorkflowException)2