Search in sources :

Example 6 with ProcessInstanceLog

use of org.jbpm.process.audit.ProcessInstanceLog 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 7 with ProcessInstanceLog

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

the class AuditCommandsTest method testFindProcessInstanceCommands.

@Test
public void testFindProcessInstanceCommands() throws Exception {
    String processId = "IntermediateCatchEvent";
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventSignal.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
    ProcessInstance processInstance = ksession.startProcess(processId);
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    Command<?> cmd = new FindProcessInstancesCommand();
    Object result = ksession.execute(cmd);
    assertNotNull("Command result is empty!", result);
    assertTrue(result instanceof List);
    List<ProcessInstanceLog> logList = (List<ProcessInstanceLog>) result;
    assertEquals("Log list size is incorrect.", 1, logList.size());
    ProcessInstanceLog log = logList.get(0);
    assertEquals(log.getProcessInstanceId().longValue(), processInstance.getId());
    assertEquals(log.getProcessId(), processInstance.getProcessId());
    cmd = new FindActiveProcessInstancesCommand(processId);
    result = ksession.execute(cmd);
    assertNotNull("Command result is empty!", result);
    assertTrue(result instanceof List);
    logList = (List<ProcessInstanceLog>) result;
    assertEquals("Log list size is incorrect.", 1, logList.size());
    log = logList.get(0);
    assertEquals("Process instance id", log.getProcessInstanceId().longValue(), processInstance.getId());
    assertEquals("Process id", log.getProcessId(), processInstance.getProcessId());
    assertEquals("Status", log.getStatus().intValue(), ProcessInstance.STATE_ACTIVE);
    cmd = new FindProcessInstanceCommand(processInstance.getId());
    result = ksession.execute(cmd);
    assertNotNull("Command result is empty!", result);
    assertTrue(result instanceof ProcessInstanceLog);
    log = (ProcessInstanceLog) result;
    assertEquals(log.getProcessInstanceId().longValue(), processInstance.getId());
    assertEquals(log.getProcessId(), processInstance.getProcessId());
    // now signal process instance
    ksession = restoreSession(ksession, true);
    ksession.signalEvent("MyMessage", "SomeValue", processInstance.getId());
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    cmd = new ClearHistoryLogsCommand();
    result = ksession.execute(cmd);
    assertEquals("There should be no more logs", 0, logService.findProcessInstances().size());
}
Also used : KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) List(java.util.List) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test)

Example 8 with ProcessInstanceLog

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

the class AsyncAuditLogProducerTest method testAsyncAuditLoggerCompleteDirectCreation.

@Test
public void testAsyncAuditLoggerCompleteDirectCreation() throws Exception {
    Environment env = createEnvironment(context);
    // load the process
    KieBase kbase = createKnowledgeBase();
    // create a new session
    KieSession session = createSession(kbase, env);
    AbstractAuditLogger logger = AuditLoggerFactory.newJMSInstance(true, factory, queue);
    Assertions.assertThat(logger).isNotNull();
    Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
    session.addEventListener(logger);
    // start process instance
    ProcessInstance processInstance = session.startProcess("com.sample.ruleflow");
    MessageReceiver receiver = new MessageReceiver();
    receiver.receiveAndProcess(queue, ((EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY)), 6000, 11);
    // validate if everything is stored in db
    AuditLogService logService = new JPAAuditLogService(env);
    List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow");
    Assertions.assertThat(processInstances.size()).isEqualTo(1);
    List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstance.getId());
    Assertions.assertThat(nodeInstances.size()).isEqualTo(6);
    for (NodeInstanceLog nodeInstance : nodeInstances) {
        Assertions.assertThat(nodeInstance.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
        Assertions.assertThat(nodeInstance.getProcessId()).isEqualTo("com.sample.ruleflow");
        Assertions.assertThat(nodeInstance.getDate()).isNotNull();
    }
    logService.clear();
    processInstances = logService.findProcessInstances("com.sample.ruleflow");
    logService.dispose();
    Assertions.assertThat(processInstances).isEmpty();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 9 with ProcessInstanceLog

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

the class AsyncAuditLogProducerTest method testAsyncAuditLoggerCompleteWithVariablesCustomIndexer.

@Test
public void testAsyncAuditLoggerCompleteWithVariablesCustomIndexer() throws Exception {
    Environment env = createEnvironment(context);
    // load the process
    KieBase kbase = createKnowledgeBase();
    // create a new session
    KieSession session = createSession(kbase, env);
    Map<String, Object> jmsProps = new HashMap<String, Object>();
    jmsProps.put("jbpm.audit.jms.transacted", false);
    jmsProps.put("jbpm.audit.jms.connection.factory", factory);
    jmsProps.put("jbpm.audit.jms.queue", queue);
    AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps);
    Assertions.assertThat(logger).isNotNull();
    Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
    List<String> names = new LinkedList<String>();
    names.add("john");
    names.add("mary");
    names.add("peter");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("list", names);
    // start process instance
    ProcessInstance processInstance = session.startProcess("com.sample.ruleflow3", params);
    MessageReceiver receiver = new MessageReceiver();
    receiver.receiveAndProcess(queue, ((EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY)), 6000, 28);
    // validate if everything is stored in db
    AuditLogService logService = new JPAAuditLogService(env);
    List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow3");
    Assertions.assertThat(processInstances.size()).isEqualTo(1);
    List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstance.getId());
    Assertions.assertThat(nodeInstances.size()).isEqualTo(12);
    for (NodeInstanceLog nodeInstance : nodeInstances) {
        Assertions.assertThat(nodeInstance.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
        Assertions.assertThat(nodeInstance.getProcessId()).isEqualTo("com.sample.ruleflow3");
        Assertions.assertThat(nodeInstance.getDate()).isNotNull();
    }
    // verify variables
    List<VariableInstanceLog> variables = logService.findVariableInstances(processInstance.getId());
    Assertions.assertThat(variables).isNotNull();
    Assertions.assertThat(variables.size()).isEqualTo(8);
    List<VariableInstanceLog> listVariables = new ArrayList<VariableInstanceLog>();
    // collect only those that are related to list process variable
    for (VariableInstanceLog v : variables) {
        if (v.getVariableInstanceId().equals("list")) {
            listVariables.add(v);
        }
    }
    Assertions.assertThat(listVariables.size()).isEqualTo(3);
    List<String> variableValues = new ArrayList<String>();
    List<String> variableIds = new ArrayList<String>();
    for (VariableInstanceLog var : listVariables) {
        variableValues.add(var.getValue());
        variableIds.add(var.getVariableId());
        Assertions.assertThat(var.getOldValue()).isIn("", " ", null);
        Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
        Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId());
        Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("list");
    }
    Assertions.assertThat(variableValues).contains("john", "mary", "peter");
    Assertions.assertThat(variableIds).contains("list[0]", "list[1]", "list[2]");
    logService.clear();
    processInstances = logService.findProcessInstances("com.sample.ruleflow3");
    logService.dispose();
    Assertions.assertThat(processInstances).isNullOrEmpty();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) LinkedList(java.util.LinkedList) VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 10 with ProcessInstanceLog

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

