diff options
author | Stela Stoykova <Stela.Stoykova@amdocs.com> | 2019-02-15 10:40:54 -0500 |
---|---|---|
committer | Stela Stoykova <Stela.Stoykova@amdocs.com> | 2019-02-15 11:25:58 -0500 |
commit | 093deaf4738d56602f94e6a4193993a77e053a51 (patch) | |
tree | dcb43790911d5bbc444f75098379631ba3b687d3 | |
parent | 3b49121e2e86b3d22704ff52d468f85fcd74d9b2 (diff) |
Allow custom ES mapping files to be used
Change-Id: Ie2fc04b381691ebba38de18ba64581952cceacc9
Issue-ID: AAI-2156
Signed-off-by: Stela Stoykova <Stela.Stoykova@amdocs.com>
-rw-r--r-- | src/main/java/org/onap/aai/datarouter/util/DataRouterConstants.java | 2 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java | 42 |
2 files changed, 35 insertions, 9 deletions
diff --git a/src/main/java/org/onap/aai/datarouter/util/DataRouterConstants.java b/src/main/java/org/onap/aai/datarouter/util/DataRouterConstants.java index 98fdc62..14cf6a7 100644 --- a/src/main/java/org/onap/aai/datarouter/util/DataRouterConstants.java +++ b/src/main/java/org/onap/aai/datarouter/util/DataRouterConstants.java @@ -54,4 +54,6 @@ public class DataRouterConstants { // Logging related public static final String DATA_ROUTER_SERVICE_NAME = "DataRouter"; + + public static final String DR_SEARCH_SCHEMA_HOME = DR_SPECIFIC_CONFIG + "search-schema"; } diff --git a/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java b/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java index 4baa81a..b62237d 100644 --- a/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java +++ b/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java @@ -37,13 +37,15 @@ import org.eclipse.jetty.util.security.Password; import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.mdc.MdcContext;
import org.onap.aai.datarouter.logging.DataRouterMsgs;
-import org.onap.aai.datarouter.policy.EntityEventPolicy;
import org.onap.aai.restclient.client.Headers;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.restclient.client.RestClient;
import org.onap.aai.restclient.enums.RestAuthenticationMode;
import org.onap.aai.restclient.rest.HttpUtil;
import org.slf4j.MDC;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
@@ -56,6 +58,7 @@ public class SearchServiceAgent { private String searchUrl = null;
private String documentEndpoint = null;
+ private String schemaHomeDir = null;
/**
@@ -109,6 +112,7 @@ public class SearchServiceAgent { this.documentEndpoint = documentEndpoint;
this.logger = logger;
+ this.schemaHomeDir = DataRouterConstants.DR_SEARCH_SCHEMA_HOME;
}
@@ -338,22 +342,42 @@ public class SearchServiceAgent { * @throws Exception
*/
protected String loadFileData(String filename) throws Exception {
- StringBuilder data = new StringBuilder();
-
- try (InputStreamReader inputStreamReader = new InputStreamReader(EntityEventPolicy.class.getClassLoader()
- .getResourceAsStream("/" + filename), StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(
- inputStreamReader)
- ) {
+ Resource fileResource = getSchemaResource(filename);
+ if (fileResource == null) {
+ throw new Exception("Could not find file = " + filename + ".");
+ }
+ try (
+ InputStreamReader inputStreamReader = new InputStreamReader(fileResource.getInputStream(), StandardCharsets.UTF_8);
+ BufferedReader in = new BufferedReader(inputStreamReader);
+ ){
String line;
- while ((line = in.readLine()) != null) {
+ StringBuilder data = new StringBuilder();
+ while((line = in.readLine()) != null) {
data.append(line);
}
+ return data.toString();
} catch (Exception e) {
throw new Exception("Failed to read from file = " + filename + ".", e);
}
+ }
+
+ private Resource getSchemaResource(String filename) {
+ Resource fileResource = null;
+
+ if(filename == null) {
+ return null;
+ }
+
+ if ((schemaHomeDir != null) && (fileResource = new FileSystemResource(schemaHomeDir + "/" + filename)).isReadable()) {
+ return fileResource;
+ }
+
+ if ((fileResource = new ClassPathResource(filename)).isReadable()) {
+ return fileResource;
+ }
- return data.toString();
+ return null;
}
|