2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.schema;
22 import org.json.simple.JSONArray;
23 import org.json.simple.JSONObject;
24 import org.json.simple.parser.JSONParser;
25 import org.json.simple.parser.ParseException;
26 import org.apache.commons.io.FileUtils;
27 import org.apache.commons.io.filefilter.DirectoryFileFilter;
28 import org.apache.commons.io.filefilter.FileFileFilter;
29 import org.apache.commons.io.filefilter.FileFilterUtils;
30 import org.apache.commons.io.filefilter.RegexFileFilter;
31 import org.junit.Test;
32 import org.junit.Ignore;
34 import org.xml.sax.SAXException;
36 import javax.xml.parsers.DocumentBuilder;
37 import javax.xml.parsers.DocumentBuilderFactory;
38 import javax.xml.parsers.ParserConfigurationException;
39 import javax.xml.xpath.XPath;
40 import javax.xml.xpath.XPathConstants;
41 import javax.xml.xpath.XPathExpressionException;
42 import javax.xml.xpath.XPathFactory;
44 import java.nio.file.Files;
45 import java.nio.file.Path;
46 import java.nio.file.Paths;
48 import java.util.stream.Collectors;
50 import static org.junit.Assert.assertTrue;
51 import static org.junit.Assert.fail;
53 public class ValidateOXMTest {
55 private String DBEDGERULES_RULES = "rules";
56 private String DBEDGERULES_FROM = "from";
57 private String DBEDGERULES_TO = "to";
58 private String DBEDGERULES_DIRECTION = "direction";
59 private String DBEDGERULES_CONTAINS_OTHER_V = "contains-other-v";
60 private String DBEDGERULES_OUT = "OUT";
61 private String DBEDGERULES_IN = "IN";
62 private String XMLROOTELEMENT = "xml-root-element";
63 private String XMLPROPERTIES = "xml-properties";
64 private String ECOMP = "ecomp";
65 private String NARAD = "narad";
66 private String ONAP = "onap";
69 public void testFindXmlPropContainingSpace() throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
70 boolean foundIssue = false;
71 List<File> fileList = getLatestFiles();
73 StringBuilder msg = new StringBuilder();
74 for (File file : fileList) {
75 msg.append(file.getAbsolutePath().replaceAll(".*aai-schema", ""));
77 Document xmlDocument = getDocument(file);
78 XPath xPath = XPathFactory.newInstance().newXPath();
79 String expression = "/xml-bindings/java-types/java-type/xml-properties/xml-property[@name!='description' and contains(@value,' ')]";
80 NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
82 for (int i = 0; i < nodeList.getLength(); i++) {
85 msg.append(nodeList.item(i).getParentNode().getParentNode().getAttributes().getNamedItem("name").getNodeValue());
94 System.out.println(msg.toString());
95 fail("Node type xml-property should have space.");
101 * Verifies that all of the node types in the oxm's have their uri templates.
102 * @throws XPathExpressionException
103 * @throws IOException
104 * @throws SAXException
105 * @throws ParserConfigurationException
108 public void allNodeTypesHaveAAIUriTemplate() throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
109 boolean foundIssue = false;
110 List<File> fileList = getFiles();
112 StringBuilder msg = new StringBuilder();
113 for (File file : fileList) {
114 msg.append(file.getAbsolutePath().replaceAll(".*aai-schema", ""));
116 Document xmlDocument = getDocument(file);
117 XPath xPath = XPathFactory.newInstance().newXPath();
118 String expression = "/xml-bindings/java-types/java-type[" +
120 "count(xml-properties/xml-property[@name='container']) > 0 " +
121 "or count(xml-properties/xml-property[@name='dependentOn']) > 0" +
123 "and count(xml-properties/xml-property[@name='uriTemplate']) = 0 " +
125 NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
127 for (int i = 0; i < nodeList.getLength(); i++) {
128 String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
129 if (name.equals("InstanceFilter") || name.equals("InventoryResponseItems") || name.equals("InventoryResponseItem")) {
139 System.out.println(msg.toString());
140 fail("Missing uriTemplate in oxm.");
146 public void verifyAllIndexedPropertiesExistInObject()
147 throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
149 boolean foundIssue = false;
150 List<File> fileList = getOxmSchemaFiles();
151 fileList.addAll(getOnapOxmSchemaFiles());
152 StringBuilder msg = new StringBuilder();
153 for (File file : fileList) {
154 Document xmlDocument = getDocument(file);
155 XPath xPath = XPathFactory.newInstance().newXPath();
156 String expression = "/xml-bindings/java-types/java-type[count(xml-properties/xml-property[@name='indexedProps']) > 0]";
157 NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
159 Map<String, List<String>> nodeTypeBadIndexProps = new HashMap<>();
160 for(int i = 0; i < nodeList.getLength(); i++){
161 String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
163 NodeList javaAttributesList = ((Element)nodeList.item(i)).getElementsByTagName("java-attributes");
165 Set<String> properties = new HashSet<>();
167 for(int j = 0; j < javaAttributesList.getLength(); j++){
168 NodeList elementList = ((Element)javaAttributesList.item(j)).getElementsByTagName("xml-element");
169 for(int k = 0; k < elementList.getLength(); k++){
170 properties.add(elementList.item(k).getAttributes().getNamedItem("name").getNodeValue());
174 NodeList xmlPropertiesList = ((Element)nodeList.item(i)).getElementsByTagName("xml-properties");
175 List<String> badIndexedProps = new ArrayList<>();
176 boolean foundIssueInNodeType = false;
178 for(int j = 0; j < xmlPropertiesList.getLength(); j++){
179 NodeList xmlProperties = ((Element)xmlPropertiesList.item(j)).getElementsByTagName("xml-property");
180 for(int k = 0; k < xmlProperties.getLength(); k++){
181 String xmlProp = xmlProperties.item(k).getAttributes().getNamedItem("name").getNodeValue();
182 if("indexedProps".equals(xmlProp)){
183 String xmlPropValue = xmlProperties.item(k).getAttributes().getNamedItem("value").getNodeValue();
185 List<String> indexProps = Arrays
186 .stream(xmlPropValue.split(","))
187 .collect(Collectors.toList());
189 for(String indexProp : indexProps){
190 if(!properties.contains(indexProp)){
191 foundIssueInNodeType = true;
192 badIndexedProps.add(indexProp);
200 if(foundIssueInNodeType){
202 nodeTypeBadIndexProps.put(name, badIndexedProps);
206 if(!nodeTypeBadIndexProps.isEmpty()){
208 msg.append("File: " + file.getAbsolutePath().replaceAll(".*aai-schema", ""));
210 for (Map.Entry<String, List<String>> nodeTypeBadIndex : nodeTypeBadIndexProps.entrySet()) {
211 msg.append("NodeType: " + nodeTypeBadIndex.getKey());
212 msg.append(" contains following indexed props that are not properties in object: ");
213 msg.append(String.join(",", nodeTypeBadIndex.getValue()));
221 fail(msg.toString());
226 public void verifyAllUniquePropertiesExistInObject()
227 throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
229 boolean foundIssue = false;
230 List<File> fileList = getOxmSchemaFiles();
231 fileList.addAll(getOnapOxmSchemaFiles());
232 StringBuilder msg = new StringBuilder();
233 for (File file : fileList) {
234 Document xmlDocument = getDocument(file);
235 XPath xPath = XPathFactory.newInstance().newXPath();
236 String expression = "/xml-bindings/java-types/java-type[count(xml-properties/xml-property[@name='uniqueProps']) > 0]";
237 NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
239 Map<String, List<String>> nodeTypeBadUniqueProps = new HashMap<>();
240 for (int i = 0; i < nodeList.getLength(); i++) {
241 String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
243 NodeList javaAttributesList = ((Element) nodeList.item(i)).getElementsByTagName("java-attributes");
245 Set<String> properties = new HashSet<>();
247 for (int j = 0; j < javaAttributesList.getLength(); j++) {
248 NodeList elementList = ((Element) javaAttributesList.item(j)).getElementsByTagName("xml-element");
249 for (int k = 0; k < elementList.getLength(); k++) {
250 properties.add(elementList.item(k).getAttributes().getNamedItem("name").getNodeValue());
254 NodeList xmlPropertiesList = ((Element) nodeList.item(i)).getElementsByTagName("xml-properties");
255 List<String> badUniqueProps = new ArrayList<>();
256 boolean foundIssueInNodeType = false;
258 for (int j = 0; j < xmlPropertiesList.getLength(); j++) {
259 NodeList xmlProperties = ((Element) xmlPropertiesList.item(j)).getElementsByTagName("xml-property");
260 for (int k = 0; k < xmlProperties.getLength(); k++) {
261 String xmlProp = xmlProperties.item(k).getAttributes().getNamedItem("name").getNodeValue();
262 if ("uniqueProps".equals(xmlProp)) {
263 String xmlPropValue = xmlProperties.item(k).getAttributes().getNamedItem("value").getNodeValue();
265 List<String> uniqueProps = Arrays
266 .stream(xmlPropValue.split(","))
267 .collect(Collectors.toList());
269 for (String uniqueProp : uniqueProps) {
270 if (!properties.contains(uniqueProp)) {
271 foundIssueInNodeType = true;
272 badUniqueProps.add(uniqueProp);
280 if (foundIssueInNodeType) {
282 nodeTypeBadUniqueProps.put(name, badUniqueProps);
286 if (!nodeTypeBadUniqueProps.isEmpty()) {
288 msg.append("File: " + file.getAbsolutePath().replaceAll(".*aai-schema", ""));
290 for (Map.Entry<String, List<String>> nodeTypeBadUnique : nodeTypeBadUniqueProps.entrySet()) {
291 msg.append("NodeType: " + nodeTypeBadUnique.getKey());
292 msg.append(" contains following unique props that are not properties in object: ");
293 msg.append(String.join(",", nodeTypeBadUnique.getValue()));
301 fail(msg.toString());
307 * Verifies that all of the top level node types in the oxm's have their namespace in uri templates.
308 * @throws XPathExpressionException
309 * @throws IOException
310 * @throws SAXException
311 * @throws ParserConfigurationException
314 public void verifyAllUriTemplateHaveNamespace()
315 throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
316 boolean foundIssue = false;
317 List<File> fileList = getOxmSchemaFiles();
318 fileList.addAll(getOnapOxmSchemaFiles());
319 StringBuilder msg = new StringBuilder();
320 for (File file : fileList) {
321 msg.append(file.getAbsolutePath().replaceAll(".*aai-schema", ""));
323 Document xmlDocument = getDocument(file);
324 XPath xPath = XPathFactory.newInstance().newXPath();
325 String expression = "/xml-bindings/java-types/java-type["
326 + "count(xml-properties/xml-property[@name='namespace']) > 0 " + "]";
327 NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
329 for (int i = 0; i < nodeList.getLength(); i++) {
330 String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
332 NodeList childNodeList = (NodeList) nodeList.item(i).getChildNodes();
333 for (int j = 0; j < childNodeList.getLength(); j++) {
335 String nodeName = childNodeList.item(j).getNodeName();
336 NodeList xmlPropertyNodeList = childNodeList.item(j).getChildNodes();
337 if (XMLPROPERTIES.equals(nodeName)) {
339 String namespaceVal = "";
340 String uriTemplateVal = "";
341 for (int k = 0; k < xmlPropertyNodeList.getLength(); k++) {
343 if ("xml-property".equals(xmlPropertyNodeList.item(k).getNodeName())) {
345 NamedNodeMap attributes = xmlPropertyNodeList.item(k).getAttributes();
347 if ("namespace".equals(attributes.getNamedItem("name").getNodeValue())) {
348 namespaceVal = attributes.getNamedItem("value").getNodeValue();
350 if ("uriTemplate".equals(attributes.getNamedItem("name").getNodeValue())) {
351 uriTemplateVal = attributes.getNamedItem("value").getNodeValue();
358 if (!uriTemplateVal.startsWith("/" + namespaceVal + "/")) {
361 msg.append(uriTemplateVal);
371 System.out.println(msg.toString());
372 fail("uriTemplate doesnt start with /namespace/.");
379 * Verifies that all specified properties are indexed
380 * Currently set to check that "model-invariant-id","model-version-id" which are aliased are indexed
381 * @throws XPathExpressionException
382 * @throws IOException
383 * @throws SAXException
384 * @throws ParserConfigurationException
387 public void aliasedIndexedPropsAreInIndexedListWithPropName() throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
389 final List<String> props = Arrays.asList("model-invariant-id","model-version-id");
391 boolean foundIssue = false;
392 List<File> fileList = getLatestFiles();
393 StringBuilder msg = new StringBuilder();
395 for (File file : fileList) {
396 msg.append(file.getAbsolutePath().replaceAll(".*aai-schema", ""));
398 for (String prop : props) {
399 Document xmlDocument = getDocument(file);
400 XPath xPath = XPathFactory.newInstance().newXPath();
401 String expression = "/xml-bindings/java-types/java-type[" +
403 "count(xml-properties/xml-property[@name='container']) > 0 " +
404 "or count(xml-properties/xml-property[@name='dependentOn']) > 0" +
406 "and count(xml-properties/xml-property[@name='indexedProps' and not(contains(@value,'" + prop + "'))]) > 0 " + //prop is not in indexed props list
407 "and count(java-attributes/xml-element[@name='" + prop + "']) > 0 " + // prop is a property on obj
410 NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
412 if (nodeList.getLength() > 0) {
417 for (int i = 0; i < nodeList.getLength(); i++) {
418 String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
419 if (name.equals("InstanceFilter") || name.equals("InventoryResponseItems") || name.equals("InventoryResponseItem")) {
431 System.out.println(msg.toString());
432 fail("Missing index entry in oxm.");
438 * Check schema versions against their respective dbEdgeRules file and check if the
439 * dependentOn relationship matches what is listed in the edge rules.
444 public void testSchemaValidationAgainstEdgeRules() throws XPathExpressionException, IOException, SAXException, ParserConfigurationException, ParseException {
445 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
446 List<File> subDirs = Arrays.asList(currentRelativePath.toFile().listFiles(File::isDirectory));
447 boolean success = true;
448 for (File subDir : subDirs) {
449 List<String> oxmSchemaList = new ArrayList<>();
450 List<String> dbEdgeRulesList = new ArrayList<>();
451 String oxm = subDir.getAbsolutePath() + "/oxm";
452 File[] oxms = new File(oxm).listFiles(File::isDirectory);
453 Arrays.stream(oxms).map(File::getAbsolutePath).max(new Comparator<String>() {
454 public int compare(String o1, String o2) {
455 return extractInt(o1) - extractInt(o2);
458 int extractInt(String s) {
459 String num = s.replaceAll("\\D", "");
460 return num.isEmpty() ? 0 : Integer.parseInt(num);
462 }).ifPresent(oxmSchemaList::add);
464 String edgeRule = subDir.getAbsolutePath() + "/dbedgerules";
465 File[] edgeRules = new File(edgeRule).listFiles(File::isDirectory);
466 Arrays.stream(edgeRules).map(File::getAbsolutePath).max(new Comparator<String>() {
467 public int compare(String o1, String o2) {
468 return extractInt(o1) - extractInt(o2);
471 int extractInt(String s) {
472 String num = s.replaceAll("\\D", "");
473 return num.isEmpty() ? 0 : Integer.parseInt(num);
475 }).ifPresent(dbEdgeRulesList::add);
478 List<File> oxmSchemaFileList = new ArrayList<>();
479 List<File> dbEdgeRulesFileList = new ArrayList<>();
480 oxmSchemaList.forEach(s ->
483 new RegexFileFilter(".*\\.xml"),
484 DirectoryFileFilter.DIRECTORY)
486 .filter(file -> file.getAbsolutePath().contains("oxm"))
487 .forEach(oxmSchemaFileList::add));
489 dbEdgeRulesList.forEach(s ->
492 new RegexFileFilter(".*\\.json"),
493 DirectoryFileFilter.DIRECTORY)
495 .filter(file -> file.getAbsolutePath().contains("DbEdgeRules"))
496 .forEach(dbEdgeRulesFileList::add));
498 // Map the dbEdgeRules json file into a HashMap for reference
499 Map<String, Set<String>> dbEdgeRules = new HashMap<>();
500 JSONParser jsonParser = new JSONParser();
501 for (File file : dbEdgeRulesFileList) {
502 FileReader reader = new FileReader(file);
503 // Read JSON file. Expecting JSON file to read an object with a JSONArray names "rules"
504 JSONObject jsonObj = (JSONObject) jsonParser.parse(reader);
505 JSONArray rules = (JSONArray) jsonObj.get(DBEDGERULES_RULES);
506 for (int i = 0; i < rules.size(); i++) {
507 JSONObject rule = (JSONObject) rules.get(i);
508 String fromNode = rule.get(DBEDGERULES_FROM).toString();
509 String toNode = rule.get(DBEDGERULES_TO).toString();
510 String direction = rule.get(DBEDGERULES_DIRECTION).toString();
511 String containsOtherV = rule.get(DBEDGERULES_CONTAINS_OTHER_V).toString();
513 // special case - cvlan-tag should be replaced with cvlan-tag-entry
514 if (fromNode.equals("cvlan-tag"))
515 fromNode = "cvlan-tag-entry";
516 if (toNode.equals("cvlan-tag"))
517 toNode = "cvlan-tag-entry";
518 if (containsOtherV.equals("!${direction}")) {
519 if (direction.equals(DBEDGERULES_IN)) {
520 direction = DBEDGERULES_OUT;
521 } else if (direction.equals(DBEDGERULES_OUT)) {
522 direction = DBEDGERULES_IN;
525 // If this value is none, the edge rule is for cousin nodes. Ignore.
526 else if (containsOtherV.equals("NONE"))
528 dbEdgeRulesMapPut(dbEdgeRules, fromNode, toNode, direction);
532 // Iterate through the most recent oxm schema files. Map the parent child relationships
533 Map<String, Set<String>> oxmSchemaFile = new HashMap<>();
534 for (File file : oxmSchemaFileList) {
535 Document xmlDocument = getDocument(file);
536 XPath xPath = XPathFactory.newInstance().newXPath();
537 String parentNodeExpression = "/xml-bindings/java-types/java-type/xml-properties/xml-property[@name='dependentOn']";
538 NodeList parentNodeList = (NodeList) xPath.compile(parentNodeExpression).evaluate(xmlDocument, XPathConstants.NODESET);
539 String childNodeExpression = "/xml-bindings/java-types/java-type[" +
541 "count(xml-properties/xml-property[@name='dependentOn']) > 0" +
543 NodeList childNodeList = (NodeList) xPath.compile(childNodeExpression).evaluate(xmlDocument, XPathConstants.NODESET);
545 for (int i = 0; i < parentNodeList.getLength(); i++) {
547 // Obtain the xml-root-element field by tracing the childNodes from the java-type parent node
548 for (int j = 0; j < childNodeList.item(i).getChildNodes().getLength(); j++) {
549 if (childNodeList.item(i).getChildNodes().item(j).getNodeName().equals(XMLROOTELEMENT)) {
552 String dependentOn = parentNodeList.item(i).getAttributes().getNamedItem("value").getNodeValue();
555 String xmlRootElement = childNodeList.item(i).getChildNodes().item(j).getAttributes().getNamedItem("name").getNodeValue();
557 Set<String> childSet;
558 String[] parents = dependentOn.split(",");
559 for (int k = 0; k < parents.length; k++) {
560 String parent = parents[k];
561 if (oxmSchemaFile.containsKey(parent)) {
562 childSet = oxmSchemaFile.get(parent);
564 childSet = new HashSet<>();
566 childSet.add(xmlRootElement);
567 oxmSchemaFile.put(parent, childSet);
575 // Compare the OXM file against the dbEdgeRules file. check what is missing in dbEdgeRules from the oxm files.
576 Set<String> oxmKeySet = oxmSchemaFile.keySet();
577 for (String key : oxmKeySet) {
578 Set<String> oxmChildren = oxmSchemaFile.get(key);
579 Set<String> dbEdgeRulesChildren = dbEdgeRules.get(key);
581 // Check if the parent vertex exists at all in the dbEdgeRules file
582 if (dbEdgeRulesChildren == null || dbEdgeRulesChildren.isEmpty()) {
583 for (String oxmChild : oxmChildren) {
584 System.out.println("ERROR: dbEdgeRules under directory '" + subDir.toString() + "' does not contain parent '" + key + "' and child '" + oxmChild + "' relationship");
590 // Compare both parent-child relationships between both files
591 if (!oxmChildren.equals(dbEdgeRulesChildren)) {
592 for (String oxmChild : oxmChildren) {
593 if (!dbEdgeRulesChildren.contains(oxmChild)) {
594 System.out.println("ERROR: dbEdgeRules under directory '" + subDir.toString() + "' does not contain parent '" + key + "' and child '" + oxmChild + "' relationship");
601 // Compare the dbEdgeRules against the OXM File
602 Set<String> dbEdgeRuleKeySet = dbEdgeRules.keySet();
603 for (String key : dbEdgeRuleKeySet) {
604 Set<String> dbEdgeRulesChildren = dbEdgeRules.get(key);
605 Set<String> oxmChildren = oxmSchemaFile.get(key);
607 // Check if the parent vertex exists at all in the dbEdgeRules file
608 if (oxmChildren == null || oxmChildren.isEmpty()) {
609 for (String dbEdgeRuleChild : dbEdgeRulesChildren) {
610 System.out.println("ERROR: oxms under directory '" + subDir.toString() + "' do not contain parent '" + key + "' and child '" + dbEdgeRuleChild + "' relationship");
616 // Compare both parent-child relationships between both files
617 if (!dbEdgeRulesChildren.equals(oxmChildren)) {
618 for (String dbEdgeRuleChild : dbEdgeRulesChildren) {
619 if (!oxmChildren.contains(dbEdgeRuleChild)) {
620 System.out.println("ERROR: oxms under directory '" + subDir.toString() + "' do not contain parent '" + key + "' and child '" + dbEdgeRuleChild + "' relationship");
631 * Null check for strings
635 private boolean isStringEmpty(String s) {
636 return (s == null || s.isEmpty()) ? true : false;
640 * Creating a hashmap to map what child nodes are associated to which parent nodes
641 * according to the dbEdgeRules json files. A HashMap was chosen for the value of the map for O(1) lookup time.
642 * @param from this variable will act as the key or value depending on the direction
643 * @param to this variable will act as the key or value depending on the direction
644 * @param direction dictates the direction of which vertex is dependent on which
645 * @return The map returned will act as a dictionary to keep track of the parent nodes. Value of the map is a hashmap to help handle collision of multiple children to one parent
647 private Map<String, Set<String>> dbEdgeRulesMapPut(Map<String, Set<String>> dbEdgeRules, String from, String to, String direction) {
648 if (isStringEmpty(from) || isStringEmpty(to) || isStringEmpty(direction))
651 // Assigning the strings to parent and child for readability
652 String parent = "", child = "";
653 if (direction.equals(DBEDGERULES_OUT)) {
656 } else if (direction.equals(DBEDGERULES_IN)) {
660 // Add to the dbEdgeRules mapping
661 Set<String> children;
662 if (!dbEdgeRules.containsKey(parent)) {
663 children = new HashSet<>();
665 dbEdgeRules.put(parent, children);
667 children = dbEdgeRules.get(parent);
669 dbEdgeRules.put(parent, children);
674 private List<File> getFiles() {
675 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
676 return FileUtils.listFiles(
677 currentRelativePath.toFile(),
678 new RegexFileFilter(".*\\.xml"),
679 DirectoryFileFilter.DIRECTORY)
681 .filter(file -> file.getAbsolutePath().contains("oxm"))
682 .filter(file -> !file.getAbsolutePath().contains("onap")) // skips onap for checks
683 .collect(Collectors.toList());
686 private List<File> getOxmSchemaFiles() {
688 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
689 return FileUtils.listFiles(
690 currentRelativePath.toFile(),
691 new RegexFileFilter(".*\\.xml"),
692 DirectoryFileFilter.DIRECTORY)
694 .filter(file -> file.getAbsolutePath().contains("oxm"))
695 .filter(file -> file.getAbsolutePath().contains("aai_schema_oxm"))
696 .filter(file -> !file.getAbsolutePath().contains("onap")) // skips onap for checks
697 .collect(Collectors.toList());
701 private List<File> getOnapOxmSchemaFiles() {
703 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
704 return FileUtils.listFiles(
705 currentRelativePath.toFile(),
706 new RegexFileFilter(".*\\.xml"),
707 DirectoryFileFilter.DIRECTORY)
709 .filter(file -> file.getAbsolutePath().contains("oxm"))
710 .filter(file -> file.getAbsolutePath().contains("aai_oxm"))
711 .collect(Collectors.toList());
715 private List<File> getAaiSchemaOxmFiles() {
716 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
717 return FileUtils.listFiles(
718 currentRelativePath.toFile(),
719 new RegexFileFilter(".*\\.xml"),
720 DirectoryFileFilter.DIRECTORY)
722 .filter(file -> file.getAbsolutePath().contains("oxm"))
723 .filter(file -> !file.getAbsolutePath().contains("onap")) // skips onap for checks
724 .collect(Collectors.toList());
727 private List<File> getDbEdgeRulesFiles() {
728 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
729 return FileUtils.listFiles(
730 currentRelativePath.toFile(),
731 new RegexFileFilter(".*\\.json"),
732 DirectoryFileFilter.DIRECTORY)
734 .filter(file -> file.getAbsolutePath().contains("DbEdgeRules"))
735 .filter(file -> !file.getAbsolutePath().contains("onap")) // skips onap for checks
736 .collect(Collectors.toList());
740 * Finds all of the oxm files for the latest version.
741 * @return list of the latest version of the oxm files.
743 private List<File> getLatestDbEdgeRulesFiles(String fileDirectory) {
744 List<String> latest = new ArrayList<>();
745 String currentRelativePath = Paths.get("../aai-schema/src/main/resources/" + fileDirectory + "/dbedgerules").toAbsolutePath().toString();
746 File[] oxms = new File(currentRelativePath).listFiles(File::isDirectory);
747 Arrays.stream(oxms).map(File::getAbsolutePath).max(new Comparator<String>() {
748 public int compare(String o1, String o2) {
749 return extractInt(o1) - extractInt(o2);
751 int extractInt(String s) {
752 String num = s.replaceAll("\\D", "");
753 return num.isEmpty() ? 0 : Integer.parseInt(num);
755 }).ifPresent(latest::add);
757 List<File> latestFiles = new ArrayList<>();
761 new RegexFileFilter(".*\\.json"),
762 DirectoryFileFilter.DIRECTORY)
764 .filter(file -> file.getAbsolutePath().contains("DbEdgeRules"))
765 .forEach(latestFiles::add));
771 * Finds all of the oxm files for the latest version.
772 * @return list of the latest version of the oxm files.
774 private List<File> getLatestFiles() {
775 List<String> latest = new ArrayList<>();
776 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
777 List<File> subDirs = Arrays.asList(currentRelativePath.toFile().listFiles(File::isDirectory));
778 for (File subDir : subDirs) {
779 String oxm = subDir.getAbsolutePath() + "/oxm";
780 File[] oxms = new File(oxm).listFiles(File::isDirectory);
781 Arrays.stream(oxms).map(File::getAbsolutePath).max(new Comparator<String>() {
782 public int compare(String o1, String o2) {
783 return extractInt(o1) - extractInt(o2);
785 int extractInt(String s) {
786 String num = s.replaceAll("\\D", "");
787 return num.isEmpty() ? 0 : Integer.parseInt(num);
789 }).ifPresent(latest::add);
792 List<File> latestFiles = new ArrayList<>();
796 new RegexFileFilter(".*\\.xml"),
797 DirectoryFileFilter.DIRECTORY)
799 .filter(file -> file.getAbsolutePath().contains("oxm"))
800 .forEach(latestFiles::add));
806 * Finds all of the oxm files for the latest version.
807 * @return list of the latest version of the oxm files.
809 private List<File> getLatestFiles(String fileDirectory) {
810 List<String> latest = new ArrayList<>();
811 String currentRelativePath = Paths.get("../aai-schema/src/main/resources/" + fileDirectory + "/oxm").toAbsolutePath().toString();
812 File[] oxms = new File(currentRelativePath).listFiles(File::isDirectory);
813 Arrays.stream(oxms).map(File::getAbsolutePath).max(new Comparator<String>() {
814 public int compare(String o1, String o2) {
815 return extractInt(o1) - extractInt(o2);
817 int extractInt(String s) {
818 String num = s.replaceAll("\\D", "");
819 return num.isEmpty() ? 0 : Integer.parseInt(num);
821 }).ifPresent(latest::add);
823 List<File> latestFiles = new ArrayList<>();
827 new RegexFileFilter(".*\\.xml"),
828 DirectoryFileFilter.DIRECTORY)
830 .filter(file -> file.getAbsolutePath().contains("oxm"))
831 .forEach(latestFiles::add));
836 //TODO test that all oxm xml are valid xml
840 public String printNodeList(NodeList nodeList, Document doc) throws IOException {
841 StringBuilder stringBuilder = new StringBuilder();
842 for (int i = 0; i < nodeList.getLength(); i++) {
843 stringBuilder.append(printNode(nodeList.item(i), doc)).append("\n");
845 return stringBuilder.toString();
848 public String printNode(Node node, Document document) throws IOException {
849 StringWriter stringWriter = new StringWriter();
850 return stringWriter.toString();
854 private Document getDocument(File file) throws ParserConfigurationException, SAXException, IOException {
855 InputStream fileIS = new FileInputStream(file);
856 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
857 DocumentBuilder builder = builderFactory.newDocumentBuilder();
858 return builder.parse(fileIS);