Search in sources :

Example 11 with InvalidRequestException

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

the class ProcessDefinitionSuspensionStateDto method updateSuspensionState.

public void updateSuspensionState(ProcessEngine engine) {
    if (processDefinitionId != null && processDefinitionKey != null) {
        String message = "Only one of processDefinitionId or processDefinitionKey should be set to update the suspension state.";
        throw new InvalidRequestException(Status.BAD_REQUEST, message);
    }
    RepositoryService repositoryService = engine.getRepositoryService();
    Date delayedExecutionDate = null;
    if (executionDate != null && !executionDate.equals("")) {
        delayedExecutionDate = DateTimeUtil.parseDate(executionDate);
    }
    if (processDefinitionId != null) {
        // activate/suspend process definition by id
        if (getSuspended()) {
            repositoryService.suspendProcessDefinitionById(processDefinitionId, includeProcessInstances, delayedExecutionDate);
        } else {
            repositoryService.activateProcessDefinitionById(processDefinitionId, includeProcessInstances, delayedExecutionDate);
        }
    } else if (processDefinitionKey != null) {
        // activate/suspend process definition by key
        if (getSuspended()) {
            repositoryService.suspendProcessDefinitionByKey(processDefinitionKey, includeProcessInstances, delayedExecutionDate);
        } else {
            repositoryService.activateProcessDefinitionByKey(processDefinitionKey, includeProcessInstances, delayedExecutionDate);
        }
    } else {
        String message = "Either processDefinitionId or processDefinitionKey should be set to update the suspension state.";
        throw new InvalidRequestException(Status.BAD_REQUEST, message);
    }
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Date(java.util.Date) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 12 with InvalidRequestException

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

the class CaseExecutionQueryDto method applyFilters.

@Override
protected void applyFilters(CaseExecutionQuery query) {
    if (caseExecutionId != null) {
        query.caseExecutionId(caseExecutionId);
    }
    if (caseInstanceId != null) {
        query.caseInstanceId(caseInstanceId);
    }
    if (businessKey != null) {
        query.caseInstanceBusinessKey(businessKey);
    }
    if (caseDefinitionKey != null) {
        query.caseDefinitionKey(caseDefinitionKey);
    }
    if (caseDefinitionId != null) {
        query.caseDefinitionId(caseDefinitionId);
    }
    if (activityId != null) {
        query.activityId(activityId);
    }
    if (tenantIds != null && !tenantIds.isEmpty()) {
        query.tenantIdIn(tenantIds.toArray(new String[tenantIds.size()]));
    }
    if (required != null && required == true) {
        query.required();
    }
    if (active != null && active == true) {
        query.active();
    }
    if (enabled != null && enabled == true) {
        query.enabled();
    }
    if (disabled != null && disabled == true) {
        query.disabled();
    }
    if (variables != null) {
        for (VariableQueryParameterDto variableQueryParam : variables) {
            String variableName = variableQueryParam.getName();
            String op = variableQueryParam.getOperator();
            Object variableValue = variableQueryParam.resolveValue(objectMapper);
            if (op.equals(VariableQueryParameterDto.EQUALS_OPERATOR_NAME)) {
                query.variableValueEquals(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.GREATER_THAN_OPERATOR_NAME)) {
                query.variableValueGreaterThan(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.GREATER_THAN_OR_EQUALS_OPERATOR_NAME)) {
                query.variableValueGreaterThanOrEqual(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LESS_THAN_OPERATOR_NAME)) {
                query.variableValueLessThan(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LESS_THAN_OR_EQUALS_OPERATOR_NAME)) {
                query.variableValueLessThanOrEqual(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.NOT_EQUALS_OPERATOR_NAME)) {
                query.variableValueNotEquals(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LIKE_OPERATOR_NAME)) {
                query.variableValueLike(variableName, String.valueOf(variableValue));
            } else {
                throw new InvalidRequestException(Status.BAD_REQUEST, "Invalid variable comparator specified: " + op);
            }
        }
    }
    if (caseInstanceVariables != null) {
        for (VariableQueryParameterDto variableQueryParam : caseInstanceVariables) {
            String variableName = variableQueryParam.getName();
            String op = variableQueryParam.getOperator();
            Object variableValue = variableQueryParam.resolveValue(objectMapper);
            if (op.equals(VariableQueryParameterDto.EQUALS_OPERATOR_NAME)) {
                query.caseInstanceVariableValueEquals(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.GREATER_THAN_OPERATOR_NAME)) {
                query.caseInstanceVariableValueGreaterThan(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.GREATER_THAN_OR_EQUALS_OPERATOR_NAME)) {
                query.caseInstanceVariableValueGreaterThanOrEqual(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LESS_THAN_OPERATOR_NAME)) {
                query.caseInstanceVariableValueLessThan(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LESS_THAN_OR_EQUALS_OPERATOR_NAME)) {
                query.caseInstanceVariableValueLessThanOrEqual(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.NOT_EQUALS_OPERATOR_NAME)) {
                query.caseInstanceVariableValueNotEquals(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LIKE_OPERATOR_NAME)) {
                query.caseInstanceVariableValueLike(variableName, String.valueOf(variableValue));
            } else {
                throw new InvalidRequestException(Status.BAD_REQUEST, "Invalid variable comparator specified: " + op);
            }
        }
    }
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) VariableQueryParameterDto(org.camunda.bpm.engine.rest.dto.VariableQueryParameterDto)

Example 13 with InvalidRequestException

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

the class JobDefinitionSuspensionStateDto method updateSuspensionState.

@Override
public void updateSuspensionState(ProcessEngine engine) {
    int params = (jobDefinitionId != null ? 1 : 0) + (processDefinitionId != null ? 1 : 0) + (processDefinitionKey != null ? 1 : 0);
    if (params > 1) {
        String message = "Only one of jobDefinitionId, processDefinitionId or processDefinitionKey should be set to update the suspension state.";
        throw new InvalidRequestException(Status.BAD_REQUEST, message);
    } else if (params == 0) {
        String message = "Either jobDefinitionId, processDefinitionId or processDefinitionKey should be set to update the suspension state.";
        throw new InvalidRequestException(Status.BAD_REQUEST, message);
    }
    UpdateJobDefinitionSuspensionStateBuilder updateSuspensionStateBuilder = createUpdateSuspensionStateBuilder(engine);
    if (executionDate != null && !executionDate.equals("")) {
        Date delayedExecutionDate = DateTimeUtil.parseDate(executionDate);
        updateSuspensionStateBuilder.executionDate(delayedExecutionDate);
    }
    updateSuspensionStateBuilder.includeJobs(includeJobs);
    if (getSuspended()) {
        updateSuspensionStateBuilder.suspend();
    } else {
        updateSuspensionStateBuilder.activate();
    }
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) UpdateJobDefinitionSuspensionStateBuilder(org.camunda.bpm.engine.management.UpdateJobDefinitionSuspensionStateBuilder) Date(java.util.Date)

Example 14 with InvalidRequestException

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

the class ExecutionQueryDto method applyFilters.

@Override
protected void applyFilters(ExecutionQuery query) {
    if (processDefinitionKey != null) {
        query.processDefinitionKey(processDefinitionKey);
    }
    if (businessKey != null) {
        query.processInstanceBusinessKey(businessKey);
    }
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (processInstanceId != null) {
        query.processInstanceId(processInstanceId);
    }
    if (activityId != null) {
        query.activityId(activityId);
    }
    if (signalEventSubscriptionName != null) {
        query.signalEventSubscriptionName(signalEventSubscriptionName);
    }
    if (messageEventSubscriptionName != null) {
        query.messageEventSubscriptionName(messageEventSubscriptionName);
    }
    if (active != null && active == true) {
        query.active();
    }
    if (suspended != null && suspended == true) {
        query.suspended();
    }
    if (incidentId != null) {
        query.incidentId(incidentId);
    }
    if (incidentType != null) {
        query.incidentType(incidentType);
    }
    if (incidentMessage != null) {
        query.incidentMessage(incidentMessage);
    }
    if (incidentMessageLike != null) {
        query.incidentMessageLike(incidentMessageLike);
    }
    if (tenantIdIn != null && !tenantIdIn.isEmpty()) {
        query.tenantIdIn(tenantIdIn.toArray(new String[tenantIdIn.size()]));
    }
    if (variables != null) {
        for (VariableQueryParameterDto variableQueryParam : variables) {
            String variableName = variableQueryParam.getName();
            String op = variableQueryParam.getOperator();
            Object variableValue = variableQueryParam.resolveValue(objectMapper);
            if (op.equals(VariableQueryParameterDto.EQUALS_OPERATOR_NAME)) {
                query.variableValueEquals(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.GREATER_THAN_OPERATOR_NAME)) {
                query.variableValueGreaterThan(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.GREATER_THAN_OR_EQUALS_OPERATOR_NAME)) {
                query.variableValueGreaterThanOrEqual(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LESS_THAN_OPERATOR_NAME)) {
                query.variableValueLessThan(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LESS_THAN_OR_EQUALS_OPERATOR_NAME)) {
                query.variableValueLessThanOrEqual(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.NOT_EQUALS_OPERATOR_NAME)) {
                query.variableValueNotEquals(variableName, variableValue);
            } else if (op.equals(VariableQueryParameterDto.LIKE_OPERATOR_NAME)) {
                query.variableValueLike(variableName, String.valueOf(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 {
                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 15 with InvalidRequestException

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

the class ProcessInstanceRestServiceImpl method deleteAsync.

@Override
public BatchDto deleteAsync(DeleteProcessInstancesDto dto) {
    RuntimeService runtimeService = getProcessEngine().getRuntimeService();
    ProcessInstanceQuery processInstanceQuery = null;
    if (dto.getProcessInstanceQuery() != null) {
        processInstanceQuery = dto.getProcessInstanceQuery().toQuery(getProcessEngine());
    }
    Batch batch = null;
    try {
        batch = runtimeService.deleteProcessInstancesAsync(dto.getProcessInstanceIds(), processInstanceQuery, dto.getDeleteReason(), dto.isSkipCustomListeners(), dto.isSkipSubprocesses());
        return BatchDto.fromBatch(batch);
    } catch (BadUserRequestException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
    }
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) RuntimeService(org.camunda.bpm.engine.RuntimeService) Batch(org.camunda.bpm.engine.batch.Batch) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

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