Search in sources :

Example 1 with JPAAuditLogService

use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.

the class SLATrackingCommandTest method testSLATrackingOnUserTaskSLAMet.

@Test
public void testSLATrackingOnUserTaskSLAMet() throws Exception {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithSLAOnTask.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("SLATimerMode", "false").get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    JPAAuditLogService logService = new JPAAuditLogService(emf);
    assertNodeInstanceSLACompliance(logService, processInstance.getId(), "Hello", ProcessInstance.SLA_PENDING);
    scheduleSLATracking(manager.getIdentifier());
    countDownListener.waitTillCompleted();
    assertNodeInstanceSLACompliance(logService, processInstance.getId(), "Hello", ProcessInstance.SLA_PENDING);
    runtime.getTaskService().start(tasks.get(0).getId(), "john");
    runtime.getTaskService().complete(tasks.get(0).getId(), "john", null);
    assertNodeInstanceSLACompliance(logService, processInstance.getId(), "Hello", ProcessInstance.SLA_MET);
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) TaskSummary(org.kie.api.task.model.TaskSummary) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest)

Example 2 with JPAAuditLogService

use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.

the class SLATrackingCommandTest method testSLATrackingOnProcessInstance.

@Test
public void testSLATrackingOnProcessInstance() throws Exception {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithSLA.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("SLATimerMode", "false").get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    JPAAuditLogService logService = new JPAAuditLogService(emf);
    assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_PENDING);
    scheduleSLATracking(manager.getIdentifier());
    countDownListener.waitTillCompleted();
    assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_PENDING);
    // wait for due date of SLA to pass
    Thread.sleep(3000);
    countDownListener.reset(1);
    scheduleSLATracking(manager.getIdentifier());
    countDownListener.waitTillCompleted();
    assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_VIOLATED);
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest)

Example 3 with JPAAuditLogService

use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.

the class ActivityTest method testScriptTaskWithHistoryLog.

@Test
@RequirePersistence
public void testScriptTaskWithHistoryLog() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ScriptTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("ScriptTask");
    assertProcessInstanceCompleted(processInstance);
    AuditLogService logService = new JPAAuditLogService(ksession.getEnvironment());
    List<NodeInstanceLog> logs = logService.findNodeInstances(processInstance.getId());
    assertNotNull(logs);
    assertEquals(6, logs.size());
    for (NodeInstanceLog log : logs) {
        assertNotNull(log.getDate());
    }
    ProcessInstanceLog pilog = logService.findProcessInstance(processInstance.getId());
    assertNotNull(pilog);
    assertNotNull(pilog.getEnd());
    List<ProcessInstanceLog> pilogs = logService.findActiveProcessInstances(processInstance.getProcessId());
    assertNotNull(pilogs);
    assertEquals(0, pilogs.size());
    logService.dispose();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) KieBase(org.kie.api.KieBase) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 4 with JPAAuditLogService

use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.

the class ActivityTest method testCallActivityWithHistoryLog.

@Test
@RequirePersistence
public void testCallActivityWithHistoryLog() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-CallActivity.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
    assertProcessInstanceCompleted(processInstance);
    assertEquals("new value", ((WorkflowProcessInstance) processInstance).getVariable("y"));
    AuditLogService logService = new JPAAuditLogService(ksession.getEnvironment());
    List<ProcessInstanceLog> subprocesses = logService.findSubProcessInstances(processInstance.getId());
    assertNotNull(subprocesses);
    assertEquals(1, subprocesses.size());
    logService.dispose();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 5 with JPAAuditLogService

use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.

the class SignalScopedToRuntimeManagerTest method testSignalEventScopedToOwningRuntimeManager.

private void testSignalEventScopedToOwningRuntimeManager() {
    // start first process instance with first manager
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ProcessInstance processInstance = ksession1.startProcess("IntermediateCatchEventWithRef");
    manager.disposeRuntimeEngine(runtime1);
    // start another process instance of the same process just owned by another manager
    RuntimeEngine runtime2 = manager2.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    ProcessInstance processInstance2 = ksession2.startProcess("IntermediateCatchEventWithRef");
    manager2.disposeRuntimeEngine(runtime2);
    // then signal via first manager, should only signal instances owned by that manager
    runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    ksession1 = runtime1.getKieSession();
    ksession1.signalEvent("Signal1", "first");
    manager.disposeRuntimeEngine(runtime1);
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    // process instance 1 should be completed by signal
    ProcessInstanceLog pi1Log = auditService.findProcessInstance(processInstance.getId());
    assertNotNull(pi1Log);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi1Log.getStatus().intValue());
    // process instance 2 should still be active
    ProcessInstanceLog pi2Log = auditService.findProcessInstance(processInstance2.getId());
    assertNotNull(pi2Log);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2Log.getStatus().intValue());
    // then signal via second manager, should only signal instances owned by that manager
    runtime2 = manager2.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance2.getId()));
    ksession2 = runtime2.getKieSession();
    ksession2.signalEvent("Signal1", "second");
    manager2.disposeRuntimeEngine(runtime2);
    pi2Log = auditService.findProcessInstance(processInstance2.getId());
    assertNotNull(pi2Log);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi2Log.getStatus().intValue());
    auditService.dispose();
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog)

Aggregations

JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)35 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)20 KieSession (org.kie.api.runtime.KieSession)19 Test (org.junit.Test)18 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)15 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)11 ProcessInstanceLog (org.kie.api.runtime.manager.audit.ProcessInstanceLog)11 AuditLogService (org.jbpm.process.audit.AuditLogService)8 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)7 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)6 KieBase (org.kie.api.KieBase)6 HashMap (java.util.HashMap)5 EntityManagerFactory (javax.persistence.EntityManagerFactory)5 Environment (org.kie.api.runtime.Environment)5 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)4 PersistenceUtil.createEnvironment (org.jbpm.persistence.util.PersistenceUtil.createEnvironment)4 AbstractAuditLogServiceTest.createKieSession (org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession)4 AbstractAuditLogger (org.jbpm.process.audit.AbstractAuditLogger)4