aboutsummaryrefslogtreecommitdiffstats
path: root/aai-schema-ingest/src/main/java/org/onap/aai/setup
diff options
context:
space:
mode:
Diffstat (limited to 'aai-schema-ingest/src/main/java/org/onap/aai/setup')
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java9
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java66
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaLocationsBean.java1
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java105
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceVersions.java48
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersion.java2
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersions.java120
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersionsBean.java83
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java67
9 files changed, 413 insertions, 88 deletions
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java
index 2cb0c99b..899a520d 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java
@@ -20,7 +20,10 @@
package org.onap.aai.setup;
import java.io.File;
-import java.util.*;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -43,7 +46,7 @@ public class AAIConfigTranslator extends ConfigTranslator {
*/
@Override
public Map<SchemaVersion, List<String>> getNodeFiles() {
-
+
Map<SchemaVersion, List<String>> files = new TreeMap<>();
for (SchemaVersion v : schemaVersions.getVersions()) {
List<String> container = getVersionNodeFiles(v);
@@ -55,7 +58,6 @@ public class AAIConfigTranslator extends ConfigTranslator {
private List<String> getVersionNodeFiles(SchemaVersion v) {
-
return getVersionFiles(
bean.getNodeDirectory(),
v,
@@ -99,7 +101,6 @@ public class AAIConfigTranslator extends ConfigTranslator {
List<String> container;
final String directoryName = startDirectory + FILESEP + schemaVersion.toString() + FILESEP;
-
container = Arrays.stream(new File(directoryName).listFiles())
.map(File::getName)
.filter(name -> inclusionPattern.get().anyMatch(name::matches))
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java
index ccbe7065..4e6a6bdf 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java
@@ -20,25 +20,35 @@
package org.onap.aai.setup;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.apache.commons.io.IOUtils;
+import org.onap.aai.edges.JsonIngestor;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.io.*;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import org.springframework.beans.factory.annotation.Autowired;
-
/**
* Converts the contents of the schema config file
* (which lists which schema files to be loaded) to
* the format the Ingestors can work with.
*
*/
-public abstract class ConfigTranslator {
+public abstract class ConfigTranslator extends Translator{
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ConfigTranslator.class);
+
protected SchemaLocationsBean bean;
- protected SchemaVersions schemaVersions;
+
@Autowired
public ConfigTranslator(SchemaLocationsBean schemaLocationbean, SchemaVersions schemaVersions) {
+ super(schemaVersions);
this.bean = schemaLocationbean;
- this.schemaVersions = schemaVersions;
+
}
/**
@@ -49,6 +59,49 @@ public abstract class ConfigTranslator {
* ingested for that version
*/
public abstract Map<SchemaVersion, List<String>> getNodeFiles();
+
+ public List<InputStream> getVersionNodeStream(SchemaVersion version) {
+
+ Map<SchemaVersion, List<String>> filesToIngest = getNodeFiles();
+ List<InputStream> streams = new ArrayList<>();
+
+ if(!filesToIngest.containsKey(version)) {
+ return streams;
+ }
+ List<String> versionFiles = filesToIngest.get(version);
+
+ for (String name : versionFiles) {
+ try {
+ InputStream stream = new FileInputStream(new File(name));
+ String value = IOUtils.toString(stream, Charset.defaultCharset());
+ InputStream bis =(IOUtils.toInputStream(value, Charset.defaultCharset()));
+ streams.add(bis);
+ } catch (FileNotFoundException e) {
+ //TODO This may have to be cascaded
+ LOGGER.warn("File Not Found"+e.getMessage());
+ } catch (IOException e) {
+ LOGGER.warn("IOException while reading files"+e.getMessage());
+ }
+ }
+ return streams;
+ }
+
+ @Override
+ public List<String> getJsonPayload(SchemaVersion version) {
+ Map<SchemaVersion, List<String>> filesToIngest = getEdgeFiles();
+ List<String> jsonPayloads = new ArrayList<>();
+ if(!filesToIngest.containsKey(version)) {
+ return jsonPayloads;
+ }
+ List<String> versionFiles = filesToIngest.get(version);
+ JsonIngestor ji = new JsonIngestor();
+ for (String rulesFilename : versionFiles) {
+ jsonPayloads.add(ji.readInJsonFile(rulesFilename));
+
+ }
+
+ return jsonPayloads;
+ }
/**
* Translates the contents of the schema config file
@@ -59,7 +112,4 @@ public abstract class ConfigTranslator {
*/
public abstract Map<SchemaVersion, List<String>> getEdgeFiles();
- public SchemaVersions getSchemaVersions(){
- return schemaVersions;
- }
}
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaLocationsBean.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaLocationsBean.java
index e3cd7236..9e740a8c 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaLocationsBean.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaLocationsBean.java
@@ -26,7 +26,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
-import java.util.Collections;
import java.util.List;
@Configuration
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java
new file mode 100644
index 00000000..21082fa1
--- /dev/null
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java
@@ -0,0 +1,105 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.setup;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.onap.aai.restclient.RestClient;
+import org.onap.aai.restclient.RestClientFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.Resource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+
+import javax.ws.rs.HttpMethod;
+import java.io.*;
+import java.util.*;
+
+/**
+ * <b>AAIConfigTranslator</b> is responsible for looking at the schema files and
+ * edge files based on the available versions Also has the ability to exclude
+ * them based on the node.exclusion.pattern
+ */
+public class SchemaServiceTranslator extends Translator {
+
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(SchemaServiceTranslator.class);
+
+ private static final String SchemaServiceClientType = "schema.service";
+
+ @Value("${schema.service.nodes.endpoint}")
+ private String nodeSchemaUri;
+
+ @Value("${schema.service.edges.endpoint}")
+ private String edgeSchemaUri;
+
+ @Autowired
+ private RestClientFactory restClientFactory;
+
+ public SchemaServiceTranslator(SchemaVersions schemaVersions) {
+ super(schemaVersions);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.aai.setup.ConfigTranslator#getNodeFiles()
+ */
+
+ @Override
+ public List<InputStream> getVersionNodeStream(SchemaVersion version) throws IOException {
+
+ List<InputStream> inputStreams = new ArrayList<>();
+ String content = "";
+ String uri = nodeSchemaUri + version.toString();
+ Map<String, String> headersMap = new HashMap<>();
+
+ headersMap.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML.toString());
+ headersMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML.toString());
+ RestClient restClient = restClientFactory.getRestClient(SchemaServiceClientType);
+ ResponseEntity<Resource> schemaResponse = restClient.getGetResource(content, uri,
+ headersMap);
+ LOGGER.debug("SchemaResponse Status code" + schemaResponse.getStatusCode());
+ inputStreams.add(schemaResponse.getBody().getInputStream());
+ return inputStreams;
+ }
+
+ @Override
+ public List<String> getJsonPayload(SchemaVersion version) throws IOException {
+ /*
+ * Call Schema MS to get versions using RestTemplate
+ */
+ List<String> inputStreams = new ArrayList<>();
+ String content = "";
+ String uri = edgeSchemaUri + version.toString();
+ Map<String, String> headersMap = new HashMap<>();
+
+ RestClient restClient = restClientFactory.getRestClient(SchemaServiceClientType);
+
+ ResponseEntity<String> schemaResponse = restClient.getGetRequest(content, uri,
+ headersMap);
+ LOGGER.debug("SchemaResponse Status code" + schemaResponse.getStatusCode());
+ inputStreams.add(schemaResponse.getBody());
+ return inputStreams;
+
+ }
+
+}
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceVersions.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceVersions.java
new file mode 100644
index 00000000..6594f232
--- /dev/null
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceVersions.java
@@ -0,0 +1,48 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-18 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.setup;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class SchemaServiceVersions extends SchemaVersions {
+ private List<String> versions;
+ private String edgeVersion;
+ private String defaultVersion;
+ private String depthVersion;
+ private String appRootVersion;
+ private String relatedLinkVersion;
+ private String namespaceChangeVersion;
+
+
+ @PostConstruct
+ public void initializeFromSchemaService() {
+ versionsValue = versions.stream().map(SchemaVersion::new).collect(Collectors.toList());
+ edgeLabelVersionValue = new SchemaVersion(edgeVersion);
+ defaultVersionValue = new SchemaVersion(defaultVersion);
+ depthVersionValue = new SchemaVersion(depthVersion);
+ appRootVersionValue = new SchemaVersion(appRootVersion);
+ relatedLinkVersionValue = new SchemaVersion(relatedLinkVersion);
+ namespaceChangeVersionValue = new SchemaVersion(namespaceChangeVersion);
+ this.validate();
+ }
+
+}
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersion.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersion.java
index c744c5a3..a1a40e69 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersion.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersion.java
@@ -21,7 +21,6 @@ package org.onap.aai.setup;
import org.onap.aai.validation.AAISchemaValidationException;
-import java.util.Comparator;
import java.util.regex.Pattern;
public class SchemaVersion implements Comparable<SchemaVersion> {
@@ -31,7 +30,6 @@ public class SchemaVersion implements Comparable<SchemaVersion> {
private final String value;
public SchemaVersion(String value){
-
if(!VERSION_PATTERN.matcher(value).matches()){
throw new AAISchemaValidationException("Invalid Schema Version " + value + ", value doesn't match the expected regex: " + VERSION_PATTERN);
}
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersions.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersions.java
index 2205b14b..028ebdeb 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersions.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersions.java
@@ -2,13 +2,13 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-18 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* 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
+ * 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,
@@ -25,7 +25,6 @@ import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
-import javax.xml.validation.Schema;
import java.util.List;
import java.util.stream.Collectors;
@@ -36,124 +35,99 @@ public class SchemaVersions {
@Value("#{'${schema.version.list}'.split(',')}")
private List<String> apiVersions;
-
@Value("${schema.version.api.default}")
private String defaultApiVersion;
-
@Value("${schema.version.edge.label.start}")
private String edgeLabelStartVersion;
-
@Value("${schema.version.depth.start}")
private String depthStartVersion;
-
@Value("${schema.version.app.root.start}")
private String appRootStartVersion;
-
@Value("${schema.version.related.link.start}")
private String relatedLinkStartVersion;
-
@Value("${schema.version.namespace.change.start}")
- private String namespaceChangeStartVersion;
- private List<SchemaVersion> versions;
-
- private SchemaVersion edgeLabelVersion;
- private SchemaVersion defaultVersion;
- private SchemaVersion depthVersion;
- private SchemaVersion appRootVersion;
- private SchemaVersion relatedLinkVersion;
- private SchemaVersion namespaceChangeVersion;
+ protected String namespaceChangeStartVersion;
+ protected List<SchemaVersion> versionsValue;
+ protected SchemaVersion edgeLabelVersionValue;
+ protected SchemaVersion defaultVersionValue;
+ protected SchemaVersion depthVersionValue;
+ protected SchemaVersion appRootVersionValue;
+ protected SchemaVersion relatedLinkVersionValue;
+ protected SchemaVersion namespaceChangeVersionValue;
@PostConstruct
public void initialize() {
- versions = apiVersions.stream().map(SchemaVersion::new).collect(Collectors.toList());
-
- edgeLabelVersion = new SchemaVersion(edgeLabelStartVersion);
- defaultVersion = new SchemaVersion(defaultApiVersion);
- depthVersion = new SchemaVersion(depthStartVersion);
- appRootVersion = new SchemaVersion(appRootStartVersion);
- relatedLinkVersion = new SchemaVersion(relatedLinkStartVersion);
- namespaceChangeVersion = new SchemaVersion(namespaceChangeStartVersion);
-
- if (!versions.contains(edgeLabelVersion)) {
- throw new AAISchemaValidationException(
- "Invalid, edge label version is not in the api versions list"
+ versionsValue = apiVersions.stream().map(SchemaVersion::new).collect(Collectors.toList());
+ edgeLabelVersionValue = new SchemaVersion(edgeLabelStartVersion);
+ defaultVersionValue = new SchemaVersion(defaultApiVersion);
+ depthVersionValue = new SchemaVersion(depthStartVersion);
+ appRootVersionValue = new SchemaVersion(appRootStartVersion);
+ relatedLinkVersionValue = new SchemaVersion(relatedLinkStartVersion);
+ namespaceChangeVersionValue = new SchemaVersion(namespaceChangeStartVersion);
+ this.validate();
+ }
+
+
+ protected void validate() {
+ String errorMessage = "Invalid, edge label version is not in the api versions list"
+ ", please check schema.version.list and ensure that the"
- + " schema.version.edge.label.start is in that list"
- );
+ + " schema.version.edge.label.start is in that list";
+ if (!versionsValue.contains(edgeLabelVersionValue)) {
+ throw new AAISchemaValidationException(errorMessage);
}
- if (!versions.contains(defaultVersion)) {
- throw new AAISchemaValidationException(
- "Invalid, default version is not in the api versions list"
- + ", please check schema.version.list and ensure that the"
- + " schema.version.api.default is in that list"
- );
+ if (!versionsValue.contains(defaultVersionValue)) {
+ throw new AAISchemaValidationException(errorMessage);
}
- if (!versions.contains(depthVersion)) {
- throw new AAISchemaValidationException(
- "Invalid, depth version is not in the api versions list"
- + ", please check schema.version.list and ensure that the"
- + " schema.version.depth.start is in that list"
- );
+ if (!versionsValue.contains(depthVersionValue)) {
+ throw new AAISchemaValidationException(errorMessage);
}
- if(!versions.contains(appRootVersion)){
- throw new AAISchemaValidationException(
- "Invalid, app root version is not in the api versions list"
- + ", please check schema.version.list and ensure that the"
- + " schema.version.app.root.start is in that list"
- );
+ if (!versionsValue.contains(appRootVersionValue)) {
+ throw new AAISchemaValidationException(errorMessage);
}
- if(!versions.contains(relatedLinkVersion)){
- throw new AAISchemaValidationException(
- "Invalid, related link version is not in the api versions list"
- + ", please check schema.version.list and ensure that the"
- + " schema.version.related.link.start is in that list"
- );
+ if (!versionsValue.contains(relatedLinkVersionValue)) {
+ throw new AAISchemaValidationException(errorMessage);
}
- if(!versions.contains(namespaceChangeVersion)){
- throw new AAISchemaValidationException(
- "Invalid, namespace change start version is not in the api versions list"
- + ", please check schema.version.list and ensure that the"
- + " schema.version.related.link.start is in that list"
- );
+ if (!versionsValue.contains(namespaceChangeVersionValue)) {
+ throw new AAISchemaValidationException(errorMessage);
}
}
-
+
public List<SchemaVersion> getVersions() {
- return versions;
+ return versionsValue;
}
public SchemaVersion getEdgeLabelVersion() {
- return edgeLabelVersion;
+ return edgeLabelVersionValue;
}
public SchemaVersion getDefaultVersion() {
- return defaultVersion;
+ return defaultVersionValue;
}
public SchemaVersion getDepthVersion() {
- return depthVersion;
+ return depthVersionValue;
}
- public SchemaVersion getAppRootVersion(){
- return appRootVersion;
+ public SchemaVersion getAppRootVersion() {
+ return appRootVersionValue;
}
- public SchemaVersion getRelatedLinkVersion(){
- return relatedLinkVersion;
+ public SchemaVersion getRelatedLinkVersion() {
+ return relatedLinkVersionValue;
}
public SchemaVersion getNamespaceChangeVersion() {
- return namespaceChangeVersion;
+ return namespaceChangeVersionValue;
}
public void setNamespaceChangeVersion(SchemaVersion namespaceChangeVersion) {
- this.namespaceChangeVersion = namespaceChangeVersion;
+ this.namespaceChangeVersionValue = namespaceChangeVersion;
}
}
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersionsBean.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersionsBean.java
new file mode 100644
index 00000000..119669d3
--- /dev/null
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersionsBean.java
@@ -0,0 +1,83 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-18 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.setup;
+
+import com.google.gson.FieldNamingPolicy;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.onap.aai.restclient.RestClient;
+import org.onap.aai.restclient.RestClientFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.ResponseEntity;
+
+import javax.annotation.PostConstruct;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SchemaVersionsBean {
+
+ private String SCHEMA_SERVICE = "schema-service";
+ private SchemaServiceVersions schemaVersions;
+
+ @Value("${schema.service.versions.endpoint}")
+ private String versionsUri;
+
+ @Autowired
+ private RestClientFactory restClientFactory;
+
+ @PostConstruct
+ public void initialize() {
+ //Call SchemaService to get versions
+ retrieveAllSchemaVersions();
+ }
+
+ public void retrieveAllSchemaVersions() {
+ /*
+ Call Schema MS to get versions using RestTemplate
+ */
+ String content = "";
+ Map<String, String> headersMap = new HashMap<>();
+ RestClient restClient = restClientFactory
+ .getRestClient(SCHEMA_SERVICE);
+
+ ResponseEntity<String> schemaResponse = restClient.getGetRequest( content, versionsUri, headersMap);
+ Gson gson = new GsonBuilder()
+ .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES)
+ .create();
+ schemaVersions = gson.fromJson(schemaResponse.getBody(), SchemaServiceVersions.class);
+ schemaVersions.initializeFromSchemaService();
+
+ }
+
+ public SchemaServiceVersions getSchemaVersions() {
+ return schemaVersions;
+ }
+
+ public void setSchemaVersions(SchemaServiceVersions schemaVersions) {
+ this.schemaVersions = schemaVersions;
+ }
+
+ public List<SchemaVersion> getVersions() {
+ return getSchemaVersions().getVersions();
+ }
+
+}
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java
new file mode 100644
index 00000000..09062e1c
--- /dev/null
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java
@@ -0,0 +1,67 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-18 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.setup;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.io.*;
+import java.util.List;
+/**
+ * Converts the contents of the schema config file
+ * (which lists which schema files to be loaded) to
+ * the format the Ingestors can work with.
+ *
+ */
+public abstract class Translator {
+
+ protected SchemaVersions schemaVersions;
+
+ public Translator(SchemaVersions schemaVersions) {
+ this.schemaVersions = schemaVersions;
+ }
+
+ /**
+ * Translates the contents of the schema config file
+ * into the input for the NodeIngestor
+ *
+ * @return Map of Version to the list of (string) filenames to be
+ * ingested for that version
+ */
+
+
+ public abstract List<InputStream> getVersionNodeStream(SchemaVersion version) throws IOException;
+
+ public abstract List<String>
+ getJsonPayload(SchemaVersion version) throws IOException;
+
+ /**
+ * Translates the contents of the schema config file
+ * into the input for the EdgeIngestor
+ *
+ * @return Map of Version to the List of (String) filenames to be
+ * ingested for that version
+ */
+
+
+ public SchemaVersions getSchemaVersions(){
+ return this.schemaVersions;
+ }
+}