Search in sources :

Example 1 with MessageCorrelationBuilder

use of org.camunda.bpm.engine.runtime.MessageCorrelationBuilder 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 2 with MessageCorrelationBuilder

use of org.camunda.bpm.engine.runtime.MessageCorrelationBuilder in project camunda-bpm-platform by camunda.

the class MessageRestServiceImpl method createMessageCorrelationBuilder.

protected MessageCorrelationBuilder createMessageCorrelationBuilder(CorrelationMessageDto messageDto) {
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ObjectMapper objectMapper = getObjectMapper();
    Map<String, Object> correlationKeys = VariableValueDto.toMap(messageDto.getCorrelationKeys(), processEngine, objectMapper);
    Map<String, Object> localCorrelationKeys = VariableValueDto.toMap(messageDto.getLocalCorrelationKeys(), processEngine, objectMapper);
    Map<String, Object> processVariables = VariableValueDto.toMap(messageDto.getProcessVariables(), processEngine, objectMapper);
    MessageCorrelationBuilder builder = runtimeService.createMessageCorrelation(messageDto.getMessageName());
    if (processVariables != null) {
        builder.setVariables(processVariables);
    }
    if (messageDto.getBusinessKey() != null) {
        builder.processInstanceBusinessKey(messageDto.getBusinessKey());
    }
    if (correlationKeys != null && !correlationKeys.isEmpty()) {
        for (Entry<String, Object> correlationKey : correlationKeys.entrySet()) {
            String name = correlationKey.getKey();
            Object value = correlationKey.getValue();
            builder.processInstanceVariableEquals(name, value);
        }
    }
    if (localCorrelationKeys != null && !localCorrelationKeys.isEmpty()) {
        for (Entry<String, Object> correlationKey : localCorrelationKeys.entrySet()) {
            String name = correlationKey.getKey();
            Object value = correlationKey.getValue();
            builder.localVariableEquals(name, value);
        }
    }
    if (messageDto.getTenantId() != null) {
        builder.tenantId(messageDto.getTenantId());
    } else if (messageDto.isWithoutTenantId()) {
        builder.withoutTenantId();
    }
    String processInstanceId = messageDto.getProcessInstanceId();
    if (processInstanceId != null) {
        builder.processInstanceId(processInstanceId);
    }
    return builder;
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) MessageCorrelationBuilder(org.camunda.bpm.engine.runtime.MessageCorrelationBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

MessageCorrelationBuilder (org.camunda.bpm.engine.runtime.MessageCorrelationBuilder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 MismatchingMessageCorrelationException (org.camunda.bpm.engine.MismatchingMessageCorrelationException)1 RuntimeService (org.camunda.bpm.engine.RuntimeService)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 MessageCorrelationResult (org.camunda.bpm.engine.runtime.MessageCorrelationResult)1