org.camunda.bpm.engine.impl.event.EventType Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.event.EventType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConditionalStartEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartInstanceWithBeanCondition() {
  List<EventSubscription> eventSubscriptions = runtimeService.createEventSubscriptionQuery().list();

  assertEquals(1, eventSubscriptions.size());
  assertEquals(EventType.CONDITONAL.name(), eventSubscriptions.get(0).getEventType());

  List<ProcessInstance> instances = runtimeService
      .createConditionEvaluation()
      .setVariable("foo", 1)
      .evaluateStartConditions();

  assertEquals(1, instances.size());

  assertNotNull(runtimeService.createProcessInstanceQuery().processDefinitionKey("conditionalEventProcess").singleResult());

  VariableInstance vars = runtimeService.createVariableInstanceQuery().singleResult();
  assertEquals(vars.getProcessInstanceId(), instances.get(0).getId());
  assertEquals(1, vars.getValue());
}
 
Example #2
Source File: ProcessDefinitionManager.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the subscriptions for the process definition, which is
 * identified by the given process definition id.
 *
 * @param processDefinitionId the id of the process definition
 */
public void deleteSubscriptionsForProcessDefinition(String processDefinitionId) {
  List<EventSubscriptionEntity> eventSubscriptionsToRemove = new ArrayList<EventSubscriptionEntity>();
  // remove message event subscriptions:
  List<EventSubscriptionEntity> messageEventSubscriptions = getEventSubscriptionManager()
    .findEventSubscriptionsByConfiguration(EventType.MESSAGE.name(), processDefinitionId);
  eventSubscriptionsToRemove.addAll(messageEventSubscriptions);

  // remove signal event subscriptions:
  List<EventSubscriptionEntity> signalEventSubscriptions = getEventSubscriptionManager().findEventSubscriptionsByConfiguration(EventType.SIGNAL.name(), processDefinitionId);
  eventSubscriptionsToRemove.addAll(signalEventSubscriptions);

  // remove conditional event subscriptions:
  List<EventSubscriptionEntity> conditionalEventSubscriptions = getEventSubscriptionManager().findEventSubscriptionsByConfiguration(EventType.CONDITONAL.name(), processDefinitionId);
  eventSubscriptionsToRemove.addAll(conditionalEventSubscriptions);

  for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptionsToRemove) {
    eventSubscriptionEntity.delete();
  }
}
 
Example #3
Source File: BpmnDeployer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void removeObsoleteEventSubscriptions(ProcessDefinitionEntity processDefinition, ProcessDefinitionEntity latestProcessDefinition) {
  // remove all subscriptions for the previous version
  if (latestProcessDefinition != null) {
    EventSubscriptionManager eventSubscriptionManager = getEventSubscriptionManager();

    List<EventSubscriptionEntity> subscriptionsToDelete = new ArrayList<EventSubscriptionEntity>();

    List<EventSubscriptionEntity> messageEventSubscriptions = eventSubscriptionManager
        .findEventSubscriptionsByConfiguration(EventType.MESSAGE.name(), latestProcessDefinition.getId());
    subscriptionsToDelete.addAll(messageEventSubscriptions);

    List<EventSubscriptionEntity> signalEventSubscriptions = eventSubscriptionManager
        .findEventSubscriptionsByConfiguration(EventType.SIGNAL.name(), latestProcessDefinition.getId());
    subscriptionsToDelete.addAll(signalEventSubscriptions);

    List<EventSubscriptionEntity> conditionalEventSubscriptions = eventSubscriptionManager
        .findEventSubscriptionsByConfiguration(EventType.CONDITONAL.name(), latestProcessDefinition.getId());
    subscriptionsToDelete.addAll(conditionalEventSubscriptions);

    for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsToDelete) {
      eventSubscriptionEntity.delete();
    }
  }
}
 
Example #4
Source File: ConditionalStartEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = SINGLE_CONDITIONAL_START_EVENT_XML)
public void testDeploymentCreatesSubscriptions() {
  // given a deployed process
  String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey(CONDITIONAL_EVENT_PROCESS).singleResult().getId();

  // when
  List<EventSubscription> eventSubscriptions = runtimeService.createEventSubscriptionQuery().list();

  // then
  assertEquals(1, eventSubscriptions.size());
  EventSubscriptionEntity conditionalEventSubscription = (EventSubscriptionEntity) eventSubscriptions.get(0);
  assertEquals(EventType.CONDITONAL.name(), conditionalEventSubscription.getEventType());
  assertEquals(processDefinitionId, conditionalEventSubscription.getConfiguration());
  assertNull(conditionalEventSubscription.getEventName());
  assertNull(conditionalEventSubscription.getExecutionId());
  assertNull(conditionalEventSubscription.getProcessInstanceId());
}
 
