Search in sources :

Example 1 with TaskSummary

use of org.jbpm.task.query.TaskSummary in project jBPM5-Developer-Guide by Salaboy.

the class TasksListUI method refreshTaskList.

private void refreshTaskList() {
    String selectedUser = (String) selectedUserjComboBox.getSelectedItem();
    System.out.println("Selected User: " + selectedUser);
    List<TaskSummary> tasks = localTaskService.getTasksAssignedAsPotentialOwner(selectedUser, "en-UK");
    System.out.println("Tasks: " + tasks + " - size: " + tasks.size());
    String selectedPerspective = (String) perspectivejComboBox.getItemAt(perspectivejComboBox.getSelectedIndex());
    if (selectedPerspective.equals("Simple")) {
        taskSummariesjTable.setModel(new SimpleTaskSummariesModel(tasks));
    } else {
        taskSummariesjTable.setModel(new DetailedTaskSummariesModel(tasks));
    }
}
Also used : TaskSummary(org.jbpm.task.query.TaskSummary) DetailedTaskSummariesModel(com.salaboy.jbpm5.dev.guide.tablemodel.DetailedTaskSummariesModel) SimpleTaskSummariesModel(com.salaboy.jbpm5.dev.guide.tablemodel.SimpleTaskSummariesModel)

Example 2 with TaskSummary

use of org.jbpm.task.query.TaskSummary in project jBPM5-Developer-Guide by Salaboy.

the class PersistentProcessTest method processInstancesAndLocalHTPlusFailTest.

@Test
public void processInstancesAndLocalHTPlusFailTest() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("process-async-interactions.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        for (KnowledgeBuilderError error : kbuilder.getErrors()) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        fail(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    Environment env = EnvironmentFactory.newEnvironment();
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.runtime.ht");
    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
    env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
    // Let's create a Persistence Knowledge Session
    System.out.println(" >>> Let's create a Persistent Knowledge Session");
    final StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
    int sessionId = ksession.getId();
    assertNotNull(sessionId);
    assertTrue(sessionId != 0);
    // We need to register the WorkItems and Listeners that the session will use
    TaskService client = createTaskService(emf);
    LocalHTWorkItemHandler localHTWorkItemHandler = new LocalHTWorkItemHandler(client, ksession);
    MockFaultWorkItemHandler mockFaultWorkItemHandler = new MockFaultWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", localHTWorkItemHandler);
    ksession.getWorkItemManager().registerWorkItemHandler("External Service Call", mockFaultWorkItemHandler);
    // KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
    // Let's create a Process Instance
    Person person = new Person("Salaboy", 29);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("person", person);
    // Each Command will generate an interaction
    System.out.println(">>> Let's Create Process Instance");
    ProcessInstance processInstance = ksession.createProcessInstance("com.salaboy.process.AsyncInteractions", params);
    System.out.println(">>> Let's Start the Process Instance");
    UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    ksession.startProcessInstance(processInstance.getId());
    ut.commit();
    System.out.println(" >>> Looking for Salaboy's Tasks");
    List<TaskSummary> salaboysTasks = client.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertTrue(salaboysTasks.size() == 1);
    TaskSummary salaboyTask = salaboysTasks.get(0);
    System.out.println(" >>> Starting Salaboy's Task");
    client.start(salaboyTask.getId(), "salaboy");
    System.out.println(" >>> Completing Salaboy's Task");
    ut.begin();
    try {
        client.complete(salaboyTask.getId(), "salaboy", null);
        ut.commit();
    } catch (WorkflowRuntimeException e) {
        System.out.println("Rolling back transaction" + e);
        ut.rollback();
    }
    System.out.println(" >>> Looking for Salaboy's Tasks");
    Task salaboysTask = client.getTask(salaboyTask.getId());
    assertNotNull(salaboysTask);
    assertEquals("InProgress", salaboysTask.getTaskData().getStatus().name());
    // We need to dispose the session, because the reference to this ksession object will no longer be valid
    // because another thread could load the same session and execute a different command.
    System.out.println(" >>> Disposing Session");
    ksession.dispose();
}
Also used : UserTransaction(javax.transaction.UserTransaction) KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) Task(org.jbpm.task.Task) HashMap(java.util.HashMap) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) TaskService(org.jbpm.task.TaskService) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) ClassPathResource(org.drools.io.impl.ClassPathResource) InitialContext(javax.naming.InitialContext) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) TaskSummary(org.jbpm.task.query.TaskSummary) ProcessInstance(org.drools.runtime.process.ProcessInstance) Person(com.salaboy.model.Person) LocalHTWorkItemHandler(org.jbpm.process.workitem.wsht.LocalHTWorkItemHandler)

