use of org.jbpm.process.audit.ProcessInstanceLog in project jbpm by kiegroup.
the class AuditQueryDataUtil method createTestProcessInstanceLogData.
static ProcessInstanceLog[] createTestProcessInstanceLogData(EntityManagerFactory emf) {
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());
pil.setCorrelationKey(randomString());
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);
createdEntities.addAll(Arrays.asList(testData));
return testData;
}
use of org.jbpm.process.audit.ProcessInstanceLog in project jbpm by kiegroup.
the class AuditQueryTest method orderByQueryBuilderTest.
@Test
public void orderByQueryBuilderTest() {
ProcessInstanceLogQueryBuilder builder = this.processInstanceLogQuery();
builder.ascending(OrderBy.processInstanceId);
List<org.kie.api.runtime.manager.audit.ProcessInstanceLog> resultList = builder.build().getResultList();
for (int i = 1; i < resultList.size(); ++i) {
ProcessInstanceLog pilB = (ProcessInstanceLog) resultList.get(i);
ProcessInstanceLog pilA = (ProcessInstanceLog) resultList.get(i - 1);
assertTrue("order by asc process instance id failed: " + pilA.getProcessInstanceId() + " ? " + pilB.getProcessInstanceId(), pilA.getProcessInstanceId() <= pilB.getProcessInstanceId());
}
builder.descending(OrderBy.processInstanceId);
resultList = builder.build().getResultList();
for (int i = 1; i < resultList.size(); ++i) {
ProcessInstanceLog pilB = (ProcessInstanceLog) resultList.get(i);
ProcessInstanceLog pilA = (ProcessInstanceLog) resultList.get(i - 1);
assertTrue("order by desc process instance id failed: " + pilA.getProcessInstanceId() + " ? " + pilB.getProcessInstanceId(), pilA.getProcessInstanceId() >= pilB.getProcessInstanceId());
}
builder.ascending(OrderBy.processId);
resultList = builder.build().getResultList();
for (int i = 1; i < resultList.size(); ++i) {
ProcessInstanceLog pilA = (ProcessInstanceLog) resultList.get(i - 1);
ProcessInstanceLog pilB = (ProcessInstanceLog) resultList.get(i);
assertTrue("order by asc process id failed: " + pilA.getProcessId() + " ? " + pilB.getProcessId(), pilA.getProcessId().compareTo(pilB.getProcessId()) <= 0);
}
builder.descending(OrderBy.processId);
resultList = builder.build().getResultList();
for (int i = 1; i < resultList.size(); ++i) {
ProcessInstanceLog pilA = (ProcessInstanceLog) resultList.get(i - 1);
ProcessInstanceLog pilB = (ProcessInstanceLog) resultList.get(i);
assertTrue("order by desc process id failed: " + pilA.getProcessId() + " ? " + pilB.getProcessId(), pilA.getProcessId().compareTo(pilB.getProcessId()) >= 0);
}
}
use of org.jbpm.process.audit.ProcessInstanceLog in project jbpm by kiegroup.
the class ServicesAwareAuditEventBuilder method buildEvent.
@Override
public AuditEvent buildEvent(ProcessCompletedEvent pce, Object log) {
ProcessInstanceLog instanceLog = (ProcessInstanceLog) super.buildEvent(pce, log);
instanceLog.setExternalId(deploymentUnitId);
return instanceLog;
}
use of org.jbpm.process.audit.ProcessInstanceLog in project jbpm by kiegroup.
the class ServicesAwareAuditEventBuilder method buildEvent.
@Override
public AuditEvent buildEvent(ProcessStartedEvent pse) {
ProcessInstanceLog log = (ProcessInstanceLog) super.buildEvent(pse);
log.setIdentity(identityProvider.getName());
log.setExternalId(deploymentUnitId);
return log;
}
use of org.jbpm.process.audit.ProcessInstanceLog in project jbpm by kiegroup.
the class AsyncAuditLogReceiver method onMessage.
@SuppressWarnings("unchecked")
@Override
public void onMessage(Message message) {
if (message instanceof TextMessage) {
EntityManager em = getEntityManager();
TextMessage textMessage = (TextMessage) message;
try {
String messageContent = textMessage.getText();
Integer eventType = textMessage.getIntProperty("EventType");
Object event = xstream.fromXML(messageContent);
switch(eventType) {
case AbstractAuditLogger.AFTER_NODE_ENTER_EVENT_TYPE:
NodeInstanceLog nodeAfterEnterEvent = (NodeInstanceLog) event;
if (nodeAfterEnterEvent.getWorkItemId() != null) {
List<NodeInstanceLog> result = em.createQuery("from NodeInstanceLog as log where log.nodeInstanceId = :nodeId and log.type = 0").setParameter("nodeId", nodeAfterEnterEvent.getNodeInstanceId()).getResultList();
if (result != null && result.size() != 0) {
NodeInstanceLog log = result.get(result.size() - 1);
log.setWorkItemId(nodeAfterEnterEvent.getWorkItemId());
em.merge(log);
}
}
break;
case AbstractAuditLogger.AFTER_COMPLETE_EVENT_TYPE:
ProcessInstanceLog processCompletedEvent = (ProcessInstanceLog) event;
List<ProcessInstanceLog> result = em.createQuery("from ProcessInstanceLog as log where log.processInstanceId = :piId and log.end is null").setParameter("piId", processCompletedEvent.getProcessInstanceId()).getResultList();
if (result != null && result.size() != 0) {
ProcessInstanceLog log = result.get(result.size() - 1);
log.setOutcome(processCompletedEvent.getOutcome());
log.setStatus(processCompletedEvent.getStatus());
log.setEnd(processCompletedEvent.getEnd());
log.setDuration(processCompletedEvent.getDuration());
em.merge(log);
}
break;
default:
em.persist(event);
break;
}
em.flush();
em.close();
} catch (JMSException e) {
e.printStackTrace();
throw new RuntimeException("Exception when receiving audit event event", e);
}
}
}
Aggregations