org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity. 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: ConditionalEventHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, Object localPayload, String businessKey, CommandContext commandContext) {
  VariableEvent variableEvent;
  if (payload == null || payload instanceof VariableEvent) {
    variableEvent = (VariableEvent) payload;
  } else {
    throw new ProcessEngineException("Payload have to be " + VariableEvent.class.getName() + ", to evaluate condition.");
  }

  ActivityImpl activity = eventSubscription.getActivity();
  ActivityBehavior activityBehavior = activity.getActivityBehavior();
  if (activityBehavior instanceof ConditionalEventBehavior) {
    ConditionalEventBehavior conditionalBehavior = (ConditionalEventBehavior) activityBehavior;
    conditionalBehavior.leaveOnSatisfiedCondition(eventSubscription, variableEvent);
  } else {
    throw new ProcessEngineException("Conditional Event has not correct behavior: " + activityBehavior);
  }
}
 
Example #2
Source File: ConditionalStartEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the case when the previous of the previous version will be needed.
 */
@Test
public void testSubscribePreviousPreviousVersion() {

  String definitionId1 = deployProcess(SINGLE_CONDITIONAL_XML);
  String definitionId2 = deployProcess(SINGLE_CONDITIONAL_XML);
  String definitionId3 = deployProcess(SINGLE_CONDITIONAL_XML); //we're deleting version 3, but as version 2 is already deleted, we must subscribe version 1

  // when
  repositoryService.deleteProcessDefinitions()
    .byIds(definitionId2, definitionId3)
    .delete();

  // then
  assertEquals(1, runtimeService.createEventSubscriptionQuery().count());
  assertEquals(definitionId1, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration());
}
 
Example #3
Source File: EventSubscriptionEntityHandler.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Statement
public List<EventSubscriptionEntity> selectEventSubscriptionsByNameAndExecution(OPersistenceSession session, final ListQueryParameterObject parameter) {
	Map<String, String> map=((Map<String, String>)parameter.getParameter());
	List<EventSubscriptionEntity> result=new ArrayList<EventSubscriptionEntity>();
	ExecutionEntity entity = HandlersManager.get().getHandler(ExecutionEntity.class).read(map.get("executionId"), session);
    if(entity==null){
      return result;
    }
    for(EventSubscriptionEntity eventSubscriptionEntity:entity.getEventSubscriptions()){
    	if((!map.containsKey("eventType") || Objects.equals(eventSubscriptionEntity.getEventType(), map.get("eventType"))) 
    		 && (!map.containsKey("eventName") || Objects.equals(eventSubscriptionEntity.getEventName(), map.get("eventName")))) {
        result.add(eventSubscriptionEntity);
      }
    }
    return result;
}
 
Example #4
Source File: ThrowSignalEventActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(ActivityExecution execution) throws Exception {

  String businessKey = signalDefinition.getEventPayload().getBusinessKey(execution);
  VariableMap variableMap = signalDefinition.getEventPayload().getInputVariables(execution);

  String eventName = signalDefinition.resolveExpressionOfEventName(execution);
  // trigger all event subscriptions for the signal (start and intermediate)
  List<EventSubscriptionEntity> signalEventSubscriptions =
      findSignalEventSubscriptions(eventName, execution.getTenantId());

  for (EventSubscriptionEntity signalEventSubscription : signalEventSubscriptions) {
    if (isActiveEventSubscription(signalEventSubscription)) {
      signalEventSubscription.eventReceived(variableMap, null, businessKey, signalDefinition.isAsync());
    }
  }
  leave(execution);
}
 
Example #5
Source File: IntermediateConditionalEventBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void leaveOnSatisfiedCondition(final EventSubscriptionEntity eventSubscription, final VariableEvent variableEvent) {
  PvmExecutionImpl execution = eventSubscription.getExecution();

  if (execution != null && !execution.isEnded()
    && variableEvent != null
    && conditionalEvent.tryEvaluate(variableEvent, execution)
    && execution.isActive() && execution.isScope()) {
    if (isAfterEventBasedGateway) {
      final ActivityImpl activity = eventSubscription.getActivity();
      execution.executeEventHandlerActivity(activity);
    } else {
      leave(execution);
    }
  }
}
 
