Person person = new Person("salaboy");
person.addPhone(new Phone(person.getId(), "555-1235"));
StatefulKnowledgeSession ksession = createKSessionWithValidationById();
KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
Validation validation = new Validation("My Validation");
ksession.insert(validation);
if (person.getAddresses() != null) {
for (Address address : person.getAddresses()) {
ksession.insert(address);
}
}
if (person.getPhones() != null) {
for (Phone phone : person.getPhones()) {
ksession.insert(phone);
}
}
ksession.insert(person);
ksession.fireAllRules();
//Result for Random ID = 0
org.drools.runtime.rule.QueryResults results =
ksession.getQueryResults("getAllErrorsByValidationId", new Object[]{UUID.randomUUID().toString()});
assertEquals(0, results.size());
//Result for All Errors ID = 1
results =
ksession.getQueryResults("getAllErrors", new Object[]{});
assertEquals(1, results.size());
//Results for this validation = 1
results =
ksession.getQueryResults("getAllErrorsByValidationId", new Object[]{validation.getId()});
assertEquals(1, results.size());
for (QueryResultsRow row : results) {
System.out.println(">>> Error ( " + ((ErrorEntry) row.get("$error")).getError().toString() + ")");