Search in sources :

Example 31 with RestException

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

the class JobResourceImpl method setJobPriority.

@Override
public void setJobPriority(PriorityDto dto) {
    if (dto.getPriority() == null) {
        throw new RestException(Status.BAD_REQUEST, "Priority for job '" + jobId + "' cannot be null.");
    }
    try {
        ManagementService managementService = engine.getManagementService();
        managementService.setJobPriority(jobId, dto.getPriority());
    } catch (AuthorizationException e) {
        throw e;
    } catch (NotFoundException e) {
        throw new InvalidRequestException(Status.NOT_FOUND, e.getMessage());
    } catch (ProcessEngineException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : ManagementService(org.camunda.bpm.engine.ManagementService) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 32 with RestException

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

the class EngineUtil method lookupProcessEngine.

/**
 * Look up the process engine from the {@link ProcessEngineProvider}. If engineName is null, the default engine is returned.
 * @param engineName
 * @return
 */
public static ProcessEngine lookupProcessEngine(String engineName) {
    ServiceLoader<ProcessEngineProvider> serviceLoader = ServiceLoader.load(ProcessEngineProvider.class);
    Iterator<ProcessEngineProvider> iterator = serviceLoader.iterator();
    if (iterator.hasNext()) {
        ProcessEngineProvider provider = iterator.next();
        if (engineName == null) {
            return provider.getDefaultProcessEngine();
        } else {
            return provider.getProcessEngine(engineName);
        }
    } else {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, "Could not find an implementation of the " + ProcessEngineProvider.class + "- SPI");
    }
}
Also used : RestException(org.camunda.bpm.engine.rest.exception.RestException) ProcessEngineProvider(org.camunda.bpm.engine.rest.spi.ProcessEngineProvider)

Example 33 with RestException

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

the class JobQueryDto method applyFilters.

@Override
protected void applyFilters(JobQuery query) {
    if (activityId != null) {
        query.activityId(activityId);
    }
    if (jobId != null) {
        query.jobId(jobId);
    }
    if (executionId != null) {
        query.executionId(executionId);
    }
    if (processInstanceId != null) {
        query.processInstanceId(processInstanceId);
    }
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (processDefinitionKey != null) {
        query.processDefinitionKey(processDefinitionKey);
    }
    if (TRUE.equals(withRetriesLeft)) {
        query.withRetriesLeft();
    }
    if (TRUE.equals(executable)) {
        query.executable();
    }
    if (TRUE.equals(timers)) {
        if (messages != null && messages) {
            throw new InvalidRequestException(Status.BAD_REQUEST, "Parameter timers cannot be used together with parameter messages.");
        }
        query.timers();
    }
    if (TRUE.equals(messages)) {
        if (timers != null && timers) {
            throw new InvalidRequestException(Status.BAD_REQUEST, "Parameter messages cannot be used together with parameter timers.");
        }
        query.messages();
    }
    if (TRUE.equals(withException)) {
        query.withException();
    }
    if (exceptionMessage != null) {
        query.exceptionMessage(exceptionMessage);
    }
    if (TRUE.equals(noRetriesLeft)) {
        query.noRetriesLeft();
    }
    if (TRUE.equals(active)) {
        query.active();
    }
    if (TRUE.equals(suspended)) {
        query.suspended();
    }
    if (priorityHigherThanOrEquals != null) {
        query.priorityHigherThanOrEquals(priorityHigherThanOrEquals);
    }
    if (priorityLowerThanOrEquals != null) {
        query.priorityLowerThanOrEquals(priorityLowerThanOrEquals);
    }
    if (jobDefinitionId != null) {
        query.jobDefinitionId(jobDefinitionId);
    }
    if (dueDates != null) {
        DateConverter dateConverter = new DateConverter();
        dateConverter.setObjectMapper(objectMapper);
        for (ConditionQueryParameterDto conditionQueryParam : dueDates) {
            String op = conditionQueryParam.getOperator();
            Date dueDate = null;
            try {
                dueDate = dateConverter.convertQueryParameterToType((String) conditionQueryParam.getValue());
            } catch (RestException e) {
                throw new InvalidRequestException(e.getStatus(), e, "Invalid due date format: " + e.getMessage());
            }
            if (op.equals(ConditionQueryParameterDto.GREATER_THAN_OPERATOR_NAME)) {
                query.duedateHigherThan(dueDate);
            } else if (op.equals(ConditionQueryParameterDto.LESS_THAN_OPERATOR_NAME)) {
                query.duedateLowerThan(dueDate);
            } else {
                throw new InvalidRequestException(Status.BAD_REQUEST, "Invalid due date comparator specified: " + op);
            }
        }
    }
    if (tenantIds != null && !tenantIds.isEmpty()) {
        query.tenantIdIn(tenantIds.toArray(new String[tenantIds.size()]));
    }
    if (TRUE.equals(withoutTenantId)) {
        query.withoutTenantId();
    }
    if (TRUE.equals(includeJobsWithoutTenantId)) {
        query.includeJobsWithoutTenantId();
    }
}
Also used : DateConverter(org.camunda.bpm.engine.rest.dto.converter.DateConverter) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Date(java.util.Date) ConditionQueryParameterDto(org.camunda.bpm.engine.rest.dto.ConditionQueryParameterDto)

Aggregations

RestException (org.camunda.bpm.engine.rest.exception.RestException)33 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)25 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)21 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)14 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)10 NotValidException (org.camunda.bpm.engine.exception.NotValidException)8 VariableMap (org.camunda.bpm.engine.variable.VariableMap)8 InputStream (java.io.InputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 URI (java.net.URI)3 FormService (org.camunda.bpm.engine.FormService)3 RepositoryService (org.camunda.bpm.engine.RepositoryService)3 MimeTypeParseException (javax.activation.MimeTypeParseException)2 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)2 ManagementService (org.camunda.bpm.engine.ManagementService)2 RuntimeService (org.camunda.bpm.engine.RuntimeService)2 TaskService (org.camunda.bpm.engine.TaskService)2 ProcessInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto)2 RestartProcessInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.RestartProcessInstanceDto)2 StartProcessInstanceDto (org.camunda.bpm.engine.rest.dto.runtime.StartProcessInstanceDto)2