aboutsummaryrefslogtreecommitdiffstats
path: root/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java
diff options
context:
space:
mode:
Diffstat (limited to 'aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java')
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java94
1 files changed, 48 insertions, 46 deletions
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java
index d4ab7aeb..73337a49 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java
@@ -21,60 +21,62 @@
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();
+ }
+ }
}