Search in sources :

Example 1 with ProcessDefinition

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

the class ProcessDefinitionAuthorizeResource method createAuthorize.

@RequestMapping(value = "/process-definition/{processDefinitionId}/authorize", method = RequestMethod.POST, name = "流程定义授权创建")
@ResponseStatus(value = HttpStatus.CREATED)
public void createAuthorize(@PathVariable String processDefinitionId, @RequestBody ProcessDefinitionAuthorizeRequest authorizeRequest) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    validateAuthorizeArguments(authorizeRequest.getIdentityId(), authorizeRequest.getType());
    if (ProcessDefinitionAuthorizeRequest.AUTHORIZE_GROUP.equals(authorizeRequest.getType())) {
        repositoryService.addCandidateStarterGroup(processDefinition.getId(), authorizeRequest.getIdentityId());
    } else if (ProcessDefinitionAuthorizeRequest.AUTHORIZE_USER.equals(authorizeRequest.getType())) {
        repositoryService.addCandidateStarterUser(processDefinition.getId(), authorizeRequest.getIdentityId());
    }
}
Also used : ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ProcessDefinition

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

the class ProcessDefinitionAuthorizeResource method getAuthorizes.

@RequestMapping(value = "/process-definition/{processDefinitionId}/authorize", method = RequestMethod.GET, produces = "application/json", name = "流程定义授权查询")
public ArrayNode getAuthorizes(@PathVariable String processDefinitionId) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    List<IdentityLink> identityLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
    ArrayNode arrayNode = objectMapper.createArrayNode();
    for (IdentityLink identityLink : identityLinks) {
        ObjectNode objectNode = objectMapper.createObjectNode();
        if (identityLink.getGroupId() != null) {
            objectNode.put("type", ProcessDefinitionAuthorizeRequest.AUTHORIZE_GROUP);
            objectNode.put("identityId", identityLink.getGroupId());
        } else if (identityLink.getUserId() != null) {
            objectNode.put("type", ProcessDefinitionAuthorizeRequest.AUTHORIZE_USER);
            objectNode.put("identityId", identityLink.getUserId());
        }
        arrayNode.add(objectNode);
    }
    return arrayNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IdentityLink(org.flowable.engine.task.IdentityLink) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ProcessDefinition

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

the class ProcessDefinitionResource method createProcessDefinition.

@RequestMapping(value = "/process-definition", method = RequestMethod.POST, produces = "application/json", name = "流程定义创建")
@ResponseStatus(value = HttpStatus.CREATED)
public ProcessDefinitionResponse createProcessDefinition(@RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request) {
    if (request instanceof MultipartHttpServletRequest == false) {
        throw new FlowableIllegalArgumentException("Multipart request is required");
    }
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    if (multipartRequest.getFileMap().size() == 0) {
        throw new FlowableIllegalArgumentException("Multipart request with file content is required");
    }
    MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
    try {
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        String fileName = file.getOriginalFilename();
        if (StringUtils.isEmpty(fileName) || !(fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn") || fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip"))) {
            fileName = file.getName();
        }
        if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
            deploymentBuilder.addInputStream(fileName, file.getInputStream());
        } else if (fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip")) {
            deploymentBuilder.addZipInputStream(new ZipInputStream(file.getInputStream()));
        } else {
            throw new FlowableIllegalArgumentException("File must be of type .bpmn20.xml, .bpmn, .bar or .zip");
        }
        deploymentBuilder.name(fileName);
        if (tenantId != null) {
            deploymentBuilder.tenantId(tenantId);
        }
        String deploymentId = deploymentBuilder.deploy().getId();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();
        return restResponseFactory.createProcessDefinitionResponse(processDefinition);
    } catch (Exception e) {
        if (e instanceof FlowableException) {
            throw (FlowableException) e;
        }
        throw new FlowableException(e.getMessage(), e);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ZipInputStream(java.util.zip.ZipInputStream) FlowableException(org.flowable.engine.common.api.FlowableException) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) DeploymentBuilder(org.flowable.engine.repository.DeploymentBuilder) FlowableForbiddenException(com.plumdo.flow.exception.FlowableForbiddenException) FlowableException(org.flowable.engine.common.api.FlowableException) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ProcessDefinition

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

the class ModelDeployResource method deployModel.

@RequestMapping(value = "/model/{modelId}/deploy", method = RequestMethod.POST, produces = "application/json", name = "模型部署")
@ResponseStatus(value = HttpStatus.CREATED)
@Transactional(propagation = Propagation.REQUIRED)
public ProcessDefinitionResponse deployModel(@PathVariable String modelId) {
    Model model = getModelFromRequest(modelId);
    Deployment deployment = managementService.executeCommand(new DeployModelCmd(model.getId()));
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    return restResponseFactory.createProcessDefinitionResponse(processDefinition);
}
Also used : Model(org.flowable.engine.repository.Model) Deployment(org.flowable.engine.repository.Deployment) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) DeployModelCmd(com.plumdo.flow.cmd.DeployModelCmd) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with ProcessDefinition

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

the class ProcessDefinitionCopyResource method copyProcessDefinition.

@RequestMapping(value = "/process-definition/{processDefinitionId}/copy", method = RequestMethod.POST, produces = "application/json", name = "复制流程定义")
@ResponseStatus(value = HttpStatus.CREATED)
public ProcessDefinitionResponse copyProcessDefinition(@PathVariable String processDefinitionId, @RequestBody(required = false) ProcessDefinitionCopyRequest processDefinitionCopyRequest) {
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    try {
        String name = null;
        if (processDefinitionCopyRequest != null && processDefinitionCopyRequest.getName() != null) {
            name = processDefinitionCopyRequest.getName();
        } else {
            name = "CopyOf" + processDefinition.getName();
        }
        String key = null;
        if (processDefinitionCopyRequest != null && processDefinitionCopyRequest.getKey() != null) {
            key = processDefinitionCopyRequest.getKey();
        } else {
            // 保证key不重复使用时间戳
            key = "CopyOf" + System.currentTimeMillis();
        }
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
        bpmnModel.getMainProcess().setName(name);
        bpmnModel.getMainProcess().setId(key);
        byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(bpmnModel);
        String fileName = processDefinition.getResourceName();
        ByteArrayInputStream bis = new ByteArrayInputStream(bpmnBytes);
        deploymentBuilder.addInputStream(fileName, bis);
        deploymentBuilder.name(fileName);
        if (processDefinition.getTenantId() != null) {
            deploymentBuilder.tenantId(processDefinition.getTenantId());
        }
        String deploymentId = deploymentBuilder.deploy().getId();
        ProcessDefinition processDefinitionNew = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();
        return restResponseFactory.createProcessDefinitionResponse(processDefinitionNew);
    } catch (Exception e) {
        throw new FlowableException("Error copy process-definition", e);
    }
}
Also used : FlowableException(org.flowable.engine.common.api.FlowableException) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) DeploymentBuilder(org.flowable.engine.repository.DeploymentBuilder) FlowableException(org.flowable.engine.common.api.FlowableException) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter) 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