Java Code Examples for org.activiti.engine.delegate.event.ActivitiEvent#getProcessInstanceId()

The following examples show how to use org.activiti.engine.delegate.event.ActivitiEvent#getProcessInstanceId() . 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: MessageThrowingEventListener.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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");
		}

		CommandContext commandContext = Context.getCommandContext();
		List<EventSubscriptionEntity> subscriptionEntities = commandContext.getEventSubscriptionEntityManager()
			    .findEventSubscriptionsByNameAndExecution(MessageEventHandler.EVENT_HANDLER_TYPE, messageName, event.getExecutionId());

		// Revert to messaging the process instance
		if(subscriptionEntities.isEmpty() && event.getProcessInstanceId() != null && !event.getExecutionId().equals(event.getProcessInstanceId())) {
			subscriptionEntities = commandContext.getEventSubscriptionEntityManager()
			    .findEventSubscriptionsByNameAndExecution(MessageEventHandler.EVENT_HANDLER_TYPE, messageName, event.getProcessInstanceId());
		}
		
		for (EventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
			signalEventSubscriptionEntity.eventReceived(null, false);
		}
	}
}
 
Example 2
Source File: MessageThrowingEventListener.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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);
    }
  }
}
 
Example 3
Source File: SignalThrowingEventListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(ActivitiEvent event) {
	if (isValidEvent(event)) {

		if (event.getProcessInstanceId() == null && processInstanceScope) {
			throw new ActivitiIllegalArgumentException(
			    "Cannot throw process-instance scoped signal, since the dispatched event is not part of an ongoing process instance");
		}

		CommandContext commandContext = Context.getCommandContext();
		List<SignalEventSubscriptionEntity> subscriptionEntities = null;
		if (processInstanceScope) {
			subscriptionEntities = commandContext.getEventSubscriptionEntityManager()
			    .findSignalEventSubscriptionsByProcessInstanceAndEventName(event.getProcessInstanceId(), signalName);
		} else {
			String tenantId = null;
			if (event.getProcessDefinitionId() != null) {
				ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration()
						.getDeploymentManager().findDeployedProcessDefinitionById(event.getProcessDefinitionId());
				tenantId = processDefinition.getTenantId();
			}
			subscriptionEntities = commandContext.getEventSubscriptionEntityManager()
			    .findSignalEventSubscriptionsByEventName(signalName, tenantId);
		}

		for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
			signalEventSubscriptionEntity.eventReceived(null, false);
		}
	}
}
 
Example 4
Source File: SignalThrowingEventListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(ActivitiEvent event) {
  if (isValidEvent(event)) {

    if (event.getProcessInstanceId() == null && processInstanceScope) {
      throw new ActivitiIllegalArgumentException("Cannot throw process-instance scoped signal, since the dispatched event is not part of an ongoing process instance");
    }

    CommandContext commandContext = Context.getCommandContext();
    EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
    List<SignalEventSubscriptionEntity> subscriptionEntities = null;
    if (processInstanceScope) {
      subscriptionEntities = eventSubscriptionEntityManager.findSignalEventSubscriptionsByProcessInstanceAndEventName(event.getProcessInstanceId(), signalName);
    } else {
      String tenantId = null;
      if (event.getProcessDefinitionId() != null) {
        ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration().getDeploymentManager().findDeployedProcessDefinitionById(event.getProcessDefinitionId());
        tenantId = processDefinition.getTenantId();
      }
      subscriptionEntities = eventSubscriptionEntityManager.findSignalEventSubscriptionsByEventName(signalName, tenantId);
    }

    for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
      eventSubscriptionEntityManager.eventReceived(signalEventSubscriptionEntity, null, false);
    }
  }
}