Add encryption for passwords
[clamp.git] / src / main / java / org / onap / clamp / clds / client / DcaeInventoryServices.java
index 8f80e07..71e57de 100644 (file)
@@ -32,6 +32,7 @@ import java.io.IOException;
 import java.io.InputStreamReader;\r
 import java.net.HttpURLConnection;\r
 import java.net.URL;\r
+import java.security.GeneralSecurityException;\r
 import java.util.Date;\r
 import java.util.List;\r
 \r
@@ -52,34 +53,37 @@ import org.onap.clamp.clds.util.LoggingUtils;
 import org.springframework.beans.factory.annotation.Autowired;\r
 \r
 /**\r
+ * \r
  * This class implements the communication with DCAE for the service inventory.\r
  *\r
+ * \r
+ * \r
  */\r
 public class DcaeInventoryServices {\r
     protected static final EELFLogger logger        = EELFManager.getInstance().getLogger(DcaeInventoryServices.class);\r
     protected static final EELFLogger auditLogger   = EELFManager.getInstance().getAuditLogger();\r
     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();\r
-\r
     @Autowired\r
     private RefProp                   refProp;\r
-\r
     @Autowired\r
     private CldsDao                   cldsDao;\r
-\r
     @Autowired\r
     private SdcCatalogServices        sdcCatalogServices;\r
 \r
     /**\r
+     * \r
      * Set the event inventory.\r
      * \r
      * @param cldsModel\r
      *            The CldsModel\r
      * @param userId\r
      *            The user ID\r
+     * @throws GeneralSecurityException\r
+     *             In case of issue when decryting the DCAE password\r
      * @throws ParseException\r
-     *             In case of issues during the parsing of DCAE answer\r
+     *             In case of DCAE Json parse exception\r
      */\r
-    public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException {\r
+    public void setEventInventory(CldsModel cldsModel, String userId) throws GeneralSecurityException, ParseException {\r
         String artifactName = cldsModel.getControlName();\r
         DcaeEvent dcaeEvent = new DcaeEvent();\r
         String isDcaeInfoAvailable = null;\r
@@ -90,8 +94,11 @@ public class DcaeInventoryServices {
         }\r
         try {\r
             /*\r
+             * \r
              * Below are the properties required for calling the dcae inventory\r
+             * \r
              * url call\r
+             * \r
              */\r
             ModelProperties prop = new ModelProperties(cldsModel.getName(), cldsModel.getControlName(), null, false,\r
                     "{}", cldsModel.getPropText());\r
@@ -105,11 +112,9 @@ public class DcaeInventoryServices {
             }\r
             /* Invemtory service url is called in this method */\r
             isDcaeInfoAvailable = getDcaeInformation(artifactName, serviceUuid, resourceUuid);\r
-\r
             /* set dcae events */\r
             dcaeEvent.setArtifactName(artifactName);\r
             dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION);\r
-\r
         } catch (JsonProcessingException e) {\r
             logger.error("Error during JSON decoding", e);\r
         } catch (IOException ex) {\r
@@ -159,6 +164,7 @@ public class DcaeInventoryServices {
      *             In case of issues with the stream\r
      * @throws ParseException\r
      *             In case of issues with the Json parsing\r
+     * \r
      */\r
     public String getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)\r
             throws IOException, ParseException {\r
@@ -167,28 +173,22 @@ public class DcaeInventoryServices {
         String queryString = "?sdcResourceId=" + resourceUuid + "&sdcServiceId=" + serviceUuid + "&typeName="\r
                 + artifactName;\r
         String fullUrl = refProp.getStringValue("DCAE_INVENTORY_URL") + "/dcae-service-types" + queryString;\r
-\r
         logger.info("Dcae Inventory Service full url - " + fullUrl);\r
         String daceInventoryResponse = null;\r
         URL inventoryUrl = new URL(fullUrl);\r
-\r
         HttpURLConnection conn = (HttpURLConnection) inventoryUrl.openConnection();\r
         conn.setRequestMethod("GET");\r
         String reqid = LoggingUtils.getRequestId();\r
         logger.info("reqid set to " + reqid);\r
         conn.setRequestProperty("X-ECOMP-RequestID", reqid);\r
-\r
         boolean requestFailed = true;\r
         int responseCode = conn.getResponseCode();\r
         if (responseCode == 200) {\r
             requestFailed = false;\r
         }\r
-\r
         StringBuilder response = new StringBuilder();\r
-\r
         try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {\r
             String inputLine = null;\r
-\r
             while ((inputLine = in.readLine()) != null) {\r
                 response.append(inputLine);\r
             }\r
@@ -203,11 +203,8 @@ public class DcaeInventoryServices {
         String jsonResponseString = response.toString();\r
         JSONParser parser = new JSONParser();\r
         Object obj0 = parser.parse(jsonResponseString);\r
-\r
         JSONObject jsonObj = (JSONObject) obj0;\r
-\r
         Long totalCount = (Long) jsonObj.get("totalCount");\r
-\r
         int numServices = totalCount.intValue();\r
         if (numServices == 0) {\r
             daceInventoryResponse = null;\r
@@ -221,5 +218,4 @@ public class DcaeInventoryServices {
         metricsLogger.info("getDcaeInformation complete: number services returned=" + numServices);\r
         return daceInventoryResponse;\r
     }\r
-\r
 }\r