Search in sources :

Example 1 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class HistoricTaskInstanceQueryDto method applyFilters.

@Override
protected void applyFilters(HistoricTaskInstanceQuery query) {
    if (taskId != null) {
        query.taskId(taskId);
    }
    if (taskParentTaskId != null) {
        query.taskParentTaskId(taskParentTaskId);
    }
    if (processInstanceId != null) {
        query.processInstanceId(processInstanceId);
    }
    if (processInstanceBusinessKey != null) {
        query.processInstanceBusinessKey(processInstanceBusinessKey);
    }
    if (processInstanceBusinessKeyIn != null && processInstanceBusinessKeyIn.length > 0) {
        query.processInstanceBusinessKeyIn(processInstanceBusinessKeyIn);
    }
    if (processInstanceBusinessKeyLike != null) {
        query.processInstanceBusinessKeyLike(processInstanceBusinessKeyLike);
    }
    if (executionId != null) {
        query.executionId(executionId);
    }
    if (activityInstanceIdIn != null && activityInstanceIdIn.length > 0) {
        query.activityInstanceIdIn(activityInstanceIdIn);
    }
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (processDefinitionKey != null) {
        query.processDefinitionKey(processDefinitionKey);
    }
    if (processDefinitionName != null) {
        query.processDefinitionName(processDefinitionName);
    }
    if (taskName != null) {
        query.taskName(taskName);
    }
    if (taskNameLike != null) {
        query.taskNameLike(taskNameLike);
    }
    if (taskDescription != null) {
        query.taskDescription(taskDescription);
    }
    if (taskDescriptionLike != null) {
        query.taskDescriptionLike(taskDescriptionLike);
    }
    if (taskDefinitionKey != null) {
        query.taskDefinitionKey(taskDefinitionKey);
    }
    if (taskDefinitionKeyIn != null && taskDefinitionKeyIn.length > 0) {
        query.taskDefinitionKeyIn(taskDefinitionKeyIn);
    }
    if (taskDeleteReason != null) {
        query.taskDeleteReason(taskDeleteReason);
    }
    if (taskDeleteReasonLike != null) {
        query.taskDeleteReasonLike(taskDeleteReasonLike);
    }
    if (assigned != null) {
        query.taskAssigned();
    }
    if (unassigned != null) {
        query.taskUnassigned();
    }
    if (taskAssignee != null) {
        query.taskAssignee(taskAssignee);
    }
    if (taskAssigneeLike != null) {
        query.taskAssigneeLike(taskAssigneeLike);
    }
    if (taskOwner != null) {
        query.taskOwner(taskOwner);
    }
    if (taskOwnerLike != null) {
        query.taskOwnerLike(taskOwnerLike);
    }
    if (taskPriority != null) {
        query.taskPriority(taskPriority);
    }
    if (finished != null) {
        query.finished();
    }
    if (unfinished != null) {
        query.unfinished();
    }
    if (processFinished != null) {
        query.processFinished();
    }
    if (processUnfinished != null) {
        query.processUnfinished();
    }
    if (taskDueDate != null) {
        query.taskDueDate(taskDueDate);
    }
    if (taskDueDateBefore != null) {
        query.taskDueBefore(taskDueDateBefore);
    }
    if (taskDueDateAfter != null) {
        query.taskDueAfter(taskDueDateAfter);
    }
    if (taskFollowUpDate != null) {
        query.taskFollowUpDate(taskFollowUpDate);
    }
    if (taskFollowUpDateBefore != null) {
        query.taskFollowUpBefore(taskFollowUpDateBefore);
    }
    if (taskFollowUpDateAfter != null) {
        query.taskFollowUpAfter(taskFollowUpDateAfter);
    }
    if (caseDefinitionId != null) {
        query.caseDefinitionId(caseDefinitionId);
    }
    if (caseDefinitionKey != null) {
        query.caseDefinitionKey(caseDefinitionKey);
    }
    if (caseDefinitionName != null) {
        query.caseDefinitionName(caseDefinitionName);
    }
    if (caseInstanceId != null) {
        query.caseInstanceId(caseInstanceId);
    }
    if (caseExecutionId != null) {
        query.caseExecutionId(caseExecutionId);
    }
    if (tenantIds != null && !tenantIds.isEmpty()) {
        query.tenantIdIn(tenantIds.toArray(new String[tenantIds.size()]));
    }
    if (taskInvolvedUser != null) {
        query.taskInvolvedUser(taskInvolvedUser);
    }
    if (taskInvolvedGroup != null) {
        query.taskInvolvedGroup(taskInvolvedGroup);
    }
    if (taskHadCandidateUser != null) {
        query.taskHadCandidateUser(taskHadCandidateUser);
    }
    if (taskHadCandidateGroup != null) {
        query.taskHadCandidateGroup(taskHadCandidateGroup);
    }
    if (withCandidateGroups != null) {
        query.withCandidateGroups();
    }
    if (withoutCandidateGroups != null) {
        query.withoutCandidateGroups();
    }
    if (finishedAfter != null) {
        query.finishedAfter(finishedAfter);
    }
    if (finishedBefore != null) {
        query.finishedBefore(finishedBefore);
    }
    if (startedAfter != null) {
        query.startedAfter(startedAfter);
    }
    if (startedBefore != null) {
        query.startedBefore(startedBefore);
    }
    if (taskVariables != null) {
        for (VariableQueryParameterDto variableQueryParam : taskVariables) {
            String variableName = variableQueryParam.getName();
            String op = variableQueryParam.getOperator();
            Object variableValue = variableQueryParam.resolveValue(objectMapper);
            if (op.equals(VariableQueryParameterDto.EQUALS_OPERATOR_NAME)) {
                query.taskVariableValueEquals(variableName, variableValue);
            } else {
                throw new InvalidRequestException(Status.BAD_REQUEST, "Invalid variable comparator specified: " + op);
            }
        }
    }
    if (processVariables != null) {
        for (VariableQueryParameterDto variableQueryParam : processVariables) {
            String variableName = variableQueryParam.getName();
            String op = variableQueryParam.getOperator();
            Object variableValue = variableQueryParam.resolveValue(objectMapper);
            if (op.equals(VariableQueryParameterDto.EQUALS_OPERATOR_NAME)) {
                query.processVariableValueEquals(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.NOT_EQUALS_OPERATOR_NAME)) {
                query.processVariableValueNotEquals(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.GREATER_THAN_OPERATOR_NAME)) {
                query.processVariableValueGreaterThan(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.GREATER_THAN_OR_EQUALS_OPERATOR_NAME)) {
                query.processVariableValueGreaterThanOrEquals(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LESS_THAN_OPERATOR_NAME)) {
                query.processVariableValueLessThan(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LESS_THAN_OR_EQUALS_OPERATOR_NAME)) {
                query.processVariableValueLessThanOrEquals(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LIKE_OPERATOR_NAME)) {
                query.processVariableValueLike(variableName, String.valueOf(variableValue));
            } else {
                throw new InvalidRequestException(Status.BAD_REQUEST, "Invalid process variable comparator specified: " + op);
            }
        }
    }
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) VariableQueryParameterDto(org.camunda.bpm.engine.rest.dto.VariableQueryParameterDto)

