Search in sources :

Example 6 with FlowableIllegalArgumentException

use of org.flowable.engine.common.api.FlowableIllegalArgumentException 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 7 with FlowableIllegalArgumentException

use of org.flowable.engine.common.api.FlowableIllegalArgumentException 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 8 with FlowableIllegalArgumentException

use of org.flowable.engine.common.api.FlowableIllegalArgumentException in project plumdo-work by wengwh.

the class RestResponseFactory method getVariableValue.

public Object getVariableValue(RestVariable restVariable) {
    Object value = null;
    if (restVariable.getType() != null) {
        RestVariableConverter converter = null;
        for (RestVariableConverter conv : variableConverters) {
            if (conv.getRestTypeName().equals(restVariable.getType())) {
                converter = conv;
                break;
            }
        }
        if (converter == null) {
            throw new FlowableIllegalArgumentException("Variable '" + restVariable.getName() + "' has unsupported type: '" + restVariable.getType() + "'.");
        }
        value = converter.getVariableValue(restVariable);
    } else {
        value = restVariable.getValue();
    }
    return value;
}
Also used : StringRestVariableConverter(com.plumdo.flow.rest.variable.StringRestVariableConverter) BooleanRestVariableConverter(com.plumdo.flow.rest.variable.BooleanRestVariableConverter) IntegerRestVariableConverter(com.plumdo.flow.rest.variable.IntegerRestVariableConverter) DoubleRestVariableConverter(com.plumdo.flow.rest.variable.DoubleRestVariableConverter) LongRestVariableConverter(com.plumdo.flow.rest.variable.LongRestVariableConverter) ShortRestVariableConverter(com.plumdo.flow.rest.variable.ShortRestVariableConverter) RestVariableConverter(com.plumdo.flow.rest.variable.RestVariableConverter) ListRestVariableConverter(com.plumdo.flow.rest.variable.ListRestVariableConverter) DateRestVariableConverter(com.plumdo.flow.rest.variable.DateRestVariableConverter) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException)

Example 9 with FlowableIllegalArgumentException

use of org.flowable.engine.common.api.FlowableIllegalArgumentException in project plumdo-work by wengwh.

the class ProcessInstanceImageResource method getProcessInstanceImage.

@RequestMapping(value = "/process-instance/{processInstanceId}/image", method = RequestMethod.GET, name = "流程实例流程图")
public ResponseEntity<byte[]> getProcessInstanceImage(@PathVariable String processInstanceId) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    ProcessDefinition pde = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
    if (pde != null && pde.hasGraphicalNotation()) {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
        ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
        InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstance.getId()), Collections.<String>emptyList(), processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader(), 1.0);
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.IMAGE_PNG);
        try {
            return new ResponseEntity<byte[]>(IOUtils.toByteArray(resource), responseHeaders, HttpStatus.OK);
        } catch (Exception e) {
            throw new FlowableIllegalArgumentException("Error exporting diagram", e);
        }
    } else {
        throw new FlowableIllegalArgumentException("Process instance with id '" + processInstance.getId() + "' has no graphical notation defined.");
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ProcessDiagramGenerator(org.flowable.image.ProcessDiagramGenerator) InputStream(java.io.InputStream) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) BpmnModel(org.flowable.bpmn.model.BpmnModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

FlowableIllegalArgumentException (org.flowable.engine.common.api.FlowableIllegalArgumentException)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)4 InputStream (java.io.InputStream)3 FlowableException (org.flowable.engine.common.api.FlowableException)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ResponseEntity (org.springframework.http.ResponseEntity)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 RestVariable (com.plumdo.flow.rest.variable.RestVariable)2 List (java.util.List)2 FlowableObjectNotFoundException (org.flowable.engine.common.api.FlowableObjectNotFoundException)2 ProcessInstance (org.flowable.engine.runtime.ProcessInstance)2 Task (org.flowable.engine.task.Task)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FlowableForbiddenException (com.plumdo.flow.exception.FlowableForbiddenException)1 MultiKey (com.plumdo.flow.rest.task.MultiKey)1 TaskCompleteResponse (com.plumdo.flow.rest.task.TaskCompleteResponse)1 BooleanRestVariableConverter (com.plumdo.flow.rest.variable.BooleanRestVariableConverter)1 DateRestVariableConverter (com.plumdo.flow.rest.variable.DateRestVariableConverter)1