When opening a service instance from the instantiation status page, the More Actions...
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / controller / InstantiationController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 IBM.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 /**
23  * The Instantiation (or View/Edit) Controller controls the instantiation/removal of
24  * deployable objects (Services, VNFs, VF-Modules, Networks, and Volume-Groups)
25  */
26 (function () {
27     "use strict";
28
29     appDS2.requires.push('ui.tree');
30
31     appDS2.controller("InstantiationController", function ($scope, $route, $location, $timeout, $uibModal, COMPONENT, VIDCONFIGURATION, FIELD, DataService, PropertyService, UtilityService, VnfService, $http, vidService, AaiService, PnfService, CrService, AsdcService, $q, featureFlags, _, CreationService, $window, DeleteResumeService) {
32         $scope.popup = new Object();
33         $scope.defaultBaseUrl = "";
34         $scope.responseTimeoutMsec = 60000;
35         $scope.properties = UtilityService.getProperties();
36         $scope.resumeStatus = COMPONENT.RESUME_STATUS;
37         //isPermitted - returned as string from url and converted into boolean
38         $scope.isPermitted = $location.search().isPermitted === "true";
39         $scope.STATUS_CONSTANTS = FIELD.STATUS;
40         $scope.pnfs = [];// PNF data init;
41         $scope.collectionResource = {};
42         $scope.collections = [];
43         $scope.networks = [];
44         $scope.isCR = false;
45         $scope.isVFC = false;
46         $scope.init = function () {
47             /*
48              * These 2 statements should be included in non-test code.
49              */
50             // takes a default value, retrieves the prop value from the file system and sets it
51             var msecs = PropertyService.retrieveMsoMaxPollingIntervalMsec();
52             PropertyService.setMsoMaxPollingIntervalMsec(msecs);
53
54             // takes a default value, retrieves the prop value from the file system and sets it
55             var polls = PropertyService.retrieveMsoMaxPolls();
56             PropertyService.setMsoMaxPolls(polls);
57         };
58
59
60         $scope.convertModel = function (asdcModel) {
61             if (!asdcModel) return undefined;
62             var convertedAsdcModel = UtilityService.convertModel(asdcModel);
63             return convertedAsdcModel;
64         };
65
66         $scope.prepareScopeWithModel = function () {
67             // skip if no model
68             if (!vidService.getModel()) return;
69
70             $scope.service = {
71                 "model": vidService.getModel(),
72                 "convertedModel": $scope.convertModel(vidService.getModel()),
73                 "instance": vidService.getInstance()
74             };
75
76
77             $scope.isCR = !_.isEmpty($scope.service.model.collectionResources);
78             if ($scope.isCR)
79                 prepareCr();
80             else
81                 preparePnfs();
82         };
83
84         function preparePnfs() {
85             var serviceInstance = {
86                 globalCustomerId: $location.search().subscriberId,
87                 serviceType: $location.search().serviceType,
88                 serviceInstanceId: $location.search().serviceInstanceId
89             };
90
91             _setPnf(serviceInstance).then(function (data) {
92                 $scope.pnfs = data;
93             });
94         }
95
96
97         function prepareCr() {
98             var serviceInstance = {
99                 globalCustomerId: $location.search().subscriberId,
100                 serviceType: $location.search().serviceType,
101                 serviceInstanceId: $location.search().serviceInstanceId
102             };
103
104             _setCr(serviceInstance).then(function (data) {
105                 $scope.collectionResource = data;
106                 $scope.collections.push($scope.collectionResource.collection);
107                 $scope.networks.push($scope.collectionResource.networks[0]);
108             });
109         }
110
111         $scope.returnVfModules = function (vnfInstance) {
112
113             var svcModel = $scope.service.convertedModel;
114             //var vnfModelInvariantUuid = vnfInstance[FIELD.ID.MODEL_INVAR_ID];
115             var vnfModelVersionId = vnfInstance[FIELD.ID.MODEL_VERSION_ID]; // model uuid
116             var vnfModelCustomizationUuid = vnfInstance[FIELD.ID.MODEL_CUSTOMIZATION_ID];
117
118             var vnfModel = null;
119
120             if ((!($scope.isObjectEmpty(svcModel))) && (!($scope.isObjectEmpty(svcModel.vnfs)))) {
121                 if ((svcModel.isNewFlow) && (vnfModelCustomizationUuid != null)) {
122                     vnfModel = svcModel.vnfs[vnfModelCustomizationUuid];
123                     if (vnfModel !== undefined) {
124                         if (!($scope.isObjectEmpty(vnfModel.vfModules))) {
125                             //console.log ("vnfModel.vfModules: "); console.log (JSON.stringify(vnfModel.vfModules, null, 4));
126                             return (vnfModel.vfModules);
127                         }
128                     }
129                 }
130                 else {
131                     // old flow
132                     if (vnfModelVersionId != null) {
133                         vnfModel = svcModel.vnfs[vnfModelVersionId];
134                         if (vnfModel !== undefined) {
135                             if (!($scope.isObjectEmpty(vnfModel.vfModules))) {
136                                 //console.log ("vnfModel.vfModules: "); console.log (JSON.stringify(vnfModel.vfModules, null, 4));
137                                 return (vnfModel.vfModules);
138                             }
139                         }
140                     }
141                 }
142
143             }
144             return null;
145         };
146         $scope.hasVfModules = function (vnfInstance) {
147             if ($scope.returnVfModules(vnfInstance) != null) {
148                 return true;
149             }
150             return false;
151         };
152         $scope.returnVolumeGroups = function (vnfInstance) {
153
154             var svcModel = $scope.service.convertedModel;
155
156             //var vnfModelInvariantUuid = vnfInstance[FIELD.ID.MODEL_INVAR_ID];
157             var vnfModelVersionId = vnfInstance[FIELD.ID.MODEL_VERSION_ID];
158             var vnfModelCustomizationUuid = vnfInstance[FIELD.ID.MODEL_CUSTOMIZATION_ID];
159
160             var vnfModel = null;
161
162             if ((!($scope.isObjectEmpty(svcModel))) && (!($scope.isObjectEmpty(svcModel.vnfs)))) {
163                 if ((svcModel.isNewFlow) && (vnfModelCustomizationUuid != null)) {
164                     vnfModel = svcModel.vnfs[vnfModelCustomizationUuid];
165                     if (vnfModel !== undefined && !($scope.isObjectEmpty(vnfModel.volumeGroups))) {
166                             //console.log ("vnfModel.volumeGroups: "); console.log (JSON.stringify(vnfModel.volumeGroups, null, 4));
167                             return (vnfModel.volumeGroups);
168                         }
169                 }
170                 else {
171                     // old flow
172                     if (vnfModelVersionId != null) {
173                         vnfModel = svcModel.vnfs[vnfModelVersionId];
174                         if (!($scope.isObjectEmpty(vnfModel.volumeGroups))) {
175                             //console.log ("vnfModel.vfModules: "); console.log (JSON.stringify(vnfModel.volumeGroups, null, 4));
176                             return (vnfModel.volumeGroups);
177                         }
178                     }
179                 }
180
181             }
182             return null;
183         };
184         $scope.hasVolumeGroups = function (vnfInstance) {
185             if ($scope.returnVolumeGroups(vnfInstance) != null) {
186                 return true;
187             }
188             return false;
189         };
190         $scope.deleteNetwork = function (serviceObject, network) {
191
192             console.log("Removing Network " + network.name);
193
194             //Send delete network request to MSO
195
196             //var networks = this.service.instance.networks;
197
198             //networks.splice(networks.indexOf(network), 1);
199
200             //Retrieve updated data from A&AI
201             var serviceInstance = serviceObject.object;
202
203             setCurrentNetworkModelInfoFromScope(network);
204
205             DataService.setInventoryItem(network.object);
206
207             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
208             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
209             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
210
211             DataService.setGlobalCustomerId(serviceObject[FIELD.ID.GLOBAL_CUST_ID]);
212             DataService.setServiceInstanceName($scope.service.instance.name);
213             DataService.setServiceName($scope.service.model.service.name);
214             DataService.setServiceUuid($scope.service.model.service.uuid);
215             DataService.setNetworkInstanceId(network.object[FIELD.ID.NETWORK_ID]);
216
217             $scope.$broadcast(COMPONENT.DELETE_RESUME_COMPONENT, {
218                 componentId: COMPONENT.NETWORK,
219                 callbackFunction: deleteOrResumeCallback,
220                 dialogMethod: COMPONENT.DELETE
221             });
222         };
223
224         $scope.allowTransferToNewScreenAndShowButton = function (isPermitted){
225           if(featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_FLASH_MORE_ACTIONS_BUTTON_IN_OLD_VIEW_EDIT)) {
226               return isPermitted;
227           }
228           return false;
229         };
230
231         $scope.navigateToNewEditViewScreen = function(){
232                 window.location.href = 'serviceModels.htm#/servicePlanning/EDIT?' +
233                     'serviceModelId=' +     _.get($scope, 'service.model.service.uuid') +
234                     '&subscriberId=' +      $location.search().subscriberId  +
235                     '&serviceType=' +       $location.search().serviceType      +
236                     '&serviceInstanceId=' + $location.search().serviceInstanceId;
237         };
238
239         $scope.deleteService = function (serviceObject, serviceOrchestrationStatus) {
240
241             var serviceInstance = serviceObject.object;
242
243             console.log("Removing Service " + $scope.service.instance.name);
244
245             if ($scope.isMacro()) {
246                 DataService.setALaCarte(false);
247             }
248             else {
249                 DataService.setALaCarte(true);
250             }
251             DataService.setMacro($scope.isMacro());
252             DataService.setInventoryItem(serviceInstance);
253             setCurrentServiceModelInfoFromScope();
254
255
256             DataService.setSubscriberName(serviceObject[FIELD.ID.SUBSCRIBER_NAME]);
257             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
258             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
259
260             DataService.setGlobalCustomerId(serviceObject[COMPONENT.GLOBAL_CUSTOMER_ID]);
261             DataService.setServiceInstanceName($scope.service.instance.name);
262
263             DataService.setServiceName($scope.service.model.service.name);
264
265             DataService.setServiceUuid($scope.service.model.service.uuid);
266
267             $scope.$broadcast(COMPONENT.DELETE_RESUME_COMPONENT, {
268                 componentId: COMPONENT.SERVICE,
269                 callbackFunction: deleteServiceInstanceCallbackFunction,
270                 dialogMethod: COMPONENT.DELETE,
271                 serviceStatus: serviceOrchestrationStatus
272             });
273
274         };
275
276         function populate_popup_vfModule(serviceObject, vfModule, vnf) {
277             var serviceInstance = serviceObject.object;
278
279             DataService.setInventoryItem(vfModule.object);
280
281             setCurrentVfModuleModelInfoFromScope(vnf, vfModule);
282             var vfModuleInstanceID = vfModule.object[FIELD.ID.VF_MODULE_ID];
283             if (vfModuleInstanceID == null) {
284                 vfModuleInstanceID = "";
285             }
286
287             DataService.setVnfInstanceId(vnf.object[FIELD.ID.VNF_ID]);
288             DataService.setVfModuleInstanceId(vfModuleInstanceID);
289
290             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
291             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
292             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
293
294             DataService.setGlobalCustomerId(serviceObject[FIELD.ID.GLOBAL_CUST_ID]);
295             DataService.setServiceInstanceName($scope.service.instance.name);
296
297             DataService.setServiceName($scope.service.model.service.name);
298
299             DataService.setServiceUuid($scope.service.model.service.uuid);
300         }
301
302         var modalInstance;
303
304         var openMsoModal = function (msoType, requestParams, callbackFunction, configuration) {
305              modalInstance = $uibModal.open({
306                 templateUrl: 'app/vid/scripts/modals/mso-commit/mso-commit.html',
307                 controller: "msoCommitModalController",
308                 backdrop: false,
309                 resolve: {
310                     msoType: function () {
311                         return msoType;
312                     },
313                     requestParams: function () {
314                         requestParams.callbackFunction = callbackFunction;
315                         return requestParams;
316                     },
317                     configuration: function () {
318                         return configuration;
319                     }
320                 }
321             });
322         };
323
324         var openVfModuleWithHomingDataModal = function(action, vfModule)  {
325             modalInstance = $uibModal.open({
326                 controller: 'vfModuleActionModalController',
327                 templateUrl: 'app/vid/scripts/modals/vf-module-homing-data-action/vf-module-homing-data-action.html',
328                 backdrop: false,
329                 resolve: {
330                     action: function () {
331                         return action;
332                     },
333                     vfModule: function() {
334                         return vfModule;
335                     }
336                 }
337             });
338
339             modalInstance.result.then(function (data) {
340                 if (data.msoType && data.requestParams) {
341                     openMsoModal(data.msoType, data.requestParams, deleteOrResumeCallback, null);
342                 }
343             });
344         };
345
346         function getLcpCloudRegionTenantList() {
347             AaiService.getLcpCloudRegionTenantList(DataService
348                 .getGlobalCustomerId(), DataService.getServiceType(), function(
349                 response) {
350                 $scope.lcpAndTenant = response;
351                 $scope.isFeatureFlagCloudOwner = featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST);
352                 $scope.lcpRegionList = _.uniqBy(response, 'cloudRegionId');
353             });
354         }
355
356         $scope.deleteVfModule = function (serviceObject, vfModule, vnf) {
357             $scope.isSoftDeleteEnabled = true;
358
359             populate_popup_vfModule(serviceObject, vfModule, vnf);
360
361             if (DataService.getLoggedInUserId())  {
362                 openVfModuleWithHomingDataModal(COMPONENT.DELETE, vfModule);
363             }
364             else {
365                 AaiService.getLoggedInUserID(function (response) {
366                     var userID = response.data;
367                     DataService.setLoggedInUserId(userID);
368                     openVfModuleWithHomingDataModal(COMPONENT.DELETE, vfModule);
369                 });
370             }
371             console.log("Removing VF-Module", vfModule);
372         };
373
374         function setCurrentServiceModelInfoFromScope() {
375             DataService.setModelInfo(COMPONENT.SERVICE, {
376                 "modelInvariantId": $scope.service.model.service.invariantUuid,
377                 "modelVersion": $scope.service.model.service.version,
378                 "modelNameVersionId": $scope.service.model.service.uuid,
379                 "modelName": $scope.service.model.service.name,
380                 "inputs": ""
381             });
382         };
383
384         function setCurrentVNFModelInfo(vnf) {
385             var svcModel = $scope.service.convertedModel;
386             var vnfModel;
387             var vnfModelCustomizationUuid = vnf.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
388             var vnfModelVersionId = vnf.object[FIELD.ID.MODEL_VERSION_ID];
389             if ((!($scope.isObjectEmpty(svcModel))) && (!($scope.isObjectEmpty(svcModel.vnfs)))) {
390                 if ((svcModel.isNewFlow) && (vnfModelCustomizationUuid != null)) {
391                     vnfModel = svcModel.vnfs[vnfModelCustomizationUuid];
392                 }
393                 else {
394                     vnfModel = svcModel.vnfs[vnfModelVersionId];
395                 }
396                 if (!($scope.isObjectEmpty(vnfModel))) {
397
398                     DataService.setModelInfo(COMPONENT.VNF, {
399                         "modelInvariantId": vnfModel.invariantUuid,
400                         "modelVersion": vnfModel.version,
401                         "modelNameVersionId": vnfModel.uuid,
402                         "modelCustomizationName": vnfModel.modelCustomizationName,
403                         "customizationUuid": vnfModel.customizationUuid,
404                         "modelName": vnfModel.name,
405                         "inputs": ""
406                     });
407                 }
408             }
409
410
411         }
412
413         function setCurrentNetworkModelInfoFromScope(network) {
414             var svcModel = $scope.service.convertedModel;
415             var netModel;
416             // set model default and override later if found
417             DataService.setModelInfo(COMPONENT.NETWORK, {});
418
419             if (network.object != null) {
420
421                 //var netModelInvariantUuid = network.object[FIELD.ID.MODEL_INVAR_ID];
422                 var netModelVersionId = network.object[FIELD.ID.MODEL_VERSION_ID]; // model uuid
423                 var netModelCustomizationUuid = network.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
424
425                 if (UtilityService.hasContents(netModelCustomizationUuid)) {
426                     // set it to what came from a&ai
427                     DataService.setResCustomizationUuid(netModelCustomizationUuid);
428                 }
429
430                 if ((!($scope.isObjectEmpty(svcModel))) && (!($scope.isObjectEmpty(svcModel.networks)))) {
431                     if ((svcModel.isNewFlow) && (UtilityService.hasContents(netModelCustomizationUuid))) {
432                         netModel = svcModel.networks[netModelCustomizationUuid];
433                     }
434                     else {
435
436                         if (UtilityService.hasContents(netModelVersionId)) {
437                             netModel = svcModel.networks[netModelVersionId];
438                         }
439
440                     }
441                 }
442             }
443             if (!($scope.isObjectEmpty(netModel))) {
444                 DataService.setModelInfo(COMPONENT.NETWORK, {
445                     "modelInvariantId": netModel.invariantUuid,
446                     "modelVersion": netModel.version,
447                     "modelNameVersionId": netModel.uuid,
448                     "modelCustomizationName": netModel.modelCustomizationName,
449                     "customizationUuid": netModel.customizationUuid,
450                     "modelName": netModel.name,
451                     "inputs": ""
452                 });
453             }
454         }
455
456         function setCurrentVfModuleModelInfoFromScope(vnf, vfModule) {
457
458             var svcModel = $scope.service.convertedModel;
459
460             //var vnfModelInvariantUuid = vnf.object[FIELD.ID.MODEL_INVAR_ID];
461             var vnfModelVersionId = vnf.object[FIELD.ID.MODEL_VERSION_ID];
462             var vnfModelCustomizationUuid = vnf.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
463             var vnfModel = null;
464             var vfModuleModel = null;
465
466             DataService.setModelInfo(COMPONENT.VF_MODULE, {
467                 "modelInvariantId": "",
468                 "modelVersion": "",
469                 "modelNameVersionId": "",
470                 "modelCustomizationName": "",
471                 "customizationUuid": "",
472                 "modelName": "",
473                 "inputs": ""
474             });
475
476             if ((!($scope.isObjectEmpty(svcModel))) && (!($scope.isObjectEmpty(svcModel.vnfs)))) {
477                 if ((svcModel.isNewFlow) && (vnfModelCustomizationUuid != null)) {
478                     vnfModel = svcModel.vnfs[vnfModelCustomizationUuid];
479
480                     var vfModuleCustomizationUuid = vfModule.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
481                     if (!($scope.isObjectEmpty(vnfModel)) && !($scope.isObjectEmpty(vnfModel.vfModules)) && UtilityService.hasContents(vfModuleCustomizationUuid)) {
482
483                         vfModuleModel = vnfModel.vfModules[vfModuleCustomizationUuid];
484
485                     }
486                 }
487                 else {
488                     // old flow
489                     if (vnfModelVersionId != null) {
490                         vnfModel = svcModel.vnfs[vnfModelVersionId];
491                     }
492                     //var vfModuleInvariantUuid = vfModule.object[FIELD.ID.MODEL_INVAR_ID];
493                     var vfModuleModelVersionId = vfModule.object[FIELD.ID.MODEL_VERSION_ID];
494                     if ((!($scope.isObjectEmpty(vnfModel))) && (!($scope.isObjectEmpty(vnfModel.vfModules))) &&
495                         UtilityService.hasContents(vfModuleModelVersionId)) {
496                         vfModuleModel = vnfModel.vfModules[vfModuleModelVersionId];
497                     }
498                 }
499                 if (!($scope.isObjectEmpty(vfModuleModel))) {
500                     DataService.setModelInfo(COMPONENT.VF_MODULE, {
501                         "modelInvariantId": vfModuleModel.invariantUuid,
502                         "modelVersion": vfModuleModel.version,
503                         "modelNameVersionId": vfModuleModel.uuid,
504                         "modelCustomizationName": vfModuleModel.modelCustomizationName,
505                         "customizationUuid": vfModuleModel.customizationUuid,
506                         "modelName": vfModuleModel.name,
507                         "inputs": ""
508                     });
509                 }
510             }
511         }
512
513         function setCurrentVolumeGroupModelInfoFromScope(vnf, vfModule) {
514             var svcModel = $scope.service.convertedModel;
515
516             var vnfModelCustomizationUuid = null;
517             var vnfModel = null;
518             var vnfModelVersionId = null;
519
520             vnfModelVersionId = vnf.object[FIELD.ID.MODEL_VERSION_ID];
521             vnfModelCustomizationUuid = vnf.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
522
523             DataService.setModelInfo(COMPONENT.VOLUME_GROUP, {
524                 "modelInvariantId": "",
525                 "modelVersion": "",
526                 "modelNameVersionId": "",
527                 "modelCustomizationName": "",
528                 "customizationUuid": "",
529                 "modelName": "",
530                 "inputs": ""
531             });
532
533             if ((!($scope.isObjectEmpty(svcModel))) && (!($scope.isObjectEmpty(svcModel.vnfs)))) {
534                 if ((svcModel.isNewFlow) && (vnfModelCustomizationUuid != null)) {
535                     vnfModel = svcModel.vnfs[vnfModelCustomizationUuid];
536                 }
537                 else {
538                     vnfModel = svcModel.vnfs[vnfModelVersionId];
539                 }
540             }
541
542
543             // volume groups don't have model-invariant-id/version in a&ai.
544             // Their model-invariant-id/version is the one for the associated vfModule
545
546             var vfModuleModelVersionId = vfModule.object[FIELD.ID.MODEL_VERSION_ID];
547             var vfModuleCustomizationUuid = vfModule.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
548             var volGroupModel = null;
549
550             if (!($scope.isObjectEmpty(vnfModel)) && !($scope.isObjectEmpty(vnfModel.volumeGroups))) {
551                 if ((svcModel.isNewFlow) && (UtilityService.hasContents(vfModuleCustomizationUuid))) {
552                     volGroupModel = vnfModel.volumeGroups[vfModuleCustomizationUuid];
553                 }
554                 else {
555                     volGroupModel = vnfModel.volumeGroups[vfModuleModelVersionId];
556                 }
557                 if (!($scope.isObjectEmpty(volGroupModel))) {
558                     DataService.setModelInfo(COMPONENT.VOLUME_GROUP, {
559                         "modelInvariantId": volGroupModel.invariantUuid,
560                         "modelVersion": volGroupModel.version,
561                         "modelNameVersionId": volGroupModel.uuid,
562                         "modelCustomizationName": volGroupModel.modelCustomizationName,
563                         "customizationUuid": volGroupModel.customizationUuid,
564                         "modelName": volGroupModel.name,
565                         "inputs": ""
566                     });
567
568                 }
569             }
570         }
571
572         function setCurrentVolumeGroupModelInfoByVfModuleFromScope(vnf, volumeGroup) {
573             var svcModel = $scope.service.convertedModel;
574
575             var vnfModelCustomizationUuid = null;
576             var vnfModel = null;
577             var vnfModelVersionId = null;
578
579             vnfModelVersionId = vnf.object[FIELD.ID.MODEL_VERSION_ID];
580             vnfModelCustomizationUuid = vnf.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
581
582             DataService.setModelInfo(COMPONENT.VOLUME_GROUP, {
583                 "modelInvariantId": "",
584                 "modelVersion": "",
585                 "modelNameVersionId": "",
586                 "modelCustomizationName": "",
587                 "customizationUuid": "",
588                 "modelName": "",
589                 "inputs": ""
590             });
591
592             if ((!($scope.isObjectEmpty(svcModel))) && (!($scope.isObjectEmpty(svcModel.vnfs)))) {
593                 if ((svcModel.isNewFlow) && (vnfModelCustomizationUuid != null)) {
594                     vnfModel = svcModel.vnfs[vnfModelCustomizationUuid];
595                 }
596                 else {
597                     vnfModel = svcModel.vnfs[vnfModelVersionId];
598                 }
599             }
600
601
602             // volume groups don't have model-invariant-id/version in a&ai.
603             // Their model-invariant-id/version is the one for the associated vfModule
604
605             var vfModuleModelVersionId = volumeGroup.object[FIELD.ID.VF_MODULE_MODEL_VERSION_ID];
606             var vfModuleCustomizationUuid = volumeGroup.object[FIELD.ID.VF_MODULE_MODEL_CUSTOMIZATION_ID];
607             var volGroupModel = null;
608             if ((!($scope.isObjectEmpty(vnfModel))) && (!($scope.isObjectEmpty(vnfModel.volumeGroups)))) {
609                 if ((svcModel.isNewFlow) && (UtilityService.hasContents(vfModuleCustomizationUuid))) {
610                     volGroupModel = vnfModel.volumeGroups[vfModuleCustomizationUuid];
611                 }
612                 else {
613                     volGroupModel = vnfModel.volumeGroups[vfModuleModelVersionId];
614                 }
615                 if (!($scope.isObjectEmpty(volGroupModel))) {
616                     DataService.setModelInfo(COMPONENT.VOLUME_GROUP, {
617                         "modelInvariantId": volGroupModel.invariantUuid,
618                         "modelVersion": volGroupModel.version,
619                         "modelNameVersionId": volGroupModel.uuid,
620                         "modelCustomizationName": volGroupModel.modelCustomizationName,
621                         "customizationUuid": volGroupModel.customizationUuid,
622                         "modelName": volGroupModel.name,
623                         "inputs": ""
624                     });
625
626                 }
627             }
628         }
629
630         $scope.deleteVnf = function (serviceObject, vnf) {
631             console.log("Removing VNF " + vnf.name);
632
633             var serviceInstance = serviceObject.object;
634             var svcModel = $scope.service.convertedModel;
635             DataService.setInventoryItem(vnf.object);
636
637             /*var vnftype = vnf.object['vnf-type'];
638             if (vnftype == null)
639                 vnftype = "";
640             else
641             {
642                 var n = vnftype.search("/");
643                 if (n >= 0)
644                     vnftype = vnftype.substring(n+1);
645             }*/
646
647             var svcModel = $scope.service.convertedModel;
648             var vnfModelInvariantUuid = null;
649             var vnfModelVersion = null;
650             var vnfModelCustomizationUuid = null;
651             var vnfModel = null;
652             var vnfModelVersionId = null;
653
654             vnfModelInvariantUuid = vnf.object[FIELD.ID.MODEL_INVAR_ID];
655             vnfModelVersionId = vnf.object[FIELD.ID.MODEL_VERSION_ID];
656             vnfModelCustomizationUuid = vnf.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
657
658             DataService.setModelInfo(COMPONENT.VNF, {
659                 "modelInvariantId": vnfModelInvariantUuid,
660                 "modelVersion": "",
661                 "modelNameVersionId": vnfModelVersionId,
662                 "modelCustomizationName": "",
663                 "customizationUuid": vnfModelCustomizationUuid,
664                 "modelName": "",
665                 "inputs": ""
666             });
667
668             if ((!($scope.isObjectEmpty(svcModel))) && (!($scope.isObjectEmpty(svcModel.vnfs)))) {
669                 if ((svcModel.isNewFlow) && (vnfModelCustomizationUuid != null)) {
670                     vnfModel = svcModel.vnfs[vnfModelCustomizationUuid];
671                 }
672                 else {
673                     vnfModel = svcModel.vnfs[vnfModelVersionId];
674                 }
675                 //console.log ( "vnf models: "); console.log ( JSON.stringify ($scope.service.convertedModel.vnfs, null, 4) );
676                 if (!($scope.isObjectEmpty(vnfModel))) {
677
678                     DataService.setModelInfo(COMPONENT.VNF, {
679                         "modelInvariantId": vnfModel.invariantUuid,
680                         "modelVersion": vnfModel.version,
681                         "modelNameVersionId": vnfModel.uuid,
682                         "modelCustomizationName": vnfModel.modelCustomizationName,
683                         "customizationUuid": vnfModel.customizationUuid,
684                         "modelName": vnfModel.name,
685                         "inputs": ""
686                     });
687                 }
688             }
689
690             DataService.setVnfInstanceId(vnf.object[FIELD.ID.VNF_ID]);
691
692             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
693             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
694             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
695
696             DataService.setGlobalCustomerId(serviceObject[FIELD.ID.GLOBAL_CUST_ID]);
697             DataService.setServiceInstanceName($scope.service.instance.name);
698
699             DataService.setServiceName($scope.service.model.service.name);
700
701             DataService.setServiceUuid($scope.service.model.service.uuid);
702
703             $scope.$broadcast(COMPONENT.DELETE_RESUME_COMPONENT, {
704                 componentId: COMPONENT.VNF,
705                 callbackFunction: deleteOrResumeCallback,
706                 dialogMethod: COMPONENT.DELETE
707             });
708
709         };
710
711         $scope.deleteVolumeGroup = function (serviceObject, vnf, vfModule, volumeGroup) {
712
713             console.log("Removing Volume Group " + volumeGroup.name);
714             var haveModel = false;
715
716             var serviceInstance = serviceObject.object;
717
718             setCurrentVolumeGroupModelInfoFromScope(vnf, vfModule);
719
720             DataService.setInventoryItem(volumeGroup.object);
721
722             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
723             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
724             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
725
726             DataService.setGlobalCustomerId(serviceObject[FIELD.ID.GLOBAL_CUST_ID]);
727             DataService.setServiceInstanceName($scope.service.instance.name);
728
729             DataService.setServiceName($scope.service.model.service.name);
730
731             DataService.setServiceUuid($scope.service.model.service.uuid);
732             DataService.setVnfInstanceId(vnf.nodeId);
733             DataService.setVolumeGroupInstanceId(volumeGroup.nodeId);
734
735             $scope.$broadcast(COMPONENT.DELETE_RESUME_COMPONENT, {
736                 componentId: COMPONENT.VOLUME_GROUP,
737                 dialogMethod: COMPONENT.DELETE
738             });
739         };
740
741         $scope.deleteVnfVolumeGroup = function (serviceObject, vnf, volumeGroup) {
742
743             console.log("Removing Volume Group " + volumeGroup.name);
744             var serviceInstance = serviceObject.object;
745
746             DataService.setInventoryItem(volumeGroup.object);
747
748             var svcModel = $scope.service.convertedModel;
749
750             var vnfModelInvariantUuid = vnf.object[FIELD.ID.MODEL_INVAR_ID];
751             var vnfModelVersionId = vnf.object[FIELD.ID.MODEL_VERSION_ID];
752             var vnfModelCustomizationUuid = vnf.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
753
754             var volGroupModelInvariantUuid = volumeGroup.object[FIELD.ID.MODEL_INVAR_ID];
755             var volGroupModelVersionId = volumeGroup.object[FIELD.ID.MODEL_VERSION_ID];
756             var volGroupModelCustomizationUuid = volumeGroup.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
757
758             var vnfModel = null;
759             var volGroupModel = null;
760
761             // send an empty model by default since model is not required for deletes
762             DataService.setModelInfo(COMPONENT.VOLUME_GROUP, {});
763
764             if (svcModel.isNewFlow) {
765                 vnfModel = svcModel.vnfs[vnfModelCustomizationUuid];
766                 if (UtilityService.hasContents(volGroupModelCustomizationUuid)) {
767                     volGroupModel = vnfModel.volumeGroups[volGroupModelCustomizationUuid];
768                 }
769             }
770             else {
771
772                 vnfModel = svcModel.vnfs[vnfModelVersionId];
773                 if (UtilityService.hasContents(volGroupModelVersionId)) {
774                     volGroupModel = vnfModel.volumeGroups[volGroupModelVersionId];
775                 }
776             }
777             if (!($scope.isObjectEmpty(volGroupModel))) {
778                 DataService.setModelInfo(COMPONENT.VOLUME_GROUP, {
779                     "modelInvariantId": volGroupModel.invariantUuid,
780                     "modelVersion": volGroupModel.version,
781                     "modelNameVersionId": volGroupModel.uuid,
782                     "modelName": volGroupModel.name,
783                     "modelCustomizationName": volGroupModel.modelCustomizationName,
784                     "customizationUuid": volGroupModel.customizationUuid,
785                     "inputs": ""
786                 });
787             }
788
789             DataService.setVnfInstanceId(vnf.object[FIELD.ID.VNF_ID]);
790
791             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
792             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
793             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
794
795             DataService.setGlobalCustomerId(serviceObject[FIELD.ID.GLOBAL_CUST_ID]);
796             DataService.setServiceInstanceName($scope.service.instance.name);
797
798             DataService.setServiceName($scope.service.model.service.name);
799
800             DataService.setServiceUuid($scope.service.model.service.uuid);
801             DataService.setVnfInstanceId(vnf.nodeId);
802             DataService.setVolumeGroupInstanceId(volumeGroup.nodeId);
803
804             $scope.$broadcast(COMPONENT.DELETE_RESUME_COMPONENT, {
805                 componentId: COMPONENT.VOLUME_GROUP,
806                 callbackFunction: deleteOrResumeCallback,
807                 dialogMethod: COMPONENT.DELETE
808             });
809         };
810
811         $scope.describeNetwork = function (serviceObject, networkObject) {
812             var serviceInstance = serviceObject.object;
813             var network = networkObject.object;
814             //console.log ("networkObject="); console.log (JSON.stringify(networkObject, null, 4));
815
816             DataService.setResCustomizationUuid(" ");
817
818             setCurrentServiceModelInfoFromScope();
819             setCurrentNetworkModelInfoFromScope(networkObject);
820
821             DataService.setNetworkInstanceId(network[FIELD.ID.NETWORK_ID]);
822             DataService.setInventoryItem(networkObject);
823             DataService.setSubscriberName(serviceObject.subscriberName);
824             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
825             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
826
827             $scope.$broadcast(COMPONENT.SHOW_COMPONENT_DETAILS, {
828                 componentId: COMPONENT.NETWORK
829             });
830         };
831
832         // for service instance id - no need for this!
833         $scope.describeService = function (serviceObject) {
834             var serviceInstance = serviceObject.object;
835             setCurrentServiceModelInfoFromScope();
836
837             DataService.setInventoryItem(serviceInstance);
838             //DataService.setModelInfo(serviceInstance['service-instance-id'], serviceInstance);
839
840             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
841             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
842             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
843
844             //Display popup with additional service information
845             $scope.$broadcast(COMPONENT.SHOW_COMPONENT_DETAILS, {
846                 componentId: COMPONENT.SERVICE
847             });
848
849         };
850
851         $scope.describeVfModule = function (serviceObject, vfModuleObject, vnf) {
852             var serviceInstance = serviceObject.object;
853             var vfModule = vfModuleObject.object;
854
855             /*var vfModuleInvariantUuid = vfModule[FIELD.ID.MODEL_INVAR_ID];
856             var vfModuleModelVersionId = vfModule[FIELD.ID.MODEL_VERSION_ID];*/
857             var vfModuleCustomizationUuid = vfModule[FIELD.ID.MODEL_CUSTOMIZATION_ID];
858
859             setCurrentServiceModelInfoFromScope();
860             setCurrentVfModuleModelInfoFromScope(vnf, vfModuleObject);
861
862             DataService.setCustomizationUuid(" ");
863             if (UtilityService.hasContents(vfModuleCustomizationUuid)) {
864                 DataService.setCustomizationUuid(vfModuleCustomizationUuid);
865             }
866
867             //Display popup with additional VF-Module information
868             DataService.setVfModuleInstanceId(vfModule[FIELD.ID.VF_MODULE_ID]);
869             DataService.setInventoryItem(vfModule);
870
871             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
872             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
873             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
874
875             $scope.$broadcast(COMPONENT.SHOW_COMPONENT_DETAILS, {
876                 componentId: COMPONENT.VF_MODULE
877             });
878         };
879
880         $scope.getStatusOfVnf = function (serviceObject, vnfObject) {
881             var serviceInstance = serviceObject.object;
882             var vnf = vnfObject.object;
883
884             DataService.setVnfInstanceId(vnf[FIELD.ID.VNF_ID]);
885             DataService.setInventoryItem(vnf);
886
887             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
888             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
889             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
890             DataService.setServiceInstanceName(serviceInstance[FIELD.ID.SERVICE_INSTANCE_NAME]);
891
892             $scope.$broadcast(COMPONENT.COMPONENT_STATUS, {
893                 componentId: COMPONENT.VNF,
894                 callbackFunction: updateProvStatusVnfCallbackFunction
895             });
896         };
897
898         $scope.describeVnf = function (serviceObject, vnfObject) {
899             var serviceInstance = serviceObject.object;
900             var vnf = vnfObject.object;
901             DataService.setResCustomizationUuid(" ");
902
903             //var vnfInvariantUuid = vnf[FIELD.ID.MODEL_INVAR_ID];
904             //var vnfVersionId = vnf[FIELD.ID.MODEL_VERSION_ID];
905             var vnfCustomizationUuid = vnf[FIELD.ID.MODEL_CUSTOMIZATION_ID];
906
907             if (UtilityService.hasContents(vnfCustomizationUuid)) {
908                 DataService.setResCustomizationUuid(vnfCustomizationUuid);
909             }
910
911             setCurrentServiceModelInfoFromScope();
912             setCurrentVNFModelInfo(vnfObject);
913
914             //Display popup with additional VNF information
915             DataService.setVnfInstanceId(vnf[FIELD.ID.VNF_ID]);
916             DataService.setInventoryItem(vnf);
917
918             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
919             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
920             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
921
922             $scope.$broadcast(COMPONENT.SHOW_COMPONENT_DETAILS, {
923                 componentId: COMPONENT.VNF
924             });
925         };
926
927         $scope.describeVolumeGroup = function (serviceObject, vnf, volumeGroupObject) {
928
929             var serviceInstance = serviceObject.object;
930             var volumeGroup = volumeGroupObject.object;
931
932             var volGroupCustomizationUuid = volumeGroup[FIELD.ID.MODEL_CUSTOMIZATION_ID];
933
934             setCurrentServiceModelInfoFromScope();
935             setCurrentVolumeGroupModelInfoByVfModuleFromScope(vnf, volumeGroupObject);
936
937             DataService.setCustomizationUuid(" ");
938             if (UtilityService.hasContents(volGroupCustomizationUuid)) {
939                 DataService.setCustomizationUuid(volGroupCustomizationUuid);
940             }
941             DataService.setVolumeGroupInstanceId(volumeGroup[FIELD.ID.VOLUME_GROUP_ID]);
942             DataService.setInventoryItem(volumeGroup);
943
944             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
945             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
946             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
947
948
949             $scope.$broadcast(COMPONENT.SHOW_COMPONENT_DETAILS, {
950                 componentId: COMPONENT.VOLUME_GROUP
951             });
952         };
953
954         $scope.addNetworkInstance = function (netModel, existingVnfs) {
955
956             // For networks we assume that we always follow the new flow
957             console.log("Adding network to service instance" + this.service.instance.name);
958             if (VIDCONFIGURATION.VNF_STATUS_CHECK_ENABLED && (UtilityService.hasContents(existingVnfs)) && (existingVnfs.length > 0)) {
959                 var msg = VnfService.isVnfListStatusValid(existingVnfs);
960                 if (msg != "") {
961                     alert(msg);
962                     return;
963                 }
964             }
965
966             DataService.setSubscriberName($scope.service.instance.subscriberName);
967             DataService.setGlobalCustomerId($scope.service.instance.globalCustomerId);
968             DataService.setServiceType($scope.service.instance.serviceType);
969             DataService.setServiceInstanceName($scope.service.instance.name);
970             DataService.setServiceInstanceId($scope.service.instance.id);
971             DataService.setServiceName($scope.service.model.service.name);
972
973             DataService.setModelInfo(COMPONENT.NETWORK, {
974                 "modelType": "network",
975                 "modelInvariantId": netModel.invariantUuid,
976                 "modelVersion": netModel.version,
977                 "modelNameVersionId": netModel.uuid,
978                 "modelName": netModel.name,
979                 "modelCustomizationName": netModel.modelCustomizationName,
980                 "customizationUuid": netModel.customizationUuid,
981                 "inputs": "",
982                 "displayInputs": netModel.displayInputs
983             });
984             setCurrentServiceModelInfoFromScope();
985
986
987             $scope.$broadcast(COMPONENT.CREATE_COMPONENT, {
988                 componentId: COMPONENT.NETWORK,
989                 callbackFunction: createVnfCallbackFunction
990             });
991         };
992
993         $scope.addVnfInstance = function (vnf, existingVnfs) {
994
995             if (VIDCONFIGURATION.VNF_STATUS_CHECK_ENABLED && (UtilityService.hasContents(existingVnfs)) && (existingVnfs.length > 0)) {
996                 var msg = VnfService.isVnfListStatusValid(existingVnfs);
997                 if (msg != "") {
998                     alert(msg);
999                     return;
1000                 }
1001             }
1002
1003             var isVfc = false;
1004
1005             _.map($scope.service.model.vnfs, function (value, key) {
1006                 if (value.uuid == vnf.uuid && !_.isEmpty(value.vfcInstanceGroups)) {
1007                         isVfc = true;
1008                         var queryData = {
1009                             serviceModelId: $scope.service.model.service.uuid,
1010                             serviceInstanceID: $scope.service.instance.id,
1011                             globalCustomerId: $scope.service.instance.globalCustomerId,
1012                             serviceType: $scope.service.instance.serviceType,
1013                             serviceInstanceName: $scope.service.instance.name,
1014                             modelCustomizationName: value.modelCustomizationName,
1015                             modelCustomizationId: value.customizationUuid,
1016                             subscriberName: $scope.service.instance.subscriberName
1017                         };
1018
1019                         $scope.$broadcast(COMPONENT.IFRAME_DIALOG, queryData);
1020                         return;
1021                     }
1022             });
1023
1024             DataService.setSubscriberName($scope.service.instance.subscriberName);
1025             DataService.setGlobalCustomerId($scope.service.instance.globalCustomerId);
1026             DataService.setServiceType($scope.service.instance.serviceType);
1027             DataService.setServiceInstanceName($scope.service.instance.name);
1028             DataService.setServiceInstanceId($scope.service.instance.id);
1029             DataService.setServiceName($scope.service.model.service.name);
1030
1031             console.log("existingVnfs: ");
1032             console.log(JSON.stringify(existingVnfs, null, 4));
1033             console.log("existingVnfs: ");
1034             console.log(JSON.stringify(existingVnfs, null, 4));
1035             var vnf_type = "";
1036             var vnf_role = "";
1037             var vnf_function = "";
1038             var vnf_code = "";
1039
1040             if (UtilityService.hasContents(vnf.nfType)) {
1041                 vnf_type = vnf.nfType;
1042             }
1043             if (UtilityService.hasContents(vnf.nfRole)) {
1044                 vnf_role = vnf.nfRole;
1045             }
1046             if (UtilityService.hasContents(vnf.nfFunction)) {
1047                 vnf_function = vnf.nfFunction;
1048             }
1049             if (UtilityService.hasContents(vnf.nfCode)) {
1050                 vnf_code = vnf.nfCode;
1051             }
1052             DataService.setModelInfo(COMPONENT.VNF, {
1053                 "modelType": vnf.isPnf ? "pnf" : "vnf",
1054                 "modelInvariantId": vnf.invariantUuid,
1055                 "modelVersion": vnf.version,
1056                 "modelNameVersionId": vnf.uuid,
1057                 "modelName": vnf.name,
1058                 "modelCustomizationName": vnf.modelCustomizationName,
1059                 "customizationUuid": vnf.customizationUuid,
1060                 "inputs": "",
1061                 "displayInputs": vnf.displayInputs,
1062                 "vnfType": vnf_type,
1063                 "vnfRole": vnf_role,
1064                 "vnfFunction": vnf_function,
1065                 "vnfCode": vnf_code,
1066                 "properties": vnf.properties
1067             });
1068
1069             DataService.setModelInstanceName($scope.service.model.service.name);
1070             setCurrentServiceModelInfoFromScope();
1071
1072             if (vnf.isConfig) {
1073                 DataService.setServiceProxies($scope.service.model.serviceProxies);
1074                 DataService.setSourceServiceProxies(vnf.sourceNodes);
1075                 DataService.setCollectorServiceProxies(vnf.collectorNodes);
1076                 DataService.setConfigurationByPolicy(vnf.isConfigurationByPolicy);
1077                 $location.path("/addNetworkNode");
1078             } else if (vnf.isPnf) {
1079                 $location.path("/pnfSearchAssociation");
1080             } else if (isVfc) {
1081                 //do nothing
1082             } else {
1083                 $scope.$broadcast(COMPONENT.CREATE_COMPONENT, {
1084                     componentId: COMPONENT.VNF,
1085                     callbackFunction: createVnfCallbackFunction
1086                 });
1087             }
1088         };
1089
1090         $scope.addVfModuleInstance = function (vnfInstance, vfModuleModel) {
1091
1092             if (VIDCONFIGURATION.VNF_STATUS_CHECK_ENABLED) {
1093                 var msg = VnfService.isVnfStatusValid(vnfInstance);
1094                 if (msg != "") {
1095                     alert(msg);
1096                     return;
1097                 }
1098
1099             }
1100             var svcModel = $scope.service.convertedModel;
1101             DataService.setSubscriberName($scope.service.instance.subscriberName);
1102             DataService.setGlobalCustomerId($scope.service.instance.globalCustomerId);
1103             DataService.setServiceType($scope.service.instance.serviceType);
1104             DataService.setServiceInstanceName($scope.service.instance.name);
1105             DataService.setServiceInstanceId($scope.service.instance.id);
1106             DataService.setServiceName($scope.service.model.service.name);
1107
1108             var vnfModelInvariantUuid = vnfInstance.object[FIELD.ID.MODEL_INVAR_ID];
1109             var vnfModelVersionId = vnfInstance.object[FIELD.ID.MODEL_VERSION_ID];
1110             var vnfModelCustomizationUuid = vnfInstance.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
1111             var vnfModel = null;
1112             if (svcModel.isNewFlow) {
1113                 vnfModel = svcModel.vnfs[vnfModelCustomizationUuid];
1114             }
1115             else {
1116                 vnfModel = svcModel.vnfs[vnfModelVersionId];
1117             }
1118
1119             var availableVolumeGroupList = [];
1120             angular.forEach(vnfInstance[FIELD.ID.AVAILABLEVOLUMEGROUPS], function (volumeGroupInstance, key) {
1121                 availableVolumeGroupList.push({"instance": volumeGroupInstance});
1122             });
1123
1124             DataService.setAvailableVolumeGroupList(availableVolumeGroupList);
1125             setCurrentServiceModelInfoFromScope();
1126
1127             DataService.setVnfInstanceId(vnfInstance.object[FIELD.ID.VNF_ID]);
1128
1129             DataService.setModelInfo(COMPONENT.VNF, {
1130                 "modelInvariantId": vnfModel.invariantUuid,
1131                 "modelVersion": vnfModel.version,
1132                 "modelNameVersionId": vnfModel.uuid,
1133                 "modelName": vnfModel.name,
1134                 "modelCustomizationName": vnfModel.modelCustomizationName,
1135                 "customizationUuid": vnfModel.customizationUuid,
1136                 "inputs": ""
1137             });
1138
1139             DataService.setModelInfo(COMPONENT.VF_MODULE, {
1140                 "modelInvariantId": vfModuleModel.invariantUuid,
1141                 "modelVersion": vfModuleModel.version,
1142                 "modelNameVersionId": vfModuleModel.uuid,
1143                 "customizationUuid": vfModuleModel.customizationUuid,
1144                 "modelCustomizationName": vfModuleModel.modelCustomizationName,
1145                 "modelName": vfModuleModel.name,
1146                 "inputs": ""
1147             });
1148
1149             $scope.$broadcast(COMPONENT.CREATE_COMPONENT, {
1150                 componentId: COMPONENT.VF_MODULE,
1151                 callbackFunction: createVfModuleCallbackFunction
1152             });
1153
1154         };
1155
1156         $scope.addVolumeGroupInstance = function (vnfInstance, volumeGroupModel) {
1157             if (VIDCONFIGURATION.VNF_STATUS_CHECK_ENABLED) {
1158                 var msg = VnfService.isVnfStatusValid(vnfInstance);
1159                 if (msg != "") {
1160                     alert(msg);
1161                     return;
1162                 }
1163             }
1164             var svcModel = $scope.service.convertedModel;
1165             DataService.setSubscriberName($scope.service.instance.subscriberName);
1166             DataService.setGlobalCustomerId($scope.service.instance.globalCustomerId);
1167             DataService.setServiceType($scope.service.instance.serviceType);
1168             DataService.setServiceInstanceName($scope.service.instance.name);
1169             DataService.setServiceInstanceId($scope.service.instance.id);
1170             DataService.setServiceName($scope.service.model.service.name);
1171             setCurrentServiceModelInfoFromScope();
1172
1173             DataService.setModelInfo(COMPONENT.SERVICE, {
1174                 "modelInvariantId": $scope.service.model.service.invariantUuid,
1175                 "modelVersion": $scope.service.model.service.version,
1176                 "modelNameVersionId": $scope.service.model.service.uuid,
1177                 "modelName": $scope.service.model.service.name,
1178                 "inputs": ""
1179             });
1180
1181             DataService.setVnfInstanceId(vnfInstance.object[FIELD.ID.VNF_ID]);
1182
1183             var vnfModelInvariantUuid = vnfInstance.object[FIELD.ID.MODEL_INVAR_ID];
1184             var vnfModelVersionId = vnfInstance.object[FIELD.ID.MODEL_VERSION_ID];
1185             var vnfCustomizationUuid = vnfInstance.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
1186             var vnfModel = null;
1187
1188             if (svcModel.isNewFlow) {
1189                 vnfModel = svcModel.vnfs[vnfCustomizationUuid];
1190             }
1191             else {
1192                 vnfModel = svcModel.vnfs[vnfModelVersionId];
1193             }
1194
1195             DataService.setModelInfo(COMPONENT.VNF, {
1196                 "modelInvariantId": vnfModel.invariantUuid,
1197                 "modelVersion": vnfModel.version,
1198                 "modelNameVersionId": vnfModel.uuid,
1199                 "modelName": vnfModel.name,
1200                 "modelCustomizationName": vnfModel.modelCustomizationName,
1201                 "customizationUuid": vnfModel.customizationUuid,
1202                 "inputs": ""
1203             });
1204
1205             DataService.setModelInfo(COMPONENT.VOLUME_GROUP, {
1206                 "modelInvariantId": volumeGroupModel.invariantUuid,
1207                 "modelVersion": volumeGroupModel.version,
1208                 "modelNameVersionId": volumeGroupModel.uuid,
1209                 "modelName": volumeGroupModel.name,
1210                 "modelCustomizationName": volumeGroupModel.modelCustomizationName,
1211                 "customizationUuid": volumeGroupModel.customizationUuid,
1212                 "inputs": ""
1213             });
1214
1215             $scope.$broadcast(COMPONENT.CREATE_COMPONENT, {
1216                 componentId: COMPONENT.VOLUME_GROUP,
1217                 callbackFunction: createVolumeGroupCallbackFunction
1218             });
1219         };
1220
1221         $scope.resume = function (serviceObject, vfModule, vnfModel) {
1222             populate_popup_vfModule(serviceObject, vfModule, vnfModel);
1223             setCurrentVNFModelInfo(vnfModel);
1224
1225             var availableVolumeGroupList = [];
1226             angular.forEach(vfModule.volumeGroups, function (volumeGroupInstance, key) {
1227                 availableVolumeGroupList.push({"instance": volumeGroupInstance});
1228             });
1229
1230             DataService.setAvailableVolumeGroupList(availableVolumeGroupList);
1231
1232             DataService.setVfModuleInstanceName(vfModule.object[FIELD.ID.VF_MODULE_NAME]);
1233             setCurrentServiceModelInfoFromScope();
1234
1235             if (DataService.getLoggedInUserId())  {
1236                 openVfModuleWithHomingDataModal(COMPONENT.RESUME, vfModule);
1237             }
1238             else {
1239                 AaiService.getLoggedInUserID(function (response) {
1240                     var userID = response.data;
1241                     DataService.setLoggedInUserId(userID);
1242                     openVfModuleWithHomingDataModal(COMPONENT.RESUME, vfModule);
1243                 });
1244             }
1245         };
1246
1247         $scope.deleteConfiguration = function (serviceObject, configuration) {
1248             console.log("Deleting Configuration " + configuration.name);
1249
1250             var serviceInstance = serviceObject.object;
1251             var svcModel = $scope.service.convertedModel;
1252             var configModel;
1253             DataService.setInventoryItem(configuration.object);
1254             // set model default and override later if found
1255             DataService.setModelInfo(COMPONENT.CONFIGURATION, {});
1256
1257             if (configuration.object != null) {
1258
1259                 //var netModelInvariantUuid = network.object[FIELD.ID.MODEL_INVAR_ID];
1260                 var configModelVersionId = configuration.object[FIELD.ID.MODEL_VERSION_ID]; // model uuid
1261                 var configModelCustomizationUuid = configuration.object[FIELD.ID.MODEL_CUSTOMIZATION_ID];
1262
1263                 //configurations added to vnfs list, in order to be part of the "Add VNF" drop-down list
1264                 if ((!($scope.isObjectEmpty(svcModel))) && (!($scope.isObjectEmpty(svcModel.vnfs)))) {
1265                     if ((svcModel.isNewFlow) && (UtilityService.hasContents(configModelCustomizationUuid))) {
1266                         configModel = svcModel.vnfs[configModelCustomizationUuid];
1267                     }
1268                     else {
1269
1270                         if (UtilityService.hasContents(configModelVersionId)) {
1271                             configModel = svcModel.vnfs[configModelVersionId];
1272                         }
1273
1274                     }
1275                 }
1276             }
1277             if (!($scope.isObjectEmpty(configModel))) {
1278                 DataService.setModelInfo(COMPONENT.CONFIGURATION, {
1279                     "modelInvariantId": configModel.invariantUuid,
1280                     "modelVersion": configModel.version,
1281                     "modelNameVersionId": configModel.uuid,
1282                     "modelCustomizationName": configModel.modelCustomizationName,
1283                     "customizationUuid": configModel.customizationUuid,
1284                     "modelName": configModel.name,
1285                     "inputs": ""
1286                 });
1287             }
1288
1289             DataService.setSubscriberName(serviceObject[COMPONENT.SUBSCRIBER_NAME]);
1290             DataService.setServiceType(serviceObject[COMPONENT.SERVICE_TYPE]);
1291             DataService.setServiceInstanceId(serviceInstance[FIELD.ID.SERVICE_INSTANCE_ID]);
1292
1293             DataService.setGlobalCustomerId(serviceObject[FIELD.ID.GLOBAL_CUST_ID]);
1294             DataService.setServiceInstanceName($scope.service.instance.name);
1295             DataService.setServiceName($scope.service.model.service.name);
1296             DataService.setServiceUuid($scope.service.model.service.uuid);
1297             DataService.setConfigurationInstanceId(configuration.object[FIELD.ID.CONFIGURATION_ID]);
1298
1299             $scope.$broadcast(COMPONENT.DELETE_RESUME_COMPONENT, {
1300                 componentId: COMPONENT.CONFIGURATION,
1301                 dialogMethod: COMPONENT.DELETE,
1302                 callbackFunction: deleteCallbackFunction
1303             });
1304         };
1305
1306         var deleteCallbackFunction = function () {
1307             console.log('hi')
1308         };
1309
1310         $scope.resetProgress = function () {
1311             $scope.percentProgress = 0;
1312             $scope.progressClass = FIELD.STYLE.PROGRESS_BAR_INFO;
1313         };
1314
1315         $scope.setProgress = function (percentProgress) {
1316             percentProgress = parseInt(percentProgress);
1317             if (percentProgress >= 100) {
1318                 $scope.progressClass = FIELD.STYLE.PROGRESS_BAR_SUCCESS;
1319             }
1320
1321             if (percentProgress < $scope.percentProgress) {
1322                 return;
1323             }
1324
1325             $scope.percentProgress = percentProgress;
1326             $scope.progressWidth = {width: percentProgress + "%"};
1327             if (percentProgress >= 5) {
1328                 $scope.progressText = percentProgress + " %";
1329             } else {
1330                 // Hidden since color combination is barely visible when progress portion is narrow.
1331                 $scope.progressText = "";
1332             }
1333         };
1334         $scope.isObjectEmpty = function (o) {
1335             var len = 0;
1336             if (UtilityService.hasContents(o)) {
1337                 var keys = Object.keys(o);
1338                 len = keys.length;
1339                 if (len == 0) {
1340                     return true;
1341                 }
1342                 else {
1343                     return false;
1344                 }
1345             }
1346             else {
1347                 return true;
1348             }
1349         };
1350         $scope.isMacro = function () {
1351             return $scope.service && AsdcService.isMacro($scope.service.model);
1352         };
1353         $scope.reloadRoute = function () {
1354             $route.reload();
1355         };
1356
1357
1358         /*
1359 Private metthods
1360 */
1361
1362         /*
1363         setPnf
1364         * set the controller pnf param using api call
1365         * return: void
1366          */
1367         function _setPnf(data) { // data is the $scope.service.instance object
1368             return PnfService.getPnfs(data)
1369                 .then(
1370                     function (response) {
1371                         return response.data;
1372                         // * can add here changes on the data that are needed to the view ( filter, ect..)
1373                     },
1374                     function (error) {
1375                         console.error(error);
1376                     }
1377                 );
1378         }
1379
1380
1381         function _setCr(data) { // data is the $scope.service.instance object
1382             return CrService.getCr(data)
1383                 .then(
1384                     function (response) {
1385                         return response.data.results;
1386                         // * can add here changes on the data that are needed to the view ( filter, ect..)
1387                     },
1388                     function (error) {
1389                         console.error(error);
1390                     }
1391                 );
1392         }
1393
1394
1395         /*
1396         Callbaks functions
1397
1398          */
1399         var updateProvStatusVnfCallbackFunction = function (response) {
1400             $scope.callbackResults = "";
1401             var color = FIELD.ID.COLOR_NONE;
1402             $scope.callbackStyle = {
1403                 "background-color": color
1404             };
1405             $scope.reloadRoute();
1406             /*
1407              * This 1/2 delay was only added to visually highlight the status
1408              * change. Probably not needed in the real application code.
1409              */
1410             $timeout(function () {
1411                 $scope.callbackResults = UtilityService.getCurrentTime()
1412                     + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
1413                 if (response.isSuccessful) {
1414                     color = FIELD.ID.COLOR_8F8;
1415
1416                 } else {
1417                     color = FIELD.ID.COLOR_F88;
1418                 }
1419                 $scope.callbackStyle = {
1420                     "background-color": color
1421                 };
1422             }, 500);
1423
1424         };
1425
1426         var createVnfCallbackFunction = function (response) {
1427             $scope.callbackResults = "";
1428             var color = FIELD.ID.COLOR_NONE;
1429             $scope.callbackStyle = {
1430                 "background-color": color
1431             };
1432
1433             /*
1434              * This 1/2 delay was only added to visually highlight the status
1435              * change. Probably not needed in the real application code.
1436              */
1437             $timeout(function () {
1438                 $scope.callbackResults = UtilityService.getCurrentTime()
1439                     + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
1440                 if (response.isSuccessful) {
1441                     color = FIELD.ID.COLOR_8F8;
1442                     $scope.reloadRoute();
1443                 } else {
1444                     color = FIELD.ID.COLOR_F88;
1445                 }
1446                 $scope.callbackStyle = {
1447                     "background-color": color
1448                 };
1449             }, 500);
1450
1451
1452         };
1453
1454         var deleteOrResumeCallback = function (response) {
1455             $scope.callbackResults = "";
1456             var color = FIELD.ID.COLOR_NONE;
1457             $scope.callbackStyle = {
1458                 "background-color": color
1459             };
1460
1461             /*
1462              * This 1/2 delay was only added to visually highlight the status
1463              * change. Probably not needed in the real application code.
1464              */
1465             $timeout(function () {
1466                 $scope.callbackResults = UtilityService.getCurrentTime()
1467                     + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
1468                 if (response.isSuccessful) {
1469                     color = FIELD.ID.COLOR_8F8;
1470                     $scope.reloadRoute();
1471                 } else {
1472                     color = FIELD.ID.COLOR_F88;
1473                 }
1474                 $scope.callbackStyle = {
1475                     "background-color": color
1476                 };
1477             }, 500);
1478
1479         };
1480
1481         var createVfModuleCallbackFunction = function (response) {
1482             $scope.callbackResults = "";
1483             var color = FIELD.ID.COLOR_NONE;
1484             $scope.callbackStyle = {
1485                 "background-color": color
1486             };
1487
1488             /*
1489              * This 1/2 delay was only added to visually highlight the status
1490              * change. Probably not needed in the real application code.
1491              */
1492             $timeout(function () {
1493                 $scope.callbackResults = UtilityService.getCurrentTime()
1494                     + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
1495                 if (response.isSuccessful) {
1496                     color = FIELD.ID.COLOR_8F8;
1497                     $scope.reloadRoute();
1498                 } else {
1499                     color = FIELD.ID.COLOR_F88;
1500                     $scope.reloadRoute();
1501                 }
1502                 $scope.callbackStyle = {
1503                     "background-color": color
1504                 };
1505             }, 500);
1506
1507         };
1508
1509         var deleteServiceInstanceCallbackFunction = function (response) {
1510             $scope.callbackResults = "";
1511             var color = FIELD.ID.COLOR_NONE;
1512             $scope.callbackStyle = {
1513                 "background-color": color
1514             };
1515
1516             /*
1517              * This 1/2 delay was only added to visually highlight the status
1518              * change. Probably not needed in the real application code.
1519              */
1520             $timeout(function () {
1521                 $scope.callbackResults = UtilityService.getCurrentTime()
1522                     + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
1523                 if (response.isSuccessful) {
1524                     color = FIELD.ID.COLOR_8F8;
1525                     $location.path(COMPONENT.SERVICEMODELS_MODELS_SERVICES_PATH);
1526                 } else {
1527                     color = FIELD.ID.COLOR_F88;
1528                 }
1529                 $scope.callbackStyle = {
1530                     "background-color": color
1531                 };
1532             }, 500);
1533
1534         };
1535
1536         var createVolumeGroupCallbackFunction = function (response) {
1537             $scope.callbackResults = "";
1538             var color = FIELD.ID.COLOR_NONE;
1539             $scope.callbackStyle = {
1540                 "background-color": color
1541             };
1542
1543             /*
1544              * This 1/2 delay was only added to visually highlight the status
1545              * change. Probably not needed in the real application code.
1546              */
1547             $timeout(function () {
1548                 $scope.callbackResults = UtilityService.getCurrentTime()
1549                     + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
1550                 if (response.isSuccessful) {
1551                     color = FIELD.ID.COLOR_8F8;
1552                     $scope.reloadRoute();
1553                 } else {
1554                     color = FIELD.ID.COLOR_F88;
1555                 }
1556                 $scope.callbackStyle = {
1557                     "background-color": color
1558                 };
1559             }, 500);
1560
1561
1562         };
1563
1564     });
1565 })();