aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--pom.xml13
-rw-r--r--src/main/java/org/onap/aai/schema/OxmConfigTranslator.java98
-rw-r--r--src/main/java/org/onap/aai/schema/OxmModelLoader.java17
-rw-r--r--src/test/java/org/onap/aai/schema/OxmModelLoaderTest.java26
-rw-r--r--src/test/resources/config/schemaIngest.properties16
-rw-r--r--src/test/resources/oxm-reader/multiple-oxm/v11/aai_oxm_v11.xml (renamed from src/test/resources/oxm-reader/multiple-oxm/aai_oxm_v11.xml)0
-rw-r--r--src/test/resources/oxm-reader/multiple-oxm/v12/aai_oxm_v12.xml (renamed from src/test/resources/oxm-reader/multiple-oxm/aai_oxm_v12.xml)0
-rw-r--r--src/test/resources/oxm-reader/multiple-oxm/v13/aai_oxm_a_v13.xml (renamed from src/test/resources/oxm-reader/multiple-oxm/aai_oxm_a_v13.xml)0
-rw-r--r--src/test/resources/oxm-reader/multiple-oxm/v13/aai_oxm_b_v13.xml (renamed from src/test/resources/oxm-reader/multiple-oxm/aai_oxm_b_v13.xml)0
-rw-r--r--src/test/resources/oxm-reader/oxm/v10/aai_oxm_v10.xml (renamed from src/test/resources/oxm-reader/oxm/aai_oxm_v10.xml)0
-rw-r--r--src/test/resources/oxm-reader/oxm/v11/aai_oxm_v11.xml (renamed from src/test/resources/oxm-reader/oxm/aai_oxm_v11.xml)0
-rw-r--r--src/test/resources/oxm-reader/oxm/v12/aai_oxm_v12.xml (renamed from src/test/resources/oxm-reader/oxm/aai_oxm_v12.xml)0
-rw-r--r--src/test/resources/oxm-reader/oxm/v13/aai_oxm_v13.xml (renamed from src/test/resources/oxm-reader/oxm/aai_oxm_v13.xml)0
-rw-r--r--src/test/resources/oxm-reader/oxm/v8/aai_oxm_v8.xml (renamed from src/test/resources/oxm-reader/oxm/aai_oxm_v8.xml)0
-rw-r--r--src/test/resources/oxm-reader/oxm/v9/aai_oxm_v9.xml (renamed from src/test/resources/oxm-reader/oxm/aai_oxm_v9.xml)0
-rw-r--r--src/test/resources/spring-beans/data-router-oxm.xml14
17 files changed, 72 insertions, 113 deletions
diff --git a/.gitignore b/.gitignore
index 33793a8..af81fcf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.checkstyle
.classpath
.project
.settings/
diff --git a/pom.xml b/pom.xml
index 7953d49..36fd561 100644
--- 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
index a829002..0000000
--- a/src/main/java/org/onap/aai/schema/OxmConfigTranslator.java
+++ /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;
- }
- }
-}
diff --git a/src/main/java/org/onap/aai/schema/OxmModelLoader.java b/src/main/java/org/onap/aai/schema/OxmModelLoader.java
index 1e62cfc..bd64f3e 100644
--- a/src/main/java/org/onap/aai/schema/OxmModelLoader.java
+++ b/src/main/java/org/onap/aai/schema/OxmModelLoader.java
@@ -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());
}
diff --git a/src/test/java/org/onap/aai/schema/OxmModelLoaderTest.java b/src/test/java/org/onap/aai/schema/OxmModelLoaderTest.java
index 060e5ed..f3e9091 100644
--- a/src/test/java/org/onap/aai/schema/OxmModelLoaderTest.java
+++ b/src/test/java/org/onap/aai/schema/OxmModelLoaderTest.java
@@ -20,29 +20,44 @@
*/
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
index 0000000..05e5555
--- /dev/null
+++ b/src/test/resources/config/schemaIngest.properties
@@ -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/oxm-reader/multiple-oxm/aai_oxm_v11.xml b/src/test/resources/oxm-reader/multiple-oxm/v11/aai_oxm_v11.xml
index 90d023c..90d023c 100644
--- a/src/test/resources/oxm-reader/multiple-oxm/aai_oxm_v11.xml
+++ b/src/test/resources/oxm-reader/multiple-oxm/v11/aai_oxm_v11.xml
diff --git a/src/test/resources/oxm-reader/multiple-oxm/aai_oxm_v12.xml b/src/test/resources/oxm-reader/multiple-oxm/v12/aai_oxm_v12.xml
index d9fbcca..d9fbcca 100644
--- a/src/test/resources/oxm-reader/multiple-oxm/aai_oxm_v12.xml
+++ b/src/test/resources/oxm-reader/multiple-oxm/v12/aai_oxm_v12.xml
diff --git a/src/test/resources/oxm-reader/multiple-oxm/aai_oxm_a_v13.xml b/src/test/resources/oxm-reader/multiple-oxm/v13/aai_oxm_a_v13.xml
index 334d32d..334d32d 100644
--- a/src/test/resources/oxm-reader/multiple-oxm/aai_oxm_a_v13.xml
+++ b/src/test/resources/oxm-reader/multiple-oxm/v13/aai_oxm_a_v13.xml
diff --git a/src/test/resources/oxm-reader/multiple-oxm/aai_oxm_b_v13.xml b/src/test/resources/oxm-reader/multiple-oxm/v13/aai_oxm_b_v13.xml
index 368fcc7..368fcc7 100644
--- a/src/test/resources/oxm-reader/multiple-oxm/aai_oxm_b_v13.xml
+++ b/src/test/resources/oxm-reader/multiple-oxm/v13/aai_oxm_b_v13.xml
diff --git a/src/test/resources/oxm-reader/oxm/aai_oxm_v10.xml b/src/test/resources/oxm-reader/oxm/v10/aai_oxm_v10.xml
index 51eaa34..51eaa34 100644
--- a/src/test/resources/oxm-reader/oxm/aai_oxm_v10.xml
+++ b/src/test/resources/oxm-reader/oxm/v10/aai_oxm_v10.xml
diff --git a/src/test/resources/oxm-reader/oxm/aai_oxm_v11.xml b/src/test/resources/oxm-reader/oxm/v11/aai_oxm_v11.xml
index 90d023c..90d023c 100644
--- a/src/test/resources/oxm-reader/oxm/aai_oxm_v11.xml
+++ b/src/test/resources/oxm-reader/oxm/v11/aai_oxm_v11.xml
diff --git a/src/test/resources/oxm-reader/oxm/aai_oxm_v12.xml b/src/test/resources/oxm-reader/oxm/v12/aai_oxm_v12.xml
index d9fbcca..d9fbcca 100644
--- a/src/test/resources/oxm-reader/oxm/aai_oxm_v12.xml
+++ b/src/test/resources/oxm-reader/oxm/v12/aai_oxm_v12.xml
diff --git a/src/test/resources/oxm-reader/oxm/aai_oxm_v13.xml b/src/test/resources/oxm-reader/oxm/v13/aai_oxm_v13.xml
index 2dfc4f0..2dfc4f0 100644
--- a/src/test/resources/oxm-reader/oxm/aai_oxm_v13.xml
+++ b/src/test/resources/oxm-reader/oxm/v13/aai_oxm_v13.xml
diff --git a/src/test/resources/oxm-reader/oxm/aai_oxm_v8.xml b/src/test/resources/oxm-reader/oxm/v8/aai_oxm_v8.xml
index d666b73..d666b73 100644
--- a/src/test/resources/oxm-reader/oxm/aai_oxm_v8.xml
+++ b/src/test/resources/oxm-reader/oxm/v8/aai_oxm_v8.xml
diff --git a/src/test/resources/oxm-reader/oxm/aai_oxm_v9.xml b/src/test/resources/oxm-reader/oxm/v9/aai_oxm_v9.xml
index ecffb2f..ecffb2f 100644
--- a/src/test/resources/oxm-reader/oxm/aai_oxm_v9.xml
+++ b/src/test/resources/oxm-reader/oxm/v9/aai_oxm_v9.xml
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
index 0000000..90e7e97
--- /dev/null
+++ b/src/test/resources/spring-beans/data-router-oxm.xml
@@ -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>