AAI-1523 Batch reformat aai-schema-ingest
[aai/aai-common.git] / aai-schema-ingest / src / main / java / org / onap / aai / validation / edges / CousinDefaultingValidationModule.java
index d4ab7ae..73337a4 100644 (file)
 package org.onap.aai.validation.edges;
 
 import com.jayway.jsonpath.DocumentContext;
+
+import java.util.*;
+
 import org.onap.aai.edges.EdgeRuleQuery;
 import org.onap.aai.edges.EdgeRuleQuery.Builder;
 import org.onap.aai.edges.enums.EdgeField;
 import org.onap.aai.edges.enums.EdgeType;
 
-import java.util.*;
-
 /**
  * Validates that in the collection of cousin rules between a given node type pair,
- * there is exactly 1 set default=true. 
+ * there is exactly 1 set default=true.
  */
 public class CousinDefaultingValidationModule {
 
-       /**
-        * Validates that in the collection of cousin rules between a given node type pair,
-        * there is exactly 1 set default=true. 
-        * 
-        * @param String nodeTypePair - pair of A&AI node types in the form "typeA|typeB"
-        * @param List<DocumentContext> ctxs - the ingested json schema to validate
-        * @return empty string if ok, appropriate error message otherwise
-        */
-       public String validate(String nodeTypePair, List<DocumentContext> ctxs) {
-               String[] types = nodeTypePair.split("\\|");
-               EdgeRuleQuery lookup = new Builder(types[0], types[1]).edgeType(EdgeType.COUSIN).build();
-               List<Map<String, String>> rules = new ArrayList<>();
-               for (DocumentContext ctx : ctxs) {
-                       rules.addAll(ctx.read("$.rules.[?]", lookup.getFilter()));
-               }
-               
-               if (rules.isEmpty()) {
-                       return ""; //bc irrelevant check
-               }
-               
-               int defaultCount = 0;
-               Set<String> defLabels = new HashSet<>();
-               for (Map<String, String> rule : rules) {
-                       if ("true".equals(rule.get(EdgeField.DEFAULT.toString()))) {
-                               defaultCount++;
-                               defLabels.add(rule.get(EdgeField.LABEL.toString()));
-                       }
-               }
-               
-               StringBuilder errorBase = new StringBuilder().append("Pair ").append(nodeTypePair).append(" must have exactly one cousin rule set as default. ");
-               if (defaultCount == 1) {
-                       return "";
-               } else if (defaultCount == 0){
-                       errorBase.append("None set.");
-                       return errorBase.toString();
-               } else {
-                       errorBase.append("Multiple set, see labels: ");
-                       for (String label : defLabels) {
-                               errorBase.append(label).append(" ");
-                       }
-                       return errorBase.toString();
-               }
-       }
+    /**
+     * Validates that in the collection of cousin rules between a given node type pair,
+     * there is exactly 1 set default=true.
+     * 
+     * @param String nodeTypePair - pair of A&AI node types in the form "typeA|typeB"
+     * @param List<DocumentContext> ctxs - the ingested json schema to validate
+     * @return empty string if ok, appropriate error message otherwise
+     */
+    public String validate(String nodeTypePair, List<DocumentContext> ctxs) {
+        String[] types = nodeTypePair.split("\\|");
+        EdgeRuleQuery lookup = new Builder(types[0], types[1]).edgeType(EdgeType.COUSIN).build();
+        List<Map<String, String>> rules = new ArrayList<>();
+        for (DocumentContext ctx : ctxs) {
+            rules.addAll(ctx.read("$.rules.[?]", lookup.getFilter()));
+        }
+
+        if (rules.isEmpty()) {
+            return ""; // bc irrelevant check
+        }
+
+        int defaultCount = 0;
+        Set<String> defLabels = new HashSet<>();
+        for (Map<String, String> rule : rules) {
+            if ("true".equals(rule.get(EdgeField.DEFAULT.toString()))) {
+                defaultCount++;
+                defLabels.add(rule.get(EdgeField.LABEL.toString()));
+            }
+        }
+
+        StringBuilder errorBase = new StringBuilder().append("Pair ").append(nodeTypePair)
+                .append(" must have exactly one cousin rule set as default. ");
+        if (defaultCount == 1) {
+            return "";
+        } else if (defaultCount == 0) {
+            errorBase.append("None set.");
+            return errorBase.toString();
+        } else {
+            errorBase.append("Multiple set, see labels: ");
+            for (String label : defLabels) {
+                errorBase.append(label).append(" ");
+            }
+            return errorBase.toString();
+        }
+    }
 }