* ============LICENSE_START=======================================================\r
* org.onap.aai\r
* ================================================================================\r
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * Copyright © 2017 Amdocs\r
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017-2018 Amdocs\r
* ================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* See the License for the specific language governing permissions and\r
* limitations under the License.\r
* ============LICENSE_END=========================================================\r
- *\r
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
*/\r
package org.onap.aai.datarouter.util;\r
\r
createIndex(index, schemaLocation);\r
}\r
\r
+ public void createSearchIndex(String index, String schemaLocation, String endUrl) {\r
+ \r
+ // Create a mapping of the index name to schema location \r
+ indexSchemaMapping.put(index, schemaLocation);\r
+ \r
+ // Now, create the index.\r
+ createIndex(index, schemaLocation, endUrl);\r
+ }\r
\r
/**\r
* This method performs the actual work of creating a search index.\r
}\r
}\r
\r
+ private void createIndex(String index, String schemaLocation, String endUrl) {\r
+ \r
+ logger.debug("Creating search index, index name: = " + index + ", schemaLocation = " + schemaLocation);\r
+ \r
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();\r
+ headers.put("Accept", Arrays.asList("application/json"));\r
+ headers.put(Headers.FROM_APP_ID, Arrays.asList("DL"));\r
+ headers.put(Headers.TRANSACTION_ID, Arrays.asList(UUID.randomUUID().toString()));\r
+ \r
+ String url = concatSubUri(searchUrl, endUrl, index);\r
+ try {\r
+\r
+ OperationResult result = searchClient.put(url, loadFileData(schemaLocation), headers,\r
+ MediaType.APPLICATION_JSON_TYPE, null);\r
+ if (!HttpUtil.isHttpResponseClassSuccess(result.getResultCode())) {\r
+ logger.error(DataRouterMsgs.FAIL_TO_CREATE_SEARCH_INDEX, index, result.getFailureCause());\r
+ } else {\r
+ logger.info(DataRouterMsgs.SEARCH_INDEX_CREATE_SUCCESS, index);\r
+ }\r
+\r
+ } catch (Exception e) {\r
+ logger.error(DataRouterMsgs.FAIL_TO_CREATE_SEARCH_INDEX, index, e.getLocalizedMessage());\r
+ }\r
+ }\r
\r
/**\r
* Retrieves a document from the search service.\r
* Removes a document from the Search Service.\r
* \r
* @param index - The index to create the document in.\r
- * @param id - The identifier for the document.\r
- * @param payload - The document contents.\r
+ * @param documentId - The identifier for the document.\r
* @param headers - HTTP headers.\r
*/\r
public void deleteDocument(String index, String documentId, Map<String, List<String>> headers) {\r
*/\r
protected String loadFileData(String filename) throws Exception {\r
StringBuilder data = new StringBuilder();\r
- try {\r
- BufferedReader in = new BufferedReader(new InputStreamReader(\r
- EntityEventPolicy.class.getClassLoader().getResourceAsStream("/" + filename),\r
- StandardCharsets.UTF_8));\r
- String line;\r
\r
+ try (InputStreamReader inputStreamReader = new InputStreamReader(EntityEventPolicy.class.getClassLoader()\r
+ .getResourceAsStream("/" + filename), StandardCharsets.UTF_8); BufferedReader in = new BufferedReader(\r
+ inputStreamReader)\r
+ ) {\r
+\r
+ String line;\r
while ((line = in.readLine()) != null) {\r
data.append(line);\r
}\r