Example 2 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class HistoricTaskInstanceReportQueryDto method executeCompletedReport.

public List<HistoricTaskInstanceReportResult> executeCompletedReport(ProcessEngine engine) {
    HistoricTaskInstanceReport reportQuery = createNewReportQuery(engine);
    applyFilters(reportQuery);
    if (PROCESS_DEFINITION.equals(groupby)) {
        return reportQuery.countByProcessDefinitionKey();
    } else if (TASK_NAME.equals(groupby)) {
        return reportQuery.countByTaskName();
    } else {
        throw new InvalidRequestException(Response.Status.BAD_REQUEST, "groupBy parameter has invalid value: " + groupby);
    }
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) HistoricTaskInstanceReport(org.camunda.bpm.engine.history.HistoricTaskInstanceReport)

Example 3 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class VariableListConverter method convertQueryParameterToType.

/**
 * Expects a query parameter of multiple variable expressions formatted as KEY_OPERATOR_VALUE, e.g. aVariable_eq_aValue.
 * Multiple values are expected to be comma-separated.
 */
@Override
public List<VariableQueryParameterDto> convertQueryParameterToType(String value) {
    String[] expressions = value.split(EXPRESSION_DELIMITER);
    List<VariableQueryParameterDto> queryVariables = new ArrayList<VariableQueryParameterDto>();
    for (String expression : expressions) {
        String[] valueTriple = expression.split(ATTRIBUTE_DELIMITER);
        if (valueTriple.length != 3) {
            throw new InvalidRequestException(Status.BAD_REQUEST, "variable query parameter has to have format KEY_OPERATOR_VALUE.");
        }
        VariableQueryParameterDto queryVariable = new VariableQueryParameterDto();
        queryVariable.setName(valueTriple[0]);
        queryVariable.setOperator(valueTriple[1]);
        queryVariable.setValue(valueTriple[2]);
        queryVariables.add(queryVariable);
    }
    return queryVariables;
}
Also used : ArrayList(java.util.ArrayList) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) VariableQueryParameterDto(org.camunda.bpm.engine.rest.dto.VariableQueryParameterDto)

