use of org.flowable.engine.task.Task in project plumdo-work by wengwh.
the class TaskReturnResource method returnTask.
@RequestMapping(value = "/task/{taskId}/return", method = RequestMethod.PUT, name = "任务回退")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public List<TaskResponse> returnTask(@PathVariable("taskId") String taskId, @RequestBody(required = false) TaskActionRequest actionRequest) {
List<TaskResponse> responses = new ArrayList<TaskResponse>();
Task task = getTaskFromRequest(taskId);
if (task.getAssignee() == null) {
taskService.setAssignee(taskId, Authentication.getAuthenticatedUserId());
}
/* List<Task> tasks = taskExtService.returnTask(task.getId());
for(Task nextTask : tasks){
TaskExt taskExt = taskExtService.getTaskExtById(nextTask.getId());
responses.add(restResponseFactory.createTaskResponse(taskExt));
}*/
return responses;
}
use of org.flowable.engine.task.Task in project plumdo-work by wengwh.
the class RestResponseFactory method createProcessInstanceStartResponse.
public ProcessInstanceStartResponse createProcessInstanceStartResponse(ProcessInstance processInstance, List<Task> tasks) {
ProcessInstanceStartResponse result = new ProcessInstanceStartResponse();
result.setId(processInstance.getId());
result.setBusinessKey(processInstance.getBusinessKey());
result.setProcessDefinitionId(processInstance.getProcessDefinitionId());
// 接口有提供获取定义名称和key但是在启动api里面没有设置进去,只能通过获取定义获取
// result.setProcessDefinitionName(((ExecutionEntity)processInstance).getProcessDefinition().getName());
// result.setProcessDefinitionKey(((ExecutionEntity)processInstance).getProcessDefinition().getKey());
result.setCurrentActivityId(processInstance.getActivityId());
result.setTenantId(processInstance.getTenantId());
List<Map<String, String>> taskInfo = new ArrayList<Map<String, String>>();
for (Task task : tasks) {
Map<String, String> taskMap = new HashMap<String, String>();
taskMap.put("taskId", task.getId());
taskMap.put("taskName", task.getName());
taskMap.put("taskDefinitionKey", task.getTaskDefinitionKey());
taskInfo.add(taskMap);
}
result.setTaskInfo(taskInfo);
return result;
}
use of org.flowable.engine.task.Task 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);
}
use of org.flowable.engine.task.Task 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;
}
use of org.flowable.engine.task.Task 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);
}
}
Aggregations