Search in sources :

Example 21 with ProcessNodeTriggeredEvent

use of org.kie.api.event.process.ProcessNodeTriggeredEvent in project jbpm by kiegroup.

the class PersistentStatefulSessionTest method testProcessListener.

@Test
public void testProcessListener() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("WorkItemsProcess.rf"), ResourceType.DRF);
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
    final List<ProcessEvent> events = new ArrayList<ProcessEvent>();
    ProcessEventListener listener = new ProcessEventListener() {

        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            logger.debug("After node left: {}", event.getNodeInstance().getNodeName());
            events.add(event);
        }

        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            logger.debug("After node triggered: {}", event.getNodeInstance().getNodeName());
            events.add(event);
        }

        public void afterProcessCompleted(ProcessCompletedEvent event) {
            logger.debug("After process completed");
            events.add(event);
        }

        public void afterProcessStarted(ProcessStartedEvent event) {
            logger.debug("After process started");
            events.add(event);
        }

        public void beforeNodeLeft(ProcessNodeLeftEvent event) {
            logger.debug("Before node left: {}", event.getNodeInstance().getNodeName());
            events.add(event);
        }

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            logger.debug("Before node triggered: {}", event.getNodeInstance().getNodeName());
            events.add(event);
        }

        public void beforeProcessCompleted(ProcessCompletedEvent event) {
            logger.debug("Before process completed");
            events.add(event);
        }

        public void beforeProcessStarted(ProcessStartedEvent event) {
            logger.debug("Before process started");
            events.add(event);
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
            logger.debug("After Variable Changed");
            events.add(event);
        }

        public void beforeVariableChanged(ProcessVariableChangedEvent event) {
            logger.debug("Before Variable Changed");
            events.add(event);
        }
    };
    ksession.addEventListener(listener);
    ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess");
    logger.debug("Started process instance {}", processInstance.getId());
    assertEquals(12, events.size());
    assertTrue(events.get(0) instanceof ProcessStartedEvent);
    assertTrue(events.get(1) instanceof ProcessNodeTriggeredEvent);
    assertTrue(events.get(2) instanceof ProcessNodeLeftEvent);
    assertTrue(events.get(3) instanceof ProcessNodeTriggeredEvent);
    assertTrue(events.get(4) instanceof ProcessNodeLeftEvent);
    assertTrue(events.get(5) instanceof ProcessNodeTriggeredEvent);
    assertTrue(events.get(6) instanceof ProcessNodeTriggeredEvent);
    assertTrue(events.get(7) instanceof ProcessNodeLeftEvent);
    assertTrue(events.get(8) instanceof ProcessNodeTriggeredEvent);
    assertTrue(events.get(9) instanceof ProcessNodeLeftEvent);
    assertTrue(events.get(10) instanceof ProcessNodeTriggeredEvent);
    assertTrue(events.get(11) instanceof ProcessStartedEvent);
    ksession.removeEventListener(listener);
    events.clear();
    processInstance = ksession.startProcess("org.drools.test.TestProcess");
    logger.debug("Started process instance {}", processInstance.getId());
    assertTrue(events.isEmpty());
}
Also used : ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) ProcessEvent(org.kie.api.event.process.ProcessEvent) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) ClassPathResource(org.drools.core.io.impl.ClassPathResource) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 22 with ProcessNodeTriggeredEvent

use of org.kie.api.event.process.ProcessNodeTriggeredEvent in project jbpm by kiegroup.

the class HumanTaskSwimlaneTest method testSwimlaneWithMultipleActorsAssigned.

