aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/aai/schema/OxmConfigTranslator.java98
-rw-r--r--src/main/java/org/onap/aai/schema/OxmModelLoader.java17
2 files changed, 8 insertions, 107 deletions
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());
}