Code refactoring
[clamp.git] / src / main / java / org / onap / clamp / clds / client / req / sdc / SdcCatalogServices.java
index 45dbf81..299ec1e 100644 (file)
@@ -58,20 +58,20 @@ import org.apache.commons.csv.CSVRecord;
 import org.apache.commons.io.IOUtils;\r
 import org.apache.commons.lang3.StringUtils;\r
 import org.apache.http.HttpHeaders;\r
+import org.onap.clamp.clds.config.CldsReferenceProperties;\r
 import org.onap.clamp.clds.exception.SdcCommunicationException;\r
 import org.onap.clamp.clds.model.CldsAlarmCondition;\r
-import org.onap.clamp.clds.model.CldsSdcArtifact;\r
-import org.onap.clamp.clds.model.CldsSdcResource;\r
-import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo;\r
-import org.onap.clamp.clds.model.CldsSdcServiceDetail;\r
-import org.onap.clamp.clds.model.CldsSdcServiceInfo;\r
 import org.onap.clamp.clds.model.CldsServiceData;\r
 import org.onap.clamp.clds.model.CldsVfData;\r
 import org.onap.clamp.clds.model.CldsVfKPIData;\r
 import org.onap.clamp.clds.model.CldsVfcData;\r
-import org.onap.clamp.clds.model.prop.Global;\r
-import org.onap.clamp.clds.model.prop.ModelProperties;\r
-import org.onap.clamp.clds.model.refprop.RefProp;\r
+import org.onap.clamp.clds.model.properties.Global;\r
+import org.onap.clamp.clds.model.properties.ModelProperties;\r
+import org.onap.clamp.clds.model.sdc.SdcArtifact;\r
+import org.onap.clamp.clds.model.sdc.SdcResource;\r
+import org.onap.clamp.clds.model.sdc.SdcResourceBasicInfo;\r
+import org.onap.clamp.clds.model.sdc.SdcServiceDetail;\r
+import org.onap.clamp.clds.model.sdc.SdcServiceInfo;\r
 import org.onap.clamp.clds.util.CryptoUtils;\r
 import org.onap.clamp.clds.util.LoggingUtils;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
