Search in sources :

Example 11 with VariableInstanceLog

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

the class DefaultAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessVariableChangedEvent pvce) {
    long processInstanceId = pvce.getProcessInstance().getId();
    String processId = pvce.getProcessInstance().getProcessId();
    String variableId = pvce.getVariableId();
    String variableInstanceId = pvce.getVariableInstanceId();
    String oldValue = (pvce.getOldValue() != null) ? pvce.getOldValue().toString() : "";
    String newValue = (pvce.getNewValue() != null) ? pvce.getNewValue().toString() : "";
    VariableInstanceLog log = new VariableInstanceLog(processInstanceId, processId, variableInstanceId, variableId, newValue, oldValue);
    log.setExternalId("" + ((KieSession) pvce.getKieRuntime()).getIdentifier());
    return log;
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) KieSession(org.kie.api.runtime.KieSession)

Example 12 with VariableInstanceLog

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

the class StandaloneBPMNProcessTest method testUserTask.

@Test
public void testUserTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-UserTask.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    String varId = "s";
    String varValue = "initialValue";
    params.put(varId, varValue);
    ProcessInstance processInstance = ksession.startProcess("UserTask", params);
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // Test jbpm-audit findVariableInstancesByName* methods
    if (isPersistence()) {
        List<VariableInstanceLog> varLogs = logService.findVariableInstancesByName(varId, true);
        assertThat(varLogs).isNotEmpty();
        for (VariableInstanceLog varLog : varLogs) {
            assertThat(varLog.getVariableId()).isEqualTo(varId);
        }
        varLogs = logService.findVariableInstancesByNameAndValue(varId, varValue, true);
        assertThat(varLogs).isNotEmpty();
        for (VariableInstanceLog varLog : varLogs) {
            assertThat(varLog.getVariableId()).isEqualTo(varId);
            assertThat(varLog.getValue()).isEqualTo(varValue);
        }
    }
    ksession = restoreSession(ksession, true);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 13 with VariableInstanceLog

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

the class AuditCommandsTest method testVarAndNodeInstanceCommands.

@Test
public void testVarAndNodeInstanceCommands() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-SubProcessUserTask.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("SubProcess");
    assertProcessInstanceActive(processInstance);
    Command<?> cmd = new FindNodeInstancesCommand(processInstance.getId());
    Object result = ksession.execute(cmd);
    assertNotNull("Command result is empty!", result);
    assertTrue(result instanceof List);
    List<NodeInstanceLog> nodeLogList = (List<NodeInstanceLog>) result;
    assertEquals("Log list size is incorrect.", 8, nodeLogList.size());
    cmd = new FindNodeInstancesCommand(processInstance.getId(), "UserTask_1");
    result = ksession.execute(cmd);
    assertNotNull("Command result is empty!", result);
    assertTrue(result instanceof List);
    nodeLogList = (List<NodeInstanceLog>) result;
    assertEquals("Log list size is incorrect.", 1, nodeLogList.size());
    cmd = new FindVariableInstancesCommand(processInstance.getId(), "2:x");
    result = ksession.execute(cmd);
    assertNotNull("Command result is empty!", result);
    assertTrue(result instanceof List);
    List<VariableInstanceLog> varLogList = (List<VariableInstanceLog>) result;
    assertEquals("Log list size is incorrect.", 1, varLogList.size());
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) WorkItem(org.kie.api.runtime.process.WorkItem) VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) List(java.util.List) Test(org.junit.Test)

Aggregations

VariableInstanceLog (org.jbpm.process.audit.VariableInstanceLog)13 Test (org.junit.Test)7 KieSession (org.kie.api.runtime.KieSession)6 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)5 Calendar (java.util.Calendar)4 GregorianCalendar (java.util.GregorianCalendar)4 HashMap (java.util.HashMap)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 KieBase (org.kie.api.KieBase)4 EntityManager (javax.persistence.EntityManager)3 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)3 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)3 StandaloneJtaStrategy (org.jbpm.process.audit.strategy.StandaloneJtaStrategy)3 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)2 PersistenceUtil.createEnvironment (org.jbpm.persistence.util.PersistenceUtil.createEnvironment)2 AbstractAuditLogServiceTest.createKieSession (org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession)2 AbstractAuditLogger (org.jbpm.process.audit.AbstractAuditLogger)2 AuditLogService (org.jbpm.process.audit.AuditLogService)2 AuditLogServiceTest (org.jbpm.process.audit.AuditLogServiceTest)2