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;
}
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);
}
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);
}
Aggregations