org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration Java Examples

The following examples show how to use org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractBpmnParseHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void addEventSubscriptionDeclaration(BpmnParse bpmnParse, EventSubscriptionDeclaration subscription, EventDefinition parsedEventDefinition, ScopeImpl scope) {
    List<EventSubscriptionDeclaration> eventDefinitions = (List<EventSubscriptionDeclaration>) scope.getProperty(PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
    if (eventDefinitions == null) {
        eventDefinitions = new ArrayList<>();
        scope.setProperty(PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION, eventDefinitions);
    } else {
        // if this is a message event, validate that it is the only one with the provided name for this scope
        if (subscription.getEventType().equals("message")) {
            for (EventSubscriptionDeclaration eventDefinition : eventDefinitions) {
                if (eventDefinition.getEventType().equals("message")
                        && eventDefinition.getEventName().equals(subscription.getEventName())
                        && eventDefinition.isStartEvent() == subscription.isStartEvent()) {

                    LOGGER.warn("Cannot have more than one message event subscription with name '{}' for scope '{}'", subscription.getEventName(), scope.getId());
                }
            }
        }
    }
    eventDefinitions.add(subscription);
}
 
Example #2
Source File: BpmnDeployer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void addSignalEventSubscriptions(ProcessDefinitionEntity processDefinition) {
    List<EventSubscriptionDeclaration> eventDefinitions = (List<EventSubscriptionDeclaration>) processDefinition.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
    if (eventDefinitions != null) {
        for (EventSubscriptionDeclaration eventDefinition : eventDefinitions) {
            if (eventDefinition.getEventType().equals("signal") && eventDefinition.isStartEvent()) {

                SignalEventSubscriptionEntity subscriptionEntity = new SignalEventSubscriptionEntity();
                subscriptionEntity.setEventName(eventDefinition.getEventName());
                subscriptionEntity.setActivityId(eventDefinition.getActivityId());
                subscriptionEntity.setProcessDefinitionId(processDefinition.getId());
                if (processDefinition.getTenantId() != null) {
                    subscriptionEntity.setTenantId(processDefinition.getTenantId());
                }
                subscriptionEntity.insert();

            }
        }
    }
}
 
Example #3
Source File: TestActivityBehaviorFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public IntermediateThrowSignalEventActivityBehavior createIntermediateThrowSignalEventActivityBehavior(
        ThrowEvent throwEvent, Signal signal,
        EventSubscriptionDeclaration eventSubscriptionDeclaration) {
    return wrappedActivityBehaviorFactory.createIntermediateThrowSignalEventActivityBehavior(
            throwEvent, signal, eventSubscriptionDeclaration);
}
 
Example #4
Source File: ExecutionEntity.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void initialize() {
    LOGGER.debug("initializing {}", this);

    ScopeImpl scope = getScopeObject();
    ensureParentInitialized();

    // initialize the lists of referenced objects (prevents db queries)
    variableInstances = new HashMap<>();
    eventSubscriptions = new ArrayList<>();

    // Cached entity-state initialized to null, all bits are zero, indicating NO entities present
    cachedEntityState = 0;

    List<TimerDeclarationImpl> timerDeclarations = (List<TimerDeclarationImpl>) scope.getProperty(BpmnParse.PROPERTYNAME_TIMER_DECLARATION);
    if (timerDeclarations != null) {
        for (TimerDeclarationImpl timerDeclaration : timerDeclarations) {
            TimerJobEntity timer = timerDeclaration.prepareTimerEntity(this);
            if (timer != null) {
                callJobProcessors(JobProcessorContext.Phase.BEFORE_CREATE, timer, Context.getProcessEngineConfiguration());
                Context.getCommandContext().getJobEntityManager().schedule(timer);
            }
        }
    }

    // create event subscriptions for the current scope
    List<EventSubscriptionDeclaration> eventSubscriptionDeclarations = (List<EventSubscriptionDeclaration>) scope.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
    if (eventSubscriptionDeclarations != null) {
        for (EventSubscriptionDeclaration eventSubscriptionDeclaration : eventSubscriptionDeclarations) {
            if (!eventSubscriptionDeclaration.isStartEvent()) {
                EventSubscriptionEntity eventSubscriptionEntity = eventSubscriptionDeclaration.prepareEventSubscriptionEntity(this);
                if (getTenantId() != null) {
                    eventSubscriptionEntity.setTenantId(getTenantId());
                }
                eventSubscriptionEntity.insert();
            }
        }
    }
}
 
Example #5
Source File: DefaultActivityBehaviorFactory.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public IntermediateThrowSignalEventActivityBehavior createIntermediateThrowSignalEventActivityBehavior(ThrowEvent throwEvent,
        Signal signal, EventSubscriptionDeclaration eventSubscriptionDeclaration) {
    return new IntermediateThrowSignalEventActivityBehavior(throwEvent, signal, eventSubscriptionDeclaration);
}
 
Example #6
Source File: IntermediateThrowSignalEventActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public IntermediateThrowSignalEventActivityBehavior(ThrowEvent throwEvent, Signal signal, EventSubscriptionDeclaration signalDefinition) {
    this.processInstanceScope = Signal.SCOPE_PROCESS_INSTANCE.equals(signal.getScope());
    this.signalDefinition = signalDefinition;
}
 
Example #7
Source File: BpmnDeployer.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@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<>();
        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 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) {
                    // throw exception only if there's already a subscription as start event
                    if (eventSubscriptionEntity.getProcessInstanceId() == null || eventSubscriptionEntity.getProcessInstanceId().isEmpty()) {
                        // the event subscription has no instance-id, so it's a message start event
                        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();
            }
        }
    }
}
 
Example #8
Source File: ActivityBehaviorFactoryDelegate.java    From openwebflow with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public IntermediateThrowSignalEventActivityBehavior createIntermediateThrowSignalEventActivityBehavior(
		ThrowEvent throwEvent, Signal signal, EventSubscriptionDeclaration eventSubscriptionDeclaration)
{
	return _source.createIntermediateThrowSignalEventActivityBehavior(throwEvent, signal,
		eventSubscriptionDeclaration);
}
 
Example #9
Source File: ActivityBehaviorFactory.java    From flowable-engine with Apache License 2.0 votes vote down vote up
public abstract IntermediateThrowSignalEventActivityBehavior createIntermediateThrowSignalEventActivityBehavior(ThrowEvent throwEvent, Signal signal, EventSubscriptionDeclaration eventSubscriptionDeclaration);