Upgrade version of aai-common
[aai/gizmo.git] / src / main / java / org / onap / schema / OxmModelConfigTranslator.java
index f6b9e70..cb82ed0 100644 (file)
@@ -32,16 +32,17 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import org.onap.aai.setup.ConfigTranslator;
 import org.onap.aai.setup.SchemaLocationsBean;
-import org.onap.aai.setup.Version;
+import org.onap.aai.setup.SchemaVersion;
+import org.onap.aai.setup.SchemaVersions;
 
 public class OxmModelConfigTranslator extends ConfigTranslator {
 
-    public OxmModelConfigTranslator(SchemaLocationsBean bean) {
-        super(bean);
+    public OxmModelConfigTranslator(SchemaLocationsBean bean, SchemaVersions schemaVersions) {
+        super(bean, schemaVersions);
     }
 
     @Override
-    public Map<Version, List<String>> getNodeFiles() {
+    public Map<SchemaVersion, List<String>> getNodeFiles() {
         String nodeDirectory = bean.getNodeDirectory();
         if (nodeDirectory == null) {
             throw new ServiceConfigurationError(
@@ -55,7 +56,7 @@ public class OxmModelConfigTranslator extends ConfigTranslator {
     }
 
     @Override
-    public Map<Version, List<String>> getEdgeFiles() {
+    public Map<SchemaVersion, List<String>> getEdgeFiles() {
         String edgeDirectory = bean.getEdgeDirectory();
         if (edgeDirectory == null) {
             throw new ServiceConfigurationError(
@@ -80,7 +81,7 @@ public class OxmModelConfigTranslator extends ConfigTranslator {
      * @return a new Map object (may be empty)
      * @throws IOException if there is a problem reading the specified directory path
      */
-    private Map<Version, List<String>> getVersionMap(Path folderPath, String globPattern) throws IOException {
+    private Map<SchemaVersion, List<String>> getVersionMap(Path folderPath, String globPattern) throws IOException {
         final PathMatcher filter = folderPath.getFileSystem().getPathMatcher("glob:**/" + globPattern);
         try (final Stream<Path> stream = Files.list(folderPath)) {
             return stream.filter(filter::matches).map(Path::toString).filter(p -> getVersionFromPath(p) != null)
@@ -88,10 +89,12 @@ public class OxmModelConfigTranslator extends ConfigTranslator {
         }
     }
 
-    private Version getVersionFromPath(String pathName) {
+    private SchemaVersion getVersionFromPath(String pathName) {
         String version = "V" + pathName.replaceAll("^.*\\/", "").replaceAll("\\D+", "");
         try {
-            return Version.valueOf(version);
+            SchemaVersion schemaVersion = schemaVersions.getVersions().stream()
+                    .filter(s -> s.toString().equalsIgnoreCase(version)).findAny().orElse(null);
+            return schemaVersion;
         } catch (IllegalArgumentException e) {
             return null;
         }