Search in sources :

Example 1 with TaskCompleteResponse

use of com.plumdo.flow.rest.task.TaskCompleteResponse in project plumdo-work by wengwh.

the class RestResponseFactory method createTaskCompleteResponse.

public TaskCompleteResponse createTaskCompleteResponse(Task taskInstance, List<IdentityLink> identityLinks) {
    TaskCompleteResponse result = new TaskCompleteResponse();
    createTaskResponse(result, taskInstance);
    result.setCandidate(createTaskIdentityResponseList(identityLinks));
    return result;
}
Also used : TaskCompleteResponse(com.plumdo.flow.rest.task.TaskCompleteResponse)

Example 2 with TaskCompleteResponse

use of com.plumdo.flow.rest.task.TaskCompleteResponse 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)

Aggregations

TaskCompleteResponse (com.plumdo.flow.rest.task.TaskCompleteResponse)2 MultiKey (com.plumdo.flow.rest.task.MultiKey)1 RestVariable (com.plumdo.flow.rest.variable.RestVariable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FlowableIllegalArgumentException (org.flowable.engine.common.api.FlowableIllegalArgumentException)1 Task (org.flowable.engine.task.Task)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1