summaryrefslogtreecommitdiffstats
path: root/aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java
diff options
context:
space:
mode:
Diffstat (limited to 'aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java')
-rw-r--r--aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java125
1 files changed, 73 insertions, 52 deletions
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java
index 16562756..713103a0 100644
--- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java
+++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java
@@ -1,4 +1,4 @@
-/**
+/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
@@ -20,64 +20,85 @@
package org.onap.aai.edges;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.jayway.jsonpath.DocumentContext;
+import com.jayway.jsonpath.JsonPath;
+import org.onap.aai.setup.SchemaVersion;
+
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
-import org.onap.aai.setup.SchemaVersion;
-
-import com.jayway.jsonpath.DocumentContext;
-import com.jayway.jsonpath.JsonPath;
-
/**
* JsonIngestor produces DocumentContexts from json files
*/
public class JsonIngestor {
-
- /**
- * Reads in given json files to queryable DocumentContexts.
- *
- * @param filesToIngest - map of filenames to ingest
- * per Version
- * @return Map<SchemaVersion, List<DocumentContext>> - map of DocumentContexts per Version
- */
- public Map<SchemaVersion, List<DocumentContext>> ingest(Map<SchemaVersion, List<String>> filesToIngest) {
- Map<SchemaVersion, List<DocumentContext>> result = new HashMap<>();
-
- for (Entry<SchemaVersion, List<String>> verFiles : filesToIngest.entrySet()) {
- SchemaVersion v = verFiles.getKey();
- List<String> files = verFiles.getValue();
-
- List<DocumentContext> docs = new ArrayList<>();
-
- for (String rulesFilename : files) {
- String fileContents = readInJsonFile(rulesFilename);
- docs.add(JsonPath.parse(fileContents));
- }
- result.put(v, docs);
- }
-
- return result;
- }
-
- /**
- * Reads the json file at the given filename into an in-memory String.
- *
- * @param rulesFilename - json file to be read (must include path to the file)
- * @return String json contents of the given file
- */
- private String readInJsonFile(String rulesFilename) {
- StringBuilder sb = new StringBuilder();
- try(BufferedReader br = new BufferedReader(new FileReader(rulesFilename))) {
- String line;
- while ((line = br.readLine()) != null) {
- sb.append(line);
- }
- } catch (IOException e) {
- throw new ExceptionInInitializerError(e);
- }
- return sb.toString();
- }
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(JsonIngestor.class);
+
+ /**
+ * Reads in given json files to queryable DocumentContexts.
+ *
+ * @param filesToIngest - map of filenames to ingest
+ * per Version
+ * @return Map<SchemaVersion, List<DocumentContext>> - map of DocumentContexts per Version
+ */
+ public Map<SchemaVersion, List<DocumentContext>> ingest(Map<SchemaVersion, List<String>> filesToIngest) {
+ Map<SchemaVersion, List<DocumentContext>> result = new HashMap<>();
+
+ for (Entry<SchemaVersion, List<String>> verFiles : filesToIngest.entrySet()) {
+ SchemaVersion v = verFiles.getKey();
+ List<String> files = verFiles.getValue();
+
+ List<DocumentContext> docs = new ArrayList<>();
+ for (String rulesFilename : files) {
+ String fileContents = readInJsonFile(rulesFilename);
+ docs.add(JsonPath.parse(fileContents));
+ }
+ result.put(v, docs);
+ }
+
+ return result;
+ }
+
+ public Map<SchemaVersion, List<DocumentContext>> ingestContent(Map<SchemaVersion, List<String>> filesToIngest) {
+ Map<SchemaVersion, List<DocumentContext>> result = new HashMap<>();
+
+ for (Entry<SchemaVersion, List<String>> verFiles : filesToIngest.entrySet()) {
+ SchemaVersion v = verFiles.getKey();
+ List<String> files = verFiles.getValue();
+
+ List<DocumentContext> docs = new ArrayList<>();
+ for (String jsonPayload : files) {
+ docs.add(JsonPath.parse(jsonPayload));
+ }
+ result.put(v, docs);
+ }
+ return result;
+ }
+
+ /**
+ * Reads the json file at the given filename into an in-memory String.
+ *
+ * @param rulesFilename - json file to be read (must include path to the file)
+ * @return String json contents of the given file
+ */
+ public String readInJsonFile(String rulesFilename) {
+ StringBuilder sb = new StringBuilder();
+ try(BufferedReader br = new BufferedReader(new FileReader(rulesFilename))) {
+ String line;
+ while ((line = br.readLine()) != null) {
+ sb.append(line);
+ }
+ } catch (IOException e) {
+ LOGGER.warn("Exception in file"+e.getMessage());
+ throw new ExceptionInInitializerError(e);
+ }
+ return sb.toString();
+ }
}