Example #6
Source File: EventSubscriptionEntityHandler.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public EventSubscriptionEntity mapToEntity(ODocument doc, EventSubscriptionEntity entity,
		OPersistenceSession session) {
	if(entity==null) {
		String eventType = doc.field("eventType");
		switch (eventType) {
		case CompensationEventHandler.EVENT_HANDLER_TYPE:
			entity = new CompensateEventSubscriptionEntity();
			break;
		case MessageEventSubscriptionEntity.EVENT_TYPE:
			entity = new MessageEventSubscriptionEntity();
			break;
		case SignalEventSubscriptionEntity.EVENT_TYPE:
			entity = new SignalEventSubscriptionEntity();
			break;
		}
	}
	return super.mapToEntity(doc, entity, session);
}
 
Example #7
Source File: CompensationEventCoverageHandler.java    From camunda-bpm-process-test-coverage with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation for older Camunda versions prior to 7.10.0
 */
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) {
    addCompensationEventCoverage(eventSubscription);

    // invoke super.handleEvent() in a backwards compatible way
    try {
      if (handleEvent == null) {
        handleEvent = MethodHandles.lookup()
            .findSpecial(CompensationEventHandler.class, "handleEvent",
                MethodType.methodType(void.class, EventSubscriptionEntity.class, Object.class, CommandContext.class),
                CompensationEventCoverageHandler.class);
      }
      handleEvent.invoke(this, eventSubscription, payload, commandContext);
    } catch (Throwable e) {
      throw new RuntimeException(e);
    }
}
 
Example #8
Source File: CompensationEventCoverageHandler.java    From camunda-bpm-process-test-coverage with Apache License 2.0 6 votes vote down vote up
private void addCompensationEventCoverage(EventSubscriptionEntity eventSubscription) {
  if (Api.Camunda.supportsCompensationEventCoverage()) {

      final ActivityImpl activity = eventSubscription.getActivity();

      // Get process definition key
      final ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) activity.getProcessDefinition();
      final String processDefinitionKey = processDefinition.getKey();

      // Get compensation boundary event ID
      final ActivityImpl sourceEvent = (ActivityImpl) activity.getProperty(
          BpmnProperties.COMPENSATION_BOUNDARY_EVENT.getName());

      if (sourceEvent != null) {

          final String sourceEventId = sourceEvent.getActivityId();

          // Register covered element
          final CoveredFlowNode compensationBoundaryEvent = new CoveredFlowNode(processDefinitionKey, sourceEventId);
          compensationBoundaryEvent.setEnded(true);
          coverageTestRunState.addCoveredElement(compensationBoundaryEvent);

      }

  }
}
 
Example #9
Source File: MessageStartEventSubscriptionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the case when the previous of the previous version will be needed.
 */
@Test
public void testSubscribePreviousPreviousVersion() {

  String definitionId1 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML);
  String definitionId2 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML);
  String definitionId3 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML); //we're deleting version 3, but as version 2 is already deleted, we must subscribe version 1

  // when
  repositoryService.deleteProcessDefinitions()
    .byIds(definitionId2, definitionId3)
    .delete();

  // then
  assertEquals(1, runtimeService.createEventSubscriptionQuery().count());
  assertEquals(definitionId1, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration());
}
 
Example #10
Source File: ConditionalStartEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the case, when no new subscription is needed, as it is not the latest version, that is being deleted.
 */
@Test
public void testDeleteNotLatestVersion() {
  @SuppressWarnings("unused")
  String definitionId1 = deployProcess(SINGLE_CONDITIONAL_XML);
  String definitionId2 = deployProcess(SINGLE_CONDITIONAL_XML);
  String definitionId3 = deployProcess(SINGLE_CONDITIONAL_XML);

  // when
  repositoryService.deleteProcessDefinitions()
    .byIds(definitionId2)
    .delete();

  // then
  assertEquals(1, runtimeService.createEventSubscriptionQuery().count());
  assertEquals(definitionId3, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration());
}
 
Example #11
Source File: MessageStartEventSubscriptionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMixedSubscriptionsWhenDeletingTwoProcessDefinitionsInOneTransaction2() {
  // given second version without condition
  String definitionId1 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML);
  String definitionId2 = deployModel(MODEL_WITHOUT_MESSAGE);
  String definitionId3 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML);

  // when
  repositoryService.deleteProcessDefinitions()
      .byIds(definitionId2, definitionId3)
      .delete();

  // then
  assertEquals(1, runtimeService.createEventSubscriptionQuery().count());
  assertEquals(definitionId1, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration());
}
 
Example #12
Source File: MessageStartEventSubscriptionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the case, when no new subscription is needed, as it is not the latest version, that is being deleted.
 */
