Search in sources :

Example 16 with JPAAuditLogService

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

the class AsyncAuditLogProducerTest method testAsyncAuditLoggerCompleteWithVariables.

@Test
public void testAsyncAuditLoggerCompleteWithVariables() 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();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("s", "test value");
    // 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)), 3000, 13);
    // 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(6);
    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).hasSize(2);
    VariableInstanceLog var = variables.get(0);
    // initial value from rule flow definition
    Assertions.assertThat(var.getValue()).isEqualTo("InitialValue");
    Assertions.assertThat(var.getOldValue()).isIn("", " ", null);
    Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
    Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId());
    Assertions.assertThat(var.getVariableId()).isEqualTo("s");
    Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("s");
    // value given at process start
    var = variables.get(1);
    // initial value from rule flow definition
    Assertions.assertThat(var.getValue()).isEqualTo("test value");
    Assertions.assertThat(var.getOldValue()).isEqualTo("InitialValue");
    Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
    Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId());
    Assertions.assertThat(var.getVariableId()).isEqualTo("s");
    Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("s");
    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) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) 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 17 with JPAAuditLogService

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

the class AuditQueryCriteriaUtilTest method configure.

@BeforeClass
public static void configure() {
    AbstractBaseTest.hackTheDatabaseMetadataLoggerBecauseTheresALogbackXmlInTheClasspath();
    context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
    emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY);
    auditLogService = new JPAAuditLogService(emf);
    util = new AuditQueryCriteriaUtil(auditLogService);
}
Also used : AuditQueryCriteriaUtil(org.jbpm.process.audit.AuditQueryCriteriaUtil) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) BeforeClass(org.junit.BeforeClass)

Example 18 with JPAAuditLogService

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

the class JbpmBpmn2TestCase method getCompletedNodes.

protected List<String> getCompletedNodes(long processInstanceId) {
    List<String> names = new ArrayList<String>();
    if (sessionPersistence) {
        AuditLogService auditLogService = new JPAAuditLogService(emf);
        List<NodeInstanceLog> logs = auditLogService.findNodeInstances(processInstanceId);
        if (logs != null) {
            for (NodeInstanceLog l : logs) {
                names.add(l.getNodeId());
            }
        }
    } else {
        for (LogEvent event : logger.getLogEvents()) {
            if (event instanceof RuleFlowNodeLogEvent) {
                if (event.getType() == 27) {
                    names.add(((RuleFlowNodeLogEvent) event).getNodeId());
                }
            }
        }
    }
    return names;
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) RuleFlowLogEvent(org.drools.core.audit.event.RuleFlowLogEvent) RuleFlowNodeLogEvent(org.drools.core.audit.event.RuleFlowNodeLogEvent) LogEvent(org.drools.core.audit.event.LogEvent) ArrayList(java.util.ArrayList) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) RuleFlowNodeLogEvent(org.drools.core.audit.event.RuleFlowNodeLogEvent)

Example 19 with JPAAuditLogService

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

the class JbpmBpmn2TestCase method createKnowledgeSession.

protected StatefulKnowledgeSession createKnowledgeSession(KieBase kbase, KieSessionConfiguration conf, Environment env) throws Exception {
    StatefulKnowledgeSession result;
    if (conf == null) {
        conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    }
    if (sessionPersistence) {
        if (env == null) {
            env = createEnvironment(emf);
        }
        if (pessimisticLocking) {
            env.set(USE_PESSIMISTIC_LOCKING, true);
        }
        conf.setOption(ForceEagerActivationOption.YES);
        result = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, conf, env);
        AuditLoggerFactory.newInstance(Type.JPA, result, null);
        logService = new JPAAuditLogService(env);
    } else {
        if (env == null) {
            env = EnvironmentFactory.newEnvironment();
        }
        Properties defaultProps = new Properties();
        defaultProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName());
        defaultProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName());
        conf = SessionConfiguration.newInstance(defaultProps);
        conf.setOption(ForceEagerActivationOption.YES);
        result = (StatefulKnowledgeSession) kbase.newKieSession(conf, env);
        logger = new WorkingMemoryInMemoryLogger(result);
    }
    return result;
}
Also used : WorkingMemoryInMemoryLogger(org.drools.core.audit.WorkingMemoryInMemoryLogger) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) DefaultSignalManagerFactory(org.jbpm.process.instance.event.DefaultSignalManagerFactory) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) DefaultProcessInstanceManagerFactory(org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory) Properties(java.util.Properties)

Example 20 with JPAAuditLogService

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

the class AuditCommandsTest method setup.

@BeforeClass
public static void setup() throws Exception {
    setUpDataSource();
    // clear logs
    Environment env = EnvironmentFactory.newEnvironment();
    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
    logService = new JPAAuditLogService(env);
    logService.clear();
}
Also used : Environment(org.kie.api.runtime.Environment) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) BeforeClass(org.junit.BeforeClass)

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