Example #5
Source File: ProcessEngineConfigurationImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void initEventHandlers() {
  if (eventHandlers == null) {
    eventHandlers = new HashMap<>();

    SignalEventHandler signalEventHander = new SignalEventHandler();
    eventHandlers.put(signalEventHander.getEventHandlerType(), signalEventHander);

    CompensationEventHandler compensationEventHandler = new CompensationEventHandler();
    eventHandlers.put(compensationEventHandler.getEventHandlerType(), compensationEventHandler);

    EventHandler messageEventHandler = new EventHandlerImpl(EventType.MESSAGE);
    eventHandlers.put(messageEventHandler.getEventHandlerType(), messageEventHandler);

    EventHandler conditionalEventHandler = new ConditionalEventHandler();
    eventHandlers.put(conditionalEventHandler.getEventHandlerType(), conditionalEventHandler);

  }
  if (customEventHandlers != null) {
    for (EventHandler eventHandler : customEventHandlers) {
      eventHandlers.put(eventHandler.getEventHandlerType(), eventHandler);
    }
  }
}
 
Example #6
Source File: EventSubscriptionCreateTimeScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("initEventSubscriptionCreateTime")
@Times(1)
public static ScenarioSetup initEventSubscriptionCreateTime() {
  return new ScenarioSetup() {
    @Override
    public void execute(ProcessEngine processEngine, String s) {

      ((ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration())
        .getCommandExecutorTxRequired()
        .execute(new Command<Void>() {

          @Override
          public Void execute(CommandContext commandContext) {

            EventSubscriptionEntity messageEventSubscriptionEntity = new EventSubscriptionEntity(EventType.MESSAGE);
            messageEventSubscriptionEntity.setEventName(EVENT_NAME);
            messageEventSubscriptionEntity.setActivityId(ACTIVITY_ID);
            messageEventSubscriptionEntity.setCreated(TIMESTAMP);
            messageEventSubscriptionEntity.insert();

            return null;
          }
        });
    }
  };
}
 
Example #7
Source File: CompensateEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * CAM-4387
 */
@Deployment
public void FAILING_testReceiveTaskCompensationHandler() {
  // given a process instance
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveTaskCompensationHandler");

  // when triggering compensation
  Task beforeCompensationTask = taskService.createTaskQuery().singleResult();
  taskService.complete(beforeCompensationTask.getId());

  // then there is a message event subscription for the receive task compensation handler
  EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
  assertNotNull(eventSubscription);
  assertEquals(EventType.MESSAGE, eventSubscription.getEventType());

  // and triggering the message completes compensation
  runtimeService.correlateMessage("Message");

  Task afterCompensationTask = taskService.createTaskQuery().singleResult();
  assertNotNull(afterCompensationTask);
  assertEquals("beforeEnd", afterCompensationTask.getTaskDefinitionKey());

  taskService.complete(afterCompensationTask.getId());

  // and the process has successfully ended
  assertProcessEnded(processInstance.getId());
}
 
Example #8
Source File: ConditionalStartEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = MULTIPLE_CONDITION_XML)
public void testStartInstanceWithMultipleConditions() {
  // given a deployed process with three conditional start events
  List<EventSubscription> eventSubscriptions = runtimeService.createEventSubscriptionQuery().list();

  assertEquals(3, eventSubscriptions.size());
  for (EventSubscription eventSubscription : eventSubscriptions) {
    assertEquals(EventType.CONDITONAL.name(), eventSubscription.getEventType());
  }

  Map<String, Object> variableMap = new HashMap<String, Object>();
  variableMap.put("foo", 1);
  variableMap.put("bar", true);

  // when
  List<ProcessInstance> resultInstances = runtimeService
      .createConditionEvaluation()
      .setVariables(variableMap)
      .evaluateStartConditions();

  // then
  assertEquals(2, resultInstances.size());

  List<ProcessInstance> instances = runtimeService.createProcessInstanceQuery().processDefinitionKey(MULTIPLE_CONDITIONS).list();
  assertEquals(2, instances.size());
}
 
