UI Feature flagging support
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / modals / new-change-management / new-change-management.controller.js
index 086ae0f..3918219 100644 (file)
@@ -2,9 +2,9 @@
     'use strict';
 
     appDS2.controller("newChangeManagementModalController", ["$uibModalInstance", "$uibModal",'$q', "AaiService", "changeManagementService", "Upload",
-        "$log", "$scope", "_", "COMPONENT", "VIDCONFIGURATION", newChangeManagementModalController]);
+        "$log", "$scope", "_", "COMPONENT", "VIDCONFIGURATION","DataService","featureFlags", newChangeManagementModalController]);
 
-    function newChangeManagementModalController($uibModalInstance, $uibModal,$q, AaiService, changeManagementService, Upload, $log, $scope, _, COMPONENT, VIDCONFIGURATION) {
+    function newChangeManagementModalController($uibModalInstance, $uibModal,$q, AaiService, changeManagementService, Upload, $log, $scope, _, COMPONENT, VIDCONFIGURATION, DataService, featureFlags) {
 
         var vm = this;
         vm.hasScheduler = !!VIDCONFIGURATION.SCHEDULER_PORTAL_URL;
 
         vm.softwareVersionRegex = "[-a-zA-Z0-9\.]+";
 
+        var attuid;
+
+        function fetchAttUid() {
+            var defer = $q.defer();
+            if (attuid) {
+                defer.resolve(attuid);
+            } else {
+                AaiService.getLoggedInUserID(function (response) {
+                        attuid = response.data;
+                        defer.resolve(attuid);
+                    },
+                    function (err) {
+                        defer.reject(err);
+                    });
+            }
+            return defer.promise;
+        }
+
         var init = function () {
             vm.changeManagement = {};
 
             loadServicesCatalog();
-            registerVNFNamesWatcher();
+            fetchAttUid().then(registerVNFNamesWatcher);
             vm.loadSubscribers();
         };
 
                                                 newVNFName.vfModules = vnf.vfModules;
                                                 newVNFName.category = response.data.service.category;
                                                 newVNFName.groupModules = _.groupBy(newVNFName.vfModules, "customizationUuid");
+
+                                                //list vfmodules ids in AAI that belong to that vnf instance
+                                                var modulesAaiIds = _.filter(newVNFName.relatedTo, function(item){
+                                                                        return item["node-type"] === "vf-module";
+                                                                    }).map(function(item){
+                                                                        return item.id;
+                                                                    });
+
                                                 _.forEach(newVNFName.vfModules, function (mdl, key) {
                                                     mdl.scale = false; //defaults to not scale unless user changes it
                                                     if(mdl.properties && mdl.properties.max_vf_module_instances) {
-                                                        mdl.scalable = mdl.properties.max_vf_module_instances.value - newVNFName.groupModules[mdl.customizationUuid].length > 0;
+
+                                                        //how many vf modules of the same customizationId belong to that vnf instance
+                                                        mdl.currentCount = _.filter(vm.vfModules, function(item){
+                                                            return modulesAaiIds.indexOf(item.id) > -1 && item.properties["model-customization-id"] === mdl.customizationUuid;
+                                                        }).length;
+
+                                                        mdl.scalable = mdl.properties.max_vf_module_instances.value - mdl.currentCount > 0;
                                                     }else{
                                                         mdl.scalable = false;
                                                     }
                     modelCustomizationName: csarVNF.modelCustomizationName,
                     modelCustomizationId: csarVNF.customizationUuid
                 },
-                cloudConfiguration: {
-                    lcpCloudRegionId: "mdt1",
-                    tenantId: "88a6ca3ee0394ade9403f075db23167e"
-                },
+                cloudConfiguration: selectionVNF.cloudConfiguration || {},
                 requestInfo: {
                     source: "VID",
                     suppressRollback: false,
-                    requestorId: "az2016"
+                    requestorId: attuid
                 },
                 relatedInstanceList: [
                     {
                     return data;
                 }]
             })
-            .then(function (configUpdateResponse) {
-                vm.changeManagement.configUpdateFile = configUpdateResponse && JSON.parse(configUpdateResponse.data).payload;
-                defer.resolve(true);
-            })
-            .catch(function (error) {
-                defer.resolve(false);
-            });
+                .then(function (configUpdateResponse) {
+                    vm.changeManagement.configUpdateFile = configUpdateResponse && JSON.parse(configUpdateResponse.data).payload;
+                    defer.resolve(true);
+                })
+                .catch(function (error) {
+                    defer.resolve(false);
+                });
             return defer.promise;
         };
 
                         relatedInstanceList: [],
                         requestParameters:requestParametersData
                     };
-                    requestInfoData.instanceName = vnf.name + "_" + (vnf.groupModules[moduleToScale.customizationUuid].length + 1);
+                    requestInfoData.instanceName = vnf.name + "_" + (moduleToScale.currentCount + 1);
                 }else{
                     data = {
                         vnfName: vnf.name,
                                vm.changeManagement.policyYN = "Y";
                                vm.changeManagement.sniroYN = "Y";
 
+                                   if (featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_ADD_MSO_TESTAPI_FIELD)) {
+                                       vm.changeManagement.testApi = DataService.getMsoRequestParametersTestApi();
+                                   }
                                var data = {
                                        widgetName: 'Portal-Common-Scheduler',
                                        widgetData: vm.changeManagement,
             // var promiseArrOfGetVnfs = preparePromiseArrOfGetVnfs(instances);
 
             vm.vnfs = [];
+            vm.vfModules = [];
 
             AaiService.getVnfsByCustomerIdAndServiceType(
                 vm.changeManagement.subscriberId,
                                     }
                                 } else if (nodeType === "service-instance") {
                                     vm.serviceInstances.push(vnfsData[i]);
+                                } else if (nodeType === "vf-module") {
+                                    vm.vfModules.push(vnfsData[i]);
                                 }
                             }
                         }
             vm.serviceInstancesToGetVersions = [];
             var versions = [];
             _.forEach(vm.vnfs, function (vnf) {
-                if (vnf.properties['nf-role'] === vm.changeManagement['vnfType']) {
-
+                if (vnf.properties['nf-role'] === vm.changeManagement['vnfType']
+                && vnf.properties["model-invariant-id"]
+                && vnf.properties["model-version-id"]) {
                     vm.serviceInstancesToGetVersions.push({
-                        "model-invariant-id": vnf.properties["model-invariant-id"],
-                        "model-version-id": vnf.properties["model-version-id"] }
+                            "model-invariant-id": vnf.properties["model-invariant-id"],
+                            "model-version-id": vnf.properties["model-version-id"]
+                        }
                     );
 
                     versions.push(vnf.properties["model-invariant-id"]);