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