Search in sources :

Example 1 with EventSubscriptionEntity

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

the class MessageEventReceivedCmd method execute.

@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, false);
    return null;
}
Also used : EventSubscriptionManager(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionManager) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 2 with EventSubscriptionEntity

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

the class BpmnDeployer method addConditionalStartEventSubscription.

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

Example 3 with EventSubscriptionEntity

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

the class BpmnDeployer method addMessageStartEventSubscription.

protected void addMessageStartEventSubscription(EventSubscriptionDeclaration messageEventDefinition, ProcessDefinitionEntity processDefinition) {
    String tenantId = processDefinition.getTenantId();
    if (isSameMessageEventSubscriptionAlreadyPresent(messageEventDefinition, tenantId)) {
        throw LOG.messageEventSubscriptionWithSameNameExists(processDefinition.getResourceName(), messageEventDefinition.getUnresolvedEventName());
    }
    EventSubscriptionEntity newSubscription = messageEventDefinition.createSubscriptionForStartEvent(processDefinition);
    newSubscription.insert();
}
Also used : EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 4 with EventSubscriptionEntity

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

the class BpmnDeployer method isSameMessageEventSubscriptionAlreadyPresent.

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();
}
Also used : EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 5 with EventSubscriptionEntity

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

the class BpmnDeployer method removeObsoleteEventSubscriptions.

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();
        }
    }
}
Also used : EventSubscriptionManager(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionManager) ArrayList(java.util.ArrayList) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

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