Search in sources :

Example 1 with FieldStandardizationRule

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

the class TestStandardizationTransform method testDateTime.

@Test
public void testDateTime() throws IOException {
    String FORMAT = "MM/dd/YYYY";
    DateTimeStandardizer standardizer = new DateTimeStandardizer(FORMAT, DateTimeStandardizer.OutputFormats.DATETIME_NOMILLIS);
    FieldStandardizationRule uiModel = StandardizationAnnotationTransformer.instance().toUIModel(standardizer);
    DateTimeStandardizer convertedPolicy = fromUI(uiModel, DateTimeStandardizer.class);
    Assert.assertEquals(FORMAT, convertedPolicy.getInputDateFormat());
    Assert.assertEquals(DateTimeStandardizer.OutputFormats.DATETIME_NOMILLIS, convertedPolicy.getOutputFormat());
}
Also used : DateTimeStandardizer(com.thinkbiganalytics.policy.standardization.DateTimeStandardizer) FieldStandardizationRule(com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule) Test(org.junit.Test)

Example 2 with FieldStandardizationRule

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

the class TestStandardizationTransform method testSimpleRegexReplacer.

@Test
public void testSimpleRegexReplacer() throws IOException {
    String regex = "\\p{Cc}";
    String replace = "REPLACE";
    SimpleRegexReplacer standardizer = new SimpleRegexReplacer(regex, replace);
    FieldStandardizationRule uiModel = StandardizationAnnotationTransformer.instance().toUIModel(standardizer);
    SimpleRegexReplacer convertedPolicy = fromUI(uiModel, SimpleRegexReplacer.class);
    Assert.assertEquals(regex, convertedPolicy.getPattern().pattern());
    Assert.assertEquals(replace, convertedPolicy.getReplacement());
    Assert.assertEquals(true, convertedPolicy.isValid());
}
Also used : SimpleRegexReplacer(com.thinkbiganalytics.policy.standardization.SimpleRegexReplacer) FieldStandardizationRule(com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule) Test(org.junit.Test)

Example 3 with FieldStandardizationRule

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

the class TestStandardizationTransform method testUiCreation.

@Test
public void testUiCreation() {
    List<FieldStandardizationRule> standardizationRules = AvailablePolicies.discoverStandardizationRules();
    FieldStandardizationRule defaultValue = Iterables.tryFind(standardizationRules, new PredicateImpl<FieldStandardizationRule>() {

        @Override
        public boolean test(FieldStandardizationRule fieldStandardizationRule) {
            return fieldStandardizationRule.getName().equalsIgnoreCase("Default Value");
        }
    }).orNull();
    defaultValue.getProperty("Default Value").setValue("a new default value");
    DefaultValueStandardizer convertedPolicy = fromUI(defaultValue, DefaultValueStandardizer.class);
    Assert.assertEquals("a new default value", convertedPolicy.getDefaultStr());
}
Also used : DefaultValueStandardizer(com.thinkbiganalytics.policy.standardization.DefaultValueStandardizer) PredicateImpl(com.thinkbiganalytics.guava.PredicateImpl) FieldStandardizationRule(com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule) Test(org.junit.Test)

Example 4 with FieldStandardizationRule

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

the class TestStandardizationTransform method testMaskLeavingLastFourDigitStandardizer.

@Test
public void testMaskLeavingLastFourDigitStandardizer() throws IOException {
    MaskLeavingLastFourDigitStandardizer standardizer = MaskLeavingLastFourDigitStandardizer.instance();
    FieldStandardizationRule uiModel = StandardizationAnnotationTransformer.instance().toUIModel(standardizer);
    MaskLeavingLastFourDigitStandardizer convertedPolicy = fromUI(uiModel, MaskLeavingLastFourDigitStandardizer.class);
    Assert.assertEquals(standardizer, convertedPolicy);
}
Also used : MaskLeavingLastFourDigitStandardizer(com.thinkbiganalytics.policy.standardization.MaskLeavingLastFourDigitStandardizer) FieldStandardizationRule(com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule) Test(org.junit.Test)

Example 5 with FieldStandardizationRule

use of com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule 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)

Aggregations

FieldStandardizationRule (com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule)16 Test (org.junit.Test)12 FieldValidationRule (com.thinkbiganalytics.policy.rest.model.FieldValidationRule)6 DefaultValueStandardizer (com.thinkbiganalytics.policy.standardization.DefaultValueStandardizer)3 ArrayList (java.util.ArrayList)3 DefaultTag (com.thinkbiganalytics.discovery.model.DefaultTag)2 FieldPolicy (com.thinkbiganalytics.policy.rest.model.FieldPolicy)2 DateTimeStandardizer (com.thinkbiganalytics.policy.standardization.DateTimeStandardizer)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 DefaultField (com.thinkbiganalytics.discovery.model.DefaultField)1 Field (com.thinkbiganalytics.discovery.schema.Field)1 Tag (com.thinkbiganalytics.discovery.schema.Tag)1 DomainType (com.thinkbiganalytics.feedmgr.rest.model.DomainType)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