Search in sources :

Example 1 with FieldValidationRule

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

the class FieldPolicyTransformer method getStandardizationAndValidationPolicies.

public List<BaseFieldPolicy> getStandardizationAndValidationPolicies() {
    List<BaseFieldPolicy> policies = new ArrayList<>();
    List<FieldStandardizationRule> standardization = uiFieldPolicy.getStandardization();
    List<FieldValidationRule> validation = uiFieldPolicy.getValidation();
    List<BaseUiPolicyRule> allUiPolicies = new ArrayList<>();
    if (standardization != null) {
        allUiPolicies.addAll(standardization);
    }
    if (validation != null) {
        allUiPolicies.addAll(validation);
    }
    // ensure the sequence is set
    int idx = 0;
    for (BaseUiPolicyRule rule : allUiPolicies) {
        if (rule.getSequence() == null) {
            rule.setSequence(idx);
        }
        idx++;
    }
    Collections.sort(allUiPolicies, new Comparator<BaseUiPolicyRule>() {

        @Override
        public int compare(BaseUiPolicyRule o1, BaseUiPolicyRule o2) {
            if (o1 == null && o2 == null) {
                return 0;
            }
            if (o1 == null && o2 != null) {
                return 1;
            }
            if (o1 != null && o2 == null) {
                return -1;
            }
            Integer sq1 = o1.getSequence();
            Integer sq2 = o2.getSequence();
            return sq1.compareTo(sq2);
        }
    });
    if (allUiPolicies != null) {
        for (BaseUiPolicyRule rule : allUiPolicies) {
            try {
                if (rule instanceof FieldStandardizationRule) {
                    StandardizationPolicy policy = StandardizationAnnotationTransformer.instance().fromUiModel((FieldStandardizationRule) rule);
                    policies.add(policy);
                    if (listener != null) {
                        listener.onAddStandardizationPolicy(policy);
                    }
                } else if (rule instanceof FieldValidationRule) {
                    ValidationPolicy policy = ValidatorAnnotationTransformer.instance().fromUiModel((FieldValidationRule) rule);
                    policies.add(policy);
                    if (listener != null) {
                        listener.onAddValidationPolicy(policy);
                    }
                }
            } catch (PolicyTransformException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return policies;
}
Also used : FieldValidationRule(com.thinkbiganalytics.policy.rest.model.FieldValidationRule) ArrayList(java.util.ArrayList) ValidationPolicy(com.thinkbiganalytics.policy.validation.ValidationPolicy) BaseUiPolicyRule(com.thinkbiganalytics.policy.rest.model.BaseUiPolicyRule) StandardizationPolicy(com.thinkbiganalytics.policy.standardization.StandardizationPolicy) FieldStandardizationRule(com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule)

Example 2 with FieldValidationRule

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

the class TestJsonPolicies method testJson.

@Test
public void testJson() throws IOException {
    List<com.thinkbiganalytics.policy.rest.model.FieldPolicy> fieldPolicies = new ArrayList<>();
    List<FieldStandardizationRule> standardizationPolicyList = new ArrayList<>();
    List<FieldValidationRule> validationRules = new ArrayList<>();
    DefaultValueStandardizer defaultValueStandardizer = new DefaultValueStandardizer("My Default");
    standardizationPolicyList.add(StandardizationAnnotationTransformer.instance().toUIModel(defaultValueStandardizer));
    DateTimeStandardizer dateTimeStandardizer = new DateTimeStandardizer("MM/DD/YYYY", DateTimeStandardizer.OutputFormats.DATETIME_NOMILLIS);
    standardizationPolicyList.add(StandardizationAnnotationTransformer.instance().toUIModel(dateTimeStandardizer));
    RangeValidator validator = new RangeValidator(10, 20);
    validationRules.add(ValidatorAnnotationTransformer.instance().toUIModel(validator));
    fieldPolicies.add(new FieldPolicyBuilder("field1").addStandardization(standardizationPolicyList).addValidations(validationRules).build());
    ObjectMapper mapper = new ObjectMapper();
    String json = mapper.writeValueAsString(fieldPolicies);
    FieldPoliciesJsonTransformer fieldPolicyTransformer = new FieldPoliciesJsonTransformer(json);
    Map<String, com.thinkbiganalytics.policy.FieldPolicy> policyMap = fieldPolicyTransformer.buildPolicies();
    com.thinkbiganalytics.policy.FieldPolicy field1Policy = policyMap.get("field1");
    Assert.assertEquals(2, field1Policy.getStandardizationPolicies().size());
    Assert.assertEquals(1, field1Policy.getValidators().size());
}
Also used : FieldValidationRule(com.thinkbiganalytics.policy.rest.model.FieldValidationRule) ArrayList(java.util.ArrayList) DefaultValueStandardizer(com.thinkbiganalytics.policy.standardization.DefaultValueStandardizer) FieldPolicyBuilder(com.thinkbiganalytics.policy.rest.model.FieldPolicyBuilder) RangeValidator(com.thinkbiganalytics.policy.validation.RangeValidator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FieldStandardizationRule(com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule) DateTimeStandardizer(com.thinkbiganalytics.policy.standardization.DateTimeStandardizer) Test(org.junit.Test)

Example 3 with FieldValidationRule

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

the class TestValidationTransformation method testNotNullValidator.

@Test
public void testNotNullValidator() {
    NotNullValidator validator = new NotNullValidator(false, true);
    FieldValidationRule uiModel = ValidatorAnnotationTransformer.instance().toUIModel(validator);
    NotNullValidator convertedValidator = fromUI(uiModel, NotNullValidator.class);
    Assert.assertFalse(convertedValidator.isAllowEmptyString());
    Assert.assertTrue(convertedValidator.isTrimString());
}
Also used : FieldValidationRule(com.thinkbiganalytics.policy.rest.model.FieldValidationRule) NotNullValidator(com.thinkbiganalytics.policy.validation.NotNullValidator) Test(org.junit.Test)

Example 4 with FieldValidationRule

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

the class TestValidationTransformation method testLookupValidator.

@Test
public void testLookupValidator() {
    String lookupList = "one,two,three";
    LookupValidator validator = new LookupValidator(lookupList);
    FieldValidationRule uiModel = ValidatorAnnotationTransformer.instance().toUIModel(validator);
    LookupValidator convertedValidator = fromUI(uiModel, LookupValidator.class);
    Assert.assertEquals(lookupList, convertedValidator.getLookupList());
    for (String value : StringUtils.split(lookupList, ",")) {
        Assert.assertTrue(value, convertedValidator.getLookupValues().contains(value));
    }
}
Also used : FieldValidationRule(com.thinkbiganalytics.policy.rest.model.FieldValidationRule) LookupValidator(com.thinkbiganalytics.policy.validation.LookupValidator) Test(org.junit.Test)

Example 5 with FieldValidationRule

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

the class TestValidationTransformation method testUSZipCodeValidator.

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

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