Search in sources :

Example 61 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus 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)

Example 62 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project plumdo-work by wengwh.

the class ProcessInstanceResource method startProcessInstance.

@RequestMapping(value = "/process-instance", method = RequestMethod.POST, produces = "application/json", name = "流程实例创建")
@ResponseStatus(value = HttpStatus.CREATED)
@Transactional(propagation = Propagation.REQUIRED)
public ProcessInstanceStartResponse startProcessInstance(@RequestBody ProcessInstanceStartRequest request) {
    if (request.getProcessDefinitionId() == null && request.getProcessDefinitionKey() == null) {
        throw new FlowableIllegalArgumentException("Either processDefinitionId, processDefinitionKey is required.");
    }
    int paramsSet = ((request.getProcessDefinitionId() != null) ? 1 : 0) + ((request.getProcessDefinitionKey() != null) ? 1 : 0);
    if (paramsSet > 1) {
        throw new FlowableIllegalArgumentException("Only one of processDefinitionId, processDefinitionKey should be set.");
    }
    if (request.isCustomTenantSet()) {
        // Tenant-id can only be used with either key
        if (request.getProcessDefinitionId() != null) {
            throw new FlowableIllegalArgumentException("TenantId can only be used with either processDefinitionKey.");
        }
    }
    Map<String, Object> startVariables = null;
    if (request.getVariables() != null) {
        startVariables = new HashMap<String, Object>();
        for (RestVariable variable : request.getVariables()) {
            if (variable.getName() == null) {
                throw new FlowableIllegalArgumentException("Variable name is required.");
            }
            startVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
        }
    }
    // Actually start the instance based on key or id
    ProcessInstance instance = null;
    if (request.getProcessDefinitionId() != null) {
        instance = runtimeService.startProcessInstanceById(request.getProcessDefinitionId(), request.getBusinessKey(), startVariables);
    } else if (request.getProcessDefinitionKey() != null) {
        if (request.isCustomTenantSet()) {
            instance = runtimeService.startProcessInstanceByKeyAndTenantId(request.getProcessDefinitionKey(), request.getBusinessKey(), startVariables, request.getTenantId());
        } else {
            instance = runtimeService.startProcessInstanceByKey(request.getProcessDefinitionKey(), request.getBusinessKey(), startVariables);
        }
    }
    // autoCommit:complete all tasks(not include sub process or father process)
    if (request.isAutoCommitTask()) {
        List<Task> tasks = taskService.createTaskQuery().processInstanceId(instance.getProcessInstanceId()).list();
        for (Task task : tasks) {
            if (StringUtils.isEmpty(task.getAssignee())) {
                taskService.setAssignee(task.getId(), Authentication.getAuthenticatedUserId());
            }
            // taskExtService.saveTaskAssigneeVar(task.getId());
            taskService.complete(task.getId());
        }
    }
    // set next task user
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(instance.getProcessInstanceId()).list();
    if (request.getNextActors() != null) {
        for (Task task : tasks) {
            this.addCandidate(task, request.getNextActors());
        }
    }
    return restResponseFactory.createProcessInstanceStartResponse(instance, tasks);
}
Also used : RestVariable(com.plumdo.flow.rest.variable.RestVariable) Task(org.flowable.engine.task.Task) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 63 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus 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 64 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project plumdo-work by wengwh.

the class TaskCompleteResource method completeTask.

@RequestMapping(value = "/task/{taskId}/complete", method = RequestMethod.PUT, name = "任务完成")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public List<TaskCompleteResponse> completeTask(@PathVariable("taskId") String taskId, @RequestBody(required = false) TaskCompleteRequest taskCompleteRequest) {
    List<TaskCompleteResponse> responses = new ArrayList<TaskCompleteResponse>();
    Task task = getTaskFromRequest(taskId);
    if (task.getAssignee() == null) {
        taskService.setAssignee(taskId, Authentication.getAuthenticatedUserId());
    }
    // 设置任务的完成人变量
    // taskExtService.saveTaskAssigneeVar(taskId);
    Map<String, Object> completeVariables = new HashMap<String, Object>();
    // 设置流程变量
    if (taskCompleteRequest != null && taskCompleteRequest.getVariables() != null) {
        for (RestVariable variable : taskCompleteRequest.getVariables()) {
            if (variable.getName() == null) {
                throw new FlowableIllegalArgumentException("Variable name is required.");
            }
            completeVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
        }
    }
    // 设置多实例变量
    if (taskCompleteRequest != null && taskCompleteRequest.getMultiKeys() != null) {
        for (MultiKey multiKey : taskCompleteRequest.getMultiKeys()) {
            if (multiKey.getName() == null) {
                throw new FlowableIllegalArgumentException("multiKey name is required.");
            }
            completeVariables.put(multiKey.getName(), multiKey.getValue());
        }
    }
    // 判断是否是协办完成还是正常流转
    if (task.getDelegationState() != null && task.getDelegationState().equals(DelegationState.PENDING)) {
        // taskExtService.setStartTime(taskId);
        if (completeVariables.isEmpty()) {
            taskService.resolveTask(taskId);
        } else {
            taskService.resolveTask(taskId, completeVariables);
        }
    } else {
        if (completeVariables.isEmpty()) {
            taskService.complete(taskId);
        } else {
            taskService.complete(taskId, completeVariables);
        }
    }
    return responses;
}
Also used : RestVariable(com.plumdo.flow.rest.variable.RestVariable) Task(org.flowable.engine.task.Task) MultiKey(com.plumdo.flow.rest.task.MultiKey) HashMap(java.util.HashMap) TaskCompleteResponse(com.plumdo.flow.rest.task.TaskCompleteResponse) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) ArrayList(java.util.ArrayList) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with ResponseStatus

use of org.springframework.web.bind.annotation.ResponseStatus in project plumdo-work by wengwh.

the class TaskIdentityResource method deleteIdentityLink.

@RequestMapping(value = "/task/{taskId}/identity/{type}/{identityId}", method = RequestMethod.DELETE, name = "任务候选人删除")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void deleteIdentityLink(@PathVariable("taskId") String taskId, @PathVariable("identityId") String identityId, @PathVariable("type") String type) {
    Task task = getTaskFromRequest(taskId, false);
    validateIdentityLinkArguments(identityId, type);
    getIdentityLink(taskId, identityId, type);
    if (TaskIdentityRequest.AUTHORIZE_GROUP.equals(type)) {
        taskService.deleteGroupIdentityLink(task.getId(), identityId, IdentityLinkType.CANDIDATE);
    } else if (TaskIdentityRequest.AUTHORIZE_USER.equals(type)) {
        taskService.deleteUserIdentityLink(task.getId(), identityId, IdentityLinkType.CANDIDATE);
    }
}
Also used : Task(org.flowable.engine.task.Task) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)149 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)118 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)36 ApiOperation (io.swagger.annotations.ApiOperation)31 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)26 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)19 GetMapping (org.springframework.web.bind.annotation.GetMapping)18 ApiResponses (io.swagger.annotations.ApiResponses)14 User (org.hisp.dhis.user.User)14 Transactional (org.springframework.transaction.annotation.Transactional)14 Date (java.util.Date)13 Configuration (org.hisp.dhis.configuration.Configuration)12 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Period (org.hisp.dhis.period.Period)11 ArrayList (java.util.ArrayList)10 QualifiedName (com.netflix.metacat.common.QualifiedName)9 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)9 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)9 Calendar (java.util.Calendar)9 Task (org.flowable.engine.task.Task)8