the class AuditDeleteTest method createTestProcessInstanceLogData.

private ProcessInstanceLog[] createTestProcessInstanceLogData() {
    StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
    EntityManager em = jtaHelper.getEntityManager();
    int numEntities = 11;
    ProcessInstanceLog[] testData = new ProcessInstanceLog[numEntities];
    Calendar cal = randomCal();
    for (int i = 0; i < numEntities; ++i) {
        ProcessInstanceLog pil = new ProcessInstanceLog(randomLong(), randomString());
        pil.setDuration(randomLong());
        pil.setExternalId(randomString());
        pil.setIdentity(randomString());
        pil.setOutcome(randomString());
        pil.setParentProcessInstanceId(randomLong());
        pil.setProcessId(randomString());
        pil.setProcessName(randomString());
        pil.setProcessVersion(randomString());
        pil.setStatus(random.nextInt());
        cal.add(Calendar.MINUTE, 1);
        pil.setStart(cal.getTime());
        cal.add(Calendar.DAY_OF_YEAR, 1);
        pil.setEnd(cal.getTime());
        testData[i] = pil;
    }
    for (int i = 0; i < numEntities; ++i) {
        switch(i) {
            case 1:
                testData[i - 1].setDuration(testData[i].getDuration());
                break;
            case 2:
                testData[i - 1].setEnd(testData[i].getEnd());
                break;
            case 3:
                testData[i - 1].setIdentity(testData[i].getIdentity());
                break;
            case 4:
                testData[i - 1].setProcessId(testData[i].getProcessId());
                break;
            case 5:
                testData[i - 1].setProcessInstanceId(testData[i].getProcessInstanceId());
                break;
            case 6:
                testData[i - 1].setProcessName(testData[i].getProcessName());
                break;
            case 7:
                testData[i - 1].setProcessVersion(testData[i].getProcessVersion());
                break;
            case 8:
                testData[i - 1].setStart(testData[i].getStart());
                break;
            case 9:
                testData[i - 1].setStatus(testData[i].getStatus());
                break;
            case 10:
                testData[i - 1].setOutcome(testData[i].getOutcome());
                break;
        }
    }
    Object tx = jtaHelper.joinTransaction(em);
    for (int i = 0; i < numEntities; ++i) {
        em.persist(testData[i]);
    }
    jtaHelper.leaveTransaction(em, tx);
    return testData;
}
Also used : StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy) EntityManager(javax.persistence.EntityManager) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Aggregations

ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)27 Test (org.junit.Test)9 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)8 KieBase (org.kie.api.KieBase)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)8 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)7 HashMap (java.util.HashMap)6 EntityManager (javax.persistence.EntityManager)6 EntityManagerFactory (javax.persistence.EntityManagerFactory)6 AuditLogService (org.jbpm.process.audit.AuditLogService)6 KieSession (org.kie.api.runtime.KieSession)6 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 StandaloneJtaStrategy (org.jbpm.process.audit.strategy.StandaloneJtaStrategy)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)5 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 Environment (org.kie.api.runtime.Environment)4 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)3