Search in sources :

Example 1 with MessageCorrelationResult

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);
}
Also used : MessageCorrelationResultDto(org.camunda.bpm.engine.rest.dto.message.MessageCorrelationResultDto) ArrayList(java.util.ArrayList) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) MessageCorrelationBuilder(org.camunda.bpm.engine.runtime.MessageCorrelationBuilder) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) MismatchingMessageCorrelationException(org.camunda.bpm.engine.MismatchingMessageCorrelationException)

Example 2 with MessageCorrelationResult

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;
}
Also used : CorrelationHandler(org.camunda.bpm.engine.impl.runtime.CorrelationHandler) CorrelationSet(org.camunda.bpm.engine.impl.runtime.CorrelationSet) ArrayList(java.util.ArrayList) CorrelationHandlerResult(org.camunda.bpm.engine.impl.runtime.CorrelationHandlerResult) List(java.util.List) ArrayList(java.util.ArrayList) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult)

Example 3 with MessageCorrelationResult

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");
    }
}
Also used : MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with MessageCorrelationResult

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());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) Test(org.junit.Test)

Example 5 with MessageCorrelationResult

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());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) Test(org.junit.Test)

Aggregations

MessageCorrelationResult (org.camunda.bpm.engine.runtime.MessageCorrelationResult)13 Test (org.junit.Test)10 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)9 Execution (org.camunda.bpm.engine.runtime.Execution)6 HashMap (java.util.HashMap)5 Deployment (org.camunda.bpm.engine.test.Deployment)5 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)5 ArrayList (java.util.ArrayList)2 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)2 List (java.util.List)1 MismatchingMessageCorrelationException (org.camunda.bpm.engine.MismatchingMessageCorrelationException)1 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)1 CorrelationHandler (org.camunda.bpm.engine.impl.runtime.CorrelationHandler)1 CorrelationHandlerResult (org.camunda.bpm.engine.impl.runtime.CorrelationHandlerResult)1 CorrelationSet (org.camunda.bpm.engine.impl.runtime.CorrelationSet)1 MessageCorrelationResultDto (org.camunda.bpm.engine.rest.dto.message.MessageCorrelationResultDto)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1 RestException (org.camunda.bpm.engine.rest.exception.RestException)1 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)1 MessageCorrelationBuilder (org.camunda.bpm.engine.runtime.MessageCorrelationBuilder)1