Example 4 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class ConditionListConverter method convertQueryParameterToType.

@Override
public List<ConditionQueryParameterDto> convertQueryParameterToType(String value) {
    String[] expressions = value.split(EXPRESSION_DELIMITER);
    List<ConditionQueryParameterDto> queryConditions = new ArrayList<ConditionQueryParameterDto>();
    for (String expression : expressions) {
        String[] valueTuple = expression.split(ATTRIBUTE_DELIMITER);
        if (valueTuple.length != 2) {
            throw new InvalidRequestException(Status.BAD_REQUEST, "condition query parameter has to have format OPERATOR_VALUE.");
        }
        ConditionQueryParameterDto queryCondition = new ConditionQueryParameterDto();
        queryCondition.setOperator(valueTuple[0]);
        queryCondition.setValue(valueTuple[1]);
        queryConditions.add(queryCondition);
    }
    return queryConditions;
}
Also used : ArrayList(java.util.ArrayList) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ConditionQueryParameterDto(org.camunda.bpm.engine.rest.dto.ConditionQueryParameterDto)

Example 5 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class AbstractSearchQueryDto method setValueBasedOnAnnotation.

/**
 * Finds the methods that are annotated with a {@link CamundaQueryParam} with a value that matches the key parameter.
 * Before invoking these methods, the annotated {@link StringToTypeConverter} is used to convert the String value to the desired Java type.
 * @param key
 * @param value
 */
protected void setValueBasedOnAnnotation(String key, String value) {
    List<Method> matchingMethods = findMatchingAnnotatedMethods(key);
    for (Method method : matchingMethods) {
        Class<? extends JacksonAwareStringToTypeConverter<?>> converterClass = findAnnotatedTypeConverter(method);
        if (converterClass == null) {
            continue;
        }
        JacksonAwareStringToTypeConverter<?> converter = null;
        try {
            converter = converterClass.newInstance();
            converter.setObjectMapper(objectMapper);
            Object convertedValue = converter.convertQueryParameterToType(value);
            method.invoke(this, convertedValue);
        } catch (InstantiationException e) {
            throw new RestException(Status.INTERNAL_SERVER_ERROR, e, "Server error.");
        } catch (IllegalAccessException e) {
            throw new RestException(Status.INTERNAL_SERVER_ERROR, e, "Server error.");
        } catch (InvocationTargetException e) {
            throw new InvalidRequestException(Status.BAD_REQUEST, e, "Cannot set query parameter '" + key + "' to value '" + value + "'");
        } catch (RestException e) {
            throw new InvalidRequestException(e.getStatus(), e, "Cannot set query parameter '" + key + "' to value '" + value + "': " + e.getMessage());
        }
    }
}
Also used : RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)116 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)30 RestException (org.camunda.bpm.engine.rest.exception.RestException)25 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)20 NotValidException (org.camunda.bpm.engine.exception.NotValidException)12 ArrayList (java.util.ArrayList)11 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)11 ManagementService (org.camunda.bpm.engine.ManagementService)11 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)11 VariableQueryParameterDto (org.camunda.bpm.engine.rest.dto.VariableQueryParameterDto)10 HistoryService (org.camunda.bpm.engine.HistoryService)9 RuntimeService (org.camunda.bpm.engine.RuntimeService)9 InputStream (java.io.InputStream)8 RepositoryService (org.camunda.bpm.engine.RepositoryService)8 Batch (org.camunda.bpm.engine.batch.Batch)8 URI (java.net.URI)6 VariableMap (org.camunda.bpm.engine.variable.VariableMap)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 FormService (org.camunda.bpm.engine.FormService)5 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)5