use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class DefaultChecklistManager method getTasks.
@SuppressWarnings("unchecked")
public List<ChecklistItem> getTasks(long processInstanceId) {
RuntimeEngine runtime = getRuntime();
KieSession ksession = runtime.getKieSession();
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
Map<String, ChecklistItem> orderingIds = new HashMap<String, ChecklistItem>();
if (processInstance != null) {
WorkflowProcess process = (WorkflowProcess) ksession.getKieBase().getProcess(processInstance.getProcessId());
Collection<ChecklistItem> result = ChecklistItemFactory.getPendingChecklistItems(process);
result.addAll(ChecklistItemFactory.getLoggedChecklistItems(process, (List<NodeInstanceLog>) runtime.getAuditService().findNodeInstances(processInstance.getId())));
for (ChecklistItem item : result) {
if (item.getOrderingNb() != null && item.getOrderingNb().trim().length() > 0) {
orderingIds.put(item.getOrderingNb(), item);
}
}
}
TaskService taskService = runtime.getTaskService();
List<Long> taskIds = taskService.getTasksByProcessInstanceId(processInstanceId);
List<ChecklistItem> result = new ArrayList<ChecklistItem>();
for (Long taskId : taskIds) {
Task task = taskService.getTaskById(taskId);
if (task != null) {
ChecklistItem item = ChecklistItemFactory.createChecklistItem(task);
if (item.getOrderingNb() != null) {
orderingIds.put(item.getOrderingNb(), item);
} else {
result.add(item);
}
}
}
for (ChecklistItem item : orderingIds.values()) {
result.add(item);
}
Collections.sort(result, new Comparator<ChecklistItem>() {
public int compare(ChecklistItem o1, ChecklistItem o2) {
if (o1.getOrderingNb() != null && o2.getOrderingNb() != null) {
return o1.getOrderingNb().compareTo(o2.getOrderingNb());
} else if (o1.getTaskId() != null && o2.getTaskId() != null) {
return o1.getTaskId().compareTo(o2.getTaskId());
} else {
throw new IllegalArgumentException();
}
}
});
manager.disposeRuntimeEngine(runtime);
return result;
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class EvaluationExample method main.
public static final void main(String[] args) {
try {
RuntimeManager manager = getRuntimeManager("evaluation/Evaluation.bpmn");
RuntimeEngine runtime = manager.getRuntimeEngine(null);
KieSession ksession = runtime.getKieSession();
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("employee", "krisv");
params.put("reason", "Yearly performance evaluation");
ksession.startProcess("com.sample.evaluation", params);
// complete Self Evaluation
TaskService taskService = runtime.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK");
TaskSummary task = tasks.get(0);
System.out.println("'krisv' completing task " + task.getName() + ": " + task.getDescription());
taskService.start(task.getId(), "krisv");
Map<String, Object> results = new HashMap<String, Object>();
results.put("performance", "exceeding");
taskService.complete(task.getId(), "krisv", results);
// john from HR
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
task = tasks.get(0);
System.out.println("'john' completing task " + task.getName() + ": " + task.getDescription());
taskService.start(task.getId(), "john");
results = new HashMap<String, Object>();
results.put("performance", "acceptable");
taskService.complete(task.getId(), "john", results);
// mary from PM
tasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
task = tasks.get(0);
System.out.println("'mary' completing task " + task.getName() + ": " + task.getDescription());
taskService.start(task.getId(), "mary");
results = new HashMap<String, Object>();
results.put("performance", "outstanding");
taskService.complete(task.getId(), "mary", results);
System.out.println("Process instance completed");
manager.disposeRuntimeEngine(runtime);
} catch (Throwable t) {
t.printStackTrace();
}
System.exit(0);
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class MultipleInstanceExample method main.
public static final void main(String[] args) {
try {
RuntimeManager manager = getRuntimeManager("multipleinstance/multipleinstance.bpmn");
RuntimeEngine runtime = manager.getRuntimeEngine(null);
KieSession ksession = runtime.getKieSession();
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
List<String> list = new ArrayList<String>();
list.add("krisv");
list.add("john doe");
list.add("superman");
params.put("list", list);
ksession.startProcess("com.sample.multipleinstance", params);
TaskService taskService = runtime.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("sales-rep", "en-UK");
for (TaskSummary task : tasks) {
System.out.println("Sales-rep executing task " + task.getName() + "(" + task.getId() + ": " + task.getDescription() + ")");
taskService.start(task.getId(), "sales-rep");
taskService.complete(task.getId(), "sales-rep", null);
}
manager.disposeRuntimeEngine(runtime);
} catch (Throwable t) {
t.printStackTrace();
}
System.exit(0);
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class ProcessTest method testEvaluationProcess.
@Test
public void testEvaluationProcess() {
RuntimeManager manager = createRuntimeManager("Evaluation.bpmn");
RuntimeEngine engine = getRuntimeEngine(null);
KieSession ksession = engine.getKieSession();
KieRuntimeLogger log = KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000);
TaskService taskService = engine.getTaskService();
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("employee", "krisv");
params.put("reason", "Yearly performance evaluation");
ProcessInstance processInstance = ksession.startProcess("com.sample.evaluation", params);
System.out.println("Process started ...");
// complete Self Evaluation
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK");
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
System.out.println("'krisv' completing task " + task.getName() + ": " + task.getDescription());
taskService.start(task.getId(), "krisv");
Map<String, Object> results = new HashMap<String, Object>();
results.put("performance", "exceeding");
taskService.complete(task.getId(), "krisv", results);
// john from HR
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
task = tasks.get(0);
System.out.println("'john' completing task " + task.getName() + ": " + task.getDescription());
taskService.claim(task.getId(), "john");
taskService.start(task.getId(), "john");
results = new HashMap<String, Object>();
results.put("performance", "acceptable");
taskService.complete(task.getId(), "john", results);
// mary from PM
tasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(1, tasks.size());
task = tasks.get(0);
System.out.println("'mary' completing task " + task.getName() + ": " + task.getDescription());
taskService.claim(task.getId(), "mary");
taskService.start(task.getId(), "mary");
results = new HashMap<String, Object>();
results.put("performance", "outstanding");
taskService.complete(task.getId(), "mary", results);
assertProcessInstanceNotActive(processInstance.getId(), ksession);
System.out.println("Process instance completed");
log.close();
manager.disposeRuntimeEngine(engine);
manager.close();
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class AbstractKieServicesBaseTest method configureServices.
protected void configureServices() {
buildDatasource();
emf = EntityManagerFactoryManager.get().getOrCreate("org.jbpm.domain");
identityProvider = new TestIdentityProvider();
formManagerService = new FormManagerServiceImpl();
// build definition service
bpmn2Service = new BPMN2DataServiceImpl();
queryService = new QueryServiceImpl();
((QueryServiceImpl) queryService).setIdentityProvider(identityProvider);
((QueryServiceImpl) queryService).setCommandService(new TransactionalCommandService(emf));
((QueryServiceImpl) queryService).init();
// build deployment service
deploymentService = new KModuleDeploymentService();
((KModuleDeploymentService) deploymentService).setBpmn2Service(bpmn2Service);
((KModuleDeploymentService) deploymentService).setEmf(emf);
((KModuleDeploymentService) deploymentService).setIdentityProvider(identityProvider);
((KModuleDeploymentService) deploymentService).setManagerFactory(new RuntimeManagerFactoryImpl());
((KModuleDeploymentService) deploymentService).setFormManagerService(formManagerService);
TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).getTaskService();
// build runtime data service
runtimeDataService = new RuntimeDataServiceImpl();
((RuntimeDataServiceImpl) runtimeDataService).setCommandService(new TransactionalCommandService(emf));
((RuntimeDataServiceImpl) runtimeDataService).setIdentityProvider(identityProvider);
((RuntimeDataServiceImpl) runtimeDataService).setTaskService(taskService);
((RuntimeDataServiceImpl) runtimeDataService).setTaskAuditService(TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService());
((KModuleDeploymentService) deploymentService).setRuntimeDataService(runtimeDataService);
// set runtime data service as listener on deployment service
((KModuleDeploymentService) deploymentService).addListener(((RuntimeDataServiceImpl) runtimeDataService));
((KModuleDeploymentService) deploymentService).addListener(((BPMN2DataServiceImpl) bpmn2Service));
((KModuleDeploymentService) deploymentService).addListener(((QueryServiceImpl) queryService));
// build process service
processService = new ProcessServiceImpl();
((ProcessServiceImpl) processService).setDataService(runtimeDataService);
((ProcessServiceImpl) processService).setDeploymentService(deploymentService);
// build user task service
userTaskService = new UserTaskServiceImpl();
((UserTaskServiceImpl) userTaskService).setDataService(runtimeDataService);
((UserTaskServiceImpl) userTaskService).setDeploymentService(deploymentService);
}
Aggregations