Search in sources :

Example 11 with ProcessInstanceLog

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;
}
Also used : StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy) EntityManager(javax.persistence.EntityManager) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 12 with ProcessInstanceLog

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);
    }
}
Also used : ProcessInstanceLogQueryBuilder(org.kie.internal.runtime.manager.audit.query.ProcessInstanceLogQueryBuilder) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) AuditLogServiceTest(org.jbpm.process.audit.AuditLogServiceTest) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 13 with ProcessInstanceLog

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;
}
Also used : ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 14 with ProcessInstanceLog

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;
}
Also used : ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 15 with ProcessInstanceLog

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);
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Aggregations

ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)27 Test (org.junit.Test)9 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)8 KieBase (org.kie.api.KieBase)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)8 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)7 HashMap (java.util.HashMap)6 EntityManager (javax.persistence.EntityManager)6 EntityManagerFactory (javax.persistence.EntityManagerFactory)6 AuditLogService (org.jbpm.process.audit.AuditLogService)6 KieSession (org.kie.api.runtime.KieSession)6 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 StandaloneJtaStrategy (org.jbpm.process.audit.strategy.StandaloneJtaStrategy)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)5 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 Environment (org.kie.api.runtime.Environment)4 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)3