Search in sources :

Example 1 with IRuleHelper

use of org.jaffa.rules.rulemeta.IRuleHelper in project jaffa-framework by jaffa-projects.

the class CxfFunctionGuardInterceptor method getPropertyRuleMap.

/**
 * Returns a Map containing a List of RuleMetaData instances per propertyName for the className+ruleName combination.
 * The class-level RuleMetaData instances defined for the className+ruleName combination will be added to the Map with propertyName null.
 * The className is obtained from the targetClass.
 *
 * @param targetClassName The target Class.
 * @param ruleName        the rule to search for.
 * @return A Map containing a List of RuleMetaData instances per propertyName for the className+ruleName combination.
 * @throws ApplicationExceptions if any application exception occurs.
 * @throws FrameworkException    if any internal error occurs.
 */
private Map<String, List<RuleMetaData>> getPropertyRuleMap(String targetClassName, String ruleName) throws ApplicationExceptions, FrameworkException {
    if (targetClassName == null) {
        return null;
    }
    Map<String, List<RuleMetaData>> map = MetaDataRepository.instance().getPropertyRuleMap(targetClassName, ruleName);
    if (map == null) {
        return null;
    }
    IRuleHelper ruleHelper = RuleHelperFactory.instance(ruleName);
    Map<String, List<RuleMetaData>> newMap = null;
    for (Map.Entry<String, List<RuleMetaData>> me : map.entrySet()) {
        List<RuleMetaData> rules = ruleHelper.getApplicableRules(targetClassName, null, me.getValue(), true);
        if (rules != null && rules.size() > 0) {
            if (newMap == null) {
                newMap = new LinkedHashMap<>();
            }
            newMap.put(me.getKey(), rules);
        }
    }
    return newMap;
}
Also used : IRuleHelper(org.jaffa.rules.rulemeta.IRuleHelper) List(java.util.List) RuleMetaData(org.jaffa.rules.meta.RuleMetaData) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with IRuleHelper

use of org.jaffa.rules.rulemeta.IRuleHelper in project jaffa-framework by jaffa-projects.

the class MetaDataAuditIntrospector method findPropertyRuleMap.

/**
 * Returns a Map of propertyName and first applicable rule for the className/ruleName combination.
 */
private Map<String, RuleMetaData> findPropertyRuleMap(String className, Object obj, String ruleName) {
    try {
        Map<String, List<RuleMetaData>> ruleMap = MetaDataRepository.instance().getPropertyRuleMap(className, ruleName);
        if (ruleMap != null) {
            Map<String, RuleMetaData> output = new LinkedHashMap<String, RuleMetaData>();
            IRuleHelper ruleHelper = new AuditRuleHelper();
            for (Map.Entry<String, List<RuleMetaData>> me : ruleMap.entrySet()) {
                List<RuleMetaData> applicableRules = ruleHelper.getApplicableRules(className, obj, me.getValue(), false);
                if (applicableRules != null && applicableRules.size() > 0)
                    output.put(me.getKey(), applicableRules.get(0));
            }
            return output;
        }
    } catch (Exception e) {
        // do nothing
        if (log.isDebugEnabled())
            log.debug("Error in finding the applicable rules of type " + ruleName, e);
    }
    return null;
}
Also used : IRuleHelper(org.jaffa.rules.rulemeta.IRuleHelper) List(java.util.List) AuditRuleHelper(org.jaffa.rules.rulemeta.AuditRuleHelper) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with IRuleHelper

use of org.jaffa.rules.rulemeta.IRuleHelper in project jaffa-framework by jaffa-projects.

the class MetaDataIntrospector method findPropertyRulesMap.

/**
 * Returns a Map of propertyName and applicable rules for the className/ruleName combination.
 */
private Map<String, List<RuleMetaData>> findPropertyRulesMap(String className, Object obj, String ruleName) {
    try {
        Map<String, List<RuleMetaData>> ruleMap = MetaDataRepository.instance().getPropertyRuleMap(className, ruleName);
        if (ruleMap != null) {
            Map<String, List<RuleMetaData>> output = new LinkedHashMap<String, List<RuleMetaData>>();
            IRuleHelper ruleHelper = RuleHelperFactory.instance(ruleName);
            for (Map.Entry<String, List<RuleMetaData>> me : ruleMap.entrySet()) {
                List<RuleMetaData> applicableRules = ruleHelper.getApplicableRules(className, obj, me.getValue(), false);
                if (applicableRules != null && applicableRules.size() > 0)
                    output.put(me.getKey(), applicableRules);
            }
            return output;
        }
    } catch (Exception e) {
        // do nothing
        if (log.isDebugEnabled())
            log.debug("Error in finding the applicable rules of type " + ruleName, e);
    }
    return null;
}
Also used : IRuleHelper(org.jaffa.rules.rulemeta.IRuleHelper) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with IRuleHelper

