use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class BoundaryErrorEventTest method testCatchErrorOnSubprocessThrownByInterruptingEventSubprocess.
@Deployment
public void testCatchErrorOnSubprocessThrownByInterruptingEventSubprocess() {
runtimeService.startProcessInstanceByKey("testProcess");
EventSubscription messageSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
runtimeService.messageEventReceived("message", messageSubscription.getExecutionId());
// should successfully have reached the task following the boundary event
Execution taskExecution = runtimeService.createExecutionQuery().activityId("afterBoundaryTask").singleResult();
assertNotNull(taskExecution);
Task task = taskService.createTaskQuery().executionId(taskExecution.getId()).singleResult();
assertNotNull(task);
}
use of org.camunda.bpm.engine.runtime.Execution 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;
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MessageCorrelationTest method testCorrelationWithoutMessageNameFluent.
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
@Test
public void testCorrelationWithoutMessageNameFluent() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("variable", "value1");
runtimeService.startProcessInstanceByKey("process", variables);
variables.put("variable", "value2");
ProcessInstance instance = runtimeService.startProcessInstanceByKey("process", variables);
runtimeService.createMessageCorrelation(null).processInstanceVariableEquals("variable", "value2").correlate();
List<Execution> correlatedExecutions = runtimeService.createExecutionQuery().activityId("task").list();
assertEquals(1, correlatedExecutions.size());
assertEquals(instance.getId(), correlatedExecutions.get(0).getId());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MessageCorrelationTest method testCorrelationByProcessInstanceIdOnly.
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
@Test
public void testCorrelationByProcessInstanceIdOnly() {
runtimeService.startProcessInstanceByKey("process");
ProcessInstance instance = runtimeService.startProcessInstanceByKey("process");
runtimeService.createMessageCorrelation(null).processInstanceId(instance.getId()).correlate();
List<Execution> correlatedExecutions = runtimeService.createExecutionQuery().activityId("task").list();
assertEquals(1, correlatedExecutions.size());
assertEquals(instance.getId(), correlatedExecutions.get(0).getId());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MessageCorrelationTest method testCorrelationByBusinessKeyAndVariables.
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
@Test
public void testCorrelationByBusinessKeyAndVariables() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("aKey", "aValue");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process", "aBusinessKey", variables);
variables = new HashMap<String, Object>();
variables.put("aKey", "aValue");
runtimeService.startProcessInstanceByKey("process", "anotherBusinessKey", variables);
String messageName = "newInvoiceMessage";
Map<String, Object> correlationKeys = new HashMap<String, Object>();
correlationKeys.put("aKey", "aValue");
Map<String, Object> processVariables = new HashMap<String, Object>();
processVariables.put("aProcessVariable", "aVariableValue");
runtimeService.correlateMessage(messageName, "aBusinessKey", correlationKeys, processVariables);
Execution correlatedExecution = runtimeService.createExecutionQuery().activityId("task").processVariableValueEquals("aProcessVariable", "aVariableValue").singleResult();
assertNotNull(correlatedExecution);
ProcessInstance correlatedProcessInstance = runtimeService.createProcessInstanceQuery().processInstanceId(correlatedExecution.getProcessInstanceId()).singleResult();
assertEquals("aBusinessKey", correlatedProcessInstance.getBusinessKey());
runtimeService.deleteProcessInstance(processInstance.getId(), null);
// fluent builder /////////////////////////////
variables = new HashMap<String, Object>();
variables.put("aKey", "aValue");
processInstance = runtimeService.startProcessInstanceByKey("process", "aBusinessKey", variables);
runtimeService.createMessageCorrelation(messageName).processInstanceBusinessKey("aBusinessKey").processInstanceVariableEquals("aKey", "aValue").setVariable("aProcessVariable", "aVariableValue").correlate();
correlatedExecution = runtimeService.createExecutionQuery().activityId("task").processVariableValueEquals("aProcessVariable", "aVariableValue").singleResult();
assertNotNull(correlatedExecution);
correlatedProcessInstance = runtimeService.createProcessInstanceQuery().processInstanceId(correlatedExecution.getProcessInstanceId()).singleResult();
assertEquals("aBusinessKey", correlatedProcessInstance.getBusinessKey());
runtimeService.deleteProcessInstance(processInstance.getId(), null);
}
Aggregations