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