Search in sources :

Example 21 with ActivitiIllegalArgumentException

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

the class ProcessDefinitionResource method executeProcessDefinitionAction.

@RequestMapping(value = "/repository/process-definitions/{processDefinitionId}", method = RequestMethod.PUT, produces = "application/json")
public ProcessDefinitionResponse executeProcessDefinitionAction(@PathVariable String processDefinitionId, @RequestBody ProcessDefinitionActionRequest actionRequest, HttpServletRequest request) {
    if (actionRequest == null) {
        throw new ActivitiIllegalArgumentException("No action found in request body.");
    }
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    if (actionRequest.getCategory() != null) {
        // Update of category required
        repositoryService.setProcessDefinitionCategory(processDefinition.getId(), actionRequest.getCategory());
        // No need to re-fetch the ProcessDefinition entity, just update category in response
        ProcessDefinitionResponse response = restResponseFactory.createProcessDefinitionResponse(processDefinition);
        response.setCategory(actionRequest.getCategory());
        return response;
    } else {
        // Actual action
        if (actionRequest.getAction() != null) {
            if (ProcessDefinitionActionRequest.ACTION_SUSPEND.equals(actionRequest.getAction())) {
                return suspendProcessDefinition(processDefinition, actionRequest.isIncludeProcessInstances(), actionRequest.getDate());
            } else if (ProcessDefinitionActionRequest.ACTION_ACTIVATE.equals(actionRequest.getAction())) {
                return activateProcessDefinition(processDefinition, actionRequest.isIncludeProcessInstances(), actionRequest.getDate());
            }
        }
        throw new ActivitiIllegalArgumentException("Invalid action: '" + actionRequest.getAction() + "'.");
    }
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with ActivitiIllegalArgumentException

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

the class BaseProcessInstanceResource method addVariables.

protected void addVariables(ProcessInstanceQuery processInstanceQuery, List<QueryVariable> variables) {
    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) {
                    processInstanceQuery.variableValueEquals(actualValue);
                } else {
                    processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
                }
                break;
            case EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    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:
                processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
                break;
            case NOT_EQUALS_IGNORE_CASE:
                if (actualValue instanceof String) {
                    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;
            case LIKE:
                if (actualValue instanceof String) {
                    processInstanceQuery.variableValueLike(variable.getName(), (String) actualValue);
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported for like, but was: " + actualValue.getClass().getName());
                }
                break;
            case LIKE_IGNORE_CASE:
                if (actualValue instanceof String) {
                    processInstanceQuery.variableValueLikeIgnoreCase(variable.getName(), (String) actualValue);
                } else {
                    throw new ActivitiIllegalArgumentException("Only string variable values are supported for like ignore case, but was: " + actualValue.getClass().getName());
                }
                break;
            case GREATER_THAN:
                processInstanceQuery.variableValueGreaterThan(variable.getName(), actualValue);
                break;
            case GREATER_THAN_OR_EQUALS:
                processInstanceQuery.variableValueGreaterThanOrEqual(variable.getName(), actualValue);
                break;
            case LESS_THAN:
                processInstanceQuery.variableValueLessThan(variable.getName(), actualValue);
                break;
            case LESS_THAN_OR_EQUALS:
                processInstanceQuery.variableValueLessThanOrEqual(variable.getName(), actualValue);
                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 23 with ActivitiIllegalArgumentException

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

the class TaskIdentityLinkFamilyResource method getIdentityLinksForFamily.

@RequestMapping(value = "/runtime/tasks/{taskId}/identitylinks/{family}", method = RequestMethod.GET, produces = "application/json")
public List<RestIdentityLink> getIdentityLinksForFamily(@PathVariable("taskId") String taskId, @PathVariable("family") String family, HttpServletRequest request) {
    Task task = getTaskFromRequest(taskId);
    if (family == null || (!RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS.equals(family) && !RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS.equals(family))) {
        throw new ActivitiIllegalArgumentException("Identity link family should be 'users' or 'groups'.");
    }
    boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);
    List<RestIdentityLink> results = new ArrayList<RestIdentityLink>();
    List<IdentityLink> allLinks = taskService.getIdentityLinksForTask(task.getId());
    for (IdentityLink link : allLinks) {
        boolean match = false;
        if (isUser) {
            match = link.getUserId() != null;
        } else {
            match = link.getGroupId() != null;
        }
        if (match) {
            results.add(restResponseFactory.createRestIdentityLink(link));
        }
    }
    return results;
}
Also used : Task(org.activiti.engine.task.Task) RestIdentityLink(org.activiti.rest.service.api.engine.RestIdentityLink) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) RestIdentityLink(org.activiti.rest.service.api.engine.RestIdentityLink) IdentityLink(org.activiti.engine.task.IdentityLink) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with ActivitiIllegalArgumentException

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

the class TaskResource method completeTask.

protected void completeTask(Task task, TaskActionRequest actionRequest) {
    if (actionRequest.getVariables() != null) {
        Map<String, Object> variablesToSet = new HashMap<String, Object>();
        for (RestVariable var : actionRequest.getVariables()) {
            if (var.getName() == null) {
                throw new ActivitiIllegalArgumentException("Variable name is required");
            }
            Object actualVariableValue = restResponseFactory.getVariableValue(var);
            variablesToSet.put(var.getName(), actualVariableValue);
        }
        taskService.complete(task.getId(), variablesToSet);
    } else {
        taskService.complete(task.getId());
    }
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 25 with ActivitiIllegalArgumentException

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

the class TaskVariableBaseResource method setSimpleVariable.

protected RestVariable setSimpleVariable(RestVariable restVariable, Task task, boolean isNew) {
    if (restVariable.getName() == null) {
        throw new ActivitiIllegalArgumentException("Variable name is required");
    }
    // Figure out scope, revert to local is omitted
    RestVariableScope scope = restVariable.getVariableScope();
    if (scope == null) {
        scope = RestVariableScope.LOCAL;
    }
    Object actualVariableValue = restResponseFactory.getVariableValue(restVariable);
    setVariable(task, restVariable.getName(), actualVariableValue, scope, isNew);
    return restResponseFactory.createRestVariable(restVariable.getName(), actualVariableValue, scope, task.getId(), RestResponseFactory.VARIABLE_TASK, false);
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) RestVariableScope(org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope)

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