Search in sources :

Example 1 with ContentData

use of org.jbpm.task.service.ContentData in project jBPM5-Developer-Guide by Salaboy.

the class TasksListUI method jButton1ActionPerformed.

// GEN-LAST:event_selectedUserjComboBoxActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_jButton1ActionPerformed
    // Create a new Task
    Task task = new Task();
    task.setPriority(1);
    List<I18NText> names = new ArrayList<I18NText>();
    names.add(new I18NText("en-UK", this.txtTaskName.getText()));
    task.setNames(names);
    task.setDescriptions(names);
    task.setSubjects(names);
    // Create people assignments
    PeopleAssignments peopleAssignments = new PeopleAssignments();
    List<OrganizationalEntity> usersEntities = new ArrayList<OrganizationalEntity>();
    usersEntities.add(users.get((String) cboAssignTo.getSelectedItem()));
    peopleAssignments.setPotentialOwners(usersEntities);
    // Admin entity
    List<OrganizationalEntity> adminsEntities = new ArrayList<OrganizationalEntity>();
    adminsEntities.add(users.get("administrator"));
    peopleAssignments.setBusinessAdministrators(adminsEntities);
    task.setPeopleAssignments(peopleAssignments);
    // Create associated Task Data
    TaskData data = new TaskData();
    // Mock ids
    data.setWorkItemId(1);
    data.setProcessInstanceId(1);
    data.setProcessSessionId(1);
    task.setTaskData(data);
    // create content parameters
    ContentData contentData = this.createContentData();
    // create task in Local Task Service
    localTaskService.addTask(task, contentData);
    // Clear form
    this.txtTaskName.setText("");
    this.cboAssignTo.setSelectedIndex(0);
    this.taskParametersTableModel.clear();
}
Also used : ContentData(org.jbpm.task.service.ContentData) ArrayList(java.util.ArrayList)

Example 2 with ContentData

use of org.jbpm.task.service.ContentData in project jBPM5-Developer-Guide by Salaboy.

the class DynamicTaskForm method completejButtonActionPerformed.

// </editor-fold>//GEN-END:initComponents
private void completejButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_completejButtonActionPerformed
    System.out.println(" Completing Task: " + task.getId() + " - userId: " + userId);
    // Create content data.
    ContentData data = createContentData();
    localTaskService.complete(task.getId(), userId, data);
}
Also used : ContentData(org.jbpm.task.service.ContentData)

Example 3 with ContentData

use of org.jbpm.task.service.ContentData in project jBPM5-Developer-Guide by Salaboy.

the class HumanTasksLifecycleAPITest 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 : ContentData(org.jbpm.task.service.ContentData) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) ArrayList(java.util.ArrayList) TaskSummary(org.jbpm.task.query.TaskSummary) PermissionDeniedException(org.jbpm.task.service.PermissionDeniedException)

Example 4 with ContentData

use of org.jbpm.task.service.ContentData 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 5 with ContentData

use of org.jbpm.task.service.ContentData 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)

Aggregations

ContentData (org.jbpm.task.service.ContentData)5 ArrayList (java.util.ArrayList)4 TaskSummary (org.jbpm.task.query.TaskSummary)3 LocalTaskService (org.jbpm.task.service.local.LocalTaskService)3 PermissionDeniedException (org.jbpm.task.service.PermissionDeniedException)1