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