use of org.jbpm.process.audit.AbstractAuditLogger in project jbpm by kiegroup.
the class AsyncAuditLogProducerTest method testAsyncAuditLoggerComplete.
@Test
public void testAsyncAuditLoggerComplete() 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();
// start process instance
ProcessInstance processInstance = session.startProcess("com.sample.ruleflow");
MessageReceiver receiver = new MessageReceiver();
receiver.receiveAndProcess(queue, ((EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY)), 2000, 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(processInstance.getId()).isEqualTo(nodeInstance.getProcessInstanceId().longValue());
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();
}
use of org.jbpm.process.audit.AbstractAuditLogger 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();
}
use of org.jbpm.process.audit.AbstractAuditLogger in project jbpm by kiegroup.
the class AsyncAuditLogProducerTest method testAsyncAuditProducerTransactionalWithRollback.
@Test
public void testAsyncAuditProducerTransactionalWithRollback() throws Exception {
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
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", true);
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();
// start process instance
long processInstanceId = session.startProcess("com.sample.ruleflow").getId();
ut.rollback();
MessageReceiver receiver = new MessageReceiver();
List<Message> messages = receiver.receive(queue);
Assertions.assertThat(messages).isNotNull();
Assertions.assertThat(messages.size()).isEqualTo(0);
}
use of org.jbpm.process.audit.AbstractAuditLogger in project jbpm by kiegroup.
the class InjectableRegisterableItemsFactory method getAuditLoggerInstance.
/**
* Provides AuditLogger implementation, JPA or JMS.
* JPA is the default one and JMS requires to have configuration file (.properties)
* to be available on classpath under 'jbpm.audit.jms.properties' name.
* This file must have following properties defined:
* <ul>
* <li>jbpm.audit.jms.connection.factory.jndi - JNDI name of the connection factory to look up - type String</li>
* <li>jbpm.audit.jms.queue.jndi - JNDI name of the queue to look up - type String</li>
* </ul>
* @return instance of the audit logger
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected AbstractAuditLogger getAuditLoggerInstance(RuntimeEngine engine) {
DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
AbstractAuditLogger auditLogger = null;
if ("true".equals(System.getProperty("jbpm.audit.jms.enabled")) || descriptor.getAuditMode() == AuditMode.JMS) {
try {
Properties properties = new Properties();
properties.load(getRuntimeManager().getEnvironment().getClassLoader().getResourceAsStream("/jbpm.audit.jms.properties"));
auditLogger = AuditLoggerFactory.newJMSInstance((Map) properties);
} catch (IOException e) {
logger.error("Unable to load jms audit properties from {}", "/jbpm.audit.jms.properties", e);
}
auditLogger.setBuilder(getAuditBuilder(engine));
} else if (descriptor.getAuditMode() == AuditMode.JPA) {
if (descriptor.getPersistenceUnit().equals(descriptor.getAuditPersistenceUnit())) {
auditLogger = AuditLoggerFactory.newJPAInstance(engine.getKieSession().getEnvironment());
} else {
auditLogger = new JPAWorkingMemoryDbLogger(EntityManagerFactoryManager.get().getOrCreate(descriptor.getAuditPersistenceUnit()));
}
auditLogger.setBuilder(getAuditBuilder(engine));
}
return auditLogger;
}
use of org.jbpm.process.audit.AbstractAuditLogger in project jbpm by kiegroup.
the class DefaultRegisterableItemsFactory method getProcessEventListeners.
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> defaultListeners = new ArrayList<ProcessEventListener>();
DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
if (descriptor == null) {
// register JPAWorkingMemoryDBLogger
AbstractAuditLogger logger = AuditLoggerFactory.newJPAInstance(runtime.getKieSession().getEnvironment());
logger.setBuilder(getAuditBuilder(runtime));
defaultListeners.add(logger);
} else if (descriptor.getAuditMode() == AuditMode.JPA) {
// register JPAWorkingMemoryDBLogger
AbstractAuditLogger logger = null;
if (descriptor.getPersistenceUnit().equals(descriptor.getAuditPersistenceUnit())) {
logger = AuditLoggerFactory.newJPAInstance(runtime.getKieSession().getEnvironment());
} else {
Environment env = EnvironmentFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, EntityManagerFactoryManager.get().getOrCreate(descriptor.getAuditPersistenceUnit()));
logger = AuditLoggerFactory.newJPAInstance(env);
}
logger.setBuilder(getAuditBuilder(runtime));
defaultListeners.add(logger);
} else if (descriptor.getAuditMode() == AuditMode.JMS) {
try {
if (jmsLogger == null) {
Properties properties = new Properties();
InputStream input = getRuntimeManager().getEnvironment().getClassLoader().getResourceAsStream("/jbpm.audit.jms.properties");
// required for junit test
if (input == null) {
input = getRuntimeManager().getEnvironment().getClassLoader().getResourceAsStream("jbpm.audit.jms.properties");
}
properties.load(input);
logger.debug("Creating AsyncAuditLogProducer {}", properties);
jmsLogger = AuditLoggerFactory.newJMSInstance((Map) properties);
jmsLogger.setBuilder(getAuditBuilder(runtime));
}
defaultListeners.add(jmsLogger);
} catch (IOException e) {
logger.error("Unable to load jms audit properties from {}", "/jbpm.audit.jms.properties", e);
}
}
// add any custom listeners
defaultListeners.addAll(super.getProcessEventListeners(runtime));
// add listeners from descriptor
defaultListeners.addAll(getEventListenerFromDescriptor(runtime, ProcessEventListener.class));
return defaultListeners;
}
Aggregations