Search in sources :

Example 36 with ActivitiIllegalArgumentException

use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.

the class ModelSourceResource method setModelSource.

@RequestMapping(value = "/repository/models/{modelId}/source", method = RequestMethod.PUT)
protected void setModelSource(@PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
    Model model = getModelFromRequest(modelId);
    if (model != null) {
        if (request instanceof MultipartHttpServletRequest == false) {
            throw new ActivitiIllegalArgumentException("Multipart request is required");
        }
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        if (multipartRequest.getFileMap().size() == 0) {
            throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
        }
        MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
        try {
            repositoryService.addModelEditorSource(modelId, file.getBytes());
            response.setStatus(HttpStatus.NO_CONTENT.value());
        } catch (Exception e) {
            throw new ActivitiException("Error adding model editor source extra", e);
        }
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Model(org.activiti.engine.repository.Model) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with ActivitiIllegalArgumentException

use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.

the class ExecutionBaseResource method addVariables.

protected void addVariables(ExecutionQuery processInstanceQuery, List<QueryVariable> variables, boolean process) {
    for (QueryVariable variable : variables) {
        if (variable.getVariableOperation() == null) {
            throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
        }
        if (variable.getValue() == null) {
            throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
        }
        boolean nameLess = variable.getName() == null;
        Object actualValue = restResponseFactory.getVariableValue(variable);
        // A value-only query is only possible using equals-operator
        if (nameLess && variable.getVariableOperation() != QueryVariableOperation.EQUALS) {
            throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is only supported when using 'equals' operation.");
        }
        switch(variable.getVariableOperation()) {
            case EQUALS:
                if (nameLess) {
                    if (process) {
                        processInstanceQuery.processVariableValueEquals(actualValue);
                    } else {
                        processInstanceQuery.variableValueEquals(actualValue);
                    }
                } else {
                    if (process) {
                        processInstanceQuery.processVariableValueEquals(variable.getName(), actualValue);
                    } else {
                        processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
                    }
                }
                break;
            case EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    if (process) {
                        processInstanceQuery.processVariableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
                    } else {
                        processInstanceQuery.variableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
                    }
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
                }
                break;
            case NOT_EQUALS:
                if (process) {
                    processInstanceQuery.processVariableValueNotEquals(variable.getName(), actualValue);
                } else {
                    processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
                }
                break;
            case NOT_EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    if (process) {
                        processInstanceQuery.processVariableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
                    } else {
                        processInstanceQuery.variableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
                    }
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
                }
                break;
            default:
                throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
        }
    }
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) QueryVariable(org.activiti.rest.service.api.engine.variable.QueryVariable)

Example 38 with ActivitiIllegalArgumentException

use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.

the class ProcessInstanceCollectionResource method createProcessInstance.

@RequestMapping(value = "/runtime/process-instances", method = RequestMethod.POST, produces = "application/json")
public ProcessInstanceResponse createProcessInstance(@RequestBody ProcessInstanceCreateRequest request, HttpServletRequest httpRequest, HttpServletResponse response) {
    if (request.getProcessDefinitionId() == null && request.getProcessDefinitionKey() == null && request.getMessage() == null) {
        throw new ActivitiIllegalArgumentException("Either processDefinitionId, processDefinitionKey or message is required.");
    }
    int paramsSet = ((request.getProcessDefinitionId() != null) ? 1 : 0) + ((request.getProcessDefinitionKey() != null) ? 1 : 0) + ((request.getMessage() != null) ? 1 : 0);
    if (paramsSet > 1) {
        throw new ActivitiIllegalArgumentException("Only one of processDefinitionId, processDefinitionKey or message should be set.");
    }
    if (request.isCustomTenantSet()) {
        // Tenant-id can only be used with either key or message
        if (request.getProcessDefinitionId() != null) {
            throw new ActivitiIllegalArgumentException("TenantId can only be used with either processDefinitionKey or message.");
        }
    }
    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 ActivitiIllegalArgumentException("Variable name is required.");
            }
            startVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
        }
    }
    // Actually start the instance based on key or id
    try {
        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);
            }
        } else {
            if (request.isCustomTenantSet()) {
                instance = runtimeService.startProcessInstanceByMessageAndTenantId(request.getMessage(), request.getBusinessKey(), startVariables, request.getTenantId());
            } else {
                instance = runtimeService.startProcessInstanceByMessage(request.getMessage(), request.getBusinessKey(), startVariables);
            }
        }
        response.setStatus(HttpStatus.CREATED.value());
        //Added by Ryan Johnston
        if (request.getReturnVariables()) {
            Map<String, Object> runtimeVariableMap = null;
            List<HistoricVariableInstance> historicVariableList = null;
            if (instance.isEnded()) {
                historicVariableList = historyService.createHistoricVariableInstanceQuery().processInstanceId(instance.getId()).list();
            } else {
                runtimeVariableMap = runtimeService.getVariables(instance.getId());
            }
            return restResponseFactory.createProcessInstanceResponse(instance, true, runtimeVariableMap, historicVariableList);
        } else {
            return restResponseFactory.createProcessInstanceResponse(instance);
        }
    //End Added by Ryan Johnston
    //Removed by Ryan Johnston (obsolete given the above).
    //return factory.createProcessInstanceResponse(this, instance);
    } catch (ActivitiObjectNotFoundException aonfe) {
        throw new ActivitiIllegalArgumentException(aonfe.getMessage(), aonfe);
    }
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with ActivitiIllegalArgumentException

