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