Search in sources :

Example 1 with MessageCorrelationResultDto

use of org.camunda.bpm.engine.rest.dto.message.MessageCorrelationResultDto 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)

Aggregations

ArrayList (java.util.ArrayList)1 MismatchingMessageCorrelationException (org.camunda.bpm.engine.MismatchingMessageCorrelationException)1 MessageCorrelationResultDto (org.camunda.bpm.engine.rest.dto.message.MessageCorrelationResultDto)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1 RestException (org.camunda.bpm.engine.rest.exception.RestException)1 MessageCorrelationBuilder (org.camunda.bpm.engine.runtime.MessageCorrelationBuilder)1 MessageCorrelationResult (org.camunda.bpm.engine.runtime.MessageCorrelationResult)1