Search in sources :

Example 1 with DebugProcessEventListener

use of org.drools.core.event.DebugProcessEventListener in project jbpm by kiegroup.

the class CustomProcessEventListenerProducer method getEventListeners.

@Override
public List<ProcessEventListener> getEventListeners(String identifier, Map<String, Object> params) {
    List<ProcessEventListener> processEventListeners = new ArrayList<ProcessEventListener>();
    processEventListeners.add(new DebugProcessEventListener());
    return processEventListeners;
}
Also used : DebugProcessEventListener(org.drools.core.event.DebugProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DebugProcessEventListener(org.drools.core.event.DebugProcessEventListener) ArrayList(java.util.ArrayList)

Example 2 with DebugProcessEventListener

use of org.drools.core.event.DebugProcessEventListener in project jbpm by kiegroup.

the class AgendaFilterTest method testActivationCancelled.

@Test
public void testActivationCancelled() {
    // JBRULES-3376
    String drl = "package org.jboss.qa.brms.agendafilter\n" + "declare CancelFact\n" + "   cancel : boolean = true\n" + "end\n" + "rule NoCancel\n" + "   ruleflow-group \"rfg\"\n" + "   when\n" + "       $fact : CancelFact ( cancel == false )\n" + "   then\n" + "       System.out.println(\"No cancel...\");\n" + "       modify ($fact) {\n" + "           setCancel(true);\n" + "       }\n" + "end\n" + "rule PresenceOfBothFacts\n" + "   ruleflow-group \"rfg\"\n" + "   salience -1\n" + "   when\n" + "       $fact1 : CancelFact( cancel == false )\n" + "       $fact2 : CancelFact( cancel == true )\n" + "   then\n" + "       System.out.println(\"Both facts!\");\n" + "end\n" + "rule PresenceOfFact\n" + "   ruleflow-group \"rfg\"\n" + "   when\n" + "       $fact : CancelFact( )\n" + "   then\n" + "       System.out.println(\"We have a \" + ($fact.isCancel() ? \"\" : \"non-\") + \"cancelling fact!\");\n" + "end\n" + "rule Cancel\n" + "   ruleflow-group \"rfg\"\n" + "   when\n" + "       $fact : CancelFact ( cancel == true )\n" + "   then\n" + "       System.out.println(\"Cancel!\");\n" + "end";
    String rf = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + "         type=\"RuleFlow\" name=\"flow\" id=\"bz761715\" package-name=\"org.jboss.qa.brms.agendafilter\" >\n" + "  <header>\n" + "  </header>\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" x=\"16\" y=\"16\" width=\"48\" height=\"48\" />\n" + "    <ruleSet id=\"2\" name=\"Rule\" x=\"208\" y=\"16\" width=\"80\" height=\"48\" ruleFlowGroup=\"rfg\" />\n" + "    <actionNode id=\"3\" name=\"Script\" x=\"320\" y=\"16\" width=\"80\" height=\"48\" >\n" + "        <action type=\"expression\" dialect=\"java\" >System.out.println(\"Finishing process...\");</action>\n" + "    </actionNode>\n" + "    <end id=\"4\" name=\"End\" x=\"432\" y=\"16\" width=\"48\" height=\"48\" />\n" + "    <actionNode id=\"5\" name=\"Script\" x=\"96\" y=\"16\" width=\"80\" height=\"48\" >\n" + "        <action type=\"expression\" dialect=\"java\" >System.out.println(\"Starting process...\");</action>\n" + "    </actionNode>\n" + "  </nodes>\n" + "  <connections>\n" + "    <connection from=\"5\" to=\"2\" />\n" + "    <connection from=\"2\" to=\"3\" />\n" + "    <connection from=\"3\" to=\"4\" />\n" + "    <connection from=\"1\" to=\"5\" />\n" + "  </connections>\n" + "</process>";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newByteArrayResource(rf.getBytes()), ResourceType.DRF);
    if (kbuilder.hasErrors()) {
        fail(kbuilder.getErrors().toString());
    }
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    KieSession ksession = kbase.newKieSession();
    ksession.addEventListener(new DebugAgendaEventListener());
    ksession.addEventListener(new DebugProcessEventListener());
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(CommandFactory.newInsert(newCancelFact(ksession, false)));
    commands.add(CommandFactory.newInsert(newCancelFact(ksession, true)));
    commands.add(CommandFactory.newStartProcess("bz761715"));
    commands.add(new FireAllRulesCommand(new CancelAgendaFilter()));
    commands.add(new FireAllRulesCommand(new CancelAgendaFilter()));
    commands.add(new FireAllRulesCommand(new CancelAgendaFilter()));
    ksession.execute(CommandFactory.newBatchExecution(commands));
}
Also used : DebugAgendaEventListener(org.kie.api.event.rule.DebugAgendaEventListener) DebugProcessEventListener(org.drools.core.event.DebugProcessEventListener) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) FireAllRulesCommand(org.drools.core.command.runtime.rule.FireAllRulesCommand) Command(org.kie.api.command.Command) FireAllRulesCommand(org.drools.core.command.runtime.rule.FireAllRulesCommand) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 3 with DebugProcessEventListener

