Search in sources :

Example 1 with SignalEventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity 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 SignalEventSubscriptionEntity

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

the class SignalThrowingEventListener method onEvent.

@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) {
                ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessEngineConfiguration().getDeploymentManager().findDeployedProcessDefinitionById(event.getProcessDefinitionId());
                tenantId = processDefinitionEntity.getTenantId();
            }
            subscriptionEntities = commandContext.getEventSubscriptionEntityManager().findSignalEventSubscriptionsByEventName(signalName, tenantId);
        }
        for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
            signalEventSubscriptionEntity.eventReceived(null, false);
        }
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)

Example 3 with SignalEventSubscriptionEntity

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

the class IntermediateThrowSignalEventActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    CommandContext commandContext = Context.getCommandContext();
    List<SignalEventSubscriptionEntity> subscriptionEntities = null;
    if (processInstanceScope) {
        subscriptionEntities = commandContext.getEventSubscriptionEntityManager().findSignalEventSubscriptionsByProcessInstanceAndEventName(execution.getProcessInstanceId(), signalDefinition.getEventName());
    } else {
        subscriptionEntities = commandContext.getEventSubscriptionEntityManager().findSignalEventSubscriptionsByEventName(signalDefinition.getEventName(), execution.getTenantId());
    }
    for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
        signalEventSubscriptionEntity.eventReceived(null, signalDefinition.isAsync());
    }
    if (execution.getActivity() != null) {
        // dont continue if process has already finished
        leave(execution);
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)

Example 4 with SignalEventSubscriptionEntity

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

the class ActivityEventsTest method testActivitySignalBoundaryEventsOnSubProcess.

@Deployment
public void testActivitySignalBoundaryEventsOnSubProcess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalOnSubProcess");
    assertNotNull(processInstance);
    Execution executionWithSignal = runtimeService.createExecutionQuery().activityId("userTaskInsideProcess").singleResult();
    assertNotNull(executionWithSignal);
    runtimeService.signalEventReceived("signalName");
    assertEquals(1, listener.getEventsReceived().size());
    // Next, an signal-event is expected, as a result of the message
    assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiActivityCancelledEvent);
    ActivitiActivityCancelledEvent signalEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, signalEvent.getType());
    assertEquals("userTaskInsideProcess", signalEvent.getActivityId());
    assertEquals(executionWithSignal.getId(), signalEvent.getExecutionId());
    assertEquals(executionWithSignal.getProcessInstanceId(), signalEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
    assertNotNull(signalEvent.getCause());
    assertTrue(signalEvent.getCause() instanceof SignalEventSubscriptionEntity);
    SignalEventSubscriptionEntity cause = (SignalEventSubscriptionEntity) signalEvent.getCause();
    assertEquals("signalName", cause.getEventName());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) Deployment(org.activiti.engine.test.Deployment)

Example 5 with SignalEventSubscriptionEntity

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

the class SignalEventReceivedCmd method execute.

public Void execute(CommandContext commandContext) {
    List<SignalEventSubscriptionEntity> signalEvents = null;
    if (executionId == null) {
        signalEvents = commandContext.getEventSubscriptionEntityManager().findSignalEventSubscriptionsByEventName(eventName, tenantId);
    } else {
        ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(executionId);
        if (execution == null) {
            throw new ActivitiObjectNotFoundException("Cannot find execution with id '" + executionId + "'", Execution.class);
        }
        if (execution.isSuspended()) {
            throw new ActivitiException("Cannot throw signal event '" + eventName + "' because execution '" + executionId + "' is suspended");
        }
        signalEvents = commandContext.getEventSubscriptionEntityManager().findSignalEventSubscriptionsByNameAndExecution(eventName, executionId);
        if (signalEvents.isEmpty()) {
            throw new ActivitiException("Execution '" + executionId + "' has not subscribed to a signal event with name '" + eventName + "'.");
        }
    }
    for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : signalEvents) {
        // Process instance scoped signals must be thrown within the process itself 
        if (signalEventSubscriptionEntity.isGlobalScoped()) {
            signalEventSubscriptionEntity.eventReceived(payload, async);
        }
    }
    return null;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)

Aggregations

SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)9 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)4 EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)3 MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)3 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 ActivitiActivityCancelledEvent (org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent)2 Execution (org.activiti.engine.runtime.Execution)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 Deployment (org.activiti.engine.test.Deployment)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1 EventSubscriptionDeclaration (org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration)1 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)1 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)1 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)1