get cloudOptionId from getHomingData

Issue-ID: VID-378
Signed-off-by: Alexey Sandler <alexey.sandler@intl.att.com>
Change-Id: Ifa5cb0a827161f62b104bf18605531a2ebb29494
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/vf-module-homing-data-action/vf-module-homing-data-action.controller.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/vf-module-homing-data-action/vf-module-homing-data-action.controller.js
index b6725b1..ecc6042 100644
--- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/vf-module-homing-data-action/vf-module-homing-data-action.controller.js
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/vf-module-homing-data-action/vf-module-homing-data-action.controller.js
@@ -59,13 +59,10 @@
         AaiService.getHomingData(DataService.getVnfInstanceId(), DataService.getVfModuleInstanceId())
             .then(function (res) {
                 if (res && res.data) {
-                    $scope.regionSelection = {
-                        optionId: (res.data[COMPONENT.CLOUD_REGION_ID]) ? res.data[COMPONENT.CLOUD_REGION_ID] : null,
-                        legacyRegion: null,
-                        tenant: (res.data[COMPONENT.TENANT_ID]) ? res.data[COMPONENT.TENANT_ID] : null
-                    };
-                    $scope.isHomingData = $scope.regionSelection.optionId !== null && res.data.tenant !== null;
-                    $scope.isHomingData = $scope.isHomingData && !$scope.selectedLcpRegionIsMegaRegion();
+                    $scope.regionSelection.optionId = (res.data.cloudRegionOptionId);
+                    $scope.regionSelection.tenant = (res.data[COMPONENT.TENANT_ID]) ? res.data[COMPONENT.TENANT_ID] : null;
+                    $scope.isHomingData = $scope.regionSelection.optionId !== null && $scope.regionSelection.tenant !== null;
+                    $scope.isHomingData = $scope.isHomingData && (($scope.megaRegion).indexOf(res.data[COMPONENT.CLOUD_REGION_ID]) === -1);
                 }
 
                 if (!$scope.isHomingData) {
@@ -145,9 +142,12 @@
     };
 
     $scope.selectedLcpRegionIsMegaRegion = function() {
-        let cloudRegionId =
-            DataService.getCloudOwnerAndLcpCloudRegionFromOptionId($scope.regionSelection.optionId).cloudRegionId;
-        return ($scope.megaRegion).indexOf(cloudRegionId) > -1
+        if ($scope.regionSelection.optionId) {
+            let cloudRegionId = DataService.getCloudOwnerAndLcpCloudRegionFromOptionId($scope.regionSelection.optionId).cloudRegionId;
+            return ($scope.megaRegion).indexOf(cloudRegionId) > -1
+        } else {
+            return false;
+        }
     };
 
     $scope.cancel = function() {
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/services/aaiService.js b/vid-app-common/src/main/webapp/app/vid/scripts/services/aaiService.js
index e940183..0d0fa6d 100755
--- a/vid-app-common/src/main/webapp/app/vid/scripts/services/aaiService.js
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/services/aaiService.js
@@ -430,6 +430,7 @@
         },
         getLcpCloudRegionTenantList : function(globalCustomerId, serviceType,
                                                successCallbackFunction) {
+            let self = this;
             $log
                 .debug("AaiService:getLcpCloudRegionTenantList: globalCustomerId: "
                     + globalCustomerId);
@@ -447,12 +448,12 @@
                 for (var i = 0; i < aaiLcpCloudRegionTenants.length; i++) {
                     var cloudOwner = aaiLcpCloudRegionTenants[i][COMPONENT.CLOUD_OWNER];
                     var cloudRegionId = aaiLcpCloudRegionTenants[i][COMPONENT.CLOUD_REGION_ID];
-                    var cloudRegionOptionId = 'option-' + cloudOwner + '-' + cloudRegionId;
+                    var cloudRegionOptionId = self.cloudRegionOptionId(cloudOwner, cloudRegionId);
 
                     lcpCloudRegionTenants.push({
                         "cloudOwner": cloudOwner,
                         "cloudRegionId": cloudRegionId,
-                        "cloudRegionOptionId": cloudRegionOptionId.toLowerCase(),
+                        "cloudRegionOptionId": cloudRegionOptionId,
                         "tenantName": aaiLcpCloudRegionTenants[i][COMPONENT.TENANT_NAME],
                         "tenantId": aaiLcpCloudRegionTenants[i][COMPONENT.TENANT_ID],
                         "isPermitted": aaiLcpCloudRegionTenants[i][COMPONENT.IS_PERMITTED]});
@@ -760,7 +761,12 @@
                 });
         },
 
+        cloudRegionOptionId: function (cloudOwner, cloudRegionId) {
+            return ('option-' + cloudOwner + '-' + cloudRegionId).toLowerCase();
+        },
+
         getHomingData: function(vnfInstanceId, vfModuleId)  {
+            let self = this;
             var url = COMPONENT.AAI_GET_HOMING_DATA.replace('@vnfInstanceId', vnfInstanceId)
                 .replace('@vfModuleId', vfModuleId);
 
@@ -768,6 +774,14 @@
 
             $http.get(url)
                 .success(function (response) {
+                    var cloudOwner = response[COMPONENT.CLOUD_OWNER];
+                    var cloudRegionId = response[COMPONENT.CLOUD_REGION_ID];
+                    if (cloudOwner && cloudRegionId) {
+                        response["cloudRegionOptionId"] = self.cloudRegionOptionId(cloudOwner, cloudRegionId);
+                    } else {
+                        response["cloudRegionOptionId"] = null;
+                    }
+
                     deferred.resolve({data: response});
                 }).error(function (data, status, headers, config) {
                 deferred.reject({message: data, status: status});