use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class HumanTaskAssignmentTest method testGetTasksAssignedAsPotentialOwnerGroup.
@Test
@BZ("1103977")
public void testGetTasksAssignedAsPotentialOwnerGroup() {
createRuntimeManager(GET_TASKS_OWNER_GROUP);
KieSession ksession = getRuntimeEngine().getKieSession();
InternalTaskService taskService = (InternalTaskService) getRuntimeEngine().getTaskService();
long pid = ksession.startProcess(GET_TASKS_OWNER_GROUP_ID).getId();
// Task is assigned to group HR.
List<TaskSummary> taskList = taskService.getTasksAssignedAsPotentialOwner(null, Arrays.asList("HR"));
Assertions.assertThat(taskList).hasSize(1);
Assertions.assertThat(taskList.get(0).getStatus()).isEqualTo(Status.Ready);
Long taskId = taskList.get(0).getId();
taskService.claim(taskId, "mary");
taskService.start(taskId, "mary");
taskService.complete(taskId, "mary", null);
Task task = taskService.getTaskById(taskId);
Assertions.assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Completed);
// Next task is assigned to group PM.
// So task list for HR will be empty.
taskList = taskService.getTasksAssignedAsPotentialOwner(null, Arrays.asList("HR"));
Assertions.assertThat(taskList).hasSize(0);
taskList = taskService.getTasksAssignedAsPotentialOwner(null, Arrays.asList("PM"));
Assertions.assertThat(taskList).hasSize(1);
Assertions.assertThat(taskList.get(0).getStatus()).isEqualTo(Status.Ready);
ksession.abortProcessInstance(pid);
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class HumanTaskAssignmentTest method testGetTasksAssignedAsPotentialOwnerUser.
@Test
@BZ("1178153")
public void testGetTasksAssignedAsPotentialOwnerUser() {
createRuntimeManager(GET_TASKS_OWNER_USER);
KieSession ksession = getRuntimeEngine().getKieSession();
InternalTaskService taskService = (InternalTaskService) getRuntimeEngine().getTaskService();
long pid = ksession.startProcess(GET_TASKS_OWNER_USER_ID).getId();
// Task is potentially assigned to several users - mary,john,ibek.
List<TaskSummary> taskList = taskService.getTasksAssignedAsPotentialOwner("jack", new ArrayList<String>());
Assertions.assertThat(taskList).hasSize(0);
taskList = taskService.getTasksAssignedAsPotentialOwner("mary", new ArrayList<String>());
Assertions.assertThat(taskList).hasSize(1);
Assertions.assertThat(taskList.get(0).getStatus()).isEqualTo(Status.Ready);
ksession.abortProcessInstance(pid);
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class NonManagedLocalHTWorkItemHandler method executeWorkItem.
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
Task task = createTaskBasedOnWorkItemParams(ksession, workItem);
ContentData content = createTaskContentBasedOnWorkItemParams(ksession, workItem);
try {
long taskId = ((InternalTaskService) taskService).addTask(task, content);
if (isAutoClaim(ksession, workItem, task)) {
taskService.claim(taskId, (String) workItem.getParameter("SwimlaneActorId"));
}
} catch (Exception e) {
if (action.equals(OnErrorAction.ABORT)) {
manager.abortWorkItem(workItem.getId());
} else if (action.equals(OnErrorAction.RETHROW)) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
} else if (action.equals(OnErrorAction.LOG)) {
StringBuilder logMsg = new StringBuilder();
logMsg.append(new Date()).append(": Error when creating task on task server for work item id ").append(workItem.getId());
logMsg.append(". Error reported by task server: ").append(e.getMessage());
logger.error(logMsg.toString(), e);
}
}
}
use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.
the class LocalHTWorkItemHandler method executeWorkItem.
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
RuntimeEngine runtime = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(workItem.getProcessInstanceId()));
KieSession ksessionById = runtime.getKieSession();
Task task = createTaskBasedOnWorkItemParams(ksessionById, workItem);
// ContentData content = createTaskContentBasedOnWorkItemParams(ksessionById, workItem);
Map<String, Object> content = createTaskDataBasedOnWorkItemParams(ksessionById, workItem);
try {
long taskId = ((InternalTaskService) runtime.getTaskService()).addTask(task, content);
if (isAutoClaim(ksessionById, workItem, task)) {
try {
runtime.getTaskService().claim(taskId, (String) workItem.getParameter("SwimlaneActorId"));
} catch (PermissionDeniedException e) {
logger.warn("User {} is not allowed to auto claim task due to permission violation", workItem.getParameter("SwimlaneActorId"));
}
}
} catch (Exception e) {
if (action.equals(OnErrorAction.ABORT)) {
manager.abortWorkItem(workItem.getId());
} else if (action.equals(OnErrorAction.RETHROW)) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
} else if (action.equals(OnErrorAction.LOG)) {
StringBuilder logMsg = new StringBuilder();
logMsg.append(new Date()).append(": Error when creating task on task server for work item id ").append(workItem.getId());
logMsg.append(". Error reported by task server: ").append(e.getMessage());
logger.error(logMsg.toString(), e);
// rethrow to cancel processing if the exception is not recoverable
if (!(e instanceof TaskException) || ((e instanceof TaskException) && !((TaskException) e).isRecoverable())) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
}
}
}
}
use of org.kie.internal.task.api.InternalTaskService 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