Search in sources :

Example 1 with VariableInstanceLog

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

the class ManagedAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessVariableChangedEvent pvce) {
    VariableInstanceLog variableLog = (VariableInstanceLog) super.buildEvent(pvce);
    variableLog.setExternalId(ownerId);
    return variableLog;
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog)

Example 2 with VariableInstanceLog

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

the class AsyncTaskCallbackTest method testTaskCallback.

@Test(timeout = 30000)
public void testTaskCallback() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Continue", 1);
    addProcessEventListener(countDownListener);
    KieSession ksession = createKSession(ASYNC_EXECUTOR_CALLBACK, ASYNC_DATA_EXECUTOR);
    WorkItemManager wim = ksession.getWorkItemManager();
    wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
    Map<String, Object> pm = new HashMap<String, Object>();
    pm.put("_command", CALLBACK_COMMAND);
    ProcessInstance pi = ksession.startProcess(ASYNC_EXECUTOR_CALLBACK_ID, pm);
    // Wait for the job to be picked up and processed. The job will send
    // the 'Continue' signal on OK or Fail. We expect OK.
    countDownListener.waitTillCompleted();
    ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
    assertNull(processInstance);
    // Make sure the user registered callback was executed (a.k.a the "continue" signal was received by the process)
    assertNodeTriggered(pi.getId(), "Process async", "Continue");
    assertProcessInstanceCompleted(pi.getId());
    // Make sure the job was processed by the job executor (a.k.a the _user property was set)
    List<VariableInstanceLog> varLogList = auditLogService.findVariableInstances(pi.getId(), "_user");
    assertEquals(1, varLogList.size());
    VariableInstanceLog userVarLog = varLogList.get(0);
    assertEquals("[Name=john after command execution, age=25]", userVarLog.getValue());
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 3 with VariableInstanceLog

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

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

the class AuditQueryTest method lastVariableTest.

@Test
public void lastVariableTest() throws Exception {
    int numLogs = 10;
    VariableInstanceLog[] testData = new VariableInstanceLog[numLogs];
    Calendar cal = GregorianCalendar.getInstance();
    for (int i = 0; i < 5; ++i) {
        cal.roll(Calendar.SECOND, 1);
        testData[i] = new VariableInstanceLog(23L, "org.lots.of.vars", "inst", "first-var", "val-a", "oldVal-" + i);
        testData[i + 5] = new VariableInstanceLog(23L, "org.lots.of.vars", "inst", "second-var", "val-b", "oldVal-" + i);
        testData[i].setDate(cal.getTime());
        testData[i + 5].setDate(cal.getTime());
    }
    persistEntities(testData);
    VariableInstanceLogQueryBuilder queryBuilder;
    ParametrizedQuery<org.kie.api.runtime.manager.audit.VariableInstanceLog> query;
    List<org.kie.api.runtime.manager.audit.VariableInstanceLog> logs;
    queryBuilder = this.variableInstanceLogQuery();
    query = queryBuilder.last().intersect().processInstanceId(23L).build();
    logs = query.getResultList();
    assertEquals("2 logs", 2, logs.size());
    queryBuilder = this.variableInstanceLogQuery();
    query = queryBuilder.value("val-a").intersect().last().build();
    logs = query.getResultList();
    assertEquals("Only 1 log expected", 1, logs.size());
    assertEquals("Incorrect variable val", "val-a", logs.get(0).getValue());
    assertEquals("Incorrect variable old val", "oldVal-4", logs.get(0).getOldValue());
    removeEntities(testData);
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) VariableInstanceLogQueryBuilder(org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) AuditLogServiceTest(org.jbpm.process.audit.AuditLogServiceTest) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 5 with VariableInstanceLog

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

the class ServicesAwareAuditEventBuilder method buildEvent.

@Override
public AuditEvent buildEvent(ProcessVariableChangedEvent pvce) {
    VariableInstanceLog variableLog = (VariableInstanceLog) super.buildEvent(pvce);
    variableLog.setExternalId(deploymentUnitId);
    return variableLog;
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog)

Aggregations

VariableInstanceLog (org.jbpm.process.audit.VariableInstanceLog)13 Test (org.junit.Test)7 KieSession (org.kie.api.runtime.KieSession)6 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)5 Calendar (java.util.Calendar)4 GregorianCalendar (java.util.GregorianCalendar)4 HashMap (java.util.HashMap)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 KieBase (org.kie.api.KieBase)4 EntityManager (javax.persistence.EntityManager)3 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)3 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)3 StandaloneJtaStrategy (org.jbpm.process.audit.strategy.StandaloneJtaStrategy)3 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)2 PersistenceUtil.createEnvironment (org.jbpm.persistence.util.PersistenceUtil.createEnvironment)2 AbstractAuditLogServiceTest.createKieSession (org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession)2 AbstractAuditLogger (org.jbpm.process.audit.AbstractAuditLogger)2 AuditLogService (org.jbpm.process.audit.AuditLogService)2 AuditLogServiceTest (org.jbpm.process.audit.AuditLogServiceTest)2