Search in sources :

Example 21 with EventSubscriptionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.

the class TransactionSubProcessTest method testSimpleCaseTxSuccessful.

@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/subprocess/transaction/TransactionSubProcessTest.testSimpleCase.bpmn20.xml" })
public void testSimpleCaseTxSuccessful() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
    // after the process is started, we have compensate event subscriptions:
    assertEquals(5, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").count());
    assertEquals(1, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").count());
    // the task is present:
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    // making the tx succeed:
    taskService.setVariable(task.getId(), "confirmed", true);
    taskService.complete(task.getId());
    // now the process instance execution is sitting in the 'afterSuccess' task
    // -> has left the transaction using the "normal" sequence flow
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(processInstance.getId());
    assertTrue(activeActivityIds.contains("afterSuccess"));
    // there is a compensate event subscription for the transaction under the process instance
    EventSubscriptionEntity eventSubscriptionEntity = (EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("tx").executionId(processInstance.getId()).singleResult();
    // there is an event-scope execution associated with the event-subscription:
    assertNotNull(eventSubscriptionEntity.getConfiguration());
    Execution eventScopeExecution = runtimeService.createExecutionQuery().executionId(eventSubscriptionEntity.getConfiguration()).singleResult();
    assertNotNull(eventScopeExecution);
    // there is a compensate event subscription for the miBody of 'bookHotel' activity
    EventSubscriptionEntity miBodyEventSubscriptionEntity = (EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("bookHotel" + BpmnParse.MULTI_INSTANCE_BODY_ID_SUFFIX).executionId(eventScopeExecution.getId()).singleResult();
    assertNotNull(miBodyEventSubscriptionEntity);
    String miBodyEventScopeExecutionId = miBodyEventSubscriptionEntity.getConfiguration();
    // we still have compensate event subscriptions for the compensation handlers, only now they are part of the event scope
    assertEquals(5, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").executionId(miBodyEventScopeExecutionId).count());
    assertEquals(1, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").executionId(eventScopeExecution.getId()).count());
    assertEquals(1, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoChargeCard").executionId(eventScopeExecution.getId()).count());
    // assert that the compensation handlers have not been invoked:
    assertNull(runtimeService.getVariable(processInstance.getId(), "undoBookHotel"));
    assertNull(runtimeService.getVariable(processInstance.getId(), "undoBookFlight"));
    assertNull(runtimeService.getVariable(processInstance.getId(), "undoChargeCard"));
    // end the process instance
    runtimeService.signal(processInstance.getId());
    assertProcessEnded(processInstance.getId());
    assertEquals(0, runtimeService.createExecutionQuery().count());
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 22 with EventSubscriptionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.

the class SignalEventDeploymentTest method testUpdateEventSubscriptionOnDeployment.

public void testUpdateEventSubscriptionOnDeployment() {
    deploymentId = repositoryService.createDeployment().addClasspathResource(SIGNAL_START_EVENT_PROCESS).deploy().getId();
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().eventType("signal").singleResult();
    assertNotNull(eventSubscription);
    assertEquals("alert", eventSubscription.getEventName());
    // deploy a new version of the process with different signal name
    String newDeploymentId = repositoryService.createDeployment().addClasspathResource(SIGNAL_START_EVENT_PROCESS_NEW_VERSION).deploy().getId();
    ProcessDefinition newProcessDefinition = repositoryService.createProcessDefinitionQuery().latestVersion().singleResult();
    assertEquals(2, newProcessDefinition.getVersion());
    List<EventSubscription> newEventSubscriptions = runtimeService.createEventSubscriptionQuery().eventType("signal").list();
    // only one event subscription for the new version of the process definition
    assertEquals(1, newEventSubscriptions.size());
    EventSubscriptionEntity newEventSubscription = (EventSubscriptionEntity) newEventSubscriptions.iterator().next();
    assertEquals(newProcessDefinition.getId(), newEventSubscription.getConfiguration());
    assertEquals("abort", newEventSubscription.getEventName());
    // clean db
    repositoryService.deleteDeployment(newDeploymentId);
}
Also used : EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 23 with EventSubscriptionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.

the class SendSignalDelegate method execute.

public void execute(DelegateExecution execution) throws Exception {
    businessProcess.setVariable("processName", "throwSignal-visited (was " + businessProcess.getVariable("processName") + ")");
    String signalProcessInstanceId = (String) execution.getVariable("signalProcessInstanceId");
    String executionId = runtimeService.createExecutionQuery().processInstanceId(signalProcessInstanceId).signalEventSubscriptionName("alert").singleResult().getId();
    CommandContext commandContext = Context.getCommandContext();
    List<EventSubscriptionEntity> findSignalEventSubscriptionsByEventName = commandContext.getEventSubscriptionManager().findSignalEventSubscriptionsByNameAndExecution("alert", executionId);
    for (EventSubscriptionEntity signalEventSubscriptionEntity : findSignalEventSubscriptionsByEventName) {
        signalEventSubscriptionEntity.eventReceived(null, true);
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 24 with EventSubscriptionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.

the class BpmnDeployer method addSignalStartEventSubscription.

protected void addSignalStartEventSubscription(EventSubscriptionDeclaration signalEventDefinition, ProcessDefinitionEntity processDefinition) {
    EventSubscriptionEntity newSubscription = signalEventDefinition.createSubscriptionForStartEvent(processDefinition);
    newSubscription.insert();
}
Also used : EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 25 with EventSubscriptionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.

the class CompensationUtil method collectCompensateEventSubscriptionsForScope.

/**
 * Collect all compensate event subscriptions for scope of given execution.
 */
public static List<EventSubscriptionEntity> collectCompensateEventSubscriptionsForScope(ActivityExecution execution) {
    final Map<ScopeImpl, PvmExecutionImpl> scopeExecutionMapping = execution.createActivityExecutionMapping();
    ScopeImpl activity = (ScopeImpl) execution.getActivity();
    // <LEGACY>: different flow scopes may have the same scope execution =>
    // collect subscriptions in a set
    final Set<EventSubscriptionEntity> subscriptions = new HashSet<EventSubscriptionEntity>();
    TreeVisitor<ScopeImpl> eventSubscriptionCollector = new TreeVisitor<ScopeImpl>() {

        @Override
        public void visit(ScopeImpl obj) {
            PvmExecutionImpl execution = scopeExecutionMapping.get(obj);
            subscriptions.addAll(((ExecutionEntity) execution).getCompensateEventSubscriptions());
        }
    };
    new FlowScopeWalker(activity).addPostVisitor(eventSubscriptionCollector).walkUntil(new ReferenceWalker.WalkCondition<ScopeImpl>() {

        @Override
        public boolean isFulfilled(ScopeImpl element) {
            Boolean consumesCompensationProperty = (Boolean) element.getProperty(BpmnParse.PROPERTYNAME_CONSUMES_COMPENSATION);
            return consumesCompensationProperty == null || consumesCompensationProperty == Boolean.TRUE;
        }
    });
    return new ArrayList<EventSubscriptionEntity>(subscriptions);
}
Also used : PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) ArrayList(java.util.ArrayList) TreeVisitor(org.camunda.bpm.engine.impl.tree.TreeVisitor) ReferenceWalker(org.camunda.bpm.engine.impl.tree.ReferenceWalker) FlowScopeWalker(org.camunda.bpm.engine.impl.tree.FlowScopeWalker) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) HashSet(java.util.HashSet)

Aggregations

EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)33 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)8 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)7 ArrayList (java.util.ArrayList)6 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)5 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)4 EventSubscription (org.camunda.bpm.engine.runtime.EventSubscription)4 Deployment (org.camunda.bpm.engine.test.Deployment)4 EventSubscriptionManager (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionManager)3 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)2 MigratingActivityInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance)2 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)2 CompositeActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior)2 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)2 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 VariableScope (org.camunda.bpm.engine.delegate.VariableScope)1