@Test public void testCompleteTaskMultipleSessionsSync() throws Exception { TestStatefulKnowledgeSession ksession = new TestStatefulKnowledgeSession(); HornetQHTWorkItemHandler handler = new HornetQHTWorkItemHandler(ksession, true); client = handler.getClient(); HornetQTestWorkItemManager manager = new HornetQTestWorkItemManager(); ksession.setWorkItemManager(manager); WorkItemImpl workItem = new WorkItemImpl(); workItem.setName("Human Task"); workItem.setParameter("TaskName", "TaskName"); workItem.setParameter("Comment", "Comment"); workItem.setParameter("Priority", "10"); workItem.setParameter("ActorId", "Darth Vader"); workItem.setProcessInstanceId(10); handler.executeWorkItem(workItem, manager); TestStatefulKnowledgeSession ksession2 = new TestStatefulKnowledgeSession(10); HornetQHTWorkItemHandler handler2 = new HornetQHTWorkItemHandler("testConnector", null, ksession2, OnErrorAction.LOG); handler2.setOwningSessionOnly(true); HornetQTestWorkItemManager manager2 = new HornetQTestWorkItemManager(); ksession2.setWorkItemManager(manager2); WorkItemImpl workItem2 = new WorkItemImpl(); workItem2.setName("Human Task"); workItem2.setParameter("TaskName", "TaskName"); workItem2.setParameter("Comment", "Comment"); workItem2.setParameter("Priority", "10"); workItem2.setParameter("ActorId", "Darth Vader"); workItem2.setProcessInstanceId(10); handler2.executeWorkItem(workItem2, manager2); List<TaskSummary> tasks = client.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK"); assertEquals(2, tasks.size()); TaskSummary task = tasks.get(0); // ensure we get first task if (task.getProcessSessionId() == 10) { task = tasks.get(1); } assertEquals("TaskName", task.getName()); assertEquals(10, task.getPriority()); assertEquals("Comment", task.getDescription()); assertEquals(Status.Reserved, task.getStatus()); assertEquals("Darth Vader", task.getActualOwner().getId()); assertEquals(10, task.getProcessInstanceId()); client.start(task.getId(), "Darth Vader"); client.complete(task.getId(), "Darth Vader", null); Thread.sleep(1000); assertEquals(1, manager.getCompleteCounter()); assertEquals(0, manager2.getCompleteCounter()); handler.dispose(); handler2.dispose(); }
public void testPotentialOwnerQueries() { Map<String, Object> vars = new HashMap(); vars.put("users", users); vars.put("groups", groups); // Reader reader; Reader reader = new InputStreamReader( getClass().getResourceAsStream("../../QueryData_TasksPotentialOwner.mvel")); List<Task> tasks = (List<Task>) eval(reader, vars); for (Task task : tasks) { client.addTask(task, null); } // Test UK I18N List<TaskSummary> actual = client.getTasksAssignedAsPotentialOwner(users.get("bobba").getId(), "es_CL"); assertEquals(2, actual.size()); }
public void testPeopleAssignmentQueries() { Map vars = new HashMap(); vars.put("users", users); vars.put("groups", groups); Reader reader = new InputStreamReader(getClass().getResourceAsStream("../../QueryData_TasksOwned.mvel")); List<Task> tasks = (List<Task>) eval(reader, vars); for (Task task : tasks) { taskSession.addTask(task, null); } reader = new InputStreamReader( getClass().getResourceAsStream("../../QueryResults_PeopleAssignmentQuerries.mvel")); Map<String, List<TaskSummary>> expected = (Map<String, List<TaskSummary>>) eval(reader, vars); List<TaskSummary> actual = client.getTasksAssignedAsTaskInitiator(users.get("darth").getId(), "es_CL"); assertEquals(1, actual.size()); assertTrue(CollectionUtils.equals(expected.get("darth"), actual)); actual = client.getTasksAssignedAsBusinessAdministrator(users.get("steve").getId(), "es_CL"); assertTrue(CollectionUtils.equals(expected.get("steve"), actual)); actual = client.getTasksAssignedAsExcludedOwner(users.get("liz").getId(), "es_CL"); assertEquals(2, actual.size()); assertTrue(CollectionUtils.equals(expected.get("liz"), actual)); actual = client.getTasksAssignedAsPotentialOwner(users.get("bobba").getId(), "es_CL"); assertEquals(3, actual.size()); assertTrue(CollectionUtils.equals(expected.get("bobba"), actual)); actual = client.getTasksAssignedAsRecipient(users.get("sly").getId(), "es_CL"); assertEquals(1, actual.size()); assertTrue(CollectionUtils.equals(expected.get("sly"), actual)); }
public static final void main(String[] args) { try { // load up the knowledge base KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000); HornetQHTWorkItemHandler hornetQHTWorkItemHandler = new HornetQHTWorkItemHandler(ksession); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", hornetQHTWorkItemHandler); // start a new process instance Map<String, Object> params = new HashMap<String, Object>(); params.put("employee", "krisv"); params.put("reason", "Yearly performance evaluation"); ksession.startProcess("com.sample.evaluation", params); SystemEventListenerFactory.setSystemEventListener(new SystemEventListener()); TaskService taskClient = new SyncTaskServiceWrapper(new AsyncHornetQTaskClient("EvaluationExample2-testClient")); taskClient.connect("127.0.0.1", 5153); Thread.sleep(1000); // "krisv" executes his own performance evaluation TaskSummary task1 = taskClient.getTasksAssignedAsPotentialOwner("krisv", "en-UK").get(0); System.out.println( "Krisv executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")"); taskClient.start(task1.getId(), "krisv"); taskClient.complete(task1.getId(), "krisv", null); Thread.sleep(1000); // "john", part of the "PM" group, executes a performance evaluation List<String> groups = new ArrayList<String>(); groups.add("PM"); TaskSummary task2 = taskClient.getTasksAssignedAsPotentialOwner("john", groups, "en-UK").get(0); System.out.println( "John executing task " + task2.getName() + "(" + task2.getId() + ": " + task2.getDescription() + ")"); taskClient.claim(task2.getId(), "john", groups); taskClient.start(task2.getId(), "john"); taskClient.complete(task2.getId(), "john", null); Thread.sleep(1000); // "mary", part of the "HR" group, delegates a performance evaluation groups = new ArrayList<String>(); groups.add("HR"); TaskSummary task3 = taskClient.getTasksAssignedAsPotentialOwner("mary", groups, "en-UK").get(0); System.out.println( "Mary delegating task " + task3.getName() + "(" + task3.getId() + ": " + task3.getDescription() + ") to krisv"); taskClient.claim(task3.getId(), "mary", groups); taskClient.delegate(task3.getId(), "mary", "krisv"); // "administrator" delegates the task back to mary System.out.println("Administrator delegating task back to mary"); taskClient.delegate(task3.getId(), "Administrator", "mary"); Thread.sleep(1000); // mary executing the task TaskSummary task3b = taskClient.getTasksAssignedAsPotentialOwner("mary", "en-UK").get(0); System.out.println( "Mary executing task " + task3b.getName() + "(" + task3b.getId() + ": " + task3b.getDescription() + ")"); taskClient.start(task3b.getId(), "mary"); taskClient.complete(task3b.getId(), "mary", null); taskClient.disconnect(); hornetQHTWorkItemHandler.dispose(); Thread.sleep(1000); logger.close(); System.exit(0); } catch (Throwable t) { t.printStackTrace(); } }