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;
}
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();
}
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();
}
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();
}
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();
}
}
}
Aggregations