use of org.jaffa.rules.meta.PropertyMetaData in project jaffa-framework by jaffa-projects.
the class MetaDataReader method classMetaDataToDto.
/**
* Convert a list of ClassMetaData objects into an array of ClassMetaDataDto
* objects
*/
private static ClassMetaDataDto[] classMetaDataToDto(List<ClassMetaData> classMetaData, Boolean returnProperties, Boolean aggregate) {
if (classMetaData == null)
return null;
List<ClassMetaDataDto> returnCmd = new LinkedList<ClassMetaDataDto>();
for (ClassMetaData metaData : classMetaData) {
ClassMetaDataDto dto = new ClassMetaDataDto();
dto.setName(metaData.getName());
dto.setSourceFileName(metaData.getSource());
dto.setCondition(metaData.getCondition());
dto.setLanguage(metaData.getLanguage());
dto.setVariation(metaData.getVariation());
dto.setExecutionRealm(metaData.getExecutionRealm());
dto.setExtendsClass(metaData.getExtendsClass());
// Load rules into dto
List<RuleMetaDataDto> ruleMetaDataDtos = new LinkedList<RuleMetaDataDto>();
List<RuleMetaData> rules = metaData.getRules();
if (rules != null) {
for (RuleMetaData rmd : rules) {
RuleMetaDataDto ruleMetaDataDto = new RuleMetaDataDto();
ruleMetaDataDto.setRuleName(rmd.getName());
ruleMetaDataDto.setVariation(rmd.getVariation());
ruleMetaDataDto.setVariationArray(rmd.getVariationArray());
ruleMetaDataDto.setParameters(rmd.getParameters());
ruleMetaDataDtos.add(ruleMetaDataDto);
}
}
dto.setRules(ruleMetaDataDtos);
// Load properties into dto
if (returnProperties != null && returnProperties) {
List<PropertyMetaDataDto> propertyMetaDataDtos = new LinkedList<PropertyMetaDataDto>();
List<PropertyMetaData> props = metaData.getProperties();
if (props != null) {
for (PropertyMetaData pmd : props) {
PropertyMetaDataDto propertyMetaDataDto = new PropertyMetaDataDto();
propertyMetaDataDto.setPropertyName(pmd.getName());
propertyMetaDataDto.setCondition(pmd.getCondition());
propertyMetaDataDto.setLanguage(pmd.getLanguage());
propertyMetaDataDto.setVariation(pmd.getVariation());
propertyMetaDataDto.setExtendsClass(pmd.getExtendsClass());
propertyMetaDataDto.setExtendsProperty(pmd.getExtendsProperty());
// Load rules into dto
List<RuleMetaDataDto> propertyRuleMetaDataDtos = new LinkedList<RuleMetaDataDto>();
List<RuleMetaData> propertyRules = pmd.getRules(metaData.getName());
if (propertyRules != null) {
for (RuleMetaData rmd : propertyRules) {
RuleMetaDataDto ruleMetaDataDto = new RuleMetaDataDto();
ruleMetaDataDto.setRuleName(rmd.getName());
ruleMetaDataDto.setVariation(rmd.getVariation());
ruleMetaDataDto.setVariationArray(rmd.getVariationArray());
ruleMetaDataDto.setParameters(rmd.getParameters());
propertyRuleMetaDataDtos.add(ruleMetaDataDto);
}
}
propertyMetaDataDto.setRules(propertyRuleMetaDataDtos);
propertyMetaDataDtos.add(propertyMetaDataDto);
}
}
dto.setProperties(propertyMetaDataDtos);
}
returnCmd.add(dto);
}
return (ClassMetaDataDto[]) returnCmd.toArray(new ClassMetaDataDto[returnCmd.size()]);
}
use of org.jaffa.rules.meta.PropertyMetaData in project jaffa-framework by jaffa-projects.
the class RuleValidatorFactory method createValidator.
/**
* Creates a validator.
*
* @param className the name of the class to create a validator for.
* @param metaDataList the class meta data to create a validator from.
* @return a validator.
*/
private Validator<?> createValidator(String className, List<ClassMetaData> metaDataList) {
// create a validator to collect all rule validators for this class
BatchValidator<?> resultValidator = new BatchValidator();
// associated with the class
for (ClassMetaData classMetaData : metaDataList) {
// Retrieve class-level rules
List<RuleMetaData> allRulesForClass = classMetaData.getClassRules();
if (allRulesForClass != null) {
for (RuleMetaData ruleMetaData : allRulesForClass) {
String ruleName = ruleMetaData.getName();
try {
// get the map of rules that apply to the class in new condition
Map<String, List<RuleMetaData>> ruleMap = getPropertyRuleMap(className, ruleName);
// look up the validator from the context
RuleValidator foundValidator = (RuleValidator) lookupValidator(ruleName);
if (ruleMap != null && !ruleMap.isEmpty() && foundValidator != null) {
// add the property map to the validator which was found in the context
foundValidator.setRuleMap(ruleMap);
// save the validator to the batch validator
if (!resultValidator.getValidatorSet().contains(foundValidator))
resultValidator.getValidatorSet().add(foundValidator);
}
} catch (Exception e) {
logger.error("Error occurred creating validator for rule: " + ruleName + " while getting property rule map");
}
}
}
List<PropertyMetaData> propertyMetaDataList = classMetaData.getProperties();
if (propertyMetaDataList != null) {
// iterate list of properties for this class to determine rules associated with it.
for (PropertyMetaData propertyMetaData : propertyMetaDataList) {
List<RuleMetaData> allRulesForProperty = propertyMetaData.getRules(className);
if (allRulesForProperty != null) {
// constructed validator
for (RuleMetaData ruleMetaData : allRulesForProperty) {
String ruleName = ruleMetaData.getName();
try {
// get the map of rules that apply to the class in new condition
Map<String, List<RuleMetaData>> ruleMap = getPropertyRuleMap(className, ruleName);
// look up the validator from the context
RuleValidator foundValidator = (RuleValidator) lookupValidator(ruleName);
if (ruleMap != null && !ruleMap.isEmpty() && foundValidator != null) {
// add the property map to the validator which was found in the context
foundValidator.setRuleMap(ruleMap);
// save the validator to the batch validator
if (!resultValidator.getValidatorSet().contains(foundValidator)) {
resultValidator.getValidatorSet().add(foundValidator);
} else {
// if a validator of the same type exists in the batch, extract the rule meta
// / data and append to the existing property map
appendPropertyRule(resultValidator, foundValidator, ruleMap);
}
}
} catch (Exception e) {
logger.error("Error occurred creating validator for rule: " + ruleName + " while getting property rule map");
}
}
}
}
}
}
return resultValidator;
}
Aggregations