Search in sources :

Example 6 with ProcessDefinition

use of org.flowable.engine.repository.ProcessDefinition in project plumdo-work by wengwh.

the class ProcessDefinitionImageResource method getProcessDefinitionImage.

@RequestMapping(value = "/process-definition/{processDefinitionId}/image", method = RequestMethod.GET, name = "流程定义流程图")
public ResponseEntity<byte[]> getProcessDefinitionImage(@PathVariable String processDefinitionId) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    InputStream imageStream = repositoryService.getProcessDiagram(processDefinition.getId());
    if (imageStream != null) {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.IMAGE_PNG);
        try {
            return new ResponseEntity<byte[]>(IOUtils.toByteArray(imageStream), responseHeaders, HttpStatus.OK);
        } catch (Exception e) {
            throw new FlowableException("Error reading image stream", e);
        }
    } else {
        throw new FlowableIllegalArgumentException("Process definition with id '" + processDefinition.getId() + "' has no image.");
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) FlowableException(org.flowable.engine.common.api.FlowableException) InputStream(java.io.InputStream) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) FlowableException(org.flowable.engine.common.api.FlowableException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ProcessDefinition

use of org.flowable.engine.repository.ProcessDefinition in project plumdo-work by wengwh.

the class ProcessDefinitionXmlResource method getProcessDefinitionXml.

@RequestMapping(value = "/process-definition/{processDefinitionId}/xml", method = RequestMethod.GET, name = "流程定义XML")
public ResponseEntity<byte[]> getProcessDefinitionXml(@PathVariable String processDefinitionId) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    String deploymentId = processDefinition.getDeploymentId();
    String resourceId = processDefinition.getResourceName();
    if (deploymentId == null) {
        throw new FlowableIllegalArgumentException("No deployment id provided");
    }
    if (resourceId == null) {
        throw new FlowableIllegalArgumentException("No resource id provided");
    }
    Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
    if (deployment == null) {
        throw new FlowableObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", Deployment.class);
    }
    List<String> resourceList = repositoryService.getDeploymentResourceNames(deploymentId);
    if (resourceList.contains(resourceId)) {
        final InputStream resourceStream = repositoryService.getResourceAsStream(deploymentId, resourceId);
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.TEXT_XML);
        try {
            return new ResponseEntity<byte[]>(IOUtils.toByteArray(resourceStream), responseHeaders, HttpStatus.OK);
        } catch (Exception e) {
            throw new FlowableException("Error converting resource stream", e);
        }
    } else {
        throw new FlowableObjectNotFoundException("Could not find a resource with id '" + resourceId + "' in deployment '" + deploymentId + "'.", String.class);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) ResponseEntity(org.springframework.http.ResponseEntity) FlowableException(org.flowable.engine.common.api.FlowableException) InputStream(java.io.InputStream) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) Deployment(org.flowable.engine.repository.Deployment) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) FlowableException(org.flowable.engine.common.api.FlowableException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ProcessDefinition

use of org.flowable.engine.repository.ProcessDefinition in project plumdo-work by wengwh.

the class ProcessDefinitionAuthorizeResource method deleteAuthorize.

@RequestMapping(value = "/process-definition/{processDefinitionId}/authorize/{type}/{id}", method = RequestMethod.DELETE, name = "流程定义授权删除")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void deleteAuthorize(@PathVariable("processDefinitionId") String processDefinitionId, @PathVariable("id") String id, @PathVariable("type") String type) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    validateAuthorizeArguments(id, type);
    getAuthorize(processDefinitionId, id, type);
    if (ProcessDefinitionAuthorizeRequest.AUTHORIZE_GROUP.equals(type)) {
        repositoryService.deleteCandidateStarterGroup(processDefinition.getId(), id);
    } else if (ProcessDefinitionAuthorizeRequest.AUTHORIZE_USER.equals(type)) {
        repositoryService.deleteCandidateStarterUser(processDefinition.getId(), id);
    }
}
Also used : ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with ProcessDefinition

