Search in sources :

Example 1 with BaseUiPolicyRule

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;
}
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

BaseUiPolicyRule (com.thinkbiganalytics.policy.rest.model.BaseUiPolicyRule)1 FieldStandardizationRule (com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule)1 FieldValidationRule (com.thinkbiganalytics.policy.rest.model.FieldValidationRule)1 StandardizationPolicy (com.thinkbiganalytics.policy.standardization.StandardizationPolicy)1 ValidationPolicy (com.thinkbiganalytics.policy.validation.ValidationPolicy)1 ArrayList (java.util.ArrayList)1