Search in sources :

Example 76 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class SerializedTimerRollbackTest method testSerizliableTestsWithEngineRollback.

@Test
public void testSerizliableTestsWithEngineRollback() {
    try {
        createRuntimeManager("org/jbpm/test/functional/timer/HumanTaskWithBoundaryTimer.bpmn");
        RuntimeEngine runtimeEngine = getRuntimeEngine();
        KieSession ksession = runtimeEngine.getKieSession();
        logger.debug("Created knowledge session");
        TaskService taskService = runtimeEngine.getTaskService();
        logger.debug("Task service created");
        List<Long> committedProcessInstanceIds = new ArrayList<Long>();
        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0) {
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("test", "john");
                logger.debug("Creating process instance: {}", i);
                ProcessInstance pi = ksession.startProcess("PROCESS_1", params);
                committedProcessInstanceIds.add(pi.getId());
            } else {
                try {
                    Map<String, Object> params = new HashMap<String, Object>();
                    // set test variable to null so engine will rollback
                    params.put("test", null);
                    logger.debug("Creating process instance: {}", i);
                    ksession.startProcess("PROCESS_1", params);
                } catch (Exception e) {
                    logger.debug("Process rolled back");
                }
            }
        }
        Connection c = getDs().getConnection();
        Statement st = c.createStatement();
        ResultSet rs = st.executeQuery("select rulesbytearray from sessioninfo");
        rs.next();
        Blob b = rs.getBlob("rulesbytearray");
        assertNotNull(b);
        KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        ProtobufMarshaller marshaller = new ProtobufMarshaller(builder.newKieBase(), new MarshallingConfigurationImpl());
        StatefulKnowledgeSession session = marshaller.unmarshall(b.getBinaryStream());
        assertNotNull(session);
        TimerManager timerManager = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) session).getProcessRuntime()).getTimerManager();
        assertNotNull(timerManager);
        Collection<TimerInstance> timers = timerManager.getTimers();
        assertNotNull(timers);
        assertEquals(5, timers.size());
        for (TimerInstance timerInstance : timers) {
            assertTrue(committedProcessInstanceIds.contains(timerInstance.getProcessInstanceId()));
            ksession.abortProcessInstance(timerInstance.getProcessInstanceId());
        }
        List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
        assertEquals(0, tasks.size());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception thrown");
    }
}
Also used : ProtobufMarshaller(org.drools.core.marshalling.impl.ProtobufMarshaller) HashMap(java.util.HashMap) TimerInstance(org.jbpm.process.instance.timer.TimerInstance) ArrayList(java.util.ArrayList) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) ResultSet(java.sql.ResultSet) KieSession(org.kie.api.runtime.KieSession) MarshallingConfigurationImpl(org.drools.core.marshalling.impl.MarshallingConfigurationImpl) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Blob(java.sql.Blob) TaskService(org.kie.api.task.TaskService) Statement(java.sql.Statement) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Connection(java.sql.Connection) TimerManager(org.jbpm.process.instance.timer.TimerManager) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) Test(org.junit.Test)

Example 77 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class RetrySyncWorkItemByJPATest method workItemRecoveryTestByJPA.

@Test
public void workItemRecoveryTestByJPA() {
    manager = createRuntimeManager("org/jbpm/test/functional/workitem/retry-workitem-jpa.bpmn2");
    RuntimeEngine runtimeEngine = getRuntimeEngine(EmptyContext.get());
    KieSession kieSession = runtimeEngine.getKieSession();
    WorkItemManager workItemManager = (org.drools.core.process.instance.WorkItemManager) kieSession.getWorkItemManager();
    workItemManager.registerWorkItemHandler("ExceptionWorkitem", new ExceptionWorkItemHandler());
    ProcessInstance pi = kieSession.startProcess(RETRY_WORKITEM_JPA_PROCESS_ID);
    TaskService taskService = runtimeEngine.getTaskService();
    assertProcessInstanceActive(pi.getId());
    assertNodeTriggered(pi.getId(), "lockingNode");
    assertNodeActive(pi.getId(), kieSession, "lockingNode");
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary taskSummary = tasks.get(0);
    taskService.start(taskSummary.getId(), "john");
    taskService.complete(taskSummary.getId(), "john", null);
    ProcessInstance processInstance = (org.kie.api.runtime.process.WorkflowProcessInstance) kieSession.getProcessInstance(pi.getId());
    Collection<NodeInstance> nis = ((org.kie.api.runtime.process.WorkflowProcessInstance) processInstance).getNodeInstances();
    retryWorkItem(workItemManager, nis);
    assertProcessInstanceCompleted(processInstance.getId());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) 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) WorkItemManager(org.drools.core.process.instance.WorkItemManager) NodeInstance(org.kie.api.runtime.process.NodeInstance) Test(org.junit.Test)

