}
}
@SuppressWarnings("unchecked")
protected void addMessageEventSubscriptions(ProcessDefinitionEntity processDefinition) {
CommandContext commandContext = Context.getCommandContext();
List<EventSubscriptionDeclaration> messageEventDefinitions = (List<EventSubscriptionDeclaration>) processDefinition.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
if(messageEventDefinitions != null) {
for (EventSubscriptionDeclaration messageEventDefinition : messageEventDefinitions) {
if(messageEventDefinition.isStartEvent()) {
// look for subscriptions for the same name in db:
List<EventSubscriptionEntity> subscriptionsForSameMessageName = commandContext
.getEventSubscriptionManager()
.findEventSubscriptionsByName(MessageEventHandler.EVENT_HANDLER_TYPE, messageEventDefinition.getEventName());
// also look for subscriptions created in the session:
List<MessageEventSubscriptionEntity> cachedSubscriptions = commandContext
.getDbEntityManager()
.getCachedEntitiesByType(MessageEventSubscriptionEntity.class);
for (MessageEventSubscriptionEntity cachedSubscription : cachedSubscriptions) {
if(messageEventDefinition.getEventName().equals(cachedSubscription.getEventName())
&& !subscriptionsForSameMessageName.contains(cachedSubscription)) {
subscriptionsForSameMessageName.add(cachedSubscription);
}
}
// remove subscriptions deleted in the same command
subscriptionsForSameMessageName = commandContext
.getDbEntityManager()
.pruneDeletedEntities(subscriptionsForSameMessageName);
if(!subscriptionsForSameMessageName.isEmpty()) {
throw new ProcessEngineException("Cannot deploy process definition '" + processDefinition.getResourceName()