Example #9
Source File: AbstractConditionalEventTestCase.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
  this.runtimeService = engine.getRuntimeService();
  this.taskService = engine.getTaskService();
  this.repositoryService = engine.getRepositoryService();
  this.historyService = engine.getHistoryService();
  this.processEngineConfiguration = engine.getProcessEngineConfiguration();
  this.conditionEventSubscriptionQuery = new EventSubscriptionQueryImpl(processEngineConfiguration.getCommandExecutorTxRequired()).eventType(EventType.CONDITONAL.name());
}
 
Example #10
Source File: SignalEventDeploymentTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testCreateEventSubscriptionOnDeployment() {
  deploymentId = repositoryService.createDeployment()
      .addClasspathResource(SIGNAL_START_EVENT_PROCESS)
      .deploy().getId();

  EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
  assertNotNull(eventSubscription);

  assertEquals(EventType.SIGNAL.name(), eventSubscription.getEventType());
  assertEquals("alert", eventSubscription.getEventName());
  assertEquals("start", eventSubscription.getActivityId());
}
 
Example #11
Source File: ReceiveTaskTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.multiParallelReceiveTaskCompensate.bpmn20.xml")
public void testSupportsMessageEventReceivedOnParallelMultiReceiveTaskWithCompensation() {

  // given: a process instance waiting in two receive tasks
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");

  // expect: there are two message event subscriptions
  List<EventSubscription> subscriptions = getEventSubscriptionList();
  assertEquals(2, subscriptions.size());

  // then: we can trigger the first event subscription
  runtimeService.messageEventReceived(subscriptions.get(0).getEventName(), subscriptions.get(0).getExecutionId());

  // expect: after completing the first receive task there is one event subscription for compensation
  assertEquals(1, runtimeService.createEventSubscriptionQuery()
      .eventType(EventType.COMPENSATE.name()).count());

  // then: we can trigger the second event subscription
  runtimeService.messageEventReceived(subscriptions.get(1).getEventName(), subscriptions.get(1).getExecutionId());

  // expect: there are three event subscriptions for compensation (two subscriptions for tasks and one for miBody)
  assertEquals(3, runtimeService.createEventSubscriptionQuery()
      .eventType(EventType.COMPENSATE.name()).count());

  // expect: one user task is created
  Task task = taskService.createTaskQuery().singleResult();
  taskService.complete(task.getId());

  // expect: this ends the process instance
  assertProcessEnded(processInstance.getId());
}
 
Example #12
Source File: EventSubscriptionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void createExampleEventSubscriptions() {
  processEngineConfiguration.getCommandExecutorTxRequired()
  .execute(new Command<Void>() {
    public Void execute(CommandContext commandContext) {
      Calendar calendar = new GregorianCalendar();


      EventSubscriptionEntity messageEventSubscriptionEntity1 = new EventSubscriptionEntity(EventType.MESSAGE);
      messageEventSubscriptionEntity1.setEventName("messageName");
      messageEventSubscriptionEntity1.setActivityId("someActivity");
      calendar.set(2001, 1, 1);
      messageEventSubscriptionEntity1.setCreated(calendar.getTime());
      messageEventSubscriptionEntity1.insert();

      EventSubscriptionEntity messageEventSubscriptionEntity2 = new EventSubscriptionEntity(EventType.MESSAGE);
      messageEventSubscriptionEntity2.setEventName("messageName");
      messageEventSubscriptionEntity2.setActivityId("someActivity");
      calendar.set(2000, 1, 1);
      messageEventSubscriptionEntity2.setCreated(calendar.getTime());
      messageEventSubscriptionEntity2.insert();

      EventSubscriptionEntity signalEventSubscriptionEntity3 = new EventSubscriptionEntity(EventType.SIGNAL);
      signalEventSubscriptionEntity3.setEventName("messageName2");
      signalEventSubscriptionEntity3.setActivityId("someOtherActivity");
      calendar.set(2002, 1, 1);
      signalEventSubscriptionEntity3.setCreated(calendar.getTime());
      signalEventSubscriptionEntity3.insert();

      return null;
    }
  });
}
 
Example #13
Source File: MultiTenancyStartProcessInstanceByConditionCmdTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void ensureEventSubscriptions(int count) {
  List<EventSubscription> eventSubscriptions = engineRule.getRuntimeService().createEventSubscriptionQuery().list();
  assertEquals(count, eventSubscriptions.size());
  for (EventSubscription eventSubscription : eventSubscriptions) {
    assertEquals(EventType.CONDITONAL.name(), eventSubscription.getEventType());
  }
}
 
