use of org.camunda.bpm.engine.rest.exception.RestException 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());
}
}
}
use of org.camunda.bpm.engine.rest.exception.RestException in project camunda-bpm-platform by camunda.
the class TaskQueryDto method sortByValueForQueryEntityRelationCondition.
public static String sortByValueForQueryEntityRelationCondition(QueryEntityRelationCondition relationCondition) {
QueryProperty property = relationCondition.getProperty();
QueryProperty comparisonProperty = relationCondition.getComparisonProperty();
if (VariableInstanceQueryProperty.EXECUTION_ID.equals(property) && TaskQueryProperty.PROCESS_INSTANCE_ID.equals(comparisonProperty)) {
return SORT_BY_PROCESS_VARIABLE;
} else if (VariableInstanceQueryProperty.EXECUTION_ID.equals(property) && TaskQueryProperty.EXECUTION_ID.equals(comparisonProperty)) {
return SORT_BY_EXECUTION_VARIABLE;
} else if (VariableInstanceQueryProperty.TASK_ID.equals(property) && TaskQueryProperty.TASK_ID.equals(comparisonProperty)) {
return SORT_BY_TASK_VARIABLE;
} else if (VariableInstanceQueryProperty.CASE_EXECUTION_ID.equals(property) && TaskQueryProperty.CASE_INSTANCE_ID.equals(comparisonProperty)) {
return SORT_BY_CASE_INSTANCE_VARIABLE;
} else if (VariableInstanceQueryProperty.CASE_EXECUTION_ID.equals(property) && TaskQueryProperty.CASE_EXECUTION_ID.equals(comparisonProperty)) {
return SORT_BY_CASE_EXECUTION_VARIABLE;
} else {
throw new RestException("Unknown relation condition for task query with query property " + property + " and comparison property " + comparisonProperty);
}
}
use of org.camunda.bpm.engine.rest.exception.RestException in project camunda-bpm-platform by camunda.
the class MultipartPayloadProvider method parseRequest.
protected void parseRequest(MultipartFormData multipartFormData, FileUpload fileUpload, RestMultipartRequestContext requestContext) {
try {
FileItemIterator itemIterator = fileUpload.getItemIterator(requestContext);
while (itemIterator.hasNext()) {
FileItemStream stream = itemIterator.next();
multipartFormData.addPart(new FormPart(stream));
}
} catch (Exception e) {
throw new RestException(Status.BAD_REQUEST, e, "multipart/form-data cannot be processed");
}
}
use of org.camunda.bpm.engine.rest.exception.RestException in project camunda-bpm-platform by camunda.
the class MessageRestServiceImpl method deliverMessage.
@Override
public Response deliverMessage(CorrelationMessageDto messageDto) {
if (messageDto.getMessageName() == null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "No message name supplied");
}
if (messageDto.getTenantId() != null && messageDto.isWithoutTenantId()) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Parameter 'tenantId' cannot be used together with parameter 'withoutTenantId'.");
}
List<MessageCorrelationResultDto> resultDtos = new ArrayList<MessageCorrelationResultDto>();
try {
MessageCorrelationBuilder correlation = createMessageCorrelationBuilder(messageDto);
if (!messageDto.isAll()) {
MessageCorrelationResult result = correlation.correlateWithResult();
resultDtos.add(MessageCorrelationResultDto.fromMessageCorrelationResult(result));
} else {
List<MessageCorrelationResult> results = correlation.correlateAllWithResult();
for (MessageCorrelationResult result : results) {
resultDtos.add(MessageCorrelationResultDto.fromMessageCorrelationResult(result));
}
}
} catch (RestException e) {
String errorMessage = String.format("Cannot deliver message: %s", e.getMessage());
throw new InvalidRequestException(e.getStatus(), e, errorMessage);
} catch (MismatchingMessageCorrelationException e) {
throw new RestException(Status.BAD_REQUEST, e);
}
return createResponse(resultDtos, messageDto);
}
use of org.camunda.bpm.engine.rest.exception.RestException in project camunda-bpm-platform by camunda.
the class NamedProcessEngineRestServiceImpl method getProcessEngineProvider.
protected ProcessEngineProvider getProcessEngineProvider() {
ServiceLoader<ProcessEngineProvider> serviceLoader = ServiceLoader.load(ProcessEngineProvider.class);
Iterator<ProcessEngineProvider> iterator = serviceLoader.iterator();
if (iterator.hasNext()) {
ProcessEngineProvider provider = iterator.next();
return provider;
} else {
throw new RestException(Status.INTERNAL_SERVER_ERROR, "No process engine provider found");
}
}
Aggregations