Search in sources :

Example 21 with AuditService

use of org.kie.api.runtime.manager.audit.AuditService in project jbpm by kiegroup.

the class AdminAPIsWithListenerTest method automaticCleanUpForSubProcessWithSingletonStrategy.

@Test
public void automaticCleanUpForSubProcessWithSingletonStrategy() throws Exception {
    TaskCleanUpProcessEventListener taskCleanUpProcessEventListener = new TaskCleanUpProcessEventListener(null);
    this.addProcessEventListener(taskCleanUpProcessEventListener);
    RuntimeManager manager = createRuntimeManager("org/jbpm/test/functional/task/ht-main.bpmn", "org/jbpm/test/functional/task/ht-sub.bpmn");
    RuntimeEngine runtime = getRuntimeEngine(ProcessInstanceIdContext.get());
    taskCleanUpProcessEventListener.setTaskService((InternalTaskService) runtime.getTaskService());
    KieSession ksession = runtime.getKieSession();
    // start a new process instance
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance pi = ksession.startProcess("com.mycompany.sample", params);
    // obtain the task service
    TaskService taskService = runtime.getTaskService();
    List<TaskSummary> tasks1 = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertFalse(tasks1.isEmpty());
    TaskSummary task1 = tasks1.get(0);
    System.out.println("Sales-rep executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");
    taskService.start(task1.getId(), "john");
    Map<String, Object> results = new HashMap<String, Object>();
    results.put("comment", "Agreed, existing laptop needs replacing");
    results.put("outcome", "Accept");
    // complete the human task of the main process
    taskService.complete(task1.getId(), "john", results);
    // abort the process instance
    ksession.abortProcessInstance(pi.getId());
    // main process instance shall be aborted
    assertProcessInstanceAborted(pi.getId());
    AuditService logService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findProcessInstances("com.mycompany.sample");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    assertEquals(ProcessInstance.STATE_ABORTED, logs.get(0).getStatus().intValue());
    logs = logService.findProcessInstances("com.mycompany.sample.subprocess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    assertEquals(ProcessInstance.STATE_ABORTED, logs.get(0).getStatus().intValue());
    manager.close();
    final EntityManager em = emfTasks.createEntityManager();
    assertEquals(0, em.createQuery("select t from TaskImpl t").getResultList().size());
    assertEquals(0, em.createQuery("select i from I18NTextImpl i").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_BAs").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_ExclOwners").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_PotOwners").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Recipients").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Stakeholders").getResultList().size());
    assertEquals(0, em.createQuery("select c from ContentImpl c").getResultList().size());
    em.close();
}
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) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TaskCleanUpProcessEventListener(org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener) EntityManager(javax.persistence.EntityManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) Test(org.junit.Test)

Example 22 with AuditService

use of org.kie.api.runtime.manager.audit.AuditService in project jbpm by kiegroup.

the class MultipleRuntimeManagerTest method testProcessStartOnManager.

private void testProcessStartOnManager(RuntimeManager manager, Context<?> context) {
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(context);
    assertNotNull(runtime);
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertNotNull(processInstance);
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Reserved);
    List<TaskSummary> tasks = runtime.getTaskService().getTasksOwnedByStatus("john", statuses, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    AuditService logService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("UserTask");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    String externalId = logs.get(0).getExternalId();
    assertEquals(manager.getIdentifier(), externalId);
    runtime.getTaskService().start(tasks.get(0).getId(), "john");
    runtime.getTaskService().complete(tasks.get(0).getId(), "john", null);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNull(processInstance);
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ArrayList(java.util.ArrayList) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService)

Example 23 with AuditService

use of org.kie.api.runtime.manager.audit.AuditService in project jbpm by kiegroup.

the class PerCaseRuntimeManagerTest method testExecuteReusableSubprocess.

