use of gov.ca.cwds.drools.DroolsConfiguration in project api-core by ca-cwds.
the class DroolsValidator method isValid.
@Override
public boolean isValid(T obj, ConstraintValidatorContext context) {
if (obj == null) {
return true;
}
DroolsConfiguration<T> configuration = getConfiguration();
Object validatedFact = configuration.getValidatedFact(obj);
DroolsService droolsService = InjectorHolder.INSTANCE.getInstance(DroolsService.class);
Set<IssueDetails> detailsList = null;
try {
detailsList = droolsService.performBusinessRules(configuration, validatedFact);
} catch (DroolsException e) {
LOGGER.warn(e.getMessage(), e);
throw new RuntimeException(String.format(DroolsErrorMessages.CANT_PERFORM_BUSINESS_VALIDATION, configuration.getAgendaGroup()));
}
if (detailsList.isEmpty()) {
return true;
} else {
context.disableDefaultConstraintViolation();
detailsList.forEach((details -> context.buildConstraintViolationWithTemplate(marshallData(details)).addPropertyNode("").addConstraintViolation()));
return false;
}
}
Aggregations