Search in sources :

Example 1 with ExecutionQueryImpl

use of org.camunda.bpm.engine.impl.ExecutionQueryImpl in project camunda-bpm-platform by camunda.

the class DefaultCorrelationHandler method correlateMessageToExecutions.

protected List<CorrelationHandlerResult> 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());
        }
    }
    Map<String, Object> localCorrelationKeys = correlationSet.getLocalCorrelationKeys();
    if (localCorrelationKeys != null) {
        for (Map.Entry<String, Object> correlationKey : localCorrelationKeys.entrySet()) {
            query.variableValueEquals(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();
    }
    if (correlationSet.isTenantIdSet) {
        String tenantId = correlationSet.getTenantId();
        if (tenantId != null) {
            query.tenantIdIn(tenantId);
        } else {
            query.withoutTenantId();
        }
    }
    // restrict to active executions
    query.active();
    List<Execution> matchingExecutions = query.evaluateExpressionsAndExecuteList(commandContext, null);
    List<CorrelationHandlerResult> result = new ArrayList<CorrelationHandlerResult>(matchingExecutions.size());
    for (Execution matchingExecution : matchingExecutions) {
        CorrelationHandlerResult correlationResult = CorrelationHandlerResult.matchedExecution((ExecutionEntity) matchingExecution);
        result.add(correlationResult);
    }
    return result;
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) ExecutionQueryImpl(org.camunda.bpm.engine.impl.ExecutionQueryImpl) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ExecutionQueryImpl (org.camunda.bpm.engine.impl.ExecutionQueryImpl)1 Execution (org.camunda.bpm.engine.runtime.Execution)1