Search in sources :

Example 6 with TaskSummary

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

the class HumanTasksLifecycleAPITest method claimNextAvailable.

@Test
public void claimNextAvailable() {
    // Create a local instance of the TaskService
    LocalTaskService localTaskService = new LocalTaskService(taskService);
    List<User> potentialOwners = new ArrayList<User>();
    potentialOwners.add(users.get("salaboy"));
    potentialOwners.add(users.get("watman"));
    // Create a Task Definition
    Task task = createSimpleTask(potentialOwners, users.get("administrator"));
    // Deploy the Task Definition to the Task Component
    localTaskService.addTask(task, new ContentData());
    // we don't need to query for our task to see what we will claim, just claim the next one available for us
    localTaskService.claimNextAvailable("watman", "en-UK");
    List<Status> status = new ArrayList<Status>();
    status.add(Status.Ready);
    List<TaskSummary> salaboyTasks = localTaskService.getTasksAssignedAsPotentialOwnerByStatus("salaboy", status, "en-UK");
    assertEquals(0, salaboyTasks.size());
}
Also used : ContentData(org.jbpm.task.service.ContentData) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.jbpm.task.query.TaskSummary)

Example 7 with TaskSummary

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

the class HumanTasksLifecycleAPITest method regularFlowTest.

@Test
public void regularFlowTest() {
    // Create a local instance of the TaskService
    LocalTaskService localTaskService = new LocalTaskService(taskService);
    List<User> potentialOwners = new ArrayList<User>();
    potentialOwners.add(users.get("salaboy"));
    // Create a Task Definition
    Task task = createSimpleTask(potentialOwners, users.get("administrator"));
    // Deploy the Task Definition to the Task Component
    localTaskService.addTask(task, new ContentData());
    // Because the Task contains a direct assignment we can query it for its Potential Owner
    // Notice that we obtain a list of TaskSummary (a lightweight representation of a task)
    List<TaskSummary> tasksAssignedAsPotentialOwner = localTaskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    // We know that there is just one task available so we get the first one
    Long taskId = tasksAssignedAsPotentialOwner.get(0).getId();
    // In order to check the task status we need to get the real task
    // The task is in a Reserved status because it already have a well-defined Potential Owner
    Task simpleTask = localTaskService.getTask(taskId);
    assertEquals(Status.Reserved, simpleTask.getTaskData().getStatus());
    // In order start working with this task we call the start() method
    localTaskService.start(simpleTask.getId(), "salaboy");
    // The task is now In Progress
    simpleTask = localTaskService.getTask(taskId);
    assertEquals(Status.InProgress, simpleTask.getTaskData().getStatus());
    // PERFORM THE TASK ACTIVITY HERE, the user need to perform the required activities here
    // Once the Task activity is performed the user can complete the task,
    // Notice that we are completing this task without results
    localTaskService.complete(simpleTask.getId(), "salaboy", null);
    // We can check the task status after completion
    simpleTask = localTaskService.getTask(taskId);
    assertEquals(Status.Completed, simpleTask.getTaskData().getStatus());
}
Also used : ContentData(org.jbpm.task.service.ContentData) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.jbpm.task.query.TaskSummary)

Example 8 with TaskSummary

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

the class TaskServiceMinaSyncTest method claimNextAvailable.

@Test
public void claimNextAvailable() {
    // Create a local instance of the TaskService
    LocalTaskService localTaskService = new LocalTaskService(taskService);
    List<User> potentialOwners = new ArrayList<User>();
    potentialOwners.add(users.get("salaboy"));
    potentialOwners.add(users.get("watman"));
    // Create a Task Definition
    Task task = createSimpleTask(potentialOwners, users.get("administrator"));
    // Deploy the Task Definition to the Task Component
    localTaskService.addTask(task, new ContentData());
    // we don't need to query for our task to see what we will claim, just claim the next one available for us
    localTaskService.claimNextAvailable("watman", "en-UK");
    List<Status> status = new ArrayList<Status>();
    status.add(Status.Ready);
    List<TaskSummary> salaboyTasks = localTaskService.getTasksAssignedAsPotentialOwnerByStatus("salaboy", status, "en-UK");
    assertEquals(0, salaboyTasks.size());
}
Also used : LocalTaskService(org.jbpm.task.service.local.LocalTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.jbpm.task.query.TaskSummary) Test(org.junit.Test)

Example 9 with TaskSummary

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

the class TaskServiceMinaSyncTest method claimConflictAndRetry.

@Test
public void claimConflictAndRetry() {
    // Create a local instance of the TaskService
    LocalTaskService localTaskService = new LocalTaskService(taskService);
    List<User> potentialOwners = new ArrayList<User>();
    potentialOwners.add(users.get("salaboy"));
    potentialOwners.add(users.get("watman"));
    // Create a Task Definition
    Task task = createSimpleTask(potentialOwners, users.get("administrator"));
    // Deploy the Task Definition to the Task Component
    localTaskService.addTask(task, new ContentData());
    // Because the Task contains a direct assignment we can query it for its Potential Owner
    // Notice that we obtain a list of TaskSummary (a lightweight representation of a task)
    List<TaskSummary> salaboyTasks = localTaskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    // We know that there is just one task available so we get the first one
    Long salaboyTaskId = salaboyTasks.get(0).getId();
    // In order to check the task status we need to get the real task
    // The task is in a Reserved status because it already have a well-defined Potential Owner
    Task salaboyTask = localTaskService.getTask(salaboyTaskId);
    assertEquals(Status.Ready, salaboyTask.getTaskData().getStatus());
    // Because the Task contains a direct assignment we can query it for its Potential Owner
    // Notice that we obtain a list of TaskSummary (a lightweight representation of a task)
    List<TaskSummary> watmanTasks = localTaskService.getTasksAssignedAsPotentialOwner("watman", "en-UK");
    // We know that there is just one task available so we get the first one
    Long watmanTaskId = watmanTasks.get(0).getId();
    assertEquals(watmanTaskId, salaboyTaskId);
    // In order to check the task status we need to get the real task
    // The task is in a Reserved status because it already have a well-defined Potential Owner
    Task watmanTask = localTaskService.getTask(watmanTaskId);
    assertEquals(Status.Ready, watmanTask.getTaskData().getStatus());
    localTaskService.claim(watmanTask.getId(), "watman");
    try {
        localTaskService.claim(salaboyTask.getId(), "salaboy");
    } catch (PermissionDeniedException ex) {
        // The Task is gone.. salaboy needs to retry
        assertNotNull(ex);
    }
}
Also used : LocalTaskService(org.jbpm.task.service.local.LocalTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.jbpm.task.query.TaskSummary) Test(org.junit.Test)

Example 10 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