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());
}
}
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");
}
}
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();
}
}
Aggregations