use of org.camunda.bpm.engine.runtime.MessageCorrelationResult 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.MessageCorrelationResult in project camunda-bpm-platform by camunda.
the class CorrelateAllMessageCmd method execute.
public List<MessageCorrelationResult> execute(final CommandContext commandContext) {
ensureAtLeastOneNotNull("At least one of the following correlation criteria has to be present: " + "messageName, businessKey, correlationKeys, processInstanceId", messageName, builder.getBusinessKey(), builder.getCorrelationProcessInstanceVariables(), builder.getProcessInstanceId());
final CorrelationHandler correlationHandler = Context.getProcessEngineConfiguration().getCorrelationHandler();
final CorrelationSet correlationSet = new CorrelationSet(builder);
List<CorrelationHandlerResult> correlationResults = commandContext.runWithoutAuthorization(new Callable<List<CorrelationHandlerResult>>() {
public List<CorrelationHandlerResult> call() throws Exception {
return correlationHandler.correlateMessages(commandContext, messageName, correlationSet);
}
});
// check authorization
for (CorrelationHandlerResult correlationResult : correlationResults) {
checkAuthorization(correlationResult);
}
List<MessageCorrelationResult> results = new ArrayList<MessageCorrelationResult>();
for (CorrelationHandlerResult correlationResult : correlationResults) {
results.add(createMessageCorrelationResult(commandContext, correlationResult));
}
return results;
}
use of org.camunda.bpm.engine.runtime.MessageCorrelationResult in project camunda-bpm-platform by camunda.
the class MessageCorrelationTest method testMessageCorrelateAllResultListWithResultTypeProcessDefinition.
@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testMessageStartEventCorrelation.bpmn20.xml")
@Test
public void testMessageCorrelateAllResultListWithResultTypeProcessDefinition() {
// when correlated all with result
List<MessageCorrelationResult> resultList = runtimeService.createMessageCorrelation("newInvoiceMessage").correlateAllWithResult();
assertEquals(1, resultList.size());
// then result should contains process definitions and start event activity ids on which messages was correlated
for (MessageCorrelationResult result : resultList) {
checkProcessDefinitionMessageCorrelationResult(result, "theStart", "messageStartEvent");
}
}
use of org.camunda.bpm.engine.runtime.MessageCorrelationResult in project camunda-bpm-platform by camunda.
the class MessageCorrelationByLocalVariablesTest method testReceiveTaskMessageCorrelation.
@Test
public void testReceiveTaskMessageCorrelation() {
// given
BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1").startEvent().subProcess("SubProcess_1").embeddedSubProcess().startEvent().receiveTask("MessageReceiver_1").message(TEST_MESSAGE_NAME).camundaInputParameter("localVar", "${loopVar}").camundaInputParameter("constVar", // to test array of parameters
"someValue").userTask("UserTask_1").endEvent().subProcessDone().multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone().endEvent().done();
testHelper.deploy(model);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("vars", Arrays.asList(1, 2, 3));
ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables);
// when correlated by local variables
String messageName = TEST_MESSAGE_NAME;
Map<String, Object> correlationKeys = new HashMap<String, Object>();
int correlationKey = 1;
correlationKeys.put("localVar", correlationKey);
correlationKeys.put("constVar", "someValue");
MessageCorrelationResult messageCorrelationResult = engineRule.getRuntimeService().createMessageCorrelation(messageName).localVariablesEqual(correlationKeys).setVariables(Variables.createVariables().putValue("newVar", "newValue")).correlateWithResult();
// then one message is correlated, two other continue waiting
checkExecutionMessageCorrelationResult(messageCorrelationResult, processInstance, "MessageReceiver_1");
// uncorrelated executions
List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("MessageReceiver_1").list();
assertEquals(2, uncorrelatedExecutions.size());
}
use of org.camunda.bpm.engine.runtime.MessageCorrelationResult in project camunda-bpm-platform by camunda.
the class MessageCorrelationByLocalVariablesTest method testBothInstanceAndLocalVariableMessageCorrelation.
@Test
public void testBothInstanceAndLocalVariableMessageCorrelation() {
// given
BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1").startEvent().subProcess("SubProcess_1").embeddedSubProcess().startEvent().receiveTask("MessageReceiver_1").message(TEST_MESSAGE_NAME).userTask("UserTask_1").endEvent().subProcessDone().multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone().endEvent().done();
model = modify(model).activityBuilder("MessageReceiver_1").camundaInputParameter("localVar", "${loopVar}").camundaInputParameter("constVar", // to test array of parameters
"someValue").done();
testHelper.deploy(model);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("vars", Arrays.asList(1, 2, 3));
variables.put("processInstanceVar", "processInstanceVarValue");
ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables);
// second process instance with another process instance variable value
variables = new HashMap<String, Object>();
variables.put("vars", Arrays.asList(1, 2, 3));
variables.put("processInstanceVar", "anotherProcessInstanceVarValue");
engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables);
// when correlated by local variables
String messageName = TEST_MESSAGE_NAME;
Map<String, Object> correlationKeys = new HashMap<String, Object>();
int correlationKey = 1;
correlationKeys.put("localVar", correlationKey);
correlationKeys.put("constVar", "someValue");
Map<String, Object> processInstanceKeys = new HashMap<String, Object>();
String processInstanceVarValue = "processInstanceVarValue";
processInstanceKeys.put("processInstanceVar", processInstanceVarValue);
Map<String, Object> messagePayload = new HashMap<String, Object>();
messagePayload.put("newVar", "newValue");
MessageCorrelationResult messageCorrelationResult = engineRule.getRuntimeService().createMessageCorrelation(messageName).processInstanceVariablesEqual(processInstanceKeys).localVariablesEqual(correlationKeys).setVariables(messagePayload).correlateWithResult();
// then exactly one message is correlated = one receive task is passed by, two + three others continue waiting
checkExecutionMessageCorrelationResult(messageCorrelationResult, processInstance, "MessageReceiver_1");
// uncorrelated executions
List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("MessageReceiver_1").list();
assertEquals(5, uncorrelatedExecutions.size());
}
Aggregations