@Test
public void testExecuteReusableSubprocess() {
    final Set<Long> ksessionUsed = new HashSet<Long>();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivity.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivitySubProcess.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(new DefaultProcessEventListener() {

                @Override
                public void beforeProcessStarted(ProcessStartedEvent event) {
                    ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
                }
            });
            return listeners;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
    assertNotNull(manager);
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long ksession1Id = ksession.getIdentifier();
    assertTrue(ksession1Id == 2);
    ProcessInstance pi1 = ksession.startProcess("ParentProcess");
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    manager.disposeRuntimeEngine(runtime);
    runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
    ksession = runtime.getKieSession();
    ksession.getWorkItemManager().completeWorkItem(1, null);
    AuditService logService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("ParentProcess");
    assertNotNull(logs);
    assertEquals(0, logs.size());
    logs = logService.findActiveProcessInstances("SubProcess");
    assertNotNull(logs);
    assertEquals(0, logs.size());
    logs = logService.findProcessInstances("ParentProcess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    String externalId = logs.get(0).getExternalId();
    assertEquals(manager.getIdentifier(), externalId);
    logs = logService.findProcessInstances("SubProcess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    externalId = logs.get(0).getExternalId();
    assertEquals(manager.getIdentifier(), externalId);
    assertEquals(1, ksessionUsed.size());
    assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
    manager.disposeRuntimeEngine(runtime);
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 24 with AuditService

use of org.kie.api.runtime.manager.audit.AuditService in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManagerTest method testSignalEventViaRuntimeManager.

@Test
public void testSignalEventViaRuntimeManager() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2IntermediateThrowEventScope.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ProcessInstance processInstance = ksession1.startProcess("intermediate-event-scope");
    manager.disposeRuntimeEngine(runtime1);
    RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    ProcessInstance processInstance2 = ksession2.startProcess("intermediate-event-scope");
    manager.disposeRuntimeEngine(runtime2);
    runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    List<Long> tasks1 = runtime1.getTaskService().getTasksByProcessInstanceId(processInstance.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());
    runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance2.getId()));
    List<Long> tasks2 = runtime1.getTaskService().getTasksByProcessInstanceId(processInstance2.getId());
    assertNotNull(tasks2);
    assertEquals(1, tasks2.size());
    Object data = "some data";
    runtime1.getTaskService().claim(tasks1.get(0), "john");
    runtime1.getTaskService().start(tasks1.get(0), "john");
    runtime1.getTaskService().complete(tasks1.get(0), "john", Collections.singletonMap("_output", data));
    manager.disposeRuntimeEngine(runtime1);
    manager.disposeRuntimeEngine(runtime2);
    runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance2.getId()));
    AuditService auditService = runtime2.getAuditService();
    ProcessInstanceLog pi1Log = auditService.findProcessInstance(processInstance.getId());
    assertNotNull(pi1Log);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi1Log.getStatus().intValue());
    ProcessInstanceLog pi2Log = auditService.findProcessInstance(processInstance2.getId());
    assertNotNull(pi2Log);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2Log.getStatus().intValue());
    List<? extends NodeInstanceLog> nLogs = auditService.findNodeInstances(processInstance2.getId(), "_527AF0A7-D741-4062-9953-A05E51479C80");
    assertNotNull(nLogs);
    assertEquals(2, nLogs.size());
    auditService.dispose();
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime1);
    manager.disposeRuntimeEngine(runtime2);
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 25 with AuditService

use of org.kie.api.runtime.manager.audit.AuditService in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManagerTest method testDependentSubprocessAbort.

@Test
public void testDependentSubprocessAbort() {
    // independent = false
    // JBPM-4422
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-DependentCallActivity.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-DependentCallActivitySubProcess.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long ksession1Id = ksession.getIdentifier();
    assertTrue(ksession1Id == 2);
    ProcessInstance pi1 = ksession.startProcess("DependentParentProcess");
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    // Aborting the parent process
    ksession.abortProcessInstance(pi1.getId());
    AuditService logService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("DependentParentProcess");
    assertNotNull(logs);
    assertEquals(0, logs.size());
    logs = logService.findActiveProcessInstances("DependentSubProcess");
    assertNotNull(logs);
    assertEquals(0, logs.size());
    logs = logService.findProcessInstances("DependentParentProcess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    assertEquals(ProcessInstance.STATE_ABORTED, (int) logs.get(0).getStatus());
    logs = logService.findProcessInstances("DependentSubProcess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    assertEquals(ProcessInstance.STATE_ABORTED, (int) logs.get(0).getStatus());
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Aggregations

AuditService (org.kie.api.runtime.manager.audit.AuditService)29 Test (org.junit.Test)28 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)26 KieSession (org.kie.api.runtime.KieSession)25 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)21 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)20 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)19 HashMap (java.util.HashMap)7 TaskService (org.kie.api.task.TaskService)6 TaskSummary (org.kie.api.task.model.TaskSummary)6 ProcessInstanceLog (org.kie.api.runtime.manager.audit.ProcessInstanceLog)5 InternalTaskService (org.kie.internal.task.api.InternalTaskService)4 ArrayList (java.util.ArrayList)3 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)3 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)3 HashSet (java.util.HashSet)2 EntityManager (javax.persistence.EntityManager)2 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)2 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)2 TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)2