Search in sources :

Example 1 with MessageEventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity in project Activiti by Activiti.

the class EventSubscriptionQueryTest method testQueryByActivityId.

public void testQueryByActivityId() {
    processEngineConfiguration.getCommandExecutor().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            MessageEventSubscriptionEntity messageEventSubscriptionEntity1 = new MessageEventSubscriptionEntity();
            messageEventSubscriptionEntity1.setEventName("messageName");
            messageEventSubscriptionEntity1.setActivityId("someActivity");
            messageEventSubscriptionEntity1.insert();
            MessageEventSubscriptionEntity messageEventSubscriptionEntity2 = new MessageEventSubscriptionEntity();
            messageEventSubscriptionEntity2.setEventName("messageName");
            messageEventSubscriptionEntity2.setActivityId("someActivity");
            messageEventSubscriptionEntity2.insert();
            SignalEventSubscriptionEntity signalEventSubscriptionEntity3 = new SignalEventSubscriptionEntity();
            signalEventSubscriptionEntity3.setEventName("messageName2");
            signalEventSubscriptionEntity3.setActivityId("someOtherActivity");
            signalEventSubscriptionEntity3.insert();
            return null;
        }
    });
    List<EventSubscriptionEntity> list = newEventSubscriptionQuery().activityId("someOtherActivity").list();
    assertEquals(1, list.size());
    list = newEventSubscriptionQuery().activityId("someActivity").eventType("message").list();
    assertEquals(2, list.size());
    cleanDb();
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 2 with MessageEventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity in project Activiti by Activiti.

the class BpmnDeployer method addMessageEventSubscriptions.

@SuppressWarnings("unchecked")
protected void addMessageEventSubscriptions(ProcessDefinitionEntity processDefinition) {
    CommandContext commandContext = Context.getCommandContext();
    List<EventSubscriptionDeclaration> eventDefinitions = (List<EventSubscriptionDeclaration>) processDefinition.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
    if (eventDefinitions != null) {
        Set<String> messageNames = new HashSet<String>();
        for (EventSubscriptionDeclaration eventDefinition : eventDefinitions) {
            if (eventDefinition.getEventType().equals("message") && eventDefinition.isStartEvent()) {
                if (!messageNames.contains(eventDefinition.getEventName())) {
                    messageNames.add(eventDefinition.getEventName());
                } else {
                    throw new ActivitiException("Cannot deploy process definition '" + processDefinition.getResourceName() + "': there are multiple message event subscriptions for the message with name '" + eventDefinition.getEventName() + "'.");
                }
                // look for subscriptions for the same name in db:
                List<EventSubscriptionEntity> subscriptionsForSameMessageName = commandContext.getEventSubscriptionEntityManager().findEventSubscriptionsByName(MessageEventHandler.EVENT_HANDLER_TYPE, eventDefinition.getEventName(), processDefinition.getTenantId());
                // also look for subscriptions created in the session:
                List<MessageEventSubscriptionEntity> cachedSubscriptions = commandContext.getDbSqlSession().findInCache(MessageEventSubscriptionEntity.class);
                for (MessageEventSubscriptionEntity cachedSubscription : cachedSubscriptions) {
                    if (eventDefinition.getEventName().equals(cachedSubscription.getEventName()) && !subscriptionsForSameMessageName.contains(cachedSubscription)) {
                        subscriptionsForSameMessageName.add(cachedSubscription);
                    }
                }
                // remove subscriptions deleted in the same command
                subscriptionsForSameMessageName = commandContext.getDbSqlSession().pruneDeletedEntities(subscriptionsForSameMessageName);
                for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsForSameMessageName) {
                    // no process instance-id = it's a message start event
                    if (StringUtils.isEmpty(eventSubscriptionEntity.getProcessInstanceId())) {
                        throw new ActivitiException("Cannot deploy process definition '" + processDefinition.getResourceName() + "': there already is a message event subscription for the message with name '" + eventDefinition.getEventName() + "'.");
                    }
                }
                MessageEventSubscriptionEntity newSubscription = new MessageEventSubscriptionEntity();
                newSubscription.setEventName(eventDefinition.getEventName());
                newSubscription.setActivityId(eventDefinition.getActivityId());
                newSubscription.setConfiguration(processDefinition.getId());
                newSubscription.setProcessDefinitionId(processDefinition.getId());
                if (processDefinition.getTenantId() != null) {
                    newSubscription.setTenantId(processDefinition.getTenantId());
                }
                newSubscription.insert();
            }
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) List(java.util.List) ArrayList(java.util.ArrayList) EventSubscriptionDeclaration(org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity) HashSet(java.util.HashSet)

Example 3 with MessageEventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity in project Activiti by Activiti.

the class MessageThrowingEventListener method onEvent.

@Override
public void onEvent(ActivitiEvent event) {
    if (isValidEvent(event)) {
        if (event.getProcessInstanceId() == null) {
            throw new ActivitiIllegalArgumentException("Cannot throw process-instance scoped message, since the dispatched event is not part of an ongoing process instance");
        }
        EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
        List<MessageEventSubscriptionEntity> subscriptionEntities = eventSubscriptionEntityManager.findMessageEventSubscriptionsByProcessInstanceAndEventName(event.getProcessInstanceId(), messageName);
        for (EventSubscriptionEntity messageEventSubscriptionEntity : subscriptionEntities) {
            eventSubscriptionEntityManager.eventReceived(messageEventSubscriptionEntity, null, false);
        }
    }
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) EventSubscriptionEntityManager(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntityManager) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 4 with MessageEventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity in project Activiti by Activiti.

the class DefaultMessageExecutionContext method createMessageEventSubscription.

@Override
public MessageEventSubscriptionEntity createMessageEventSubscription(CommandContext commandContext, DelegateExecution execution) {
    String messageName = getMessageName(execution);
    Optional<String> correlationKey = getCorrelationKey(execution);
    correlationKey.ifPresent(key -> assertNoExistingDuplicateEventSubscriptions(messageName, key, commandContext));
    MessageEventSubscriptionEntity messageEvent = commandContext.getEventSubscriptionEntityManager().insertMessageEvent(messageName, ExecutionEntity.class.cast(execution));
    correlationKey.ifPresent(messageEvent::setConfiguration);
    return messageEvent;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)

Example 5 with MessageEventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity in project Activiti by Activiti.

the class MybatisEventSubscriptionDataManager method findMessageStartEventSubscriptionByName.

@Override
public MessageEventSubscriptionEntity findMessageStartEventSubscriptionByName(String messageName, String tenantId) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("eventName", messageName);
    if (tenantId != null && !tenantId.equals(ProcessEngineConfiguration.NO_TENANT_ID)) {
        params.put("tenantId", tenantId);
    }
    MessageEventSubscriptionEntity entity = (MessageEventSubscriptionEntity) getDbSqlSession().selectOne("selectMessageStartEventSubscriptionByName", params);
    return entity;
}
Also used : HashMap(java.util.HashMap) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)

Aggregations

MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)18 EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)11 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)9 SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)7 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)6 EventSubscriptionEntityManager (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntityManager)4 ActivitiException (org.activiti.engine.ActivitiException)3 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)3 StartEvent (org.activiti.bpmn.model.StartEvent)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 MessageSubscriptionImpl (org.activiti.api.runtime.model.impl.MessageSubscriptionImpl)1 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 EventDefinition (org.activiti.bpmn.model.EventDefinition)1 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)1 FlowElement (org.activiti.bpmn.model.FlowElement)1