Search in sources :

Example 11 with NodeInstanceLog

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;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) Node(org.kie.api.definition.process.Node) KieSession(org.kie.api.runtime.KieSession) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance)

Example 12 with NodeInstanceLog

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();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) HashMap(java.util.HashMap) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 13 with NodeInstanceLog

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();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) HashMap(java.util.HashMap) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 14 with NodeInstanceLog

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

Example 15 with NodeInstanceLog

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);
}
Also used : NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) QueryWhere(org.jbpm.query.jpa.data.QueryWhere) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

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