Search in sources :

Example 1 with RestException

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

Example 2 with RestException

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);
    }
}
Also used : TaskQueryProperty(org.camunda.bpm.engine.impl.TaskQueryProperty) QueryProperty(org.camunda.bpm.engine.query.QueryProperty) VariableInstanceQueryProperty(org.camunda.bpm.engine.impl.VariableInstanceQueryProperty) RestException(org.camunda.bpm.engine.rest.exception.RestException)

Example 3 with RestException

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");
    }
}
Also used : FormPart(org.camunda.bpm.engine.rest.mapper.MultipartFormData.FormPart) FileItemStream(org.apache.commons.fileupload.FileItemStream) RestException(org.camunda.bpm.engine.rest.exception.RestException) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) IOException(java.io.IOException) RestException(org.camunda.bpm.engine.rest.exception.RestException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 4 with RestException

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);
}
Also used : MessageCorrelationResultDto(org.camunda.bpm.engine.rest.dto.message.MessageCorrelationResultDto) ArrayList(java.util.ArrayList) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) MessageCorrelationBuilder(org.camunda.bpm.engine.runtime.MessageCorrelationBuilder) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) MismatchingMessageCorrelationException(org.camunda.bpm.engine.MismatchingMessageCorrelationException)

Example 5 with RestException

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");
    }
}
Also used : RestException(org.camunda.bpm.engine.rest.exception.RestException) ProcessEngineProvider(org.camunda.bpm.engine.rest.spi.ProcessEngineProvider)

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