}
protected List<MessageCorrelationResult> correlateMessageToExecutions(CommandContext commandContext, String messageName,
CorrelationSet correlationSet) {
ExecutionQueryImpl query = new ExecutionQueryImpl();
Map<String, Object> correlationKeys = correlationSet.getCorrelationKeys();
if (correlationKeys != null) {
for (Map.Entry<String, Object> correlationKey : correlationKeys.entrySet()) {
query.processVariableValueEquals(correlationKey.getKey(), correlationKey.getValue());
}
}
String businessKey = correlationSet.getBusinessKey();
if(businessKey != null) {
query.processInstanceBusinessKey(businessKey);
}
String processInstanceId = correlationSet.getProcessInstanceId();
if(processInstanceId != null) {
query.processInstanceId(processInstanceId);
}
if (messageName != null) {
query.messageEventSubscriptionName(messageName);
} else {
query.messageEventSubscription();
}
List<Execution> matchingExecutions = query.evaluateExpressionsAndExecuteList(commandContext, null);
List<MessageCorrelationResult> result = new ArrayList<MessageCorrelationResult>(matchingExecutions.size());
for(Execution matchingExecution: matchingExecutions) {
result.add(MessageCorrelationResult.matchedExecution((ExecutionEntity) matchingExecution));