Search in sources :

Example 6 with FieldValidationRule

use of com.thinkbiganalytics.policy.rest.model.FieldValidationRule in project kylo by Teradata.

the class TestValidationTransformation method testRangeValidator.

@Test
@Ignore
public void testRangeValidator() {
    Integer min = 10;
    Integer max = 20;
    RangeValidator validator = new RangeValidator(min, max);
    FieldValidationRule uiModel = ValidatorAnnotationTransformer.instance().toUIModel(validator);
    RangeValidator convertedValidator = fromUI(uiModel, RangeValidator.class);
    Assert.assertEquals(min, convertedValidator.getMin());
    Assert.assertEquals(max, convertedValidator.getMin());
}
Also used : FieldValidationRule(com.thinkbiganalytics.policy.rest.model.FieldValidationRule) RangeValidator(com.thinkbiganalytics.policy.validation.RangeValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with FieldValidationRule

use of com.thinkbiganalytics.policy.rest.model.FieldValidationRule in project kylo by Teradata.

the class TestValidationTransformation method testEmailValidator.

@Test
public void testEmailValidator() {
    EmailValidator validator = EmailValidator.instance();
    FieldValidationRule uiModel = ValidatorAnnotationTransformer.instance().toUIModel(validator);
    EmailValidator convertedValidator = fromUI(uiModel, EmailValidator.class);
    Assert.assertEquals(validator, convertedValidator);
}
Also used : EmailValidator(com.thinkbiganalytics.policy.validation.EmailValidator) FieldValidationRule(com.thinkbiganalytics.policy.rest.model.FieldValidationRule) Test(org.junit.Test)

Example 8 with FieldValidationRule

use of com.thinkbiganalytics.policy.rest.model.FieldValidationRule in project kylo by Teradata.

the class TestValidationTransformation method testTimestampValidator.

@Test
public void testTimestampValidator() {
    TimestampValidator validator = new TimestampValidator(false);
    FieldValidationRule uiModel = ValidatorAnnotationTransformer.instance().toUIModel(validator);
    TimestampValidator convertedValidator = fromUI(uiModel, TimestampValidator.class);
    Assert.assertEquals(validator.isAllowNull(), convertedValidator.isAllowNull());
}
Also used : FieldValidationRule(com.thinkbiganalytics.policy.rest.model.FieldValidationRule) TimestampValidator(com.thinkbiganalytics.policy.validation.TimestampValidator) Test(org.junit.Test)

Example 9 with FieldValidationRule

use of com.thinkbiganalytics.policy.rest.model.FieldValidationRule in project kylo by Teradata.

the class AvailablePolicies method discoverValidationRules.

public static List<FieldValidationRule> discoverValidationRules() {
    List<FieldValidationRule> rules = new ArrayList<>();
    Set<Class<?>> validators = ReflectionPolicyAnnotationDiscoverer.getTypesAnnotatedWith(Validator.class);
    for (Class c : validators) {
        Validator validator = (Validator) c.getAnnotation(Validator.class);
        List<FieldRuleProperty> properties = ValidatorAnnotationTransformer.instance().getUiProperties(c);
        rules.add(new FieldValidationRuleBuilder(validator.name()).description(validator.description()).addProperties(properties).objectClassType(c).build());
    }
    return rules;
}
Also used : FieldValidationRule(com.thinkbiganalytics.policy.rest.model.FieldValidationRule) FieldValidationRuleBuilder(com.thinkbiganalytics.policy.rest.model.FieldValidationRuleBuilder) ArrayList(java.util.ArrayList) FieldRuleProperty(com.thinkbiganalytics.policy.rest.model.FieldRuleProperty) Validator(com.thinkbiganalytics.policy.validation.Validator)

Example 10 with FieldValidationRule

use of com.thinkbiganalytics.policy.rest.model.FieldValidationRule in project kylo by Teradata.

the class FieldPoliciesJsonTransformer method augmentPartitionColumnValidation.

public void augmentPartitionColumnValidation() {
    log.info("Augmenting partition column validation");
    for (com.thinkbiganalytics.policy.rest.model.FieldPolicy uiFieldPolicy : uiFieldPolicies) {
        if (uiFieldPolicy.isPartitionColumn()) {
            log.info("Found a partition column: " + uiFieldPolicy.getFieldName());
            boolean augmentRule = true;
            List<FieldValidationRule> currentValidationRules = uiFieldPolicy.getValidation();
            if (currentValidationRules != null) {
                log.info("There are validation rules already set for " + uiFieldPolicy.getFieldName());
                for (FieldValidationRule fieldValidationRule : currentValidationRules) {
                    if (fieldValidationRule.getObjectClassType().equals("com.thinkbiganalytics.policy.validation.NotNullValidator") || (fieldValidationRule.getObjectShortClassType().equals("NotNullValidator"))) {
                        log.info("NotNull validation rule already set for " + uiFieldPolicy.getFieldName());
                        augmentRule = false;
                    }
                }
            }
            if (augmentRule) {
                log.info("Augmenting the field " + uiFieldPolicy.getFieldName() + " with NotNull validation rule");
                if (currentValidationRules == null) {
                    currentValidationRules = new ArrayList<>();
                }
                FieldValidationRule fvRule = new FieldValidationRule();
                fvRule.setName("Partition Column Not Null");
                fvRule.setObjectClassType("com.thinkbiganalytics.policy.validation.NotNullValidator");
                fvRule.setObjectShortClassType("NotNullValidator");
                List<FieldRuleProperty> fieldRulePropertyList = new ArrayList<>();
                FieldRuleProperty fieldRuleProperty1 = new FieldRuleProperty();
                fieldRuleProperty1.setName("EMPTY_STRING");
                fieldRuleProperty1.setDisplayName(null);
                fieldRuleProperty1.setValue("false");
                fieldRuleProperty1.setPlaceholder(null);
                fieldRuleProperty1.setType(null);
                fieldRuleProperty1.setHint(null);
                fieldRuleProperty1.setObjectProperty("allowEmptyString");
                fieldRuleProperty1.setRequired(false);
                fieldRuleProperty1.setGroup(null);
                fieldRuleProperty1.setLayout(null);
                fieldRuleProperty1.setHidden(false);
                fieldRuleProperty1.setPattern(null);
                fieldRuleProperty1.setPatternInvalidMessage(null);
                FieldRuleProperty fieldRuleProperty2 = new FieldRuleProperty();
                fieldRuleProperty2.setName("TRIM_STRING");
                fieldRuleProperty2.setDisplayName(null);
                fieldRuleProperty2.setValue("true");
                fieldRuleProperty2.setPlaceholder(null);
                fieldRuleProperty2.setType(null);
                fieldRuleProperty2.setHint(null);
                fieldRuleProperty2.setObjectProperty("trimString");
                fieldRuleProperty2.setRequired(false);
                fieldRuleProperty2.setGroup(null);
                fieldRuleProperty2.setLayout(null);
                fieldRuleProperty2.setHidden(false);
                fieldRuleProperty2.setPattern(null);
                fieldRuleProperty2.setPatternInvalidMessage(null);
                fieldRulePropertyList.add(fieldRuleProperty1);
                fieldRulePropertyList.add(fieldRuleProperty2);
                fvRule.setProperties(fieldRulePropertyList);
                currentValidationRules.add(fvRule);
                log.info("Added rule for NotNull validation on " + uiFieldPolicy.getFieldName());
                uiFieldPolicy.setValidation(currentValidationRules);
            }
        }
    }
}
Also used : FieldValidationRule(com.thinkbiganalytics.policy.rest.model.FieldValidationRule) ArrayList(java.util.ArrayList) FieldRuleProperty(com.thinkbiganalytics.policy.rest.model.FieldRuleProperty)

Aggregations

FieldValidationRule (com.thinkbiganalytics.policy.rest.model.FieldValidationRule)17 Test (org.junit.Test)14 FieldStandardizationRule (com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule)4 ArrayList (java.util.ArrayList)4 FieldRuleProperty (com.thinkbiganalytics.policy.rest.model.FieldRuleProperty)2 RangeValidator (com.thinkbiganalytics.policy.validation.RangeValidator)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 DefaultTag (com.thinkbiganalytics.discovery.model.DefaultTag)1 EntityDifference (com.thinkbiganalytics.feedmgr.rest.model.EntityDifference)1 EntityVersion (com.thinkbiganalytics.feedmgr.rest.model.EntityVersion)1 EntityVersionDifference (com.thinkbiganalytics.feedmgr.rest.model.EntityVersionDifference)1 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)1 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)1 FeedVersions (com.thinkbiganalytics.feedmgr.rest.model.FeedVersions)1 ImportTemplate (com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate)1 Diff (com.thinkbiganalytics.integration.Diff)1 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)1 BaseUiPolicyRule (com.thinkbiganalytics.policy.rest.model.BaseUiPolicyRule)1