Example #14
Source File: MultiTenancyStartProcessInstanceByConditionCmdTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvaluateConditionByProcessDefinitionIdWithAuthenticatedTenants() {
  // given
  testRule.deployForTenant(TENANT_ONE, PROCESS);

  ensureEventSubscriptions(1);

  ProcessDefinition processDefinition = engineRule.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("conditionStart").singleResult();

  identityService = engineRule.getIdentityService();
  identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  // when
  List<ProcessInstance> instances = engineRule.getRuntimeService()
    .createConditionEvaluation()
    .setVariable("foo", "bar")
    .tenantId(TENANT_ONE)
    .processDefinitionId(processDefinition.getId())
    .evaluateStartConditions();

  // then
  assertNotNull(instances);
  assertEquals(1, instances.size());
  assertEquals(TENANT_ONE, instances.get(0).getTenantId());

  identityService.clearAuthentication();

  ProcessInstanceQuery processInstanceQuery = engineRule.getRuntimeService().createProcessInstanceQuery();
  assertEquals(1, processInstanceQuery.tenantIdIn(TENANT_ONE).count());

  EventSubscription eventSubscription = engineRule.getRuntimeService().createEventSubscriptionQuery().singleResult();
  assertEquals(EventType.CONDITONAL.name(), eventSubscription.getEventType());
}
 
Example #15
Source File: BpmnDeployer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected boolean isSameMessageEventSubscriptionAlreadyPresent(EventSubscriptionDeclaration eventSubscription, String tenantId) {
  // look for subscriptions for the same name in db:
  List<EventSubscriptionEntity> subscriptionsForSameMessageName = getEventSubscriptionManager()
    .findEventSubscriptionsByNameAndTenantId(EventType.MESSAGE.name(), eventSubscription.getUnresolvedEventName(), tenantId);

  // also look for subscriptions created in the session:
  List<EventSubscriptionEntity> cachedSubscriptions = getDbEntityManager()
    .getCachedEntitiesByType(EventSubscriptionEntity.class);

  for (EventSubscriptionEntity cachedSubscription : cachedSubscriptions) {

    if(eventSubscription.getUnresolvedEventName().equals(cachedSubscription.getEventName())
      && hasTenantId(cachedSubscription, tenantId)
      && !subscriptionsForSameMessageName.contains(cachedSubscription)) {

      subscriptionsForSameMessageName.add(cachedSubscription);
    }
  }

  // remove subscriptions deleted in the same command
  subscriptionsForSameMessageName = getDbEntityManager().pruneDeletedEntities(subscriptionsForSameMessageName);

  // remove subscriptions for different type of event (i.e. remove intermediate message event subscriptions)
  subscriptionsForSameMessageName = filterSubscriptionsOfDifferentType(eventSubscription, subscriptionsForSameMessageName);

  return !subscriptionsForSameMessageName.isEmpty();
}
 
Example #16
Source File: BpmnDeployer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void addEventSubscription(ProcessDefinitionEntity processDefinition, EventSubscriptionDeclaration eventDefinition) {
  if (eventDefinition.isStartEvent()) {
    String eventType = eventDefinition.getEventType();

    if (eventType.equals(EventType.MESSAGE.name())) {
      addMessageStartEventSubscription(eventDefinition, processDefinition);
    } else if (eventType.equals(EventType.SIGNAL.name())) {
      addSignalStartEventSubscription(eventDefinition, processDefinition);
    } else if (eventType.equals(EventType.CONDITONAL.name())) {
      addConditionalStartEventSubscription(eventDefinition, processDefinition);
    }
  }
}
 
Example #17
Source File: AbstractBpmnActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void createCompensateEventSubscription(ActivityExecution execution, ActivityImpl compensationHandler) {
  // the compensate event subscription is created at subprocess or miBody of the the current activity
  PvmActivity currentActivity = execution.getActivity();
  ActivityExecution scopeExecution = execution.findExecutionForFlowScope(currentActivity.getFlowScope());

  EventSubscriptionEntity.createAndInsert((ExecutionEntity) scopeExecution, EventType.COMPENSATE, compensationHandler);
}
 
Example #18
Source File: ExecutionQueryImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public ExecutionQuery eventSubscription(EventType eventType, String eventName) {
  ensureNotNull("event type", eventType);
  if (!EventType.MESSAGE.equals(eventType)) {
    // event name is optional for message events
    ensureNotNull("event name", eventName);
  }
  if(eventSubscriptions == null) {
    eventSubscriptions = new ArrayList<EventSubscriptionQueryValue>();
  }
  eventSubscriptions.add(new EventSubscriptionQueryValue(eventName, eventType.name()));
  return this;
}
 