use of org.jaffa.rules.rulemeta.IRuleHelper in project jaffa-framework by jaffa-projects.

the class RuleActor method getPropertyRuleMap.

/**
 * Returns a Map containing a List of RuleMetaData instances per propertyName for the className+ruleName combination.
 * The class-level RuleMetaData instances defined for the className+ruleName combination will be added to the Map with propertyName null.
 * The className is obtained from the targetClass.
 *
 * @param targetClassName The target Class.
 * @param ruleName        the rule to search for.
 * @return a Map containing a List of RuleMetaData instances per propertyName for the className+ruleName combination.
 * @throws ApplicationExceptions if any application exception occurs.
 * @throws FrameworkException    if any internal error occurs.
 */
protected Map<String, List<RuleMetaData>> getPropertyRuleMap(String targetClassName, String ruleName) throws ApplicationExceptions, FrameworkException {
    if (targetClassName != null) {
        Map<String, List<RuleMetaData>> map = MetaDataRepository.instance().getPropertyRuleMap(targetClassName, ruleName);
        if (map != null) {
            IRuleHelper ruleHelper = RuleHelperFactory.instance(ruleName);
            Map<String, List<RuleMetaData>> newMap = null;
            for (Map.Entry<String, List<RuleMetaData>> me : map.entrySet()) {
                List<RuleMetaData> rules = ruleHelper.getApplicableRules(targetClassName, me.getValue(), true);
                if (rules != null && rules.size() > 0) {
                    if (newMap == null) {
                        newMap = new LinkedHashMap<>();
                    }
                    newMap.put(me.getKey(), rules);
                }
            }
            map = newMap;
        }
        return map;
    } else {
        return null;
    }
}
Also used : IRuleHelper(org.jaffa.rules.rulemeta.IRuleHelper) RuleMetaData(org.jaffa.rules.meta.RuleMetaData)

Example 5 with IRuleHelper

use of org.jaffa.rules.rulemeta.IRuleHelper in project jaffa-framework by jaffa-projects.

the class RuleValidatorFactory method getPropertyRuleMap.

/**
 * Returns a Map containing a List of RuleMetaData instances per propertyName for the className+ruleName combination.
 * The class-level RuleMetaData instances defined for the className+ruleName combination will be added to the Map with propertyName null.
 * The className is obtained from the targetClass.
 *
 * @param targetClassName The target Class.
 * @param ruleName        the rule to search for.
 * @return a Map containing a List of RuleMetaData instances per propertyName for the className+ruleName combination.
 * @throws org.jaffa.exceptions.ApplicationExceptions if any application exception occurs.
 * @throws org.jaffa.exceptions.FrameworkException    if any internal error occurs.
 */
protected Map<String, List<RuleMetaData>> getPropertyRuleMap(String targetClassName, String ruleName) throws ApplicationExceptions, FrameworkException {
    if (targetClassName != null) {
        Map<String, List<RuleMetaData>> map = MetaDataRepository.instance().getPropertyRuleMap(targetClassName, ruleName);
        if (map != null) {
            IRuleHelper ruleHelper = RuleHelperFactory.instance(ruleName);
            Map<String, List<RuleMetaData>> newMap = null;
            for (Map.Entry<String, List<RuleMetaData>> me : map.entrySet()) {
                List<RuleMetaData> rules = ruleHelper.getApplicableRules(targetClassName, me.getValue(), true);
                if (rules != null && rules.size() > 0) {
                    if (newMap == null)
                        newMap = new LinkedHashMap<>();
                    newMap.put(me.getKey(), rules);
                }
            }
            map = newMap;
        }
        return map;
    } else {
        return null;
    }
}
Also used : IRuleHelper(org.jaffa.rules.rulemeta.IRuleHelper) ArrayList(java.util.ArrayList) List(java.util.List) RuleMetaData(org.jaffa.rules.meta.RuleMetaData) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

IRuleHelper (org.jaffa.rules.rulemeta.IRuleHelper)10 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 Map (java.util.Map)6 RuleMetaData (org.jaffa.rules.meta.RuleMetaData)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Fault (org.apache.cxf.interceptor.Fault)1 CxfFunctionGuardInterceptor (org.jaffa.rules.interceptors.CxfFunctionGuardInterceptor)1 MetaDataRepository (org.jaffa.rules.meta.MetaDataRepository)1 AuditRuleHelper (org.jaffa.rules.rulemeta.AuditRuleHelper)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1