use of org.drools.core.event.DebugProcessEventListener in project duangframework by tcrct.

the class KieSessionHolder method kieSession.

public KieSession kieSession() {
    if (ToolsKit.isEmpty(kieContainer)) {
        init();
    }
    KieSession session = kieContainer.newKieSession();
    session.addEventListener(new DebugRuleRuntimeEventListener());
    session.addEventListener(new DebugProcessEventListener());
    session.addEventListener(new DebugAgendaEventListener());
    return session;
}
Also used : DebugProcessEventListener(org.drools.core.event.DebugProcessEventListener) DebugAgendaEventListener(org.drools.core.event.DebugAgendaEventListener) DebugRuleRuntimeEventListener(org.drools.core.event.DebugRuleRuntimeEventListener) KieSession(org.kie.api.runtime.KieSession)

Example 4 with DebugProcessEventListener

use of org.drools.core.event.DebugProcessEventListener in project jbpm by kiegroup.

the class SingleRuntimeManagerWithListenersTest method testProcessStartOnManager.

private void testProcessStartOnManager(RuntimeEngine runtime) {
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    Collection<ProcessEventListener> pListeners = ksession.getProcessEventListeners();
    assertNotNull(pListeners);
    // prepare listeners class names for assertion
    List<String> listenerCLassNames = new ArrayList<String>();
    for (Object o : pListeners) {
        listenerCLassNames.add(o.getClass().getName());
    }
    // DebugProcessEventListener was added by custom producer
    assertTrue(listenerCLassNames.contains(DebugProcessEventListener.class.getName()));
    // JPAWorkingMemoryDbLogger one is always added to deal with user tasks
    assertTrue(listenerCLassNames.contains(JPAWorkingMemoryDbLogger.class.getName()));
    if (((RuntimeEngineImpl) runtime).getManager() instanceof PerProcessInstanceRuntimeManager) {
        assertEquals(3, pListeners.size());
    } else {
        assertEquals(2, pListeners.size());
    }
    TaskService taskService = runtime.getTaskService();
    assertNotNull(taskService);
    List<?> listeners = ((EventService<?>) taskService).getTaskEventListeners();
    assertNotNull(listeners);
    assertEquals(3, listeners.size());
    // prepare listeners class names for assertion
    listenerCLassNames = new ArrayList<String>();
    for (Object o : listeners) {
        System.out.println("###### " + o.getClass().getName());
        listenerCLassNames.add(o.getClass().getName());
    }
    assertEquals(3, listenerCLassNames.size());
    // JPATaskLifeCycleEventListener was added by custom producer
    assertTrue(listenerCLassNames.contains(JPATaskLifeCycleEventListener.class.getName()));
    // external one is always added to deal with user tasks
    assertTrue(listenerCLassNames.contains(ExternalTaskEventListener.class.getName()));
    // BAMTaskEventListener was added by custom producer
    assertTrue(listenerCLassNames.contains(BAMTaskEventListener.class.getName()));
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertNotNull(processInstance);
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Reserved);
    List<TaskSummary> tasks = taskService.getTasksOwnedByStatus("john", statuses, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    taskService.start(tasks.get(0).getId(), "john");
    taskService.complete(tasks.get(0).getId(), "john", null);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNull(processInstance);
}
Also used : Status(org.kie.api.task.model.Status) TaskService(org.kie.api.task.TaskService) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DebugProcessEventListener(org.drools.core.event.DebugProcessEventListener) ArrayList(java.util.ArrayList) PerProcessInstanceRuntimeManager(org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager) EventService(org.kie.internal.task.api.EventService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) PerProcessInstance(org.kie.internal.runtime.manager.cdi.qualifier.PerProcessInstance)

Aggregations

DebugProcessEventListener (org.drools.core.event.DebugProcessEventListener)4 ArrayList (java.util.ArrayList)3 KieSession (org.kie.api.runtime.KieSession)3 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)2 FireAllRulesCommand (org.drools.core.command.runtime.rule.FireAllRulesCommand)1 DebugAgendaEventListener (org.drools.core.event.DebugAgendaEventListener)1 DebugRuleRuntimeEventListener (org.drools.core.event.DebugRuleRuntimeEventListener)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 PerProcessInstanceRuntimeManager (org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager)1 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)1 Test (org.junit.Test)1 Command (org.kie.api.command.Command)1 DebugAgendaEventListener (org.kie.api.event.rule.DebugAgendaEventListener)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 TaskService (org.kie.api.task.TaskService)1 Status (org.kie.api.task.model.Status)1 TaskSummary (org.kie.api.task.model.TaskSummary)1 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)1 PerProcessInstance (org.kie.internal.runtime.manager.cdi.qualifier.PerProcessInstance)1 EventService (org.kie.internal.task.api.EventService)1