Search in sources :

Example 61 with TaskService

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");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) EntityManagerFactory(javax.persistence.EntityManagerFactory) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 62 with TaskService

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);
}
Also used : Status(org.kie.api.task.model.Status) Task(org.kie.api.task.model.Task) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 63 with TaskService

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");
}
Also used : Task(org.kie.api.task.model.Task) TaskService(org.kie.api.task.TaskService) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 64 with TaskService

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;
}
Also used : TaskService(org.kie.api.task.TaskService) NonManagedLocalHTWorkItemHandler(org.jbpm.services.task.wih.NonManagedLocalHTWorkItemHandler)

Example 65 with 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);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) InternalTaskService(org.kie.internal.task.api.InternalTaskService) QueryContext(org.kie.api.runtime.query.QueryContext) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) Content(org.kie.api.task.model.Content) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

TaskService (org.kie.api.task.TaskService)129 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)111 KieSession (org.kie.api.runtime.KieSession)79 Test (org.junit.Test)73 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)70 TaskSummary (org.kie.api.task.model.TaskSummary)66 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)53 InternalTaskService (org.kie.internal.task.api.InternalTaskService)52 HashMap (java.util.HashMap)41 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)39 UserTaskService (org.jbpm.services.api.UserTaskService)38 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)34 ArrayList (java.util.ArrayList)17 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)17 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)15 Task (org.kie.api.task.model.Task)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)12 BZ (qa.tools.ikeeper.annotation.BZ)10 TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)9