Search in sources :

Example 1 with NodeInstanceLog

use of org.kie.api.runtime.manager.audit.NodeInstanceLog in project jbpm by kiegroup.

the class NodeInstanceLogCleanTest method deleteLogsByNodeNameAndInstanceId.

@Test
public void deleteLogsByNodeNameAndInstanceId() {
    KieSession kieSession = createKSession(HELLO_WORLD_PROCESS);
    List<ProcessInstance> instanceList = startProcess(kieSession, HELLO_WORLD_PROCESS_ID, 2);
    // Delete one node named "Hello world"
    int resultCount = auditService.nodeInstanceLogDelete().nodeName("Hello world").processInstanceId(instanceList.get(0).getId()).build().execute();
    // There are two node types in the log (value NodeInstanceLog.TYPE_ENTER and NodeInstanceLog.TYPE_EXIT)
    Assertions.assertThat(resultCount).isEqualTo(2);
    // Now check that all other node records are still present
    List<NodeInstanceLog> nodeList = auditService.nodeInstanceLogQuery().nodeName("Start", "End", "Hello world").build().getResultList();
    Assertions.assertThat(nodeList).hasSize(10).extracting("nodeName").containsOnly("Start", "End", "Hello world");
}
Also used : NodeInstanceLog(org.kie.api.runtime.manager.audit.NodeInstanceLog) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 2 with NodeInstanceLog

use of org.kie.api.runtime.manager.audit.NodeInstanceLog in project jbpm by kiegroup.

the class JbpmJUnitBaseTestCase method assertNodeTriggered.

public void assertNodeTriggered(long processInstanceId, String... nodeNames) {
    List<String> names = new ArrayList<String>();
    for (String nodeName : nodeNames) {
        names.add(nodeName);
    }
    if (sessionPersistence) {
        List<? extends NodeInstanceLog> logs = logService.findNodeInstances(processInstanceId);
        if (logs != null) {
            for (NodeInstanceLog l : logs) {
                String nodeName = l.getNodeName();
                if ((l.getType() == NodeInstanceLog.TYPE_ENTER || l.getType() == NodeInstanceLog.TYPE_EXIT) && names.contains(nodeName)) {
                    names.remove(nodeName);
                }
            }
        }
    } else {
        for (LogEvent event : inMemoryLogger.getLogEvents()) {
            if (event instanceof RuleFlowNodeLogEvent) {
                String nodeName = ((RuleFlowNodeLogEvent) event).getNodeName();
                if (names.contains(nodeName)) {
                    names.remove(nodeName);
                }
            }
        }
    }
    if (!names.isEmpty()) {
        String s = names.get(0);
        for (int i = 1; i < names.size(); i++) {
            s += ", " + names.get(i);
        }
        fail("Node(s) not executed: " + s);
    }
}
Also used : NodeInstanceLog(org.kie.api.runtime.manager.audit.NodeInstanceLog) RuleFlowNodeLogEvent(org.drools.core.audit.event.RuleFlowNodeLogEvent) LogEvent(org.drools.core.audit.event.LogEvent) ArrayList(java.util.ArrayList) RuleFlowNodeLogEvent(org.drools.core.audit.event.RuleFlowNodeLogEvent)

Example 3 with NodeInstanceLog

use of org.kie.api.runtime.manager.audit.NodeInstanceLog in project jbpm by kiegroup.

the class ChecklistItemFactory method getLoggedChecklistItems.

public static Collection<ChecklistItem> getLoggedChecklistItems(WorkflowProcess process, List<NodeInstanceLog> nodeInstances) {
    Map<String, ChecklistItem> result = new HashMap<String, ChecklistItem>();
    Map<String, String> relevantNodes = new HashMap<String, String>();
    getRelevantNodes(process, relevantNodes);
    for (NodeInstanceLog log : nodeInstances) {
        String orderingNb = relevantNodes.get(log.getNodeId());
        if (orderingNb != null) {
            if (log.getType() == NodeInstanceLog.TYPE_EXIT) {
                result.put(orderingNb, createChecklistItem(log.getNodeName(), log.getNodeType(), "", orderingNb, 0, log.getProcessId(), Status.Completed));
            } else {
                if (result.get(orderingNb) == null) {
                    result.put(orderingNb, createChecklistItem(log.getNodeName(), log.getNodeType(), "", orderingNb, 0, log.getProcessId(), Status.InProgress));
                }
            }
        }
    }
    return result.values();
}
Also used : NodeInstanceLog(org.kie.api.runtime.manager.audit.NodeInstanceLog) HashMap(java.util.HashMap) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem)

Example 4 with NodeInstanceLog

use of org.kie.api.runtime.manager.audit.NodeInstanceLog in project jbpm by kiegroup.

the class SLATrackingCommandTest method assertNodeInstanceSLACompliance.

private void assertNodeInstanceSLACompliance(JPAAuditLogService logService, Long processInstanceId, String name, int slaCompliance) {
    List<NodeInstanceLog> logs = logService.nodeInstanceLogQuery().processInstanceId(processInstanceId).and().nodeName(name).build().getResultList();
    NodeInstanceLog log = logs.get(logs.size() - 1);
    assertEquals(processInstanceId, log.getProcessInstanceId());
    assertEquals(slaCompliance, ((org.jbpm.process.audit.NodeInstanceLog) log).getSlaCompliance().intValue());
}
Also used : NodeInstanceLog(org.kie.api.runtime.manager.audit.NodeInstanceLog)

Example 5 with NodeInstanceLog

use of org.kie.api.runtime.manager.audit.NodeInstanceLog in project jbpm by kiegroup.

the class NodeInstanceLogCleanTest method deleteLogsByNodeInstanceId.

@Test
public void deleteLogsByNodeInstanceId() {
    KieSession kieSession = null;
    List<ProcessInstance> processInstanceList = null;
    try {
        kieSession = createKSession(HUMAN_TASK_LOCALE);
        processInstanceList = startProcess(kieSession, HUMAN_TASK_LOCALE_ID, 1);
        // Let's see how the code will manage Japan characters.
        List<NodeInstanceLog> nodeInstanceList = auditService.nodeInstanceLogQuery().nodeName("空手").build().getResultList();
        // We are expecting only NodeInstanceLog.TYPE_ENTERED as execution will be paused on the human task
        Assertions.assertThat(nodeInstanceList).hasSize(1);
        // Delete node named "空手" based on it's id.
        int resultCount = auditService.nodeInstanceLogDelete().nodeInstanceId(nodeInstanceList.get(0).getNodeId()).build().execute();
        Assertions.assertThat(resultCount).isEqualTo(0);
    } finally {
        if (processInstanceList != null) {
            abortProcess(kieSession, processInstanceList);
        }
        if (kieSession != null) {
            kieSession.dispose();
        }
    }
}
Also used : NodeInstanceLog(org.kie.api.runtime.manager.audit.NodeInstanceLog) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Aggregations

NodeInstanceLog (org.kie.api.runtime.manager.audit.NodeInstanceLog)7 Test (org.junit.Test)3 KieSession (org.kie.api.runtime.KieSession)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 LogEvent (org.drools.core.audit.event.LogEvent)1 RuleFlowNodeLogEvent (org.drools.core.audit.event.RuleFlowNodeLogEvent)1 ChecklistItem (org.jbpm.examples.checklist.ChecklistItem)1 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)1