1.3.0 schema ingest changes 77/68477/2
authorrv871f <richard.vondadelszen@amdocs.com>
Fri, 21 Sep 2018 17:42:04 +0000 (13:42 -0400)
committerrv871f <richard.vondadelszen@amdocs.com>
Fri, 21 Sep 2018 19:07:02 +0000 (15:07 -0400)
Issue-ID: AAI-1670
Change-Id: I402e56f0371f60641190e182bff4c3b954ad8987
Signed-off-by: rv871f <richard.vondadelszen@amdocs.com>
17 files changed:
.gitignore
pom.xml
src/main/java/org/onap/aai/schema/OxmConfigTranslator.java [deleted file]
src/main/java/org/onap/aai/schema/OxmModelLoader.java
src/test/java/org/onap/aai/schema/OxmModelLoaderTest.java
src/test/resources/config/schemaIngest.properties [new file with mode: 0644]
src/test/resources/oxm-reader/multiple-oxm/v11/aai_oxm_v11.xml [moved from src/test/resources/oxm-reader/multiple-oxm/aai_oxm_v11.xml with 100% similarity]
src/test/resources/oxm-reader/multiple-oxm/v12/aai_oxm_v12.xml [moved from src/test/resources/oxm-reader/multiple-oxm/aai_oxm_v12.xml with 100% similarity]
src/test/resources/oxm-reader/multiple-oxm/v13/aai_oxm_a_v13.xml [moved from src/test/resources/oxm-reader/multiple-oxm/aai_oxm_a_v13.xml with 100% similarity]
src/test/resources/oxm-reader/multiple-oxm/v13/aai_oxm_b_v13.xml [moved from src/test/resources/oxm-reader/multiple-oxm/aai_oxm_b_v13.xml with 100% similarity]
src/test/resources/oxm-reader/oxm/v10/aai_oxm_v10.xml [moved from src/test/resources/oxm-reader/oxm/aai_oxm_v10.xml with 100% similarity]
src/test/resources/oxm-reader/oxm/v11/aai_oxm_v11.xml [moved from src/test/resources/oxm-reader/oxm/aai_oxm_v11.xml with 100% similarity]
src/test/resources/oxm-reader/oxm/v12/aai_oxm_v12.xml [moved from src/test/resources/oxm-reader/oxm/aai_oxm_v12.xml with 100% similarity]
src/test/resources/oxm-reader/oxm/v13/aai_oxm_v13.xml [moved from src/test/resources/oxm-reader/oxm/aai_oxm_v13.xml with 100% similarity]
src/test/resources/oxm-reader/oxm/v8/aai_oxm_v8.xml [moved from src/test/resources/oxm-reader/oxm/aai_oxm_v8.xml with 100% similarity]
src/test/resources/oxm-reader/oxm/v9/aai_oxm_v9.xml [moved from src/test/resources/oxm-reader/oxm/aai_oxm_v9.xml with 100% similarity]
src/test/resources/spring-beans/data-router-oxm.xml [new file with mode: 0644]

index 33793a8..af81fcf 100644 (file)
@@ -1,3 +1,4 @@
+.checkstyle
 .classpath
 .project
 .settings/
diff --git a/pom.xml b/pom.xml
index 7953d49..36fd561 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -93,7 +93,7 @@ limitations under the License.
       <dependency>
          <groupId>org.onap.aai.aai-common</groupId>
          <artifactId>aai-schema-ingest</artifactId>
-         <version>1.2.2</version>
+         <version>1.3.0-SNAPSHOT</version>
          <!--<exclusions>-->
             <!--<exclusion>-->
                <!--<groupId>com.google.guava</groupId>-->
@@ -129,6 +129,17 @@ limitations under the License.
        <version>1.10.19</version>
        <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context</artifactId>
+      <version>4.3.0.RELEASE</version>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-test</artifactId>
+      <version>4.3.0.RELEASE</version>
+      <scope>test</scope>
+    </dependency>
    </dependencies>
    <build>
       <defaultGoal>install</defaultGoal>
