@Test public void testLocalTaskService() throws Exception { // Create the task service EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.services.task"); DefaultUserGroupCallbackImpl userGroupCallback = new DefaultUserGroupCallbackImpl(); // create mock groups userGroupCallback.addUser("john", "users"); userGroupCallback.addUser("Administrator", "users"); // start taskService TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator() .entityManagerFactory(emf) .userGroupCallback(userGroupCallback) .getTaskService(); // Create the KIE session KieServices ks = KieServices.Factory.get(); KieContainer kc = ks.getKieClasspathContainer(); KieSession ksession = kc.newKieSession(); // create the work item handler for human task WorkItemHandler humanTaskHandler = new NonManagedLocalHTWorkItemHandler(ksession, taskService); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler); WorkflowProcessInstance instance = (WorkflowProcessInstance) ksession.startProcess("htHomeworkProcess", null); Assert.assertEquals(ProcessInstance.STATE_ACTIVE, instance.getState()); List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK"); Assert.assertNotNull(tasks); Assert.assertEquals(1, tasks.size()); TaskSummary firstTask = tasks.iterator().next(); Assert.assertNotNull(instance.getVariable("requestId")); String requestId = instance.getVariable("requestId").toString(); InternalTask actualFirstTask = (InternalTask) taskService.getTaskById(firstTask.getId()); System.out.println("requestId = " + requestId); System.out.println("formName = " + actualFirstTask.getFormName()); Assert.assertNotNull(actualFirstTask.getFormName()); Assert.assertTrue(actualFirstTask.getFormName().contains(requestId)); taskService.claim(firstTask.getId(), "john"); taskService.start(firstTask.getId(), "john"); taskService.complete(firstTask.getId(), "john", null); // now that the second task is completed, the process is completed as well Assert.assertEquals(ProcessInstance.STATE_COMPLETED, instance.getState()); }
private void postInit(Object result) { if (result instanceof Task) { Task task = (Task) result; if (task != null && !eagerDisabled) { task.getNames().size(); task.getDescriptions().size(); task.getSubjects().size(); task.getPeopleAssignments().getBusinessAdministrators().size(); task.getPeopleAssignments().getPotentialOwners().size(); ((InternalPeopleAssignments) task.getPeopleAssignments()).getRecipients().size(); ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().size(); ((InternalPeopleAssignments) task.getPeopleAssignments()).getTaskStakeholders().size(); task.getTaskData().getAttachments().size(); task.getTaskData().getComments().size(); ((InternalTask) task).getDeadlines().getStartDeadlines().size(); ((InternalTask) task).getDeadlines().getEndDeadlines().size(); } } else if (result instanceof Collection<?>) { ((Collection<?>) result).size(); } }
protected static TaskSummaryImpl convertTaskToTaskSummary(InternalTask task) { TaskSummaryImpl taskSummary = new TaskSummaryImpl( task.getId().longValue(), task.getNames().get(0).getText(), task.getSubjects().get(0).getText(), task.getDescriptions().get(0).getText(), task.getTaskData().getStatus(), task.getPriority(), task.getTaskData().isSkipable(), task.getTaskData().getActualOwner(), task.getTaskData().getCreatedBy(), task.getTaskData().getCreatedOn(), task.getTaskData().getActivationTime(), task.getTaskData().getExpirationTime(), task.getTaskData().getProcessId(), task.getTaskData().getProcessSessionId(), task.getTaskData().getProcessInstanceId(), task.getTaskData().getDeploymentId(), task.getSubTaskStrategy(), task.getTaskData().getParentId()); return taskSummary; }