Rework the submit operation
[clamp.git] / src / main / java / org / onap / clamp / clds / client / DcaeInventoryServices.java
index 327aff1..d8bfeea 100644 (file)
@@ -26,7 +26,6 @@ package org.onap.clamp.clds.client;
 \r
 import com.att.eelf.configuration.EELFLogger;\r
 import com.att.eelf.configuration.EELFManager;\r
-import com.fasterxml.jackson.core.JsonProcessingException;\r
 \r
 import java.io.IOException;\r
 import java.util.Date;\r
@@ -44,8 +43,9 @@ import org.onap.clamp.clds.model.DcaeEvent;
 import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse;\r
 import org.onap.clamp.clds.model.properties.Global;\r
 import org.onap.clamp.clds.model.properties.ModelProperties;\r
-import org.onap.clamp.clds.util.JacksonUtils;\r
+import org.onap.clamp.clds.util.JsonUtils;\r
 import org.onap.clamp.clds.util.LoggingUtils;\r
+import org.onap.clamp.util.HttpConnectionManager;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
 import org.springframework.stereotype.Component;\r
 \r
@@ -63,14 +63,17 @@ public class DcaeInventoryServices {
     public static final String DCAE_INVENTORY_RETRY_LIMIT = "dcae.intentory.retry.limit";\r
     private final ClampProperties refProp;\r
     private final CldsDao cldsDao;\r
-    private final DcaeHttpConnectionManager dcaeHttpConnectionManager;\r
+    private final HttpConnectionManager httpConnectionManager;\r
 \r
+    /**\r
+     * Constructor.\r
+     */\r
     @Autowired\r
     public DcaeInventoryServices(ClampProperties refProp, CldsDao cldsDao,\r
-        DcaeHttpConnectionManager dcaeHttpConnectionManager) {\r
+               HttpConnectionManager httpConnectionManager) {\r
         this.refProp = refProp;\r
         this.cldsDao = cldsDao;\r
-        this.dcaeHttpConnectionManager = dcaeHttpConnectionManager;\r
+        this.httpConnectionManager = httpConnectionManager;\r
     }\r
 \r
     /**\r
@@ -83,7 +86,7 @@ public class DcaeInventoryServices {
      * @throws ParseException\r
      *         In case of DCAE Json parse exception\r
      */\r
-    public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException, InterruptedException {\r
+    public void setEventInventory(CldsModel cldsModel, String userId) throws InterruptedException {\r
         String artifactName = cldsModel.getControlName();\r
         DcaeEvent dcaeEvent = new DcaeEvent();\r
         DcaeInventoryResponse dcaeResponse = null;\r
@@ -109,7 +112,7 @@ public class DcaeInventoryServices {
             dcaeEvent.setArtifactName(artifactName);\r
             dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION);\r
             LoggingUtils.setResponseContext("0", "Set inventory success", this.getClass().getName());\r
-        } catch (JsonProcessingException e) {\r
+        } catch (ParseException e) {\r
             LoggingUtils.setResponseContext("900", "Set inventory failed", this.getClass().getName());\r
             LoggingUtils.setErrorContext("900", "Set inventory error");\r
             logger.error("Error during JSON decoding", e);\r
@@ -154,15 +157,13 @@ public class DcaeInventoryServices {
         return totalCount.intValue();\r
     }\r
 \r
-    private DcaeInventoryResponse getItemsFromDcaeInventoryResponse(String responseStr)\r
-        throws ParseException, IOException {\r
+    private DcaeInventoryResponse getItemsFromDcaeInventoryResponse(String responseStr) throws ParseException {\r
         JSONParser parser = new JSONParser();\r
         Object obj0 = parser.parse(responseStr);\r
         JSONObject jsonObj = (JSONObject) obj0;\r
         JSONArray itemsArray = (JSONArray) jsonObj.get("items");\r
         JSONObject dcaeServiceType0 = (JSONObject) itemsArray.get(0);\r
-        return JacksonUtils.getObjectMapperInstance().readValue(dcaeServiceType0.toString(),\r
-            DcaeInventoryResponse.class);\r
+        return JsonUtils.GSON.fromJson(dcaeServiceType0.toString(), DcaeInventoryResponse.class);\r
     }\r
 \r
     /**\r
@@ -182,7 +183,6 @@ public class DcaeInventoryServices {
      */\r
     public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)\r
         throws IOException, ParseException, InterruptedException {\r
-        Date startTime = new Date();\r
         LoggingUtils.setTargetContext("DCAE", "getDcaeInformation");\r
         String queryString = "?asdcResourceId=" + resourceUuid + "&asdcServiceId=" + serviceUuid + "&typeName="\r
             + artifactName;\r
@@ -190,6 +190,7 @@ public class DcaeInventoryServices {
         logger.info("Dcae Inventory Service full url - " + fullUrl);\r
         DcaeInventoryResponse response = queryDcaeInventory(fullUrl);\r
         LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName());\r
+        Date startTime = new Date();\r
         LoggingUtils.setTimeContext(startTime, new Date());\r
         return response;\r
     }\r
@@ -206,7 +207,7 @@ public class DcaeInventoryServices {
         }\r
         for (int i = 0; i < retryLimit; i++) {\r
             metricsLogger.info("Attempt n°" + i + " to contact DCAE inventory");\r
-            String response = dcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);\r
+            String response = httpConnectionManager.doGeneralHttpQuery(fullUrl, "GET", null, null, "DCAE", null, null);\r
             int totalCount = getTotalCountFromDcaeInventoryResponse(response);\r
             metricsLogger.info("getDcaeInformation complete: totalCount returned=" + totalCount);\r
             if (totalCount > 0) {\r