use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.

the class ProcessInstanceIdentityLinkCollectionResource method createIdentityLink.

@RequestMapping(value = "/runtime/process-instances/{processInstanceId}/identitylinks", method = RequestMethod.POST, produces = "application/json")
public RestIdentityLink createIdentityLink(@PathVariable String processInstanceId, @RequestBody RestIdentityLink identityLink, HttpServletRequest request, HttpServletResponse response) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    if (identityLink.getGroup() != null) {
        throw new ActivitiIllegalArgumentException("Only user identity links are supported on a process instance.");
    }
    if (identityLink.getUser() == null) {
        throw new ActivitiIllegalArgumentException("The user is required.");
    }
    if (identityLink.getType() == null) {
        throw new ActivitiIllegalArgumentException("The identity link type is required.");
    }
    runtimeService.addUserIdentityLink(processInstance.getId(), identityLink.getUser(), identityLink.getType());
    response.setStatus(HttpStatus.CREATED.value());
    return restResponseFactory.createRestIdentityLink(identityLink.getType(), identityLink.getUser(), identityLink.getGroup(), null, null, processInstance.getId());
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with ActivitiIllegalArgumentException

use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.

the class TaskAttachmentCollectionResource method createAttachment.

@RequestMapping(value = "/runtime/tasks/{taskId}/attachments", method = RequestMethod.POST, produces = "application/json")
public AttachmentResponse createAttachment(@PathVariable String taskId, HttpServletRequest request, HttpServletResponse response) {
    AttachmentResponse result = null;
    Task task = getTaskFromRequest(taskId);
    if (request instanceof MultipartHttpServletRequest) {
        result = createBinaryAttachment((MultipartHttpServletRequest) request, task, response);
    } else {
        AttachmentRequest attachmentRequest = null;
        try {
            attachmentRequest = objectMapper.readValue(request.getInputStream(), AttachmentRequest.class);
        } catch (Exception e) {
            throw new ActivitiIllegalArgumentException("Failed to serialize to a AttachmentRequest instance", e);
        }
        if (attachmentRequest == null) {
            throw new ActivitiIllegalArgumentException("AttachmentRequest properties not found in request");
        }
        result = createSimpleAttachment(attachmentRequest, task);
    }
    response.setStatus(HttpStatus.CREATED.value());
    return result;
}
Also used : Task(org.activiti.engine.task.Task) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) AttachmentResponse(org.activiti.rest.service.api.engine.AttachmentResponse) AttachmentRequest(org.activiti.rest.service.api.engine.AttachmentRequest) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)180 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)47 ActivitiException (org.activiti.engine.ActivitiException)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)23 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)19 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)12 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)12 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)11 VariableInstance (org.activiti.engine.impl.persistence.entity.VariableInstance)10 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)10 Path (javax.ws.rs.Path)9 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)9 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)9 QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)9 IOException (java.io.IOException)8 Date (java.util.Date)8 Produces (javax.ws.rs.Produces)8