Example 3 with TaskSummary

use of org.jbpm.task.query.TaskSummary in project jBPM5-Developer-Guide by Salaboy.

the class HumanTasksAndRulesTest method simpleTest.

@Test
public void simpleTest() throws InterruptedException {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    // Adds resources to the builder
    kbuilder.add(new ClassPathResource("rules/SimpleRulesAndTask.drl"), ResourceType.DRL);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    // Checks for errors
    if (errors.size() > 0) {
        for (KnowledgeBuilderError error : errors) {
            System.out.println(error.getMessage());
        }
        throw new IllegalStateException("Error building kbase!");
    }
    // Creates a new kbase and add all the packages from the builder
    KnowledgeBaseConfiguration kbaseConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kbaseConf.setOption(EventProcessingOption.STREAM);
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConf);
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    ksessionConf.setOption(ClockTypeOption.get("pseudo"));
    final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(ksessionConf, null);
    HornetQHTWorkItemHandler hornetQHTWorkItemHandler = new HornetQHTWorkItemHandler(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", hornetQHTWorkItemHandler);
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
    // ksession.addEventListener(new DebugAgendaEventListener());
    // Force Init
    TaskClientHelper.getInstance();
    Thread.sleep(3000);
    Task task = createTask();
    // new Thread(new Runnable() {
    // 
    // public void run() {
    // ksession.fireUntilHalt();
    // }
    // }).start();
    // Insert Tasks
    ksession.insert(task);
    // Insert Average
    ksession.insert(new Average(0.0));
    // Create and Insert Threshold
    Threshold avgThreshold = new Threshold("AverageThreshold", 2, -1);
    ksession.insert(avgThreshold);
    // Insert User
    ksession.insert(new User("salaboy"));
    clock = ksession.getSessionClock();
    System.out.println(">>> Time " + clock.getCurrentTime());
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(10.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(10.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(10.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(10.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(10.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    System.out.println(">>> Time " + clock.getCurrentTime());
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(10.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(10.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(10.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(10.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(10.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    System.out.println(">>> Time " + clock.getCurrentTime());
    org.drools.runtime.rule.QueryResults results = ksession.getQueryResults("getAverage", new Object[] {});
    for (QueryResultsRow row : results) {
        System.out.println(">>> Current Average: " + ((Average) row.get("$currentAverage")).getValue().toString());
        assertEquals("10.0", ((Average) row.get("$currentAverage")).getValue().toString());
    }
    Thread.sleep(3000);
    List<TaskSummary> tasks = TaskClientHelper.getInstance().getAssignedTasksByUser("salaboy");
    assertEquals(1, tasks.size());
    System.out.println(">>> Current Assigned Tasks: " + tasks.get(0).getName());
    System.out.println(">>> Time " + clock.getCurrentTime());
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(1.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(1.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(1.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(1.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(1.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    System.out.println(">>> Time " + clock.getCurrentTime());
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(1.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(1.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(1.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(1.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    ksession.getWorkingMemoryEntryPoint("water-events").insert(new WaterFlowingEvent(1.0));
    ksession.fireAllRules();
    clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    System.out.println(">>> Time " + clock.getCurrentTime());
    results = ksession.getQueryResults("getAverage", new Object[] {});
    Thread.sleep(3000);
    for (QueryResultsRow row : results) {
        System.out.println(">>> Current Average: " + ((Average) row.get("$currentAverage")).getValue().toString());
        assertEquals("1.0", ((Average) row.get("$currentAverage")).getValue().toString());
    }
    Thread.sleep(3000);
    tasks = TaskClientHelper.getInstance().getAssignedTasksByUser("salaboy");
    assertEquals(0, tasks.size());
    System.out.println(">>> I don't have any task assigned now!");
    Thread.sleep(3000);
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) Task(org.jbpm.task.Task) User(org.jbpm.task.User) KnowledgeBuilderErrors(org.drools.builder.KnowledgeBuilderErrors) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) ClassPathResource(org.drools.io.impl.ClassPathResource) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) HornetQHTWorkItemHandler(org.jbpm.process.workitem.wsht.HornetQHTWorkItemHandler) KnowledgeBase(org.drools.KnowledgeBase) KnowledgeBaseConfiguration(org.drools.KnowledgeBaseConfiguration) QueryResultsRow(org.drools.runtime.rule.QueryResultsRow) KnowledgeSessionConfiguration(org.drools.runtime.KnowledgeSessionConfiguration) TaskSummary(org.jbpm.task.query.TaskSummary) Test(org.junit.Test)

Example 4 with TaskSummary

use of org.jbpm.task.query.TaskSummary in project jBPM5-Developer-Guide by Salaboy.

the class ProcessAndHumanTasksTest method testProcessWithHumanTasks.

@Test
public void testProcessWithHumanTasks() throws InterruptedException {
    StatefulKnowledgeSession ksession = this.initializeSession();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
    GenericHTWorkItemHandler htHandler = this.createTaskHandler(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", htHandler);
    Map<String, Object> initialParams = new HashMap<String, Object>();
    initialParams.put("user_self_evaluation", "calcacuervo");
    ProcessInstance processInstance = ksession.startProcess("chapter_07_simple_review", initialParams);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    // first, calcacuervo will make its own review..
    List<TaskSummary> tasks = this.service.getTasksAssignedAsPotentialOwner("calcacuervo", "en-UK");
    assertEquals(1, tasks.size());
    this.service.start(tasks.get(0).getId(), "calcacuervo");
    this.service.complete(tasks.get(0).getId(), "calcacuervo", null);
    // now, a user with role TL will see the task.. esteban is one of them
    List<TaskSummary> estebanTasks = this.service.getTasksAssignedAsPotentialOwner("esteban", "en-UK");
    Assert.assertEquals(1, estebanTasks.size());
    this.service.claim(estebanTasks.get(0).getId(), "esteban");
    this.service.start(estebanTasks.get(0).getId(), "esteban");
    this.service.complete(estebanTasks.get(0).getId(), "esteban", null);
    // now, a user with role HR will see the task.. mariano is one of them
    List<TaskSummary> marianoTasks = this.service.getTasksAssignedAsPotentialOwner("mariano", "en-UK");
    Assert.assertEquals(1, marianoTasks.size());
    this.service.claim(marianoTasks.get(0).getId(), "mariano");
    this.service.start(marianoTasks.get(0).getId(), "mariano");
    this.service.complete(marianoTasks.get(0).getId(), "mariano", null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : GenericHTWorkItemHandler(org.jbpm.process.workitem.wsht.GenericHTWorkItemHandler) HashMap(java.util.HashMap) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) TaskSummary(org.jbpm.task.query.TaskSummary) ProcessInstance(org.drools.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 5 with TaskSummary

use of org.jbpm.task.query.TaskSummary in project jBPM5-Developer-Guide by Salaboy.

the class PersistentProcessTest method processInstancesAndLocalHTTest.

@Test
public void processInstancesAndLocalHTTest() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("process-async-interactions.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        for (KnowledgeBuilderError error : kbuilder.getErrors()) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        fail(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    Environment env = EnvironmentFactory.newEnvironment();
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.runtime.ht");
    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
    env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
    // Let's create a Persistence Knowledge Session
    System.out.println(" >>> Let's create a Persistent Knowledge Session");
    final StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
    int sessionId = ksession.getId();
    assertNotNull(sessionId);
    assertTrue(sessionId != 0);
    // We need to register the WorkItems and Listeners that the session will use
    TaskService client = createTaskService(emf);
    LocalHTWorkItemHandler localHTWorkItemHandler = new LocalHTWorkItemHandler(client, ksession);
    MockExternalServiceWorkItemHandler mockExternalServiceWorkItemHandler = new MockExternalServiceWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", localHTWorkItemHandler);
    ksession.getWorkItemManager().registerWorkItemHandler("External Service Call", mockExternalServiceWorkItemHandler);
    // KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
    // Let's create a Process Instance
    Person person = new Person("Salaboy", 29);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("person", person);
    // Each Command will generate an interaction
    System.out.println(">>> Let's Create Process Instance");
    ProcessInstance processInstance = ksession.createProcessInstance("com.salaboy.process.AsyncInteractions", params);
    System.out.println(">>> Let's Start the Process Instance");
    processInstance = ksession.startProcessInstance(processInstance.getId());
    System.out.println(" >>> Looking for Salaboy's Tasks");
    List<TaskSummary> salaboysTasks = client.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertTrue(salaboysTasks.size() == 1);
    TaskSummary salaboyTask = salaboysTasks.get(0);
    System.out.println(" >>> Starting Salaboy's Task");
    client.start(salaboyTask.getId(), "salaboy");
    System.out.println(" >>> Completing Salaboy's Task");
    client.complete(salaboyTask.getId(), "salaboy", null);
    List<TaskSummary> adminTasks = client.getTasksAssignedAsPotentialOwner("Administrator", "en-UK");
    assertTrue(adminTasks.size() == 1);
    TaskSummary adminTask = adminTasks.get(0);
    client.start(adminTask.getId(), "Administrator");
    client.complete(adminTask.getId(), "Administrator", null);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    // The process instance was completed and it should be out of the Ksession.
    assertNull(processInstance);
    // We need to dispose the session, because the reference to this ksession object will no longer be valid
    // Another thread could load the same session and execute a different command.
    System.out.println(">>> Disposing Session");
    ksession.dispose();
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) HashMap(java.util.HashMap) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) TaskService(org.jbpm.task.TaskService) ClassPathResource(org.drools.io.impl.ClassPathResource) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) TaskSummary(org.jbpm.task.query.TaskSummary) ProcessInstance(org.drools.runtime.process.ProcessInstance) Person(com.salaboy.model.Person) LocalHTWorkItemHandler(org.jbpm.process.workitem.wsht.LocalHTWorkItemHandler)

Aggregations

TaskSummary (org.jbpm.task.query.TaskSummary)11 LocalTaskService (org.jbpm.task.service.local.LocalTaskService)7 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 KnowledgeBase (org.drools.KnowledgeBase)3 KnowledgeBuilder (org.drools.builder.KnowledgeBuilder)3 KnowledgeBuilderError (org.drools.builder.KnowledgeBuilderError)3 ClassPathResource (org.drools.io.impl.ClassPathResource)3 ProcessInstance (org.drools.runtime.process.ProcessInstance)3 ContentData (org.jbpm.task.service.ContentData)3 Person (com.salaboy.model.Person)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 StatefulKnowledgeSession (org.drools.runtime.StatefulKnowledgeSession)2 LocalHTWorkItemHandler (org.jbpm.process.workitem.wsht.LocalHTWorkItemHandler)2 Task (org.jbpm.task.Task)2 TaskService (org.jbpm.task.TaskService)2 DetailedTaskSummariesModel (com.salaboy.jbpm5.dev.guide.tablemodel.DetailedTaskSummariesModel)1 SimpleTaskSummariesModel (com.salaboy.jbpm5.dev.guide.tablemodel.SimpleTaskSummariesModel)1 InitialContext (javax.naming.InitialContext)1