Example #19
Source File: MessageEventReceivedCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
  ensureNotNull("executionId", executionId);

  EventSubscriptionManager eventSubscriptionManager = commandContext.getEventSubscriptionManager();
  List<EventSubscriptionEntity> eventSubscriptions = null;
  if (messageName != null) {
    eventSubscriptions = eventSubscriptionManager.findEventSubscriptionsByNameAndExecution(
            EventType.MESSAGE.name(), messageName, executionId, exclusive);
  } else {
    eventSubscriptions = eventSubscriptionManager.findEventSubscriptionsByExecutionAndType(
        executionId, EventType.MESSAGE.name(), exclusive);
  }

  ensureNotEmpty("Execution with id '" + executionId + "' does not have a subscription to a message event with name '" + messageName + "'", "eventSubscriptions", eventSubscriptions);
  ensureNumberOfElements("More than one matching message subscription found for execution " + executionId, "eventSubscriptions", eventSubscriptions, 1);

  // there can be only one:
  EventSubscriptionEntity eventSubscriptionEntity = eventSubscriptions.get(0);

  // check authorization
  String processInstanceId = eventSubscriptionEntity.getProcessInstanceId();
  for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
    checker.checkUpdateProcessInstanceById(processInstanceId);
  }

  eventSubscriptionEntity.eventReceived(processVariables, processVariablesLocal, null, false);

  return null;
}
 
Example #20
Source File: PublishSubscribeAdapter.java    From flowing-retail with Apache License 2.0 5 votes vote down vote up
protected void addMessageSubscription(final ActivityExecution context, String eventName) {
  ExecutionEntity executionEntity = (ExecutionEntity)context;
  EventSubscriptionEntity eventSubscriptionEntity = new EventSubscriptionEntity(executionEntity, EventType.MESSAGE);
  eventSubscriptionEntity.setEventName(eventName);
  eventSubscriptionEntity.setActivity(executionEntity.getActivity());
  eventSubscriptionEntity.insert();
}
 
Example #21
Source File: CustomBpmnParse.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected EventSubscriptionDeclaration parseSignalEventDefinition(Element signalEventDefinitionElement,
        boolean isThrowing) {
    logger.debug("parse signal event definition");

    String signalRef = signalEventDefinitionElement.attribute("signalRef");
    if (signalRef == null) {
        logger.debug("add default signal {}:{}", DEFAULT_SIGNAL_ID, DEFAULT_SIGNAL_NAME);
        signalRef = DEFAULT_SIGNAL_ID;
    }

    SignalDefinition signalDefinition = signals.get(resolveName(signalRef));
    if (signalDefinition == null) {
        addError("Could not find signal with id '" + signalRef + "'", signalEventDefinitionElement);
    }

    EventSubscriptionDeclaration signalEventDefinition;
    if (isThrowing) {
        CallableElement payload = new CallableElement();
        parseInputParameter(signalEventDefinitionElement, payload);
        signalEventDefinition = new EventSubscriptionDeclaration(signalDefinition != null ? signalDefinition.getExpression() : null, EventType.SIGNAL,
                payload);
    } else {
        signalEventDefinition = new EventSubscriptionDeclaration(signalDefinition != null ? signalDefinition.getExpression() : null,
                EventType.SIGNAL);
    }

    boolean throwingAsync = TRUE
            .equals(signalEventDefinitionElement.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, "async", "false"));
    signalEventDefinition.setAsync(throwingAsync);

    return signalEventDefinition;

}
 
Example #22
Source File: EventSubscriptionEntity.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public EventSubscriptionEntity(ExecutionEntity executionEntity, EventType eventType) {
  this(eventType);
  setExecution(executionEntity);
  setActivity(execution.getActivity());
  this.processInstanceId = executionEntity.getProcessInstanceId();
  this.tenantId = executionEntity.getTenantId();
}
 
Example #23
Source File: EventSubscriptionEntity.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static EventSubscriptionEntity createAndInsert(ExecutionEntity executionEntity, EventType eventType, ActivityImpl activity, String configuration) {
  EventSubscriptionEntity eventSubscription = new EventSubscriptionEntity(executionEntity, eventType);
  eventSubscription.setActivity(activity);
  eventSubscription.setTenantId(executionEntity.getTenantId());
  eventSubscription.setConfiguration(configuration);
  eventSubscription.insert();
  return eventSubscription;
}
 
