Change-Id: Ie2fc04b381691ebba38de18ba64581952cceacc9
Issue-ID: AAI-2156
Signed-off-by: Stela Stoykova <Stela.Stoykova@amdocs.com>
// Logging related
public static final String DATA_ROUTER_SERVICE_NAME = "DataRouter";
// Logging related
public static final String DATA_ROUTER_SERVICE_NAME = "DataRouter";
+
+ public static final String DR_SEARCH_SCHEMA_HOME = DR_SPECIFIC_CONFIG + "search-schema";
import org.onap.aai.cl.api.Logger;\r
import org.onap.aai.cl.mdc.MdcContext;\r
import org.onap.aai.datarouter.logging.DataRouterMsgs;\r
import org.onap.aai.cl.api.Logger;\r
import org.onap.aai.cl.mdc.MdcContext;\r
import org.onap.aai.datarouter.logging.DataRouterMsgs;\r
-import org.onap.aai.datarouter.policy.EntityEventPolicy;\r
import org.onap.aai.restclient.client.Headers;\r
import org.onap.aai.restclient.client.OperationResult;\r
import org.onap.aai.restclient.client.RestClient;\r
import org.onap.aai.restclient.enums.RestAuthenticationMode;\r
import org.onap.aai.restclient.rest.HttpUtil;\r
import org.slf4j.MDC;\r
import org.onap.aai.restclient.client.Headers;\r
import org.onap.aai.restclient.client.OperationResult;\r
import org.onap.aai.restclient.client.RestClient;\r
import org.onap.aai.restclient.enums.RestAuthenticationMode;\r
import org.onap.aai.restclient.rest.HttpUtil;\r
import org.slf4j.MDC;\r
+import org.springframework.core.io.ClassPathResource;\r
+import org.springframework.core.io.FileSystemResource;\r
+import org.springframework.core.io.Resource;\r
\r
import com.sun.jersey.core.util.MultivaluedMapImpl;\r
\r
\r
import com.sun.jersey.core.util.MultivaluedMapImpl;\r
\r
\r
private String searchUrl = null;\r
private String documentEndpoint = null;\r
\r
private String searchUrl = null;\r
private String documentEndpoint = null;\r
+ private String schemaHomeDir = null;\r
this.documentEndpoint = documentEndpoint;\r
\r
this.logger = logger;\r
this.documentEndpoint = documentEndpoint;\r
\r
this.logger = logger;\r
+ this.schemaHomeDir = DataRouterConstants.DR_SEARCH_SCHEMA_HOME;\r
* @throws Exception\r
*/\r
protected String loadFileData(String filename) throws Exception {\r
* @throws Exception\r
*/\r
protected String loadFileData(String filename) throws Exception {\r
- StringBuilder data = new StringBuilder();\r
-\r
- try (InputStreamReader inputStreamReader = new InputStreamReader(EntityEventPolicy.class.getClassLoader()\r
- .getResourceAsStream("/" + filename), StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(\r
- inputStreamReader)\r
- ) {\r
+ Resource fileResource = getSchemaResource(filename);\r
+ if (fileResource == null) {\r
+ throw new Exception("Could not find file = " + filename + ".");\r
+ }\r
+ try (\r
+ InputStreamReader inputStreamReader = new InputStreamReader(fileResource.getInputStream(), StandardCharsets.UTF_8);\r
+ BufferedReader in = new BufferedReader(inputStreamReader);\r
+ ){\r
- while ((line = in.readLine()) != null) {\r
+ StringBuilder data = new StringBuilder();\r
+ while((line = in.readLine()) != null) {\r
+ return data.toString();\r
} catch (Exception e) {\r
throw new Exception("Failed to read from file = " + filename + ".", e);\r
}\r
} catch (Exception e) {\r
throw new Exception("Failed to read from file = " + filename + ".", e);\r
}\r
+ }\r
+\r
+ private Resource getSchemaResource(String filename) {\r
+ Resource fileResource = null;\r
+\r
+ if(filename == null) {\r
+ return null;\r
+ }\r
+ \r
+ if ((schemaHomeDir != null) && (fileResource = new FileSystemResource(schemaHomeDir + "/" + filename)).isReadable()) {\r
+ return fileResource;\r
+ }\r
+\r
+ if ((fileResource = new ClassPathResource(filename)).isReadable()) {\r
+ return fileResource;\r
+ }\r
- return data.toString();\r