Adding UI extensibility
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / sync / task / StoreDocumentTask.java
  *
  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
-package org.onap.aai.sparky.synchronizer.task;
+package org.onap.aai.sparky.sync.task;
 
 import java.util.Map;
 import java.util.function.Supplier;
 
+import javax.ws.rs.core.MediaType;
+
+import org.onap.aai.restclient.client.OperationResult;
+import org.onap.aai.sparky.dal.ElasticSearchAdapter;
 import org.onap.aai.sparky.dal.NetworkTransaction;
-import org.onap.aai.sparky.dal.rest.OperationResult;
-import org.onap.aai.sparky.dal.rest.RestDataProvider;
-import org.onap.aai.sparky.synchronizer.entity.IndexDocument;
+import org.onap.aai.sparky.sync.entity.IndexDocument;
 import org.slf4j.MDC;
 
 /**
@@ -38,65 +40,9 @@ public class StoreDocumentTask implements Supplier<NetworkTransaction> {
 
   private IndexDocument doc;
 
-  /**
-   * @return the doc
-   */
-  public IndexDocument getDoc() {
-    return doc;
-  }
-
-  /**
-   * @param doc the doc to set
-   */
-  public void setDoc(IndexDocument doc) {
-    this.doc = doc;
-  }
-
-  /**
-   * @return the txn
-   */
-  public NetworkTransaction getTxn() {
-    return txn;
-  }
-
-  /**
-   * @param txn the txn to set
-   */
-  public void setTxn(NetworkTransaction txn) {
-    this.txn = txn;
-  }
-
-  /**
-   * @return the esDataProvider
-   */
-  public RestDataProvider getEsDataProvider() {
-    return esDataProvider;
-  }
-
-  /**
-   * @param esDataProvider the esDataProvider to set
-   */
-  public void setEsDataProvider(RestDataProvider esDataProvider) {
-    this.esDataProvider = esDataProvider;
-  }
-
-  /**
-   * @return the contextMap
-   */
-  public Map<String, String> getContextMap() {
-    return contextMap;
-  }
-
-  /**
-   * @param contextMap the contextMap to set
-   */
-  public void setContextMap(Map<String, String> contextMap) {
-    this.contextMap = contextMap;
-  }
-
   private NetworkTransaction txn;
 
-  private RestDataProvider esDataProvider;
+  private ElasticSearchAdapter esAdapter;
   private Map<String, String> contextMap;
 
   /**
@@ -107,10 +53,10 @@ public class StoreDocumentTask implements Supplier<NetworkTransaction> {
    * @param esDataProvider the es data provider
    */
   public StoreDocumentTask(IndexDocument doc, NetworkTransaction txn,
-      RestDataProvider esDataProvider) {
+      ElasticSearchAdapter esAdapter) {
     this.doc = doc;
     this.txn = txn;
-    this.esDataProvider = esDataProvider;
+    this.esAdapter = esAdapter;
     this.contextMap = MDC.getCopyOfContextMap();
   }
 
@@ -125,11 +71,18 @@ public class StoreDocumentTask implements Supplier<NetworkTransaction> {
 
     long startTimeInMs = System.currentTimeMillis();
     MDC.setContextMap(contextMap);
-    OperationResult or =
-        esDataProvider.doPut(txn.getLink(), doc.getIndexDocumentJson(), "application/json");
-    or.setResponseTimeInMs(System.currentTimeMillis() - startTimeInMs);
+    OperationResult operationResult = null;
+
+    try {
+
+      operationResult =
+          esAdapter.doPut(txn.getLink(), doc.getAsJson(), MediaType.APPLICATION_JSON_TYPE);
+      txn.setOpTimeInMs(System.currentTimeMillis() - startTimeInMs);
+    } catch (Exception exception) {
+      operationResult.setResult(500, exception.getMessage());
+    }
 
-    txn.setOperationResult(or);
+    txn.setOperationResult(operationResult);
 
     return txn;
   }