@Override public ValidationResult preEntitlement( Consumer consumer, Pool entitlementPool, Integer quantity) { jsRules.reinitTo("entitlement_name_space"); rulesInit(); return new ValidationResult(); }
protected void rulesInit() { String mappings; try { mappings = jsRules.invokeMethod("attribute_mappings"); this.attributesToRules = parseAttributeMappings(mappings); } catch (RhinoException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
protected void invokeGlobalPostUnbindRule(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 { jsRules.invokeMethod(GLOBAL_POST_FUNCTION, context); log.debug("Ran rule: " + GLOBAL_POST_FUNCTION); } catch (NoSuchMethodException ex) { // This is fine, I hope... log.warn("No default rule found: " + GLOBAL_POST_FUNCTION); } catch (RhinoException ex) { throw new RuleExecutionException(ex); } }
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; }
protected void callPostUnbindRules(List<Rule> matchingRules) { for (Rule rule : matchingRules) { jsRules.invokeRule(POST_PREFIX + rule.getRuleName()); } }