@Test
public void testDeleteNotLatestVersion() {
  @SuppressWarnings("unused")
  String definitionId1 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML);
  String definitionId2 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML);
  String definitionId3 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML);

  // when
  repositoryService.deleteProcessDefinitions()
    .byIds(definitionId2)
    .delete();

  // then
  assertEquals(1, runtimeService.createEventSubscriptionQuery().count());
  assertEquals(definitionId3, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration());
}
 
Example #13
Source File: EventSubscriptionDeclaration.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and inserts a subscription entity depending on the message type of this declaration.
 */
public EventSubscriptionEntity createSubscriptionForExecution(ExecutionEntity execution) {
  EventSubscriptionEntity eventSubscriptionEntity = new EventSubscriptionEntity(execution, eventType);

  String eventName = resolveExpressionOfEventName(execution);
  eventSubscriptionEntity.setEventName(eventName);
  if (activityId != null) {
    ActivityImpl activity = execution.getProcessDefinition().findActivity(activityId);
    eventSubscriptionEntity.setActivity(activity);
  }

  eventSubscriptionEntity.insert();
  LegacyBehavior.removeLegacySubscriptionOnParent(execution, eventSubscriptionEntity);

  return eventSubscriptionEntity;
}
 
Example #14
Source File: MessageStartEventSubscriptionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testEventSubscriptionAfterDeleteLatestProcessVersion() {
  // given a deployed process
  testRule.deploy(SINGLE_MESSAGE_START_EVENT_XML);
  ProcessDefinition processDefinitionV1 = repositoryService.createProcessDefinitionQuery().singleResult();
  assertNotNull(processDefinitionV1);

  // deploy second version of the process
  String deploymentId = testRule.deploy(SINGLE_MESSAGE_START_EVENT_XML).getId();

  // when
  repositoryService.deleteDeployment(deploymentId, true);

  // then
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(MESSAGE_EVENT_PROCESS).singleResult();
  assertEquals(processDefinitionV1.getId(), processDefinition.getId());

  EventSubscriptionEntity eventSubscription = (EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult();
  assertNotNull(eventSubscription);
  assertEquals(processDefinitionV1.getId(), eventSubscription.getConfiguration());
}
 
Example #15
Source File: CompensationInstanceHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected MigratingProcessElementInstance createMigratingEventSubscriptionInstance(MigratingInstanceParseContext parseContext,
    EventSubscriptionEntity element) {
  ActivityImpl compensationHandler = parseContext.getSourceProcessDefinition().findActivity(element.getActivityId());

  MigrationInstruction migrationInstruction = getMigrationInstruction(parseContext, compensationHandler);

  ActivityImpl targetScope = null;
  if (migrationInstruction != null) {
    ActivityImpl targetEventScope = (ActivityImpl) parseContext.getTargetActivity(migrationInstruction).getEventScope();
    targetScope = targetEventScope.findCompensationHandler();
  }

  MigratingCompensationEventSubscriptionInstance migratingCompensationInstance =
      parseContext.getMigratingProcessInstance().addCompensationSubscriptionInstance(
          migrationInstruction,
          element,
          compensationHandler,
          targetScope);

  parseContext.consume(element);

  return migratingCompensationInstance;
}
 
Example #16
Source File: CompensationInstanceHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(MigratingInstanceParseContext parseContext, EventSubscriptionEntity element) {

  MigratingProcessElementInstance migratingInstance;
  if (element.getConfiguration() != null) {
    migratingInstance = createMigratingEventScopeInstance(parseContext, element);
  }
  else {
    migratingInstance = createMigratingEventSubscriptionInstance(parseContext, element);
  }


  ExecutionEntity owningExecution = element.getExecution();
  MigratingScopeInstance parentInstance = null;
  if (owningExecution.isEventScope()) {
    parentInstance = parseContext.getMigratingCompensationInstanceByExecutionId(owningExecution.getId());
  }
  else {
    parentInstance = parseContext.getMigratingActivityInstanceById(owningExecution.getParentActivityInstanceId());
  }
  migratingInstance.setParent(parentInstance);
}
 
Example #17
Source File: SignalEventHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void handleStartEvent(EventSubscriptionEntity eventSubscription, Map<String, Object> payload, String businessKey, CommandContext commandContext) {
  String processDefinitionId = eventSubscription.getConfiguration();
  ensureNotNull("Configuration of signal start event subscription '" + eventSubscription.getId() + "' contains no process definition id.",
      processDefinitionId);

  DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache();
  ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
  if (processDefinition == null || processDefinition.isSuspended()) {
    // ignore event subscription
    LOG.debugIgnoringEventSubscription(eventSubscription, processDefinitionId);
  } else {
    ActivityImpl signalStartEvent = processDefinition.findActivity(eventSubscription.getActivityId());
    PvmProcessInstance processInstance = processDefinition.createProcessInstance(businessKey, signalStartEvent);
    processInstance.start(payload);
  }
}
 
Example #18
Source File: MigratingProcessInstance.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public MigratingEventScopeInstance addEventScopeInstance(
    MigrationInstruction migrationInstruction,
    ExecutionEntity eventScopeExecution,
    ScopeImpl sourceScope,
    ScopeImpl targetScope,
    MigrationInstruction eventSubscriptionInstruction,
    EventSubscriptionEntity eventSubscription,
    ScopeImpl eventSubscriptionSourceScope,
    ScopeImpl eventSubscriptionTargetScope) {

  MigratingEventScopeInstance compensationInstance = new MigratingEventScopeInstance(
      migrationInstruction,
      eventScopeExecution,
      sourceScope,
      targetScope,
      eventSubscriptionInstruction,
      eventSubscription,
      eventSubscriptionSourceScope,
      eventSubscriptionTargetScope);

  migratingEventScopeInstances.add(compensationInstance);

  return compensationInstance;
}
 
Example #19
Source File: MessageStartEventSubscriptionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMixedSubscriptionsWhenDeletingTwoProcessDefinitionsInOneTransaction3() {
  // given third version without condition
  String definitionId1 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML);
  String definitionId2 = deployProcess(SINGLE_MESSAGE_START_EVENT_XML);
  String definitionId3 = deployModel(MODEL_WITHOUT_MESSAGE);

  // when
  repositoryService.deleteProcessDefinitions()
      .byIds(definitionId2, definitionId3)
      .delete();

  // then
  assertEquals(1, runtimeService.createEventSubscriptionQuery().count());
  assertEquals(definitionId1, ((EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().singleResult()).getConfiguration());
}
 
Example #20
Source File: SignalEventReceivedCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected Map<String, ProcessDefinitionEntity> getProcessDefinitionsOfSubscriptions(List<EventSubscriptionEntity> startSignalEventSubscriptions) {
  DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache();

  Map<String, ProcessDefinitionEntity> processDefinitions = new HashMap<String, ProcessDefinitionEntity>();

  for (EventSubscriptionEntity eventSubscription : startSignalEventSubscriptions) {

    String processDefinitionId = eventSubscription.getConfiguration();
    ensureNotNull("Configuration of signal start event subscription '" + eventSubscription.getId() + "' contains no process definition id.",
        processDefinitionId);

    ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
    if (processDefinition != null && !processDefinition.isSuspended()) {
      processDefinitions.put(eventSubscription.getId(), processDefinition);
    }
  }

  return processDefinitions;
}
 
Example #21
Source File: DefaultCorrelationHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected List<CorrelationHandlerResult> correlateStartMessageByEventSubscription(CommandContext commandContext, String messageName, CorrelationSet correlationSet) {
  List<CorrelationHandlerResult> results = new ArrayList<CorrelationHandlerResult>();
  DeploymentCache deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentCache();

  List<EventSubscriptionEntity> messageEventSubscriptions = findMessageStartEventSubscriptions(commandContext, messageName, correlationSet);
  for (EventSubscriptionEntity messageEventSubscription : messageEventSubscriptions) {

    if (messageEventSubscription.getConfiguration() != null) {
      String processDefinitionId = messageEventSubscription.getConfiguration();
      ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
      // only an active process definition will be returned
      if (processDefinition != null && !processDefinition.isSuspended()) {
        CorrelationHandlerResult result = CorrelationHandlerResult.matchedProcessDefinition(processDefinition, messageEventSubscription.getActivityId());
        results.add(result);

      } else {
        LOG.couldNotFindProcessDefinitionForEventSubscription(messageEventSubscription, processDefinitionId);
      }
    }
  }
  return results;
}
 
Example #22
Source File: DefaultConditionHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected List<ConditionHandlerResult> evaluateConditionStartByEventSubscription(CommandContext commandContext, ConditionSet conditionSet) {
  List<EventSubscriptionEntity> subscriptions = findConditionalStartEventSubscriptions(commandContext, conditionSet);
  if (subscriptions.isEmpty()) {
    throw LOG.exceptionWhenEvaluatingConditionalStartEvent();
  }
  List<ConditionHandlerResult> results = new ArrayList<ConditionHandlerResult>();
  for (EventSubscriptionEntity subscription : subscriptions) {

    ProcessDefinitionEntity processDefinition = subscription.getProcessDefinition();
    if (!processDefinition.isSuspended()) {

      ActivityImpl activity = subscription.getActivity();

      if (evaluateCondition(conditionSet, activity)) {
        results.add(new ConditionHandlerResult(processDefinition, activity));
      }

    }
  }

  return results;
}
 
Example #23
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 #24
Source File: BpmnDeployer.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * It is possible to deploy a process containing a start and intermediate
 * message event that wait for the same message or to have two processes, one
 * with a message start event and the other one with a message intermediate
 * event, that subscribe for the same message. Therefore we have to find out
 * if there are subscriptions for the other type of event and remove those.
 *
 * @param eventSubscription
 * @param subscriptionsForSameMessageName
 */
protected List<EventSubscriptionEntity> filterSubscriptionsOfDifferentType(EventSubscriptionDeclaration eventSubscription,
    List<EventSubscriptionEntity> subscriptionsForSameMessageName) {
  ArrayList<EventSubscriptionEntity> filteredSubscriptions = new ArrayList<EventSubscriptionEntity>(subscriptionsForSameMessageName);

  for (EventSubscriptionEntity subscriptionEntity : new ArrayList<EventSubscriptionEntity>(subscriptionsForSameMessageName)) {

    if (isSubscriptionOfDifferentTypeAsDeclaration(subscriptionEntity, eventSubscription)) {
      filteredSubscriptions.remove(subscriptionEntity);
    }
  }

  return filteredSubscriptions;
}
 
Example #25
Source File: SignalEventReceivedCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected List<EventSubscriptionEntity> findSignalEventSubscriptions(CommandContext commandContext, String signalName) {
  EventSubscriptionManager eventSubscriptionManager = commandContext.getEventSubscriptionManager();

  if (builder.isTenantIdSet()) {
    return eventSubscriptionManager.findSignalEventSubscriptionsByEventNameAndTenantId(signalName, builder.getTenantId());

  } else {
    return eventSubscriptionManager.findSignalEventSubscriptionsByEventName(signalName);
  }
}
 
Example #26
Source File: SignalEventReceivedCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void sendSignal(CommandContext commandContext, String signalName) {

    List<EventSubscriptionEntity> signalEventSubscriptions = findSignalEventSubscriptions(commandContext, signalName);

    List<EventSubscriptionEntity> catchSignalEventSubscription = filterIntermediateSubscriptions(signalEventSubscriptions);
    List<EventSubscriptionEntity> startSignalEventSubscriptions = filterStartSubscriptions(signalEventSubscriptions);
    Map<String, ProcessDefinitionEntity> processDefinitions = getProcessDefinitionsOfSubscriptions(startSignalEventSubscriptions);

    checkAuthorizationOfCatchSignals(commandContext, catchSignalEventSubscription);
    checkAuthorizationOfStartSignals(commandContext, startSignalEventSubscriptions, processDefinitions);

    notifyExecutions(catchSignalEventSubscription);
    startProcessInstances(startSignalEventSubscriptions, processDefinitions);
  }
 
Example #27
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 #28
Source File: ProcessEventJobHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(EventSubscriptionJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
  // lookup subscription:
  String eventSubscriptionId = configuration.getEventSubscriptionId();
  EventSubscriptionEntity eventSubscription = commandContext.getEventSubscriptionManager()
    .findEventSubscriptionById(eventSubscriptionId);

  // if event subscription is null, ignore
  if(eventSubscription != null) {
    eventSubscription.eventReceived(null, false);
  }

}
 
Example #29
Source File: EventSubscriptionJobDeclaration.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Assumes that an activity has at most one declaration of a certain eventType.
 */
public static EventSubscriptionJobDeclaration findDeclarationForSubscription(EventSubscriptionEntity eventSubscription) {
  List<EventSubscriptionJobDeclaration> declarations = getDeclarationsForActivity(eventSubscription.getActivity());

  for (EventSubscriptionJobDeclaration declaration : declarations) {
    if (declaration.getEventType().equals(eventSubscription.getEventType())) {
      return declaration;
    }
  }

  return null;
}
 
Example #30
Source File: SignalEventReceivedCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void checkAuthorizationOfCatchSignals(final CommandContext commandContext, List<EventSubscriptionEntity> catchSignalEventSubscription) {
  // check authorization for each fetched signal event
  for (EventSubscriptionEntity event : catchSignalEventSubscription) {
    String processInstanceId = event.getProcessInstanceId();
    for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
      checker.checkUpdateProcessInstanceById(processInstanceId);
    }
  }
}