@Test
public void testSwimlaneWithMultipleActorsAssigned() {
    createRuntimeManager(SWIMLANE_MULTIPLE_ACTORS);
    String user = "john";
    RuntimeEngine runtime = getRuntimeEngine();
    KieSession kSession = runtime.getKieSession();
    TaskService taskservice = runtime.getTaskService();
    kSession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            if (event.getNodeInstance().getNodeName().equals("TASK")) {
                Object swimlaneActorId = ((HumanTaskNodeInstance) event.getNodeInstance()).getWorkItem().getParameter("SwimlaneActorId");
                assertNull(swimlaneActorId);
            }
        }
    });
    Map<String, Object> map = new HashMap<String, Object>();
    ProcessInstance instance = kSession.startProcess(SWIMLANE_MULTIPLE_ACTORS_ID, map);
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Ready);
    statuses.add(Status.Reserved);
    statuses.add(Status.InProgress);
    List<TaskSummary> tasks = taskservice.getTasksByStatusByProcessInstanceId(instance.getId(), statuses, "en_US");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    assertEquals(Status.Ready, task.getStatus());
    taskservice.claim(task.getId(), user);
    taskservice.start(task.getId(), user);
    tasks = taskservice.getTasksByStatusByProcessInstanceId(instance.getId(), statuses, "en_US");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    assertEquals(Status.InProgress, task.getStatus());
    taskservice.complete(task.getId(), user, map);
    assertProcessInstanceCompleted(instance.getId());
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) ArrayList(java.util.ArrayList) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) TaskSummary(org.kie.api.task.model.TaskSummary) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 23 with ProcessNodeTriggeredEvent

use of org.kie.api.event.process.ProcessNodeTriggeredEvent in project jbpm by kiegroup.

the class EjbTimerServiceIntegrationTest method testProcessWithTimerOverEJBTimerServiceCancelTimer.

@Test
public void testProcessWithTimerOverEJBTimerServiceCancelTimer() throws InterruptedException {
    cleanupSingletonSessionId();
    final List<String> timerExecution = new ArrayList<String>();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-TimerTask.bpmn2"), ResourceType.BPMN2).schedulerService(new EjbSchedulerService()).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(new DefaultProcessEventListener() {

                @Override
                public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
                    if (event.getNodeInstance().getNodeName().equals("Event")) {
                        timerExecution.add(event.getNodeInstance().getNodeName());
                    }
                }
            });
            return listeners;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance instance = ksession.startProcess("IntermediateCatchEvent");
    assertNotNull(instance);
    ksession.abortProcessInstance(instance.getId());
    instance = ksession.getProcessInstance(instance.getId());
    assertNull(instance);
    Thread.sleep(3000);
    assertEquals(0, timerExecution.size());
    manager.disposeRuntimeEngine(runtime);
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) EjbSchedulerService(org.jbpm.services.ejb.timer.EjbSchedulerService) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 24 with ProcessNodeTriggeredEvent

use of org.kie.api.event.process.ProcessNodeTriggeredEvent in project jbpm by kiegroup.

the class AsyncThreadIsolationTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    executorService = ExecutorServiceFactory.newExecutorService(getEmf());
    executorService.setInterval(1);
    executorService.init();
    addEnvironmentEntry("ExecutorService", executorService);
    addWorkItemHandler("Service Task", new ServiceTaskHandler());
    addProcessEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            if (event.getNodeInstance().getNodeName().equals("Async Hello Service Exception")) {
                if (firstAttempt) {
                    firstAttempt = false;
                } else {
                    synchronized (LOCK) {
                        LOCK.notifyAll();
                    }
                }
            }
        }
    });
}
Also used : ServiceTaskHandler(org.jbpm.process.workitem.bpmn2.ServiceTaskHandler) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) Before(org.junit.Before)

Aggregations

ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)24 Test (org.junit.Test)22 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)19 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)18 KieBase (org.kie.api.KieBase)14 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)13 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)9 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)8 KieSession (org.kie.api.runtime.KieSession)8 WorkItem (org.kie.api.runtime.process.WorkItem)8 ProcessVariableChangedEvent (org.kie.api.event.process.ProcessVariableChangedEvent)7 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)6 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)6 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)6 Map (java.util.Map)5 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)5 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)5