Search in sources :

Example 16 with NodeInstanceLog

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

the class AuditQueryDataUtil method createTestNodeInstanceLogData.

static NodeInstanceLog[] createTestNodeInstanceLogData(EntityManagerFactory emf) {
    StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
    EntityManager em = jtaHelper.getEntityManager();
    int numEntities = 9;
    NodeInstanceLog[] testData = new NodeInstanceLog[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;
    }
    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(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) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar)

Example 17 with NodeInstanceLog

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

the class AsyncAuditLogProducer method afterNodeLeft.

@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
    NodeInstanceLog log = (NodeInstanceLog) builder.buildEvent(event, null);
    sendMessage(log, AFTER_NODE_LEFT_EVENT_TYPE);
}
Also used : NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog)

Example 18 with NodeInstanceLog

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

the class AsyncAuditLogProducer method afterNodeTriggered.

@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
    // trigger this to record some of the data (like work item id) after activity was triggered
    NodeInstanceLog log = (NodeInstanceLog) ((NodeInstanceImpl) event.getNodeInstance()).getMetaData().get("NodeInstanceLog");
    NodeInstanceLog logUpdated = (NodeInstanceLog) builder.buildEvent(event, log);
    if (logUpdated != null) {
        sendMessage(log, AFTER_NODE_ENTER_EVENT_TYPE);
    }
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog)

Example 19 with NodeInstanceLog

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

the class JbpmBpmn2TestCase method assertNodeActive.

public void assertNodeActive(long processInstanceId, KieSession ksession, String... name) {
    List<String> names = new ArrayList<String>();
    for (String n : name) {
        names.add(n);
    }
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    if (processInstance instanceof WorkflowProcessInstance) {
        if (sessionPersistence) {
            // ENTER -> EXIT is correctly ordered
            List<? extends NodeInstanceLog> logs = logService.findNodeInstances(processInstanceId);
            if (logs != null) {
                List<String> activeNodes = new ArrayList<String>();
                for (NodeInstanceLog l : logs) {
                    String nodeName = l.getNodeName();
                    if (l.getType() == NodeInstanceLog.TYPE_ENTER && names.contains(nodeName)) {
                        activeNodes.add(nodeName);
                    }
                    if (l.getType() == NodeInstanceLog.TYPE_EXIT && names.contains(nodeName)) {
                        activeNodes.remove(nodeName);
                    }
                }
                names.removeAll(activeNodes);
            }
        } else {
            assertNodeActive((WorkflowProcessInstance) processInstance, names);
        }
    }
    if (!names.isEmpty()) {
        String s = names.get(0);
        for (int i = 1; i < names.size(); i++) {
            s += ", " + names.get(i);
        }
        fail("Node(s) not active: " + s);
    }
}
Also used : NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance)

Example 20 with NodeInstanceLog

use of org.jbpm.process.audit.NodeInstanceLog 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)

Aggregations

NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)25 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)8 Test (org.junit.Test)8 KieSession (org.kie.api.runtime.KieSession)7 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 AuditLogService (org.jbpm.process.audit.AuditLogService)6 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)6 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)6 KieBase (org.kie.api.KieBase)6 EntityManagerFactory (javax.persistence.EntityManagerFactory)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)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 NodeInstanceImpl (org.jbpm.workflow.instance.impl.NodeInstanceImpl)4 Environment (org.kie.api.runtime.Environment)4 EntityManager (javax.persistence.EntityManager)3 VariableInstanceLog (org.jbpm.process.audit.VariableInstanceLog)3 SubProcessNodeInstance (org.jbpm.workflow.instance.node.SubProcessNodeInstance)3