Search in sources :

Example 1 with LocalTaskService

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

the class ProcessAndHumanTasksTest method createTaskHandler.

// Creates a local task service and attaches it to a human task handler
private GenericHTWorkItemHandler createTaskHandler(StatefulKnowledgeSession ksession) {
    TaskService ts = new TaskService(Persistence.createEntityManagerFactory("org.jbpm.task"), SystemEventListenerFactory.getSystemEventListener());
    LocalTaskService taskService = new LocalTaskService(ts);
    LocalHTWorkItemHandler taskHandler = new LocalHTWorkItemHandler(taskService, ksession);
    // taskHandler.connect();
    this.service = taskService;
    return taskHandler;
}
Also used : TaskService(org.jbpm.task.service.TaskService) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) LocalHTWorkItemHandler(org.jbpm.process.workitem.wsht.LocalHTWorkItemHandler)

Example 2 with LocalTaskService

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

the class TasksListUI method initTaskComponents.

// End of variables declaration//GEN-END:variables
private void initTaskComponents() {
    // Create an EntityManagerFactory based on the PU configuration
    emf = Persistence.createEntityManagerFactory("org.jbpm.task");
    // The Task Service will use the EMF to store our Task Status
    taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
    // We can uset the Task Service to get an instance of the Task Session which
    // allows us to introduce to our database the users and groups information before
    // running our tests
    taskSession = taskService.createSession();
    // create new Local Task Service
    localTaskService = new LocalTaskService(taskService);
    // regisister task event listener to Local Task Service
    localTaskService.addEventListener(taskEventListener);
    // Adds 1 Administrator, 2 users and 1 Group
    addUsersAndGroups(taskSession);
    // We need to set up an user to represent the user that is making the requests
    MockUserInfo userInfo = new MockUserInfo();
    taskService.setUserinfo(userInfo);
    this.taskParametersTableModel = new TaskParametersTableModel();
    this.tblParameters.setColumnModel(new TaskParametersTableModel.ColumnModel());
    this.tblParameters.setModel(taskParametersTableModel);
}
Also used : TaskService(org.jbpm.task.service.TaskService) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) TaskParametersTableModel(com.salaboy.jbpm5.dev.guide.tablemodel.TaskParametersTableModel)

Example 3 with LocalTaskService

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

the class PersistentProcessTest method createTaskService.

private TaskService createTaskService(EntityManagerFactory emf) {
    org.jbpm.task.service.TaskService taskService = new org.jbpm.task.service.TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
    Map<String, User> users = new HashMap<String, User>();
    users.put("salaboy", new User("salaboy"));
    users.put("Administrator", new User("Administrator"));
    Map<String, Group> groups = new HashMap<String, Group>();
    taskService.addUsersAndGroups(users, groups);
    TaskService client = new LocalTaskService(taskService);
    return client;
}
Also used : Group(org.jbpm.task.Group) User(org.jbpm.task.User) HashMap(java.util.HashMap) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) TaskService(org.jbpm.task.TaskService) LocalTaskService(org.jbpm.task.service.local.LocalTaskService)

Example 4 with LocalTaskService

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

the class TasksListUI method selectTaskForm.

// GEN-LAST:event_refreshjButtonActionPerformed
private void selectTaskForm(JTable target, int row) {
    long taskId = ((TaskSummariesModel) target.getModel()).getTaskId(row);
    String taskName = ((TaskSummariesModel) target.getModel()).getTaskName(row);
    String selectedUser = (String) selectedUserjComboBox.getItemAt(selectedUserjComboBox.getSelectedIndex());
    System.out.println("Selected User: " + selectedUser);
    Class clazz = taskForms.get(taskName);
    if (clazz == null) {
        // no custom form for this task. Let's see if there is a default
        // form defined.
        clazz = taskForms.get("*");
        if (clazz == null) {
            JOptionPane.showMessageDialog(this, "No form defined for '" + taskName + " and not default (*) form is configured.", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    Constructor constructor = null;
    try {
        constructor = clazz.getConstructor(LocalTaskService.class, long.class, String.class);
    } catch (NoSuchMethodException ex) {
        Logger.getLogger(TasksListUI.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        Logger.getLogger(TasksListUI.class.getName()).log(Level.SEVERE, null, ex);
    }
    JPanel taskForm = null;
    try {
        taskForm = (JPanel) constructor.newInstance(localTaskService, taskId, selectedUser);
    } catch (InstantiationException ex) {
        Logger.getLogger(TasksListUI.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(TasksListUI.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalArgumentException ex) {
        Logger.getLogger(TasksListUI.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvocationTargetException ex) {
        Logger.getLogger(TasksListUI.class.getName()).log(Level.SEVERE, null, ex);
    }
    // new MyTaskFormJPanel(localTaskService, taskId, selectedUser);
    tasklistsjTabbedPane.add(taskForm);
    tasklistsjTabbedPane.setSelectedComponent(taskForm);
    openedTaskForms.put(taskId, taskForm);
}
Also used : MySimpleTaskFormJPanel(com.salaboy.jbpm5.dev.guide.taskform.MySimpleTaskFormJPanel) JPanel(javax.swing.JPanel) Constructor(java.lang.reflect.Constructor) LocalTaskService(org.jbpm.task.service.local.LocalTaskService) InvocationTargetException(java.lang.reflect.InvocationTargetException) DetailedTaskSummariesModel(com.salaboy.jbpm5.dev.guide.tablemodel.DetailedTaskSummariesModel) SimpleTaskSummariesModel(com.salaboy.jbpm5.dev.guide.tablemodel.SimpleTaskSummariesModel) TaskSummariesModel(com.salaboy.jbpm5.dev.guide.tablemodel.TaskSummariesModel)

Example 5 with LocalTaskService

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

Aggregations

LocalTaskService (org.jbpm.task.service.local.LocalTaskService)9 ArrayList (java.util.ArrayList)5 TaskSummary (org.jbpm.task.query.TaskSummary)5 ContentData (org.jbpm.task.service.ContentData)3 TaskService (org.jbpm.task.service.TaskService)2 Test (org.junit.Test)2 DetailedTaskSummariesModel (com.salaboy.jbpm5.dev.guide.tablemodel.DetailedTaskSummariesModel)1 SimpleTaskSummariesModel (com.salaboy.jbpm5.dev.guide.tablemodel.SimpleTaskSummariesModel)1 TaskParametersTableModel (com.salaboy.jbpm5.dev.guide.tablemodel.TaskParametersTableModel)1 TaskSummariesModel (com.salaboy.jbpm5.dev.guide.tablemodel.TaskSummariesModel)1 MySimpleTaskFormJPanel (com.salaboy.jbpm5.dev.guide.taskform.MySimpleTaskFormJPanel)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 JPanel (javax.swing.JPanel)1 LocalHTWorkItemHandler (org.jbpm.process.workitem.wsht.LocalHTWorkItemHandler)1 Group (org.jbpm.task.Group)1 TaskService (org.jbpm.task.TaskService)1 User (org.jbpm.task.User)1 PermissionDeniedException (org.jbpm.task.service.PermissionDeniedException)1