diff --git a/src/main/java/org/onap/aai/schema/OxmConfigTranslator.java b/src/main/java/org/onap/aai/schema/OxmConfigTranslator.java
deleted file mode 100644 (file)
index a829002..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.schema;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.PathMatcher;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceConfigurationError;
-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;
-
-public class OxmConfigTranslator extends ConfigTranslator {
-    public OxmConfigTranslator(SchemaLocationsBean bean) {
-        super(bean);
-    }
-
-    @Override
-    public Map<Version, List<String>> getNodeFiles() {
-        String nodeDirectory = bean.getNodeDirectory();
-        if (nodeDirectory == null) {
-            throw new ServiceConfigurationError(
-                    "Node(s) directory is empty in the schema location bean (" + bean.getSchemaConfigLocation() + ")");
-        }
-        try {
-            return getVersionMap(Paths.get(nodeDirectory), "*_v*.xml");
-        } catch (IOException e) {
-            throw new ServiceConfigurationError("Failed to read node(s) directory " + getPath(nodeDirectory), e);
-        }
-    }
-
-    @Override
-    public Map<Version, List<String>> getEdgeFiles() {
-        String edgeDirectory = bean.getEdgeDirectory();
-        if (edgeDirectory == null) {
-            throw new ServiceConfigurationError(
-                    "Edge(s) directory is empty in the schema location bean (" + bean.getSchemaConfigLocation() + ")");
-        }
-        try {
-            return getVersionMap(Paths.get(edgeDirectory), "*_v*.json");
-        } catch (IOException e) {
-            throw new ServiceConfigurationError("Failed to read edge(s) directory " + getPath(edgeDirectory), e);
-        }
-    }
-
-    private String getPath(String nodeDirectory) {
-        return Paths.get(nodeDirectory).toAbsolutePath().toString();
-    }
-
-    /**
-     * Creates a map containing each OXM Version and the matching OXM file path(s)
-     *
-     * @param folderPath the folder/directory containing the OXM files
-     * @param fileSuffix
-     * @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 {
-        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)
-                    .collect(Collectors.groupingBy(this::getVersionFromPath));
-        }
-    }
-
-    private Version getVersionFromPath(String pathName) {
-        String version = "V" + pathName.replaceAll("^.*\\/", "").replaceAll("\\D+", "");
-        try {
-            return Version.valueOf(version);
-        } catch (IllegalArgumentException e) {
-            return null;
-        }
-    }
-}
index 1e62cfc..bd64f3e 100644 (file)
@@ -34,7 +34,9 @@ import org.onap.aai.util.ExternalOxmModelProcessor;
 import org.onap.aai.nodes.NodeIngestor;
 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;
+import org.onap.aai.setup.AAIConfigTranslator;
 
 public class OxmModelLoader {
 
@@ -48,14 +50,11 @@ public class OxmModelLoader {
         throw new IllegalStateException("Utility class");
     }
 
-    public static synchronized void loadModels() {
-        SchemaIngestPropertiesReader schemaIngestPropReader = new SchemaIngestPropertiesReader();
-        SchemaLocationsBean schemaLocationsBean = new SchemaLocationsBean();
-        schemaLocationsBean.setNodeDirectory(schemaIngestPropReader.getNodeDir());
-        ConfigTranslator configTranslator = new OxmConfigTranslator(schemaLocationsBean);
+    public static synchronized void loadModels(SchemaVersions schemaVersions, SchemaLocationsBean schemaLocationsBean) {
+        ConfigTranslator configTranslator = new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
         NodeIngestor nodeIngestor = new NodeIngestor(configTranslator);
 
-        for (Version oxmVersion : Version.values()) {
+        for (SchemaVersion oxmVersion : schemaVersions.getVersions()) {
             DynamicJAXBContext jaxbContext = nodeIngestor.getContextForVersion(oxmVersion);
             if (jaxbContext != null) {
                 loadModel(oxmVersion.toString(), jaxbContext);
@@ -63,9 +62,9 @@ public class OxmModelLoader {
         }
     }
 
-    public static DynamicJAXBContext getContextForVersion(String version) {
+    public static DynamicJAXBContext getContextForVersion(String version, SchemaVersions schemaVersions, SchemaLocationsBean schemaLocationsBean) {
         if (versionContextMap == null || versionContextMap.isEmpty()) {
-            loadModels();
+            loadModels(schemaVersions, schemaLocationsBean);
         } else if (!versionContextMap.containsKey(version)) {
             throw new NoSuchElementException(Status.NOT_FOUND.toString());
         }
index 060e5ed..f3e9091 100644 (file)
  */
 package org.onap.aai.schema;
 
+
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+
 import java.util.ArrayList;
+
 import org.eclipse.persistence.dynamic.DynamicType;
 import org.eclipse.persistence.internal.helper.DatabaseField;
 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
 import org.eclipse.persistence.mappings.DatabaseMapping;
 import org.junit.Test;
-import org.onap.aai.schema.OxmModelLoader;
+import org.junit.runner.RunWith;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersions;
 import org.onap.aai.util.EntityOxmReferenceHelper;
 import org.onap.aai.util.ExternalOxmModelProcessor;
-import org.onap.aai.setup.Version;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("file:src/test/resources/spring-beans/data-router-oxm.xml")
 public class OxmModelLoaderTest {
 
+  @Autowired
+  private SchemaVersions schemaVersions;
+  @Autowired
+  private SchemaLocationsBean schemaLocationsBean;
+  
     @Test
     public void testLoadingMultipleOxmFiles() {
+      
         ArrayList<ExternalOxmModelProcessor> externalOxmModelProcessors = new ArrayList<ExternalOxmModelProcessor>();
         externalOxmModelProcessors.add(EntityOxmReferenceHelper.getInstance());
         OxmModelLoader.registerExternalOxmModelProcessors(externalOxmModelProcessors);
-        OxmModelLoader.loadModels();
+        OxmModelLoader.loadModels(schemaVersions, schemaLocationsBean);
 
-        DynamicJAXBContext jaxbContext = OxmModelLoader.getContextForVersion(Version.getLatest().toString());
+        DynamicJAXBContext jaxbContext = OxmModelLoader.getContextForVersion("v13", schemaVersions, schemaLocationsBean);
 
         DynamicType pserver = jaxbContext.getDynamicType("Pserver");
         DynamicType genericVnf = jaxbContext.getDynamicType("GenericVnf");
@@ -63,6 +78,7 @@ public class OxmModelLoaderTest {
             String keyName = f.getName().substring(0, f.getName().indexOf("/"));
             assertTrue(keyName.equals("vnf-id"));
         }
-
+      
     }
+    
 }
diff --git a/src/test/resources/config/schemaIngest.properties b/src/test/resources/config/schemaIngest.properties
new file mode 100644 (file)
index 0000000..05e5555
--- /dev/null
@@ -0,0 +1,16 @@
+# Properties for the SchemaLocationsBean
+# Properties required by the aai-common - aai-schema-ingest lib as of 1.3.0
+schema.configuration.location=N/A
+schema.nodes.location=src/test/resources/oxm-reader/multiple-oxm/
+schema.edges.location=
+# These versions need to exist if they are included in the list
+schema.version.list=v11,v12,v13
+# Decalares the oxm version to load
+schema.version.api.default=v13
+
+# Don't use these properties in our application, need to be set to prevent an exception on startup (see SchemaVersions bean)
+schema.version.depth.start=v13
+schema.version.related.link.start=v13
+schema.version.app.root.start=v13
+schema.version.namespace.change.start=v13
+schema.version.edge.label.start=v13
\ No newline at end of file
diff --git a/src/test/resources/spring-beans/data-router-oxm.xml b/src/test/resources/spring-beans/data-router-oxm.xml
new file mode 100644 (file)
index 0000000..90e7e97
--- /dev/null
@@ -0,0 +1,14 @@
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:task="http://www.springframework.org/schema/task"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+               http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd 
+               http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
+
+  <context:property-placeholder location="file:src/test/resources/config/schemaIngest.properties" ignore-unresolvable="true" />
+  
+  <bean id="schemaVersions" class="org.onap.aai.setup.SchemaVersions"/>
+  
+  <bean id="schemaLocationsBean" class="org.onap.aai.setup.SchemaLocationsBean"/>
+  
+</beans>