- //-----filter building helpers-----//
- /**
- * ANDs together the given start criteria with each criteria in the pieces list, and
- * then ORs together these segments into one filter.
- *
- * JsonPath doesn't have an OR method on Criteria, only on Filters, so assembling
- * a complete filter requires this sort of roundabout construction.
- *
- * @param start - Criteria of the form where(from/to).is(nodeType)
- * (ie the start of any A&AI edge rule query)
- * @param pieces - Other Criteria to be applied
- * @return Filter constructed from the given Criteria
- */
- private Filter assembleFilterSegments(Criteria start, List<Criteria> pieces) {
- List<Filter> segments = new ArrayList<>();
- for (Criteria c : pieces) {
- segments.add(filter(start).and(c));
- }
- Filter assembled = segments.remove(0);
- for (Filter f : segments) {
- assembled = assembled.or(f);
- }
- return assembled;
- }
-
- /**
- * Builds the sub-Criteria for a containment edge rule query where the direction
- * and containment fields must match.
- *
- * Used for getChildRules() where the container node type is in the "from" position and
- * for getParentRules() where the containee type is in the "to" position.
- *
- * @return List<Criteria> covering property permutations defined with either notation or explicit direction
- */
- private List<Criteria> getSameDirectionContainmentCriteria() {
- List<Criteria> crits = new ArrayList<>();
-
- crits.add(where(EdgeField.CONTAINS.toString()).is(DirectionNotation.DIRECTION.toString()));
-
- crits.add(where(EdgeField.DIRECTION.toString()).is(Direction.OUT.toString())
- .and(EdgeField.CONTAINS.toString()).is(Direction.OUT.toString()));
-
- crits.add(where(EdgeField.DIRECTION.toString()).is(Direction.IN.toString())
- .and(EdgeField.CONTAINS.toString()).is(Direction.IN.toString()));
-
- return crits;
- }
-
- /**
- * Builds the sub-Criteria for a containment edge rule query where the direction
- * and containment fields must not match.
- *
- * Used for getChildRules() where the container node type is in the "to" position and
- * for getParentRules() where the containee type is in the "from" position.
- *
- * @return List<Criteria> covering property permutations defined with either notation or explicit direction
- */
- private List<Criteria> getOppositeDirectionContainmentCriteria() {
- List<Criteria> crits = new ArrayList<>();
-
- crits.add(where(EdgeField.CONTAINS.toString()).is(DirectionNotation.OPPOSITE.toString()));
-
- crits.add(where(EdgeField.DIRECTION.toString()).is(Direction.OUT.toString())
- .and(EdgeField.CONTAINS.toString()).is(Direction.IN.toString()));
-
- crits.add(where(EdgeField.DIRECTION.toString()).is(Direction.IN.toString())
- .and(EdgeField.CONTAINS.toString()).is(Direction.OUT.toString()));
-
- return crits;
- }
-
- //-----rule packaging helpers-----//
- /**
- * Converts the raw output from reading the json file to the Multimap<String key, EdgeRule> format
- *
- * @param allFound - raw edge rule output read from json file(s)
- * (could be empty if none found)
- * @return Multimap<String, EdgeRule> of node names keys to the EdgeRules where the key takes the form of
- * {alphabetically first nodetype}|{alphabetically second nodetype}. Will be empty if input
- * was empty.
- * ex: buildAlphabetizedKey("l-interface", "logical-link") -> "l-interface|logical-link"
- * buildAlphabetizedKey("logical-link", "l-interface") -> "l-interface|logical-link"
- *
- * This is alphabetical order to normalize the keys, as sometimes there will be multiple
- * rules for a pair of node types but the from/to value in the json is flipped for some of them.
- */
- private Multimap<String, EdgeRule> convertToEdgeRules(List<Map<String, String>> allFound) {
- Multimap<String, EdgeRule> rules = ArrayListMultimap.create();
-
- TypeAlphabetizer alpher = new TypeAlphabetizer();
-
- for (Map<String, String> raw : allFound) {
- EdgeRule converted = new EdgeRule(raw);
- if (converted.getFrom().equals(converted.getTo())) {
- /* the way the code worked in the past was with outs and
- * when we switched it to in the same-node-type to
- * same-node-type parent child edges were failing because all
- * of the calling code would pass the parent as the left argument,
- * so it was either in that method swap the parent/child,
- * flip the edge rule or make all callers swap. the last seemed
- * like a bad idea. and felt like the edge flip was the better
- * of the remaining 2 */
- converted.flipDirection();
- }
- String alphabetizedKey = alpher.buildAlphabetizedKey(raw.get(EdgeField.FROM.toString()), raw.get(EdgeField.TO.toString()));
- rules.put(alphabetizedKey, converted);
- }
-
- return rules;
- }
+ // -----filter building helpers-----//
+ /**
+ * ANDs together the given start criteria with each criteria in the pieces list, and
+ * then ORs together these segments into one filter.
+ *
+ * JsonPath doesn't have an OR method on Criteria, only on Filters, so assembling
+ * a complete filter requires this sort of roundabout construction.
+ *
+ * @param start - Criteria of the form where(from/to).is(nodeType)
+ * (ie the start of any A&AI edge rule query)
+ * @param pieces - Other Criteria to be applied
+ * @return Filter constructed from the given Criteria
+ */
+ private Filter assembleFilterSegments(Criteria start, List<Criteria> pieces) {
+ List<Filter> segments = new ArrayList<>();
+ for (Criteria c : pieces) {
+ segments.add(filter(start).and(c));
+ }
+ Filter assembled = segments.remove(0);
+ for (Filter f : segments) {
+ assembled = assembled.or(f);
+ }
+ return assembled;
+ }
+
+ /**
+ * Builds the sub-Criteria for a containment edge rule query where the direction
+ * and containment fields must match.
+ *
+ * Used for getChildRules() where the container node type is in the "from" position and
+ * for getParentRules() where the containee type is in the "to" position.
+ *
+ * @return List<Criteria> covering property permutations defined with either notation or explicit direction
+ */
+ private List<Criteria> getSameDirectionContainmentCriteria() {
+ List<Criteria> crits = new ArrayList<>();
+
+ crits.add(where(EdgeField.CONTAINS.toString()).is(DirectionNotation.DIRECTION.toString()));
+
+ crits.add(where(EdgeField.DIRECTION.toString()).is(Direction.OUT.toString()).and(EdgeField.CONTAINS.toString())
+ .is(Direction.OUT.toString()));
+
+ crits.add(where(EdgeField.DIRECTION.toString()).is(Direction.IN.toString()).and(EdgeField.CONTAINS.toString())
+ .is(Direction.IN.toString()));
+
+ return crits;
+ }
+
+ /**
+ * Builds the sub-Criteria for a containment edge rule query where the direction
+ * and containment fields must not match.
+ *
+ * Used for getChildRules() where the container node type is in the "to" position and
+ * for getParentRules() where the containee type is in the "from" position.
+ *
+ * @return List<Criteria> covering property permutations defined with either notation or explicit direction
+ */
+ private List<Criteria> getOppositeDirectionContainmentCriteria() {
+ List<Criteria> crits = new ArrayList<>();
+
+ crits.add(where(EdgeField.CONTAINS.toString()).is(DirectionNotation.OPPOSITE.toString()));
+
+ crits.add(where(EdgeField.DIRECTION.toString()).is(Direction.OUT.toString()).and(EdgeField.CONTAINS.toString())
+ .is(Direction.IN.toString()));
+
+ crits.add(where(EdgeField.DIRECTION.toString()).is(Direction.IN.toString()).and(EdgeField.CONTAINS.toString())
+ .is(Direction.OUT.toString()));
+
+ return crits;
+ }
+
+ // -----rule packaging helpers-----//
+ /**
+ * Converts the raw output from reading the json file to the Multimap<String key, EdgeRule> format
+ *
+ * @param allFound - raw edge rule output read from json file(s)
+ * (could be empty if none found)
+ * @return Multimap<String, EdgeRule> of node names keys to the EdgeRules where the key takes the form of
+ * {alphabetically first nodetype}|{alphabetically second nodetype}. Will be empty if input
+ * was empty.
+ * ex: buildAlphabetizedKey("l-interface", "logical-link") -> "l-interface|logical-link"
+ * buildAlphabetizedKey("logical-link", "l-interface") -> "l-interface|logical-link"
+ *
+ * This is alphabetical order to normalize the keys, as sometimes there will be multiple
+ * rules for a pair of node types but the from/to value in the json is flipped for some of them.
+ */
+ private Multimap<String, EdgeRule> convertToEdgeRules(List<Map<String, String>> allFound) {
+ Multimap<String, EdgeRule> rules = ArrayListMultimap.create();
+
+ TypeAlphabetizer alpher = new TypeAlphabetizer();
+
+ for (Map<String, String> raw : allFound) {
+ EdgeRule converted = new EdgeRule(raw);
+ if (converted.getFrom().equals(converted.getTo())) {
+ /*
+ * the way the code worked in the past was with outs and
+ * when we switched it to in the same-node-type to
+ * same-node-type parent child edges were failing because all
+ * of the calling code would pass the parent as the left argument,
+ * so it was either in that method swap the parent/child,
+ * flip the edge rule or make all callers swap. the last seemed
+ * like a bad idea. and felt like the edge flip was the better
+ * of the remaining 2
+ */
+ converted.flipDirection();
+ }
+ String alphabetizedKey =
+ alpher.buildAlphabetizedKey(raw.get(EdgeField.FROM.toString()), raw.get(EdgeField.TO.toString()));
+ rules.put(alphabetizedKey, converted);
+ }
+
+ return rules;
+ }