Example 78 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class LogCleanupCommandTest method skipTaskLog.

@Ignore
@Test(timeout = 10000)
public void skipTaskLog() throws Exception {
    KieSession kieSession = null;
    List<ProcessInstance> processInstanceList = null;
    try {
        CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
        ((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
        // Generate data
        kieSession = createKSession(LOG_CLEANUP);
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("assigneeName", "krisv");
        processInstanceList = startProcess(kieSession, LOG_CLEANUP_ID, paramMap, 1);
        TaskService taskService = getRuntimeEngine().getTaskService();
        List<Long> taskIdList = taskService.getTasksByProcessInstanceId(processInstanceList.get(0).getId());
        taskService.start(taskIdList.get(0), "krisv");
        taskService.complete(taskIdList.get(0), "krisv", null);
        // Verify presence of data
        Assertions.assertThat(getProcessLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
        Assertions.assertThat(getTaskLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
        Assertions.assertThat(getNodeInstanceLogSize(LOG_CLEANUP_ID)).isPositive();
        Assertions.assertThat(getVariableLogSize(LOG_CLEANUP_ID)).isEqualTo(3);
        // Schedule cleanup job
        scheduleLogCleanup(false, true, false, getTomorrow(), null, LOG_CLEANUP_ID);
        countDownListener.waitTillCompleted();
        // Verify absence of data
        Assertions.assertThat(getProcessLogSize(LOG_CLEANUP_ID)).isZero();
        Assertions.assertThat(getTaskLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
        Assertions.assertThat(getNodeInstanceLogSize(LOG_CLEANUP_ID)).isZero();
        Assertions.assertThat(getVariableLogSize(LOG_CLEANUP_ID)).isZero();
    } finally {
        if (processInstanceList != null) {
            abortProcess(kieSession, processInstanceList);
        }
    }
}
Also used : CountDownAsyncJobListener(org.jbpm.test.listener.CountDownAsyncJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) TaskService(org.kie.api.task.TaskService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 79 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class SupportProcessTest method simpleSupportProcessTest.

@Test
public void simpleSupportProcessTest() {
    createRuntimeManager("org/jbpm/test/functional/jpa/support.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("customer", "salaboy");
    ProcessInstance processInstance = ksession.startProcess("support.process", params);
    assertProcessInstanceActive(processInstance.getId());
    assertProcessVarExists(processInstance, "customer");
    // Configure Release
    List<TaskSummary> tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertNodeTriggered(processInstance.getId(), "Create Support");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Create Support", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary createSupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(createSupportTask.getId(), "salaboy");
    Map<String, Object> taskContent = ((InternalTaskService) taskService).getTaskContent(createSupportTask.getId());
    assertEquals("salaboy", taskContent.get("input_customer"));
    Map<String, Object> output = new HashMap<String, Object>();
    output.put("output_customer", "salaboy/redhat");
    taskService.complete(createSupportTask.getId(), "salaboy", output);
    assertNodeTriggered(processInstance.getId(), "Resolve Support");
    tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Resolve Support", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary resolveSupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(resolveSupportTask.getId(), "salaboy");
    taskService.complete(resolveSupportTask.getId(), "salaboy", null);
    assertNodeTriggered(processInstance.getId(), "Notify Customer");
    tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Notify Customer", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary notifySupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(notifySupportTask.getId(), "salaboy");
    output = new HashMap<String, Object>();
    output.put("output_solution", "solved today");
    taskService.complete(notifySupportTask.getId(), "salaboy", output);
    assertProcessInstanceCompleted(processInstance.getId());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) 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) InternalTaskService(org.kie.internal.task.api.InternalTaskService) Test(org.junit.Test)

Example 80 with TaskService

use of org.kie.api.task.TaskService in project jbpm by kiegroup.

the class HumanTaskResolver method populateOrgEntity.

@Before
public void populateOrgEntity() {
    TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(getEmf()).getTaskService();
    ((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("krisv"));
    ((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("sales-rep"));
    ((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("john"));
    ((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("Administrator"));
    ((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("sales"));
    ((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("PM"));
    ((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("Administrators"));
}
Also used : InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) InternalTaskService(org.kie.internal.task.api.InternalTaskService) Before(org.junit.Before)

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