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());
}
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());
}
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());
}
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);
}
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;
}
Aggregations