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;
}
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);
}
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;
}
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);
}
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);
}
}
Aggregations