@@ -93,7 +93,7 @@ public class SdcCatalogServices {
     private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool";\r
     private static final String RESOURCE_URL_PREFIX = "resources";\r
     @Autowired\r
-    private RefProp refProp;\r
+    private CldsReferenceProperties refProp;\r
 \r
     /**\r
      * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic\r
@@ -165,8 +165,8 @@ public class SdcCatalogServices {
      *            A list of CldsSdcServiceInfo\r
      * @return A list of CldsSdcServiceInfo without duplicate service UUID\r
      */\r
-    public List<CldsSdcServiceInfo> removeDuplicateServices(List<CldsSdcServiceInfo> rawCldsSdcServiceList) {\r
-        List<CldsSdcServiceInfo> cldsSdcServiceInfoList = null;\r
+    public List<SdcServiceInfo> removeDuplicateServices(List<SdcServiceInfo> rawCldsSdcServiceList) {\r
+        List<SdcServiceInfo> cldsSdcServiceInfoList = null;\r
         if (rawCldsSdcServiceList != null && !rawCldsSdcServiceList.isEmpty()) {\r
             // sort list\r
             Collections.sort(rawCldsSdcServiceList);\r
@@ -176,7 +176,7 @@ public class SdcCatalogServices {
             for (int i = 1; i < rawCldsSdcServiceList.size(); i++) {\r
                 // compare name with previous - if not equal, then keep the\r
                 // previous (it's the last with that name)\r
-                CldsSdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1);\r
+                SdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1);\r
                 if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) {\r
                     cldsSdcServiceInfoList.add(prev);\r
                 }\r
@@ -193,8 +193,8 @@ public class SdcCatalogServices {
      * @param rawCldsSdcResourceList\r
      * @return List of CldsSdcResource\r
      */\r
-    public List<CldsSdcResource> removeDuplicateSdcResourceInstances(List<CldsSdcResource> rawCldsSdcResourceList) {\r
-        List<CldsSdcResource> cldsSdcResourceList = null;\r
+    public List<SdcResource> removeDuplicateSdcResourceInstances(List<SdcResource> rawCldsSdcResourceList) {\r
+        List<SdcResource> cldsSdcResourceList = null;\r
         if (rawCldsSdcResourceList != null && !rawCldsSdcResourceList.isEmpty()) {\r
             // sort list\r
             Collections.sort(rawCldsSdcResourceList);\r
@@ -204,7 +204,7 @@ public class SdcCatalogServices {
             for (int i = 1; i < rawCldsSdcResourceList.size(); i++) {\r
                 // compare name with previous - if not equal, then keep the\r
                 // previous (it's the last with that name)\r
-                CldsSdcResource prev = rawCldsSdcResourceList.get(i - 1);\r
+                SdcResource prev = rawCldsSdcResourceList.get(i - 1);\r
                 if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) {\r
                     cldsSdcResourceList.add(prev);\r
                 }\r
@@ -221,9 +221,9 @@ public class SdcCatalogServices {
      * @param rawCldsSdcResourceListBasicList\r
      * @return List of CldsSdcResourceBasicInfo\r
      */\r
-    public List<CldsSdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(\r
-            List<CldsSdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
-        List<CldsSdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;\r
+    public List<SdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(\r
+            List<SdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
+        List<SdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;\r
         if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) {\r
             // sort list\r
             Collections.sort(rawCldsSdcResourceListBasicList);\r
@@ -233,7 +233,7 @@ public class SdcCatalogServices {
             for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) {\r
                 // compare name with previous - if not equal, then keep the\r
                 // previous (it's the last with that name)\r
-                CldsSdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1);\r
+                SdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1);\r
                 if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) {\r
                     cldsSdcResourceBasicInfoList.add(prev);\r
                 }\r
@@ -260,10 +260,10 @@ public class SdcCatalogServices {
             throws GeneralSecurityException, DecoderException {\r
         String serviceUuid = "";\r
         String responseStr = getSdcServicesInformation(null);\r
-        List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);\r
-        List<CldsSdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);\r
+        List<SdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);\r
+        List<SdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);\r
         if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {\r
-            for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {\r
+            for (SdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {\r
                 if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null\r
                         && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {\r
                     serviceUuid = currCldsSdcServiceInfo.getUuid();\r
@@ -282,14 +282,14 @@ public class SdcCatalogServices {
      * @return The list of CldsSdcServiceInfo, if there is a failure it return\r
      *         an empty list\r
      */\r
-    private List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
+    private List<SdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
         ObjectMapper objectMapper = new ObjectMapper();\r
         if (StringUtils.isBlank(jsonStr)) {\r
             return new ArrayList<>();\r
         }\r
         try {\r
             return objectMapper.readValue(jsonStr,\r
-                    objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));\r
+                    objectMapper.getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));\r
         } catch (IOException e) {\r
             logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);\r
             return new ArrayList<>();\r
@@ -304,14 +304,14 @@ public class SdcCatalogServices {
      * @return The list of CldsSdcResourceBasicInfo, an empty list in case of\r
      *         issues\r
      */\r
-    private List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
+    private List<SdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
         ObjectMapper objectMapper = new ObjectMapper();\r
         if (StringUtils.isBlank(jsonStr)) {\r
             return new ArrayList<>();\r
         }\r
         try {\r
             return objectMapper.readValue(jsonStr,\r
-                    objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));\r
+                    objectMapper.getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class));\r
         } catch (IOException e) {\r
             logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);\r
             return new ArrayList<>();\r
@@ -324,10 +324,10 @@ public class SdcCatalogServices {
      * @param jsonStr\r
      * @return\r
      */\r
-    public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) {\r
+    public SdcServiceDetail decodeCldsSdcServiceDetailFromJson(String jsonStr) {\r
         ObjectMapper objectMapper = new ObjectMapper();\r
         try {\r
-            return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);\r
+            return objectMapper.readValue(jsonStr, SdcServiceDetail.class);\r
         } catch (IOException e) {\r
             logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e);\r
             return null;\r
@@ -472,9 +472,9 @@ public class SdcCatalogServices {
         ObjectMapper objectMapper = new ObjectMapper();\r
         CldsServiceData cldsServiceData = new CldsServiceData();\r
         if (responseStr != null) {\r
-            CldsSdcServiceDetail cldsSdcServiceDetail;\r
+            SdcServiceDetail cldsSdcServiceDetail;\r
             try {\r
-                cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);\r
+                cldsSdcServiceDetail = objectMapper.readValue(responseStr, SdcServiceDetail.class);\r
             } catch (IOException e) {\r
                 logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);\r
                 throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);\r
@@ -484,11 +484,11 @@ public class SdcCatalogServices {
             if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {\r
                 cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());\r
                 cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());\r
-                List<CldsSdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(\r
+                List<SdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(\r
                         cldsSdcServiceDetail.getResources());\r
                 if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {\r
                     List<CldsVfData> cldsVfDataList = new ArrayList<>();\r
-                    for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) {\r
+                    for (SdcResource currCldsSdcResource : cldsSdcResourceList) {\r
                         if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null\r
                                 && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {\r
                             CldsVfData currCldsVfData = new CldsVfData();\r
@@ -511,9 +511,8 @@ public class SdcCatalogServices {
             throws GeneralSecurityException {\r
         // todo : refact this..\r
         if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
-            List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
-                    RESOURCE_VF_TYPE);\r
-            List<CldsSdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
+            List<SdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_VF_TYPE);\r
+            List<SdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
                     RESOURCE_VFC_TYPE);\r
             allVfcResources.addAll(getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_CVFC_TYPE));\r
             for (CldsVfData currCldsVfData : cldsVfDataList) {\r
@@ -1128,18 +1127,18 @@ public class SdcCatalogServices {
      *            The artifact name that will be searched\r
      * @return The artifact UUID found\r
      */\r
-    public String getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail cldsSdcServiceDetail, String artifactName) {\r
+    public String getArtifactIdIfArtifactAlreadyExists(SdcServiceDetail cldsSdcServiceDetail, String artifactName) {\r
         String artifactUuid = null;\r
         boolean artifactExists = false;\r
         if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null\r
                 && !cldsSdcServiceDetail.getResources().isEmpty()) {\r
-            for (CldsSdcResource currCldsSdcResource : cldsSdcServiceDetail.getResources()) {\r
+            for (SdcResource currCldsSdcResource : cldsSdcServiceDetail.getResources()) {\r
                 if (artifactExists) {\r
                     break;\r
                 }\r
                 if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null\r
                         && !currCldsSdcResource.getArtifacts().isEmpty()) {\r
-                    for (CldsSdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {\r
+                    for (SdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {\r
                         if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null\r
                                 && currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {\r
                             artifactUuid = currCldsSdcArtifact.getArtifactUUID();\r
@@ -1154,7 +1153,7 @@ public class SdcCatalogServices {
     }\r
 \r
     // To get all sdc VF/VFC Resources basic info.\r
-    private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {\r
+    private List<SdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {\r
         String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);\r
         String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;\r
         String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl);\r
@@ -1162,10 +1161,10 @@ public class SdcCatalogServices {
     }\r
 \r
     private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,\r
-            List<CldsSdcResourceBasicInfo> resourceInfoList) {\r
+            List<SdcResourceBasicInfo> resourceInfoList) {\r
         String resourceUuid = null;\r
         if (resourceInfoList != null && !resourceInfoList.isEmpty()) {\r
-            for (CldsSdcResourceBasicInfo currResource : resourceInfoList) {\r
+            for (SdcResourceBasicInfo currResource : resourceInfoList) {\r
                 if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null\r
                         && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {\r
                     resourceUuid = currResource.getUuid();\r
@@ -1220,7 +1219,7 @@ public class SdcCatalogServices {
                     String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
                     logger.info("ServiceUUID used before upload in url:" + originalServiceUuid);\r
                     String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid);\r
-                    CldsSdcServiceDetail cldsSdcServiceDetail = getCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
+                    SdcServiceDetail cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
                     String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,\r
                             artifactName);\r
                     // Upload artifacts to sdc\r
@@ -1233,7 +1232,7 @@ public class SdcCatalogServices {
                     }\r
                     logger.info("ServiceUUID used after upload in ulr:" + updatedServiceUuid);\r
                     sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid);\r
-                    cldsSdcServiceDetail = getCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
+                    cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
                     uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,\r
                             locationArtifactName);\r
                     // To send location information also to sdc\r