Search in sources :

Example 1 with ValidationRule

use of org.commonjava.indy.promote.validate.model.ValidationRule in project indy by Commonjava.

the class ValidationRuleParser method parseRule.

public ValidationRuleMapping parseRule(final String spec, final String scriptName) throws PromotionValidationException {
    if (spec == null) {
        return null;
    }
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Parsing rule from: {} with content:\n{}\n", scriptName, spec);
    ValidationRule rule = null;
    try {
        rule = scriptEngine.parseScriptInstance(spec, ValidationRule.class);
        logger.debug("Parsed: {}", rule.getClass().getName());
    } catch (final IndyGroovyException e) {
        throw new PromotionValidationException("[PROMOTE] Cannot load validation rule from: {} as an instance of: {}. Reason: {}", e, scriptName, ValidationRule.class.getSimpleName(), e.getMessage());
    }
    if (rule != null) {
        return new ValidationRuleMapping(scriptName, spec, rule);
    }
    return null;
}
Also used : ValidationRuleMapping(org.commonjava.indy.promote.validate.model.ValidationRuleMapping) Logger(org.slf4j.Logger) IndyGroovyException(org.commonjava.indy.subsys.template.IndyGroovyException) ValidationRule(org.commonjava.indy.promote.validate.model.ValidationRule)

Aggregations

ValidationRule (org.commonjava.indy.promote.validate.model.ValidationRule)1 ValidationRuleMapping (org.commonjava.indy.promote.validate.model.ValidationRuleMapping)1 IndyGroovyException (org.commonjava.indy.subsys.template.IndyGroovyException)1 Logger (org.slf4j.Logger)1