summaryrefslogtreecommitdiffstats
path: root/sparkybe-onap-service/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'sparkybe-onap-service/src/main')
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmConfigTranslator.java116
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java18
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java2
-rw-r--r--sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java4
4 files changed, 12 insertions, 128 deletions
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmConfigTranslator.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmConfigTranslator.java
deleted file mode 100644
index 4a46e22..0000000
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmConfigTranslator.java
+++ /dev/null
@@ -1,116 +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.sparky.config.oxm;
-
-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.Arrays;
-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.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.setup.ConfigTranslator;
-import org.onap.aai.setup.SchemaLocationsBean;
-import org.onap.aai.setup.Version;
-import org.onap.aai.sparky.logging.AaiUiMsgs;
-import org.onap.aai.sparky.util.NodeUtils;
-
-/**
- * Determine which OXM and edge rules files to return based on the latest Version
- *
- */
-public class OxmConfigTranslator extends ConfigTranslator {
-
- private static final Logger LOG = LoggerFactory.getInstance().getLogger(OxmConfigTranslator.class);
-
- 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" + NodeUtils.extractOxmVersionFromPath(pathName);
-
- try {
- return Version.valueOf(version);
- } catch (IllegalArgumentException e) {
- LOG.error(AaiUiMsgs.ERROR_GENERIC, "Failed to find OXM version '" + version
- + "' from Version enumeration value set = " + Arrays.asList(Version.values()) + ".");
- }
-
- return null;
- }
-} \ No newline at end of file
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java
index 0c89dcb..7ad01c7 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/config/oxm/OxmModelLoader.java
@@ -26,7 +26,8 @@ import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.nodes.NodeIngestor;
-import org.onap.aai.setup.Version;
+import org.onap.aai.setup.SchemaVersion;
+import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.sparky.logging.AaiUiMsgs;
public class OxmModelLoader {
@@ -42,25 +43,24 @@ public class OxmModelLoader {
* specified version, and that stream will be returned if available.
*/
- protected Version oxmApiVersion;
+ protected SchemaVersion oxmApiVersion;
protected Set<OxmModelProcessor> processors;
private NodeIngestor nodeIngestor;
- public OxmModelLoader(Version apiVersionOverride, Set<OxmModelProcessor> oxmModelProcessors,
- NodeIngestor nodeIngestor) {
- this.oxmApiVersion = apiVersionOverride;
+ public OxmModelLoader(String apiVersionOverride, Set<OxmModelProcessor> oxmModelProcessors, NodeIngestor nodeIngestor) {
+ this.oxmApiVersion = new SchemaVersion(apiVersionOverride);
this.processors = oxmModelProcessors;
this.nodeIngestor = nodeIngestor;
}
- public OxmModelLoader(Set<OxmModelProcessor> oxmModelProcessors, NodeIngestor nodeIngestor) {
- this.oxmApiVersion = Version.getLatest();
+ public OxmModelLoader(Set<OxmModelProcessor> oxmModelProcessors, NodeIngestor nodeIngestor, SchemaVersions schemaVersions) {
+ this.oxmApiVersion = schemaVersions.getDefaultVersion();
this.processors = oxmModelProcessors;
this.nodeIngestor = nodeIngestor;
}
- public Version getLatestVersionNum() {
+ public SchemaVersion getOxmApiVersion() {
return oxmApiVersion;
}
@@ -93,7 +93,7 @@ public class OxmModelLoader {
if (processors != null && processors.size() > 0) {
for (OxmModelProcessor processor : processors) {
-
+
try {
processor.processOxmModel(oxmContext);
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java
index e168f43..bd00d20 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java
@@ -145,7 +145,7 @@ public class ActiveInventoryAdapter {
String versionStr;
if (oxmModelLoader != null) {
- versionStr = String.valueOf(oxmModelLoader.getLatestVersionNum());
+ versionStr = String.valueOf(oxmModelLoader.getOxmApiVersion());
} else {
throw new RuntimeException("Unable to resolve aai version.");
}
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java
index 79b5466..9371a4a 100644
--- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java
+++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java
@@ -156,7 +156,7 @@ public class AttributeUpdater {
String versionStr = null;
if (oxmModelLoader != null) {
- versionStr = String.valueOf(oxmModelLoader.getLatestVersionNum());
+ versionStr = String.valueOf(oxmModelLoader.getOxmApiVersion());
}
return "/aai/v" + versionStr;
@@ -263,7 +263,7 @@ public class AttributeUpdater {
String version = getVersionFromUri(objectUri);
if ( null == version ) {
- version = "v" + String.valueOf(oxmModelLoader.getLatestVersionNum());
+ version = "v" + String.valueOf(oxmModelLoader.getOxmApiVersion());
}
object.setSchemaVersion(version);