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