use of org.flowable.engine.repository.ProcessDefinition in project plumdo-work by wengwh.

the class ProcessDefinitionGetModelResource method processDefinitionGetModel.

@RequestMapping(value = "/process-definition/{processDefinitionId}/getModel", method = RequestMethod.GET, produces = "application/json", name = "流程定义获取对应模型")
public ModelResponse processDefinitionGetModel(@PathVariable String processDefinitionId) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    try {
        Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(processDefinition.getDeploymentId()).singleResult();
        if (deployment == null) {
            throw new FlowableObjectNotFoundException("Could not find a process deployment with id '" + processDefinition.getDeploymentId() + "'.", Deployment.class);
        }
        Model modelData = null;
        if (deployment.getCategory() != null) {
            modelData = repositoryService.getModel(deployment.getCategory());
        }
        // 如果不存在,创建对应模型
        if (modelData == null) {
            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);
            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(managementService.executeCommand(new GetDeploymentProcessDiagramCmd(processDefinitionId))));
            repositoryService.setDeploymentCategory(processDefinition.getDeploymentId(), modelData.getId());
        }
        return restResponseFactory.createModelResponse(modelData);
    } catch (Exception e) {
        throw new FlowableException("Error  process-definition get model", e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) GetDeploymentProcessDiagramCmd(org.flowable.engine.impl.cmd.GetDeploymentProcessDiagramCmd) InputStreamReader(java.io.InputStreamReader) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) Deployment(org.flowable.engine.repository.Deployment) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) FlowableException(org.flowable.engine.common.api.FlowableException) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter) FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) FlowableException(org.flowable.engine.common.api.FlowableException) Model(org.flowable.engine.repository.Model) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) XMLInputFactory(javax.xml.stream.XMLInputFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with ProcessDefinition

use of org.flowable.engine.repository.ProcessDefinition in project plumdo-work by wengwh.

the class ProcessDefinitionResource method deleteProcessDefinition.

@RequestMapping(value = "/process-definition/{processDefinitionId}", method = RequestMethod.DELETE, produces = "application/json", name = "流程定义删除")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void deleteProcessDefinition(@PathVariable String processDefinitionId, @RequestParam(value = "cascade", required = false, defaultValue = "false") Boolean cascade) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    if (processDefinition.getDeploymentId() == null) {
        throw new FlowableObjectNotFoundException("No found deployment ");
    }
    if (cascade) {
        repositoryService.deleteDeployment(processDefinition.getDeploymentId(), true);
    } else {
        long count = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinitionId).count();
        if (count != 0) {
            throw new FlowableForbiddenException("Cannot delete a process-definition that have process-instance");
        }
        repositoryService.deleteDeployment(processDefinition.getDeploymentId());
    }
}
Also used : FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) FlowableForbiddenException(com.plumdo.flow.exception.FlowableForbiddenException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 FlowableException (org.flowable.engine.common.api.FlowableException)6 InputStream (java.io.InputStream)5 BpmnModel (org.flowable.bpmn.model.BpmnModel)4 FlowableIllegalArgumentException (org.flowable.engine.common.api.FlowableIllegalArgumentException)4 FlowableObjectNotFoundException (org.flowable.engine.common.api.FlowableObjectNotFoundException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 BpmnXMLConverter (org.flowable.bpmn.converter.BpmnXMLConverter)3 Deployment (org.flowable.engine.repository.Deployment)3 Model (org.flowable.engine.repository.Model)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ResponseEntity (org.springframework.http.ResponseEntity)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 FlowableForbiddenException (com.plumdo.flow.exception.FlowableForbiddenException)2 InputStreamReader (java.io.InputStreamReader)2 XMLInputFactory (javax.xml.stream.XMLInputFactory)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 BpmnJsonConverter (org.flowable.editor.language.json.converter.BpmnJsonConverter)2