protected ValidationResult invokeGlobalPreEntitlementRule(JsContext context) { // No method for this product, try to find a global function, if // neither exists this is ok and we'll just carry on. try { String resultJson = jsRules.invokeMethod(GLOBAL_PRE_FUNCTION, context); log.debug("Ran rule: " + GLOBAL_PRE_FUNCTION); return objectMapper.toObject(resultJson, ValidationResult.class); } catch (NoSuchMethodException ex) { // This is fine, I hope... log.warn("No default rule found: " + GLOBAL_PRE_FUNCTION); } catch (Exception ex) { throw new RuleExecutionException(ex); } return new ValidationResult(); }
protected ValidationResult callPreEntitlementRules(List<Rule> matchingRules, JsContext context) { ValidationResult result = new ValidationResult(); for (Rule rule : matchingRules) { String validationJson = jsRules.invokeRule(PRE_PREFIX + rule.getRuleName(), context); // If the resulting validation json is empty, either the method // did not exist in the rules, or the method did not return // anything. In this case we skip the result. if (validationJson == null) { continue; } result.add(objectMapper.toObject(validationJson, ValidationResult.class)); } return result; }