Search in sources :

Example 1 with VariableInstanceLog

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

the class VariableInstanceLogCleanTest method deleteDataObjectLogsByDateRange.

/**
 * TBD - test is failing on the last line - probably a test error
 */
@Ignore
@Test
public void deleteDataObjectLogsByDateRange() throws InterruptedException {
    kieSession = createKSession(DATA_OBJECT);
    Person person = new Person("Marge");
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("person", person);
    Date start = new Date();
    processInstanceList.addAll(startProcess(kieSession, DATA_OBJECT_ID, paramMap, 1));
    Date mid = new Date();
    processInstanceList.addAll(startProcess(kieSession, DATA_OBJECT_ID, paramMap, 2));
    Date end = new Date();
    processInstanceList.addAll(startProcess(kieSession, DATA_OBJECT_ID, paramMap, 1));
    // Delete by date range but only from a part of the instance created in the date range.
    int resultCount = auditService.variableInstanceLogDelete().dateRangeStart(start).dateRangeEnd(mid).build().execute();
    Assertions.assertThat(resultCount).isEqualTo(1);
    // Assert remaining logs - We expect 2 logs to be present - One from instance 3 and one from instance 4
    List<VariableInstanceLog> variableList = auditService.variableInstanceLogQuery().dateRangeStart(mid).dateRangeEnd(end).variableId("person").build().getResultList();
    Assertions.assertThat(variableList.size()).isEqualTo(2);
    Assertions.assertThat(variableList.get(0).getDate()).isBefore(mid);
    Assertions.assertThat(variableList.get(1).getDate()).isAfter(end);
}
Also used : VariableInstanceLog(org.kie.api.runtime.manager.audit.VariableInstanceLog) Person(org.jbpm.test.domain.Person) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with VariableInstanceLog

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

the class BPMN2DataServicesReferencesTest method testCallActivity.

@Test
public void testCallActivity() throws IOException {
    Assume.assumeTrue("Skip call activity tests", loadCallActivityProcesses);
    String processId = PROC_ID_CALL_ACTIVITY;
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentId, processId);
    assertNotNull(procDef);
    // run process (to verify that it works)
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    Long procId = startProcess(deploymentId, processId, params);
    ProcessInstance procInst = processService.getProcessInstance(procId);
    assertNull(procInst);
    AuditService auditService = deploymentService.getRuntimeManager(deploymentId).getRuntimeEngine(null).getAuditService();
    List<? extends VariableInstanceLog> logs = auditService.findVariableInstances(procId);
    boolean foundY = false;
    for (VariableInstanceLog log : logs) {
        if (log.getVariableId().equals("y") && log.getValue().equals("new value")) {
            foundY = true;
        }
    }
    assertTrue("Parent process did not call sub process", foundY);
    // check information about process
    Collection<String> refProcesses = bpmn2Service.getReusableSubProcesses(deploymentId, processId);
    assertNotNull("Null set of referenced processes", refProcesses);
    assertFalse("Empty set of referenced processes", refProcesses.isEmpty());
    assertEquals("Number referenced processes", 1, refProcesses.size());
    assertEquals("Imported class in processes", PROC_ID_ACTIVITY_CALLED, refProcesses.iterator().next());
}
Also used : VariableInstanceLog(org.kie.api.runtime.manager.audit.VariableInstanceLog) HashMap(java.util.HashMap) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 3 with VariableInstanceLog

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

the class BPMN2DataServicesReferencesTest method testCallActivityByName.

@Test
public void testCallActivityByName() throws IOException {
    Assume.assumeTrue("Skip call activity tests", loadCallActivityProcesses);
    String processId = PROC_ID_CALL_ACTIVITY_BY_NAME;
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentId, processId);
    assertNotNull(procDef);
    // run process (to verify that it works)
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    Long procId = startProcess(deploymentId, processId, params);
    ProcessInstance procInst = processService.getProcessInstance(procId);
    assertNull(procInst);
    AuditService auditService = deploymentService.getRuntimeManager(deploymentId).getRuntimeEngine(null).getAuditService();
    List<? extends VariableInstanceLog> logs = auditService.findVariableInstances(procId);
    boolean foundY = false;
    for (VariableInstanceLog log : logs) {
        if (log.getVariableId().equals("y") && log.getValue().equals("new value")) {
            foundY = true;
        }
    }
    assertTrue("Parent process did not call sub process", foundY);
    // check information about process
    Collection<String> refProcesses = bpmn2Service.getReusableSubProcesses(deploymentId, processId);
    assertNotNull("Null set of referenced processes", refProcesses);
    assertFalse("Empty set of referenced processes", refProcesses.isEmpty());
    assertEquals("Number referenced processes", 1, refProcesses.size());
    assertEquals("Imported class in processes", PROC_ID_ACTIVITY_CALLED, refProcesses.iterator().next());
}
Also used : VariableInstanceLog(org.kie.api.runtime.manager.audit.VariableInstanceLog) HashMap(java.util.HashMap) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 4 with VariableInstanceLog

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

