use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class HumanTaskTest method testLocale.
@Test
@BZ("1139496")
public void testLocale() {
KieSession ksession = createKSession(LOCALE);
ProcessInstance pi = ksession.startProcess(LOCALE_ID);
RuntimeEngine engine = getRuntimeEngine();
TaskService taskService = engine.getTaskService();
List<TaskSummary> taskList = taskService.getTasksAssignedAsPotentialOwner("john", "ja_JP");
TaskSummary task = taskList.get(0);
taskService.start(task.getId(), "john");
taskService.complete(task.getId(), "john", null);
EntityManagerFactory emf = getEmf();
assertProcessInstanceCompleted(pi.getId());
String language = emf.createEntityManager().createNativeQuery("SELECT language from I18NTEXT WHERE shorttext='空手'").getSingleResult().toString();
Assertions.assertThat(language).isEqualTo("ja_JP");
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class HumanTaskTest method testCompletionRollback.
@Test
@BZ("1004681")
public void testCompletionRollback() {
createRuntimeManager(COMPLETION_ROLLBACK);
TaskService taskService = getRuntimeEngine().getTaskService();
KieSession ksession = getRuntimeEngine().getKieSession();
ProcessInstance pi = ksession.startProcess(COMPLETION_ROLLBACK_ID);
logger.debug("Process with id = " + pi.getId() + " has just been started.");
List<TaskSummary> taskList = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
long taskId = taskList.get(0).getId();
taskService.start(taskId, "john");
Task task = taskService.getTaskById(taskId);
logger.debug("Actual task status: " + task.getTaskData().getStatus());
try {
taskService.complete(taskId, "john", null);
Assertions.fail("Exception should have been thrown from the process script task.");
} catch (Exception ex) {
// exception thrown in process script task is intentional
}
disposeRuntimeManager();
createRuntimeManager(COMPLETION_ROLLBACK);
taskService = getRuntimeEngine().getTaskService();
Status status = taskService.getTaskById(taskId).getTaskData().getStatus();
Assertions.assertThat(status).as("Task completion has not been rolled back!").isEqualTo(Status.InProgress);
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class HumanTaskTest method testOnEntryScriptException.
@Test
@BZ("1120122")
public void testOnEntryScriptException() {
createRuntimeManager(ON_ENTRY_SCRIPT_EXCEPTION);
KieSession ksession = getRuntimeEngine().getKieSession();
TaskService taskService = getRuntimeEngine().getTaskService();
long pid = ksession.startProcess(ON_ENTRY_SCRIPT_EXCEPTION_ID).getId();
List<Long> tasks = taskService.getTasksByProcessInstanceId(pid);
Assertions.assertThat(tasks).hasSize(1);
Task task = taskService.getTaskById(tasks.get(0));
Assertions.assertThat(task.getNames().get(0).getText()).isEqualTo("Human task 2");
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class LocalHTWorkItemHandlerUtil method registerLocalHTWorkItemHandler.
public static TaskService registerLocalHTWorkItemHandler(KieSession ksession, EntityManagerFactory emf, UserGroupCallback userGroupCallback) {
TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).userGroupCallback(userGroupCallback).getTaskService();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new NonManagedLocalHTWorkItemHandler(ksession, taskService));
return taskService;
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class HumanResourcesHiringTest method testHiringProcess.
@SuppressWarnings("unchecked")
private void testHiringProcess(RuntimeManager manager, Context<?> context) {
RuntimeEngine runtime = manager.getRuntimeEngine(context);
KieSession ksession = runtime.getKieSession();
TaskService taskService = runtime.getTaskService();
assertNotNull(runtime);
assertNotNull(ksession);
ksession.getWorkItemManager().registerWorkItemHandler("EmailService", new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
manager.completeWorkItem(workItem.getId(), null);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
});
ksession.getWorkItemManager().registerWorkItemHandler("TwitterService", new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
manager.completeWorkItem(workItem.getId(), null);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
});
ProcessInstance processInstance = ksession.startProcess("hiring");
Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
Collection<NodeInstanceDesc> completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(1, completedNodes.size());
List<TaskSummary> tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("HR");
TaskSummary HRInterview = tasks.get(0);
taskService.claim(HRInterview.getId(), "katy");
taskService.start(HRInterview.getId(), "katy");
Map<String, Object> hrOutput = new HashMap<String, Object>();
hrOutput.put("out_name", "salaboy");
hrOutput.put("out_age", 29);
hrOutput.put("out_mail", "salaboy@gmail.com");
hrOutput.put("out_score", 8);
taskService.complete(HRInterview.getId(), "katy", hrOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(2, completedNodes.size());
assertNotNull(processInstance);
assertNotNull(tasks);
assertEquals(1, tasks.size());
tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("IT");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary techInterview = tasks.get(0);
Task techInterviewTask = taskService.getTaskById(techInterview.getId());
Content contentById = taskService.getContentById(techInterviewTask.getTaskData().getDocumentContentId());
assertNotNull(contentById);
Map<String, Object> taskContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
assertEquals(7, taskContent.size());
assertEquals("salaboy@gmail.com", taskContent.get("in_mail"));
assertEquals(29, taskContent.get("in_age"));
assertEquals("salaboy", taskContent.get("in_name"));
taskService.claim(techInterview.getId(), "salaboy");
taskService.start(techInterview.getId(), "salaboy");
Map<String, Object> techOutput = new HashMap<String, Object>();
techOutput.put("out_skills", "java, jbpm, drools");
techOutput.put("out_twitter", "@salaboy");
techOutput.put("out_score", 8);
taskService.complete(techInterview.getId(), "salaboy", techOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(3, completedNodes.size());
tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("Accounting");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary createProposal = tasks.get(0);
Task createProposalTask = taskService.getTaskById(createProposal.getId());
contentById = taskService.getContentById(createProposalTask.getTaskData().getDocumentContentId());
assertNotNull(contentById);
taskContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
assertEquals(6, taskContent.size());
assertEquals(8, taskContent.get("in_tech_score"));
assertEquals(8, taskContent.get("in_hr_score"));
taskService.claim(createProposal.getId(), "john");
taskService.start(createProposal.getId(), "john");
Map<String, Object> proposalOutput = new HashMap<String, Object>();
proposalOutput.put("out_offering", 10000);
taskService.complete(createProposal.getId(), "john", proposalOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(5, completedNodes.size());
tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("HR");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary signContract = tasks.get(0);
Task signContractTask = taskService.getTaskById(signContract.getId());
contentById = taskService.getContentById(signContractTask.getTaskData().getDocumentContentId());
assertNotNull(contentById);
taskContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
assertEquals(6, taskContent.size());
assertEquals(10000, taskContent.get("in_offering"));
assertEquals("salaboy", taskContent.get("in_name"));
taskService.claim(signContract.getId(), "katy");
taskService.start(signContract.getId(), "katy");
Map<String, Object> signOutput = new HashMap<String, Object>();
signOutput.put("out_signed", true);
taskService.complete(signContract.getId(), "katy", signOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(8, completedNodes.size());
int removeAllTasks = ((InternalTaskService) taskService).removeAllTasks();
logger.debug(">>> Removed Tasks > {}", removeAllTasks);
}
Aggregations