Example #24
Source File: ExecutionEntity.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void removeEventSubscriptionsExceptCompensation() {
  // remove event subscriptions which are not compensate event subscriptions
  List<EventSubscriptionEntity> eventSubscriptions = getEventSubscriptions();
  for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptions) {
    if (!EventType.COMPENSATE.name().equals(eventSubscriptionEntity.getEventType())) {
      eventSubscriptionEntity.delete();
    }
  }
}
 
Example #25
Source File: ExecutionEntity.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public List<EventSubscriptionEntity> getCompensateEventSubscriptions() {
  List<EventSubscriptionEntity> eventSubscriptions = getEventSubscriptionsInternal();
  List<EventSubscriptionEntity> result = new ArrayList<>(eventSubscriptions.size());
  for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptions) {
    if (eventSubscriptionEntity.isSubscriptionForEventType(EventType.COMPENSATE)) {
      result.add(eventSubscriptionEntity);
    }
  }
  return result;
}
 
Example #26
Source File: EventSubscriptionManager.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void deleteEventSubscription(EventSubscriptionEntity persistentObject) {
  getDbEntityManager().delete(persistentObject);
  if (persistentObject.isSubscriptionForEventType(EventType.SIGNAL)) {
    createdSignalSubscriptions.remove(persistentObject);
  }

  // if the event subscription has been triggered asynchronously but not yet executed
  List<JobEntity> asyncJobs = getJobManager().findJobsByConfiguration(ProcessEventJobHandler.TYPE, persistentObject.getId(), persistentObject.getTenantId());
  for (JobEntity asyncJob : asyncJobs) {
    asyncJob.delete();
  }
}
 
Example #27
Source File: MigrationCompensationInstanceVisitor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void instantiateScopes(
    MigratingScopeInstance ancestorScopeInstance,
    MigratingScopeInstanceBranch executionBranch,
    List<ScopeImpl> scopesToInstantiate) {

  if (scopesToInstantiate.isEmpty()) {
    return;
  }

  ExecutionEntity ancestorScopeExecution = ancestorScopeInstance.resolveRepresentativeExecution();

  ExecutionEntity parentExecution = ancestorScopeExecution;

  for (ScopeImpl scope : scopesToInstantiate) {
    ExecutionEntity compensationScopeExecution = parentExecution.createExecution();
    compensationScopeExecution.setScope(true);
    compensationScopeExecution.setEventScope(true);

    compensationScopeExecution.setActivity((PvmActivity) scope);
    compensationScopeExecution.setActive(false);
    compensationScopeExecution.activityInstanceStarting();
    compensationScopeExecution.enterActivityInstance();

    EventSubscriptionEntity eventSubscription = EventSubscriptionEntity.createAndInsert(parentExecution, EventType.COMPENSATE, (ActivityImpl) scope);
    eventSubscription.setConfiguration(compensationScopeExecution.getId());

    executionBranch.visited(new MigratingEventScopeInstance(eventSubscription, compensationScopeExecution, scope));

    parentExecution = compensationScopeExecution;
  }

}
 
Example #28
Source File: ExecutionEntity.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public List<EventSubscriptionEntity> getCompensateEventSubscriptions(String activityId) {
  List<EventSubscriptionEntity> eventSubscriptions = getEventSubscriptionsInternal();
  List<EventSubscriptionEntity> result = new ArrayList<>(eventSubscriptions.size());
  for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptions) {
    if (eventSubscriptionEntity.isSubscriptionForEventType(EventType.COMPENSATE)
            && activityId.equals(eventSubscriptionEntity.getActivityId())) {
        result.add(eventSubscriptionEntity);
      }
  }
  return result;
}
 
Example #29
Source File: ProcessDefinitionQueryImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public ProcessDefinitionQuery eventSubscription(EventType eventType, String eventName) {
  ensureNotNull("event type", eventType);
  ensureNotNull("event name", eventName);
  this.eventSubscriptionType = eventType.name();
  this.eventSubscriptionName = eventName;
  return this;
}
 
Example #30
Source File: CommandPubEventSubAdapter.java    From flowing-retail-old with Apache License 2.0 5 votes vote down vote up
protected void addMessageSubscription(final ActivityExecution execution, String eventName) {
  ExecutionEntity executionEntity = (ExecutionEntity)execution;
  EventSubscriptionEntity eventSubscriptionEntity = new EventSubscriptionEntity(executionEntity, EventType.MESSAGE);
  eventSubscriptionEntity.setEventName(eventName);
  eventSubscriptionEntity.setActivity(executionEntity.getActivity());
  eventSubscriptionEntity.insert();
}