the class ProcessIndexerManager method index.

public List<VariableInstanceLog> index(AuditEventBuilder builder, ProcessVariableChangedEvent event) {
    String variableName = event.getVariableId();
    Object variable = event.getNewValue();
    for (ProcessVariableIndexer indexer : indexers) {
        if (indexer.accept(variable)) {
            List<VariableInstanceLog> indexed = indexer.index(variableName, variable);
            if (indexed != null) {
                // populate all indexed variables with task information
                for (VariableInstanceLog processVariable : indexed) {
                    VariableInstanceLog log = (VariableInstanceLog) builder.buildEvent(event);
                    ((org.jbpm.process.audit.VariableInstanceLog) processVariable).setProcessId(log.getProcessId());
                    ((org.jbpm.process.audit.VariableInstanceLog) processVariable).setProcessInstanceId(log.getProcessInstanceId());
                    ((org.jbpm.process.audit.VariableInstanceLog) processVariable).setDate(log.getDate());
                    ((org.jbpm.process.audit.VariableInstanceLog) processVariable).setExternalId(log.getExternalId());
                    ((org.jbpm.process.audit.VariableInstanceLog) processVariable).setOldValue(log.getOldValue());
                    ((org.jbpm.process.audit.VariableInstanceLog) processVariable).setVariableInstanceId(log.getVariableInstanceId());
                }
                return indexed;
            }
        }
    }
    return null;
}
Also used : VariableInstanceLog(org.kie.api.runtime.manager.audit.VariableInstanceLog) ProcessVariableIndexer(org.kie.internal.process.ProcessVariableIndexer)

Example 5 with VariableInstanceLog

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

the class VariableInstanceLogCleanTest method deleteDataObjectLogsByDate.

/**
 * BZ-TBD - what is the difference between 'queryVariableInstanceLogs' and
 * 'variableInstanceLogQuery'
 * BZ-TBD - Assertion will fail on line 71 where 3 results will be found instead
 * of 2!
 */
@Ignore
@Test
public void deleteDataObjectLogsByDate() {
    kieSession = createKSession(DATA_OBJECT);
    Person person = new Person("Homer");
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("person", person);
    processInstanceList = startProcess(kieSession, DATA_OBJECT_ID, paramMap, 3);
    Assertions.assertThat(processInstanceList).hasSize(3);
    // retrieve person variable of process instance 2 and 3
    List<VariableInstanceLog> variableList = auditService.variableInstanceLogQuery().processInstanceId(processInstanceList.get(1).getId(), processInstanceList.get(2).getId()).variableId("person").build().getResultList();
    Assertions.assertThat(variableList).hasSize(2);
    // delete the variable log which belongs to instance 2 and 3
    int resultCount = auditService.variableInstanceLogDelete().date(variableList.get(0).getDate(), variableList.get(1).getDate()).build().execute();
    Assertions.assertThat(resultCount).isEqualTo(2);
    // check what has remained in the database - we expect to find only the person variable
    // belonging to instance 1 as the others where deleted in the previous ste
    variableList = auditService.variableInstanceLogQuery().variableId("person").build().getResultList();
    Assertions.assertThat(variableList).hasSize(1);
    Assertions.assertThat(variableList.get(0).getValue()).contains("name='Homer'");
}
Also used : VariableInstanceLog(org.kie.api.runtime.manager.audit.VariableInstanceLog) Person(org.jbpm.test.domain.Person) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

VariableInstanceLog (org.kie.api.runtime.manager.audit.VariableInstanceLog)9 Test (org.junit.Test)8 HashMap (java.util.HashMap)5 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)5 KieSession (org.kie.api.runtime.KieSession)4 ArrayList (java.util.ArrayList)3 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)2 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)2 Person (org.jbpm.test.domain.Person)2 Ignore (org.junit.Ignore)2 AuditService (org.kie.api.runtime.manager.audit.AuditService)2 SignalObjectReport (org.jbpm.test.iodata.SignalObjectReport)1 ProcessVariableIndexer (org.kie.internal.process.ProcessVariableIndexer)1 BZ (qa.tools.ikeeper.annotation.BZ)1