summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Arrastia <MArrasti@amdocs.com>2018-11-28 17:27:31 +0000
committerMichael Arrastia <MArrasti@amdocs.com>2018-11-28 17:27:31 +0000
commitd894ec51a86cfb4d711d3c053d8aa46759584456 (patch)
treec60a1680d735c5c76bc1e9ec625be6140d4b7667 /src/main/java
parent9eb82afe62f6891d1e140fd9003e1ceb7df119ee (diff)
Upgrade version of aai-common
* Configure Spike with schema ingestion beans. * Update OXMModelLoader and EdgeRulesLoader to make use of schema ingestion beans. Here there is an acknowledged awkward marrying of bean creation and static method use. * Update tests to mock schema ingestion beans and organise test resources. Change-Id: I1f043aa5852dbd2737a804ebc282a12afb9fb39f Issue-ID: AAI-1951 Signed-off-by: Michael Arrastia <MArrasti@amdocs.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/aai/spike/SchemaIngestConfiguration.java62
-rw-r--r--src/main/java/org/onap/aai/spike/SpikeApplication.java13
-rw-r--r--src/main/java/org/onap/aai/spike/schema/EdgePropsConfiguration.java42
-rw-r--r--src/main/java/org/onap/aai/spike/schema/EdgeRulesLoader.java72
-rw-r--r--src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java138
-rw-r--r--src/main/java/org/onap/aai/spike/schema/OxmConfigTranslator.java19
-rw-r--r--src/main/java/org/onap/aai/spike/util/SchemaIngestPropertiesReader.java116
7 files changed, 240 insertions, 222 deletions
diff --git a/src/main/java/org/onap/aai/spike/SchemaIngestConfiguration.java b/src/main/java/org/onap/aai/spike/SchemaIngestConfiguration.java
new file mode 100644
index 0000000..fcb1e71
--- /dev/null
+++ b/src/main/java/org/onap/aai/spike/SchemaIngestConfiguration.java
@@ -0,0 +1,62 @@
+/**
+ * ============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.spike;
+
+import org.onap.aai.edges.EdgeIngestor;
+import org.onap.aai.nodes.NodeIngestor;
+import org.onap.aai.setup.AAIConfigTranslator;
+import org.onap.aai.setup.ConfigTranslator;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersions;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+
+@Configuration
+@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true)
+public class SchemaIngestConfiguration {
+
+ @Bean
+ public SchemaVersions schemaVersions() {
+ return new SchemaVersions();
+ }
+
+ @Bean
+ public SchemaLocationsBean schemaLocationsBean() {
+ return new SchemaLocationsBean();
+ }
+
+ @Bean
+ public ConfigTranslator configTranslator() {
+ return new AAIConfigTranslator(schemaLocationsBean(), schemaVersions());
+ }
+
+ @Bean
+ public NodeIngestor nodeIngestor() {
+ return new NodeIngestor(configTranslator());
+ }
+
+ @Bean
+ public EdgeIngestor edgeIngestor() {
+ return new EdgeIngestor(configTranslator(), schemaVersions());
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/spike/SpikeApplication.java b/src/main/java/org/onap/aai/spike/SpikeApplication.java
index 426731b..2768c24 100644
--- a/src/main/java/org/onap/aai/spike/SpikeApplication.java
+++ b/src/main/java/org/onap/aai/spike/SpikeApplication.java
@@ -1,5 +1,5 @@
/**
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
@@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.env.Environment;
@@ -34,20 +35,23 @@ import org.springframework.core.env.Environment;
* Spike service Spring Boot Application
*/
@SpringBootApplication
+@Import({SchemaIngestConfiguration.class})
@ImportResource({"file:${SERVICE_BEANS}/*.xml"})
public class SpikeApplication extends SpringBootServletInitializer {
@Autowired
private Environment env;
-
+
public static void main(String[] args) {
String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD");
if (keyStorePassword == null || keyStorePassword.isEmpty()) {
throw new IllegalArgumentException("System Property KEY_STORE_PASSWORD not set");
}
+
HashMap<String, Object> props = new HashMap<>();
props.put("server.ssl.key-store-password", Password.deobfuscate(keyStorePassword));
- new SpikeApplication().configure(new SpringApplicationBuilder(SpikeApplication.class).properties(props))
- .run(args);
+
+ new SpikeApplication().configure(new SpringApplicationBuilder(SchemaIngestConfiguration.class)
+ .child(SpikeApplication.class).properties(props)).run(args);
}
/**
@@ -67,4 +71,5 @@ public class SpikeApplication extends SpringBootServletInitializer {
}
}
}
+
}
diff --git a/src/main/java/org/onap/aai/spike/schema/EdgePropsConfiguration.java b/src/main/java/org/onap/aai/spike/schema/EdgePropsConfiguration.java
new file mode 100644
index 0000000..f721262
--- /dev/null
+++ b/src/main/java/org/onap/aai/spike/schema/EdgePropsConfiguration.java
@@ -0,0 +1,42 @@
+/**
+ * ============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.spike.schema;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.stereotype.Component;
+
+@Component
+@PropertySource(value = "file:${edgeprops.ingest.file}", ignoreResourceNotFound = true)
+public class EdgePropsConfiguration {
+
+ @Value("${edgePropsDir}")
+ private String edgePropsDir;
+
+ public String getEdgePropsDir() {
+ return edgePropsDir;
+ }
+
+ public void setEdgePropsDir(String edgePropsDir) {
+ this.edgePropsDir = edgePropsDir;
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/spike/schema/EdgeRulesLoader.java b/src/main/java/org/onap/aai/spike/schema/EdgeRulesLoader.java
index b914421..be303f5 100644
--- a/src/main/java/org/onap/aai/spike/schema/EdgeRulesLoader.java
+++ b/src/main/java/org/onap/aai/spike/schema/EdgeRulesLoader.java
@@ -20,6 +20,7 @@
*/
package org.onap.aai.spike.schema;
+import com.google.common.collect.Multimap;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -31,29 +32,33 @@ import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-import com.google.common.collect.Multimap;
import org.apache.commons.io.IOUtils;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.edges.EdgeRule;
import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
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.spike.exception.SpikeException;
import org.onap.aai.spike.logging.SpikeMsgs;
-import org.onap.aai.spike.util.SchemaIngestPropertiesReader;
-
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+@Component
public class EdgeRulesLoader {
+ private static ConfigTranslator configTranslator;
+ private static EdgeIngestor edgeIngestor;
+
+ private static EdgePropsConfiguration edgePropsConfiguration;
+
private static Map<String, RelationshipSchema> versionContextMap = new ConcurrentHashMap<>();
- static final Pattern versionPattern = Pattern.compile("V(\\d*)");
+ static final Pattern versionPattern = Pattern.compile("(?i)v(\\d*)");
static final String propsPrefix = "edge_properties_";
static final String propsSuffix = ".json";
final static Pattern propsFilePattern = Pattern.compile(propsPrefix + "(.*)" + propsSuffix);
- final static Pattern propsVersionPattern = Pattern.compile("v\\d*");
+ final static Pattern propsVersionPattern = Pattern.compile("(?i)v\\d*");
private static org.onap.aai.cl.api.Logger logger =
LoggerFactory.getInstance().getLogger(EdgeRulesLoader.class.getName());
@@ -61,17 +66,28 @@ public class EdgeRulesLoader {
private EdgeRulesLoader() {}
/**
+ * This constructor presents an awkward marrying of Spring bean creation and static method use. This
+ * is technical debt that will need fixing.
+ *
+ * @param configTranslator contains schema versions configuration
+ * @param edgeIngestor provides edge rules
+ * @param edgePropsConfiguration edge property validation configuration
+ */
+ @Autowired
+ public EdgeRulesLoader(ConfigTranslator configTranslator, EdgeIngestor edgeIngestor,
+ EdgePropsConfiguration edgePropsConfiguration) {
+ EdgeRulesLoader.configTranslator = configTranslator;
+ EdgeRulesLoader.edgeIngestor = edgeIngestor;
+ EdgeRulesLoader.edgePropsConfiguration = edgePropsConfiguration;
+ }
+
+ /**
* Finds all DB Edge Rules and Edge Properties files for all OXM models.
*
* @throws SpikeException
*/
public static synchronized void loadModels() throws SpikeException {
- SchemaIngestPropertiesReader SchemaIngestPropertiesReader = new SchemaIngestPropertiesReader();
- SchemaLocationsBean schemaLocationsBean = new SchemaLocationsBean();
- schemaLocationsBean.setEdgeDirectory(SchemaIngestPropertiesReader.getEdgeDir());
- ConfigTranslator configTranslator = new OxmConfigTranslator(schemaLocationsBean);
- EdgeIngestor edgeIngestor = new EdgeIngestor(configTranslator);
- Map<String, File> propFiles = edgePropertyFiles(SchemaIngestPropertiesReader);
+ Map<String, File> propFiles = edgePropertyFiles(edgePropsConfiguration);
if (logger.isDebugEnabled()) {
logger.debug("Loading DB Edge Rules");
@@ -79,7 +95,9 @@ public class EdgeRulesLoader {
for (String version : OXMModelLoader.getLoadedOXMVersions()) {
try {
- loadModel(Version.valueOf(version), edgeIngestor, propFiles);
+ SchemaVersion schemaVersion = configTranslator.getSchemaVersions().getVersions().stream()
+ .filter(s -> s.toString().equalsIgnoreCase(version)).findAny().orElse(null);
+ loadModel(schemaVersion, edgeIngestor, propFiles);
} catch (IOException | EdgeRuleNotFoundException e) {
throw new SpikeException(e.getMessage(), e);
}
@@ -93,20 +111,17 @@ public class EdgeRulesLoader {
*/
public static synchronized void loadModels(String v) throws SpikeException {
- SchemaIngestPropertiesReader SchemaIngestPropertiesReader = new SchemaIngestPropertiesReader();
- SchemaLocationsBean schemaLocationsBean = new SchemaLocationsBean();
- schemaLocationsBean.setEdgeDirectory(SchemaIngestPropertiesReader.getEdgeDir());
- ConfigTranslator configTranslator = new OxmConfigTranslator(schemaLocationsBean);
- EdgeIngestor edgeIngestor = new EdgeIngestor(configTranslator);
- String version = v.toUpperCase();
- Map<String, File> propFiles = edgePropertyFiles(SchemaIngestPropertiesReader);
+ Map<String, File> propFiles = edgePropertyFiles(edgePropsConfiguration);
if (logger.isDebugEnabled()) {
logger.debug("Loading DB Edge Rules ");
}
try {
- loadModel(Version.valueOf(version), edgeIngestor, propFiles);
+ SchemaVersion schemaVersion = configTranslator.getSchemaVersions().getVersions().stream()
+ .filter(s -> s.toString().equalsIgnoreCase(v)).findAny().orElse(null);
+
+ loadModel(schemaVersion, edgeIngestor, propFiles);
} catch (IOException | EdgeRuleNotFoundException e) {
throw new SpikeException(e.getMessage());
}
@@ -172,7 +187,7 @@ public class EdgeRulesLoader {
String latestVersionStr = null;
for (String versionKey : versionContextMap.keySet()) {
- Matcher matcher = versionPattern.matcher(versionKey.toUpperCase());
+ Matcher matcher = versionPattern.matcher(versionKey);
if (matcher.find()) {
int currentVersion = Integer.parseInt(matcher.group(1));
@@ -191,13 +206,12 @@ public class EdgeRulesLoader {
* Reset the loaded DB Edge Rule schemas
*
*/
-
public static void resetSchemaVersionContext() {
versionContextMap = new ConcurrentHashMap<>();
}
- private static synchronized void loadModel(Version version, EdgeIngestor edgeIngestor, Map<String, File> props)
- throws IOException, SpikeException, EdgeRuleNotFoundException {
+ private static synchronized void loadModel(SchemaVersion version, EdgeIngestor edgeIngestor,
+ Map<String, File> props) throws IOException, SpikeException, EdgeRuleNotFoundException {
Multimap<String, EdgeRule> edges = edgeIngestor.getAllRules(version);
String edgeProps;
@@ -213,11 +227,13 @@ public class EdgeRulesLoader {
}
}
- private static Map<String, File> edgePropertyFiles(SchemaIngestPropertiesReader dir) throws SpikeException {
+ private static Map<String, File> edgePropertyFiles(EdgePropsConfiguration edgePropsConfiguration)
+ throws SpikeException {
Map<String, File> propsFiles = Arrays
- .stream(new File(dir.getEdgePropsDir())
+ .stream(new File(edgePropsConfiguration.getEdgePropsDir())
.listFiles((d, name) -> propsFilePattern.matcher(name).matches()))
.collect(Collectors.toMap(new Function<File, String>() {
+ @Override
public String apply(File f) {
Matcher m1 = propsVersionPattern.matcher(f.getName());
m1.find();
diff --git a/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java b/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java
index 5d35017..7f41d8c 100644
--- a/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java
+++ b/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java
@@ -20,6 +20,7 @@
*/
package org.onap.aai.spike.schema;
+import com.google.common.base.CaseFormat;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -28,58 +29,64 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
-import javax.ws.rs.core.Response.Status;
-
import org.eclipse.persistence.dynamic.DynamicType;
import org.eclipse.persistence.internal.oxm.mappings.Descriptor;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.onap.aai.cl.eelf.LoggerFactory;
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.spike.exception.SpikeException;
import org.onap.aai.spike.logging.SpikeMsgs;
-import org.onap.aai.spike.util.SchemaIngestPropertiesReader;
-import com.google.common.base.CaseFormat;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
/**
* This class contains all of the logic for importing OXM model schemas from the available OXM
* schema files.
*/
+@Component
public class OXMModelLoader {
- private static Map<String, DynamicJAXBContext> versionContextMap =
- new ConcurrentHashMap<String, DynamicJAXBContext>();
- private static Map<String, HashMap<String, DynamicType>> xmlElementLookup = new ConcurrentHashMap<String, HashMap<String, DynamicType>>();
-
- final static Pattern p = Pattern.compile("aai_oxm_(.*).xml");
- final static Pattern versionPattern = Pattern.compile("V(\\d*)");
+ private static ConfigTranslator configTranslator;
+ private static NodeIngestor nodeIngestor;
+
+ private static Map<String, DynamicJAXBContext> versionContextMap = new ConcurrentHashMap<>();
+ private static Map<String, HashMap<String, DynamicType>> xmlElementLookup = new ConcurrentHashMap<>();
+
+ final static Pattern versionPattern = Pattern.compile("(?i)v(\\d*)");
private static org.onap.aai.cl.api.Logger logger =
LoggerFactory.getInstance().getLogger(OXMModelLoader.class.getName());
+ private OXMModelLoader() {}
+
+ /**
+ * This constructor presents an awkward marrying of Spring bean creation and static method use. This
+ * is technical debt that will need fixing.
+ *
+ * @param configTranslator contains schema versions configuration
+ * @param nodeIngestor provides DynamicJAXBContext for the OXM version
+ */
+ @Autowired
+ public OXMModelLoader(ConfigTranslator configTranslator, NodeIngestor nodeIngestor) {
+ OXMModelLoader.configTranslator = configTranslator;
+ OXMModelLoader.nodeIngestor = nodeIngestor;
+ }
+
/**
* Finds all OXM model files
- *
+ *
* @throws SpikeException
* @throws IOException
*
*/
public synchronized static void loadModels() throws SpikeException {
- SchemaIngestPropertiesReader schemaIngestPropReader = new SchemaIngestPropertiesReader();
- SchemaLocationsBean schemaLocationsBean = new SchemaLocationsBean();
- schemaLocationsBean.setNodeDirectory(schemaIngestPropReader.getNodeDir());
- schemaLocationsBean.setEdgeDirectory(schemaIngestPropReader.getEdgeDir());
- ConfigTranslator configTranslator = new OxmConfigTranslator(schemaLocationsBean);
- NodeIngestor nodeIngestor = new NodeIngestor(configTranslator);
-
if (logger.isDebugEnabled()) {
logger.debug("Loading OXM Models");
}
- for (Version oxmVersion : Version.values()) {
+ for (SchemaVersion oxmVersion : configTranslator.getSchemaVersions().getVersions()) {
DynamicJAXBContext jaxbContext = nodeIngestor.getContextForVersion(oxmVersion);
if (jaxbContext != null) {
loadModel(oxmVersion.toString(), jaxbContext);
@@ -87,7 +94,6 @@ public class OXMModelLoader {
}
}
-
private synchronized static void loadModel(String oxmVersion, DynamicJAXBContext jaxbContext) {
versionContextMap.put(oxmVersion, jaxbContext);
loadXmlLookupMap(oxmVersion, jaxbContext);
@@ -167,57 +173,57 @@ public class OXMModelLoader {
OXMModelLoader.versionContextMap = versionContextMap;
}
- public static void loadXmlLookupMap(String version, DynamicJAXBContext jaxbContext) {
+ public static void loadXmlLookupMap(String version, DynamicJAXBContext jaxbContext) {
- @SuppressWarnings("rawtypes")
- List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
- HashMap<String, DynamicType> types = new HashMap<String, DynamicType>();
+ @SuppressWarnings("rawtypes")
+ List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
+ HashMap<String, DynamicType> types = new HashMap<String, DynamicType>();
- for (@SuppressWarnings("rawtypes")
- Descriptor desc : descriptorsList) {
+ for (@SuppressWarnings("rawtypes")
+ Descriptor desc : descriptorsList) {
- DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
- String entityName = desc.getDefaultRootElement();
- types.put(entityName, entity);
- }
- xmlElementLookup.put(version, types);
- }
-
- public static DynamicType getDynamicTypeForVersion(String version, String type) throws SpikeException {
-
- DynamicType dynamicType;
- // If we haven't already loaded in the available OXM models, then do so now.
- if (versionContextMap == null || versionContextMap.isEmpty()) {
- loadModels();
- } else if (!versionContextMap.containsKey(version)) {
- logger.error(SpikeMsgs.OXM_LOAD_ERROR, "Error loading oxm model: " + version);
- throw new SpikeException("Error loading oxm model: " + version);
+ DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
+ String entityName = desc.getDefaultRootElement();
+ types.put(entityName, entity);
+ }
+ xmlElementLookup.put(version, types);
}
- // First try to match the Java-type based on hyphen to camel case
- // translation
- String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, type);
- dynamicType = versionContextMap.get(version).getDynamicType(javaTypeName);
+ public static DynamicType getDynamicTypeForVersion(String version, String type) throws SpikeException {
- if (xmlElementLookup.containsKey(version)) {
- if (dynamicType == null) {
- // Try to lookup by xml root element by exact match
- dynamicType = xmlElementLookup.get(version).get(type);
- }
+ DynamicType dynamicType;
+ // If we haven't already loaded in the available OXM models, then do so now.
+ if (versionContextMap == null || versionContextMap.isEmpty()) {
+ loadModels();
+ } else if (!versionContextMap.containsKey(version)) {
+ logger.error(SpikeMsgs.OXM_LOAD_ERROR, "Error loading oxm model: " + version);
+ throw new SpikeException("Error loading oxm model: " + version);
+ }
- if (dynamicType == null) {
- // Try to lookup by xml root element by lowercase
- dynamicType = xmlElementLookup.get(version).get(type.toLowerCase());
- }
+ // First try to match the Java-type based on hyphen to camel case
+ // translation
+ String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, type);
+ dynamicType = versionContextMap.get(version).getDynamicType(javaTypeName);
- if (dynamicType == null) {
- // Direct lookup as java-type name
- dynamicType = versionContextMap.get(version).getDynamicType(type);
- }
- }
+ if (xmlElementLookup.containsKey(version)) {
+ if (dynamicType == null) {
+ // Try to lookup by xml root element by exact match
+ dynamicType = xmlElementLookup.get(version).get(type);
+ }
+
+ if (dynamicType == null) {
+ // Try to lookup by xml root element by lowercase
+ dynamicType = xmlElementLookup.get(version).get(type.toLowerCase());
+ }
+
+ if (dynamicType == null) {
+ // Direct lookup as java-type name
+ dynamicType = versionContextMap.get(version).getDynamicType(type);
+ }
+ }
- return dynamicType;
- }
+ return dynamicType;
+ }
/**
* Retrieves the list of all Loaded OXM versions.
@@ -238,7 +244,7 @@ public class OXMModelLoader {
}
List<String> versions = new ArrayList<String>();
for (String versionKey : versionContextMap.keySet()) {
- Matcher matcher = versionPattern.matcher(versionKey.toUpperCase());
+ Matcher matcher = versionPattern.matcher(versionKey);
if (matcher.find()) {
versions.add("V" + matcher.group(1));
}
diff --git a/src/main/java/org/onap/aai/spike/schema/OxmConfigTranslator.java b/src/main/java/org/onap/aai/spike/schema/OxmConfigTranslator.java
index 51ed93e..389781f 100644
--- a/src/main/java/org/onap/aai/spike/schema/OxmConfigTranslator.java
+++ b/src/main/java/org/onap/aai/spike/schema/OxmConfigTranslator.java
@@ -32,15 +32,16 @@ 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 OxmConfigTranslator extends ConfigTranslator {
- public OxmConfigTranslator(SchemaLocationsBean bean) {
- super(bean);
+ public OxmConfigTranslator(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(
@@ -54,7 +55,7 @@ public class OxmConfigTranslator 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(
@@ -79,7 +80,7 @@ public class OxmConfigTranslator 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)
@@ -87,10 +88,12 @@ public class OxmConfigTranslator 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;
}
diff --git a/src/main/java/org/onap/aai/spike/util/SchemaIngestPropertiesReader.java b/src/main/java/org/onap/aai/spike/util/SchemaIngestPropertiesReader.java
deleted file mode 100644
index 48e26c8..0000000
--- a/src/main/java/org/onap/aai/spike/util/SchemaIngestPropertiesReader.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.spike.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
-import java.nio.file.Files;
-import java.nio.file.NoSuchFileException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Properties;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.spike.exception.SpikeException;
-import org.onap.aai.spike.logging.SpikeMsgs;
-
-public class SchemaIngestPropertiesReader {
-
- private static final String SCHEMA_INGEST_PROPERTIES_LOCATION =
- System.getProperty("CONFIG_HOME") + "/schemaIngest.properties";
-
- private static org.onap.aai.cl.api.Logger logger =
- LoggerFactory.getInstance().getLogger(SchemaIngestPropertiesReader.class.getName());
-
- /**
- * Gets the Node directory location to ingest OXMs
- *
- * @return path to OXMs
- * @throws SpikeException
- */
- public String getNodeDir() throws SpikeException {
- Properties prop = findSchemaIngestPropertyFile();
- return prop.getProperty("nodeDir");
- }
-
- /**
- * Gets the Edge directory location to ingest OXM
- *
- * @return path to OXMs
- * @throws SpikeException
- */
- public String getEdgeDir() throws SpikeException {
- Properties prop = findSchemaIngestPropertyFile();
- return prop.getProperty("edgeDir");
- }
-
- /**
- * Gets the location of the Edge Properties
- *
- * @return
- * @throws SpikeException
- */
- public String getEdgePropsDir() throws SpikeException {
-
- Properties prop = findSchemaIngestPropertyFile();
- return prop.getProperty("edgePropsDir");
- }
-
-
- private Properties findSchemaIngestPropertyFile() throws SpikeException {
- Properties prop = new Properties();
- try {
- prop = loadFromFile(SCHEMA_INGEST_PROPERTIES_LOCATION);
- } catch (NoSuchFileException e) {
- // if file not found, try via classpath
- try {
- prop = loadFromClasspath("schemaIngest.properties");
- } catch (URISyntaxException | IOException e1) {
- logger.error(SpikeMsgs.SPIKE_SCHEMA_INGEST_LOAD_ERROR, e1.getMessage());
- throw new SpikeException("Failed to load schemaIngest.properties", e1);
- }
- } catch (IOException e) {
- logger.error(SpikeMsgs.SPIKE_SCHEMA_INGEST_LOAD_ERROR, e.getMessage());
- throw new SpikeException("Failed to load schemaIngest.properties", e);
- }
- return prop;
- }
-
- private Properties loadFromFile(String filename) throws IOException {
- Path configLocation = Paths.get(filename);
- try (InputStream stream = Files.newInputStream(configLocation)) {
- return loadProperties(stream);
- }
- }
-
- private Properties loadFromClasspath(String resourceName) throws URISyntaxException, IOException {
- Path path = Paths.get(ClassLoader.getSystemResource(resourceName).toURI());
- try (InputStream stream = Files.newInputStream(path)) {
- return loadProperties(stream);
- }
- }
-
- private Properties loadProperties(InputStream stream) throws IOException {
- Properties config = new Properties();
- config.load(stream);
- return config;
- }
-}