use of org.jbpm.process.audit.NodeInstanceLog in project jbpm by kiegroup.
the class DefaultAuditEventBuilderImpl method buildEvent.
@Override
public AuditEvent buildEvent(ProcessNodeLeftEvent pnle, Object log) {
ProcessInstanceImpl pi = (ProcessInstanceImpl) pnle.getProcessInstance();
NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnle.getNodeInstance();
Node node = nodeInstance.getNode();
String nodeId = null;
String nodeType = null;
String nodeContainerId = null;
if (node != null) {
nodeId = (String) node.getMetaData().get("UniqueId");
nodeType = node.getClass().getSimpleName();
nodeContainerId = getNodeContainerId(node.getNodeContainer());
} else {
nodeId = Long.toString(nodeInstance.getNodeId());
nodeType = (String) nodeInstance.getMetaData("NodeType");
}
NodeInstanceLog logEvent = null;
if (log != null) {
logEvent = (NodeInstanceLog) log;
} else {
logEvent = new NodeInstanceLog(NodeInstanceLog.TYPE_EXIT, pi.getId(), pi.getProcessId(), Long.toString(nodeInstance.getId()), nodeId, nodeInstance.getNodeName());
}
if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) {
logEvent.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId());
}
if (nodeInstance instanceof SubProcessNodeInstance) {
logEvent.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
}
String connection = (String) nodeInstance.getMetaData().get("OutgoingConnection");
logEvent.setConnection(connection);
logEvent.setExternalId("" + ((KieSession) pnle.getKieRuntime()).getIdentifier());
logEvent.setNodeType(nodeType);
logEvent.setNodeContainerId(nodeContainerId);
logEvent.setDate(pnle.getEventDate());
logEvent.setSlaCompliance(nodeInstance.getSlaCompliance());
logEvent.setSlaDueDate(nodeInstance.getSlaDueDate());
return logEvent;
}
use of org.jbpm.process.audit.NodeInstanceLog 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.NodeInstanceLog 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.NodeInstanceLog in project jbpm by kiegroup.
the class AuditDeleteTest method createTestNodeInstanceLogData.
private NodeInstanceLog[] createTestNodeInstanceLogData() {
StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
EntityManager em = jtaHelper.getEntityManager();
int numEntities = 9;
NodeInstanceLog[] testData = new NodeInstanceLog[numEntities];
ProcessInstanceLog[] testDataPI = new ProcessInstanceLog[numEntities];
Calendar cal = randomCal();
for (int i = 0; i < numEntities; ++i) {
NodeInstanceLog nil = new NodeInstanceLog();
nil.setProcessInstanceId(randomLong());
nil.setProcessId(randomString());
cal.add(Calendar.SECOND, 1);
nil.setDate(cal.getTime());
nil.setType(Math.abs(random.nextInt()));
nil.setNodeInstanceId(randomString());
nil.setNodeId(randomString());
nil.setNodeName(randomString());
nil.setNodeType(randomString());
nil.setWorkItemId(randomLong());
nil.setConnection(randomString());
nil.setExternalId(randomString());
testData[i] = nil;
ProcessInstanceLog pLog = buildCompletedProcessInstance(nil.getProcessInstanceId());
testDataPI[i] = pLog;
}
for (int i = 0; i < numEntities; ++i) {
switch(i) {
case 1:
testData[i - 1].setDate(testData[i].getDate());
break;
case 2:
testData[i - 1].setNodeId(testData[i].getNodeId());
break;
case 3:
testData[i - 1].setNodeInstanceId(testData[i].getNodeInstanceId());
break;
case 4:
testData[i - 1].setNodeName(testData[i].getNodeName());
break;
case 5:
testData[i - 1].setNodeType(testData[i].getNodeType());
break;
case 6:
testData[i - 1].setProcessId(testData[i].getProcessId());
break;
case 7:
testData[i - 1].setProcessInstanceId(testData[i].getProcessInstanceId());
break;
case 8:
testData[i - 1].setWorkItemId(testData[i].getWorkItemId());
break;
}
}
Object tx = jtaHelper.joinTransaction(em);
for (int i = 0; i < numEntities; ++i) {
em.persist(testDataPI[i]);
em.persist(testData[i]);
}
jtaHelper.leaveTransaction(em, tx);
return testData;
}
use of org.jbpm.process.audit.NodeInstanceLog in project jbpm by kiegroup.
the class AuditQueryCriteriaUtilTest method auditQueryCriteriaMetaTest.
@Test
public void auditQueryCriteriaMetaTest() {
QueryWhere where = new QueryWhere();
where.setAscending(QueryParameterIdentifiers.NODE_INSTANCE_ID_LIST);
where.setCount(10);
where.setOffset(2);
List<NodeInstanceLog> result = util.doCriteriaQuery(where, NodeInstanceLog.class);
assertNotNull("Null result from 1rst query.", result);
}
Aggregations