use of org.jbpm.process.audit.VariableInstanceLog in project jbpm by kiegroup.
the class ManagedAuditEventBuilderImpl method buildEvent.
@Override
public AuditEvent buildEvent(ProcessVariableChangedEvent pvce) {
VariableInstanceLog variableLog = (VariableInstanceLog) super.buildEvent(pvce);
variableLog.setExternalId(ownerId);
return variableLog;
}
use of org.jbpm.process.audit.VariableInstanceLog in project jbpm by kiegroup.
the class AsyncTaskCallbackTest method testTaskCallback.
@Test(timeout = 30000)
public void testTaskCallback() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Continue", 1);
addProcessEventListener(countDownListener);
KieSession ksession = createKSession(ASYNC_EXECUTOR_CALLBACK, ASYNC_DATA_EXECUTOR);
WorkItemManager wim = ksession.getWorkItemManager();
wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
Map<String, Object> pm = new HashMap<String, Object>();
pm.put("_command", CALLBACK_COMMAND);
ProcessInstance pi = ksession.startProcess(ASYNC_EXECUTOR_CALLBACK_ID, pm);
// Wait for the job to be picked up and processed. The job will send
// the 'Continue' signal on OK or Fail. We expect OK.
countDownListener.waitTillCompleted();
ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
assertNull(processInstance);
// Make sure the user registered callback was executed (a.k.a the "continue" signal was received by the process)
assertNodeTriggered(pi.getId(), "Process async", "Continue");
assertProcessInstanceCompleted(pi.getId());
// Make sure the job was processed by the job executor (a.k.a the _user property was set)
List<VariableInstanceLog> varLogList = auditLogService.findVariableInstances(pi.getId(), "_user");
assertEquals(1, varLogList.size());
VariableInstanceLog userVarLog = varLogList.get(0);
assertEquals("[Name=john after command execution, age=25]", userVarLog.getValue());
}
use of org.jbpm.process.audit.VariableInstanceLog in project jbpm by kiegroup.
the class AsyncAuditLogProducerTest method testAsyncAuditLoggerCompleteWithVariablesCustomIndexer.
@Test
public void testAsyncAuditLoggerCompleteWithVariablesCustomIndexer() 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();
List<String> names = new LinkedList<String>();
names.add("john");
names.add("mary");
names.add("peter");
Map<String, Object> params = new HashMap<String, Object>();
params.put("list", names);
// 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)), 6000, 28);
// 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(12);
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.size()).isEqualTo(8);
List<VariableInstanceLog> listVariables = new ArrayList<VariableInstanceLog>();
// collect only those that are related to list process variable
for (VariableInstanceLog v : variables) {
if (v.getVariableInstanceId().equals("list")) {
listVariables.add(v);
}
}
Assertions.assertThat(listVariables.size()).isEqualTo(3);
List<String> variableValues = new ArrayList<String>();
List<String> variableIds = new ArrayList<String>();
for (VariableInstanceLog var : listVariables) {
variableValues.add(var.getValue());
variableIds.add(var.getVariableId());
Assertions.assertThat(var.getOldValue()).isIn("", " ", null);
Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId());
Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("list");
}
Assertions.assertThat(variableValues).contains("john", "mary", "peter");
Assertions.assertThat(variableIds).contains("list[0]", "list[1]", "list[2]");
logService.clear();
processInstances = logService.findProcessInstances("com.sample.ruleflow3");
logService.dispose();
Assertions.assertThat(processInstances).isNullOrEmpty();
}
use of org.jbpm.process.audit.VariableInstanceLog in project jbpm by kiegroup.
the class AuditQueryTest method lastVariableTest.
@Test
public void lastVariableTest() throws Exception {
int numLogs = 10;
VariableInstanceLog[] testData = new VariableInstanceLog[numLogs];
Calendar cal = GregorianCalendar.getInstance();
for (int i = 0; i < 5; ++i) {
cal.roll(Calendar.SECOND, 1);
testData[i] = new VariableInstanceLog(23L, "org.lots.of.vars", "inst", "first-var", "val-a", "oldVal-" + i);
testData[i + 5] = new VariableInstanceLog(23L, "org.lots.of.vars", "inst", "second-var", "val-b", "oldVal-" + i);
testData[i].setDate(cal.getTime());
testData[i + 5].setDate(cal.getTime());
}
persistEntities(testData);
VariableInstanceLogQueryBuilder queryBuilder;
ParametrizedQuery<org.kie.api.runtime.manager.audit.VariableInstanceLog> query;
List<org.kie.api.runtime.manager.audit.VariableInstanceLog> logs;
queryBuilder = this.variableInstanceLogQuery();
query = queryBuilder.last().intersect().processInstanceId(23L).build();
logs = query.getResultList();
assertEquals("2 logs", 2, logs.size());
queryBuilder = this.variableInstanceLogQuery();
query = queryBuilder.value("val-a").intersect().last().build();
logs = query.getResultList();
assertEquals("Only 1 log expected", 1, logs.size());
assertEquals("Incorrect variable val", "val-a", logs.get(0).getValue());
assertEquals("Incorrect variable old val", "oldVal-4", logs.get(0).getOldValue());
removeEntities(testData);
}
use of org.jbpm.process.audit.VariableInstanceLog in project jbpm by kiegroup.
the class ServicesAwareAuditEventBuilder method buildEvent.
@Override
public AuditEvent buildEvent(ProcessVariableChangedEvent pvce) {
VariableInstanceLog variableLog = (VariableInstanceLog) super.buildEvent(pvce);
variableLog.setExternalId(deploymentUnitId);
return variableLog;
}
Aggregations