9cb90503818f5fa150787b10879a59ea0542f1a5
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / controller / ServiceModelController.js
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * VID\r
4  * ================================================================================\r
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.\r
6  * Modifications Copyright (C) 2019 IBM.\r
7  * ================================================================================\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  * \r
12  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * \r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * ============LICENSE_END=========================================================\r
20  */\r
21 \r
22 (function () {\r
23         'use strict';\r
24 \r
25         appDS2.controller("ServiceModelController",function ($uibModal, $scope, $http, $location, COMPONENT, VIDCONFIGURATION, FIELD, DataService, vidService,\r
26                         PropertyService, UtilityService, AsdcService, $timeout, featureFlags) {\r
27 \r
28                 $scope.popup = {};\r
29                 var defaultViewPerPage = 10;\r
30         //      var baseEndpoint = "vid";\r
31                 var pathQuery = COMPONENT.SERVICES_DIST_STATUS_PATH + VIDCONFIGURATION.ASDC_MODEL_STATUS;\r
32                 \r
33                 if ( VIDCONFIGURATION.ASDC_MODEL_STATUS === FIELD.STATUS.ALL) {\r
34                         pathQuery = COMPONENT.SERVICES_PATH;\r
35                 }\r
36         window.addEventListener("message", receiveMessage, false);\r
37 \r
38                 function receiveMessage(event){\r
39             if(event.data == 'navigateTo') {\r
40                 $location.path('/models/services').search({});\r
41                 $scope.$apply();\r
42                 $scope.rememberFilter = true;\r
43             }\r
44             if(event.data == 'navigateToInstantiationStatus') {\r
45                 $location.path('/instantiationStatus').search({});\r
46                 $scope.$apply();\r
47             }\r
48                 }\r
49 \r
50                 $scope.getServiceModels = function() {\r
51                         $scope.status = FIELD.STATUS.FETCHING_SERVICE_CATALOG_ASDC;\r
52 \r
53                         $http.get(pathQuery)\r
54                         .then(function (response) {\r
55                                 $scope.services = [];\r
56                                 if (response.data && angular.isArray(response.data.services)) {\r
57                                         wholeData = response.data.services;\r
58                     $scope.services = $scope.filterDataWithHigherVersion(wholeData);\r
59                     $scope.viewPerPage = defaultViewPerPage;\r
60                     $scope.totalPage=$scope.services.length/$scope.viewPerPage;\r
61                     $scope.sortBy=COMPONENT.NAME;\r
62                     $scope.scrollViewPerPage=2;\r
63                     $scope.currentPage=1;\r
64                     $scope.currentPageNum=1;\r
65                     $scope.isSpinnerVisible = false;\r
66                     $scope.isProgressVisible = false;\r
67                                         var searchKey = sessionStorage.getItem("searchKey");\r
68                     if (searchKey != 'undefined' && searchKey!=null && ($scope.rememberFilter)) {\r
69                         var searchKey = JSON.parse(sessionStorage.getItem("searchKey"));\r
70                         $scope.searchString = searchKey.searchString || '';\r
71                         $scope.viewPerPage = searchKey.viewPerPage || defaultViewPerPage;\r
72                         $scope.totalPage = $scope.services.length / $scope.viewPerPage;\r
73                         $timeout(function () {\r
74                                 // the table controller handles the current page once\r
75                                                         // data is loaded, therefore we're delying the paging\r
76                                                         // override\r
77                             $scope.currentPage = $scope.currentPageNum = searchKey.currentPage ? parseInt(searchKey.currentPage) : 1;\r
78                         }, 0);\r
79                         $scope.rememberFilter = false;\r
80                     }\r
81                                 } else {\r
82                                         $scope.status = FIELD.STATUS.FAILED_SERVICE_MODELS_ASDC;\r
83                                         $scope.error = true;\r
84                                         $scope.isSpinnerVisible = false;\r
85                                 }\r
86                                 $scope.deployButtonType = response.data.readOnly ? 'disabled' : 'primary';\r
87                         }, function (response) {\r
88                                 console.log("Error: " + response);\r
89                         });\r
90                 };\r
91 \r
92                 var wholeData=[];\r
93 \r
94                 $scope.filterDataWithHigherVersion = function(serviceData){\r
95                         var delimiter = '$$';\r
96                         var fiterDataServices = {};\r
97                         for(var i=0;i<serviceData.length;i++) {\r
98                                 var index = serviceData[i].invariantUUID.trim() + delimiter + serviceData[i].name.trim();\r
99                                 if(!fiterDataServices[index]) {\r
100                     var hasPreviousVersion = false;\r
101                     fiterDataServices[index] = {\r
102                         service: serviceData[i],\r
103                         hasPreviousVersion: false\r
104                     };\r
105                 }\r
106                 else {\r
107                     fiterDataServices[index].hasPreviousVersion = true;\r
108                     if(parseFloat(serviceData[i].version.trim())>parseFloat(fiterDataServices[index].service.version.trim())) {\r
109                         fiterDataServices[index].service = serviceData[i];\r
110                                         }\r
111                                 }\r
112                         }\r
113             return Object.keys(fiterDataServices).map(function(key) {\r
114                 var service = fiterDataServices[key].service;\r
115                 service.hasPreviousVersion = fiterDataServices[key].hasPreviousVersion;\r
116                 return  service;\r
117             });\r
118                 };\r
119 \r
120                 $scope.init = function() {\r
121                 var msecs = PropertyService.retrieveMsoMaxPollingIntervalMsec();\r
122                 PropertyService.setMsoMaxPollingIntervalMsec(msecs);\r
123                 \r
124                 var polls = PropertyService.retrieveMsoMaxPolls();\r
125                 PropertyService.setMsoMaxPolls(polls);\r
126         };\r
127                 \r
128                 $scope.prevPage = function() {\r
129                         $scope.currentPage--;\r
130                 };\r
131                 \r
132                 $scope.nextPage = function() {\r
133                         $scope.currentPage++;\r
134                 };\r
135 \r
136                 $scope.showReportWindow = function() {\r
137 \r
138                         const modalWindow = $uibModal.open({\r
139                                 templateUrl: 'app/vid/scripts/modals/report-modal/report-modal.html',\r
140                                 controller: 'reportModalController',\r
141                                 controllerAs: 'vm',\r
142                                 resolve: {\r
143                                         errorMsg: function () {\r
144                                                 return $scope.status;\r
145                                         }\r
146                                 }\r
147                         });\r
148 \r
149                 };\r
150 \r
151                 $scope.isShowErrorReport = function() {\r
152                         return featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_CREATE_ERROR_REPORTS);\r
153                 };\r
154                 \r
155                 $scope.createType = COMPONENT.A_LA_CARTE;\r
156                 $scope.deployService = function(service) {\r
157                         var searchKey = {\r
158                                 searchString: $scope.searchString,\r
159                 viewPerPage: $scope.viewPerPage,\r
160                 currentPage: $scope.currentPage\r
161                         };\r
162                         sessionStorage.setItem("searchKey",JSON.stringify(searchKey));\r
163 \r
164                         console.log("Instantiating SDC service " + service.uuid);\r
165 \r
166                         $http.get(COMPONENT.SERVICES_PATH + service.uuid)\r
167                                 .then(function (getServiceResponse) {\r
168 \r
169                                         var serviceModel = getServiceResponse.data;\r
170 \r
171                                         //VID-233 bug fix when models doesn't exists\r
172                                         if(typeof(serviceModel)==="string"){  //not an object\r
173                                                 $scope.status = FIELD.STATUS.FAILED_SERVICE_MODELS_ASDC;\r
174                                                 $scope.error = true;\r
175                                                 $scope.isSpinnerVisible = false;\r
176                                                 $scope.isProgressVisible = true;\r
177                                                 return;\r
178                                         } else{ //clean error message\r
179                                                 $scope.status = "";\r
180                                                 $scope.error = false;\r
181                                                 $scope.isSpinnerVisible = false;\r
182                                                 $scope.isProgressVisible = false;\r
183                                         }\r
184 \r
185                                         DataService.setServiceName(serviceModel.service.name);\r
186 \r
187                                         //VOLTE services need input list generated and macro style\r
188                                         DataService.setE2EService(false);\r
189                                         if(serviceModel.service.category === 'E2E Service') {\r
190                                                 DataService.setE2EService(true);\r
191                                                 DataService.setHideServiceFields(false);\r
192                                                 VIDCONFIGURATION.MACRO_SERVICES.push(serviceModel.service.invariantUuid);\r
193                                         }\r
194 \r
195                                         DataService.setModelInfo(COMPONENT.SERVICE, {\r
196                                                 "modelInvariantId": serviceModel.service.invariantUuid,\r
197                                                 "modelVersion": serviceModel.service.version,\r
198                                                 "serviceType" : serviceModel.service.serviceType,\r
199                                                 "serviceRole": serviceModel.service.serviceRole,\r
200                                                 "modelNameVersionId": serviceModel.service.uuid,\r
201                                                 "modelName": serviceModel.service.name,\r
202                                                 "description": serviceModel.service.description,\r
203                                                 "category":serviceModel.service.category\r
204                                         });\r
205 \r
206                     var shouldTakeTheAsyncInstantiationFlow = AsdcService.shouldTakeTheAsyncInstantiationFlow(serviceModel);\r
207                     DataService.setShouldIncludeInAsyncInstantiationFlow(shouldTakeTheAsyncInstantiationFlow);\r
208 \r
209                     DataService.setALaCarte (true);\r
210                     DataService.setPnf(!angular.equals(serviceModel.pnfs, {}));\r
211                                         $scope.createType = COMPONENT.A_LA_CARTE;\r
212                                         var broadcastType = COMPONENT.CREATE_COMPONENT;\r
213                     if (AsdcService.isMacro(serviceModel) || DataService.getE2EService()) {\r
214                         DataService.setALaCarte(false);\r
215                         if(!shouldTakeTheAsyncInstantiationFlow){\r
216                             $scope.createType = COMPONENT.MACRO;\r
217                             var convertedAsdcModel = UtilityService.convertModel(serviceModel);\r
218 \r
219                             DataService.setModelInfo(COMPONENT.SERVICE, {\r
220                                 "modelInvariantId": serviceModel.service.invariantUuid,\r
221                                 "modelVersion": serviceModel.service.version,\r
222                                 "modelNameVersionId": serviceModel.service.uuid,\r
223                                 "modelName": serviceModel.service.name,\r
224                                 "description": serviceModel.service.description,\r
225                                 "category": serviceModel.service.category,\r
226                                 "serviceEcompNaming": serviceModel.service.serviceEcompNaming,\r
227                                 "inputs": serviceModel.service.inputs,\r
228                                 "serviceType": serviceModel.service.serviceType,\r
229                                 "serviceRole": serviceModel.service.serviceRole,\r
230                                 "displayInputs": convertedAsdcModel.completeDisplayInputs\r
231                             });\r
232                         }\r
233                     }\r
234 \r
235                                         $scope.$broadcast(broadcastType, {\r
236                                             componentId : COMPONENT.SERVICE,\r
237                         modelNameVersionId: serviceModel.service.uuid,\r
238                                             callbackFunction : function(response) {\r
239                                                 if (response.isSuccessful) {\r
240                                                                 vidService.setModel(serviceModel);\r
241 \r
242                                                                 var subscriberId = FIELD.STATUS.NOT_FOUND;\r
243                                                                 var serviceType = FIELD.STATUS.NOT_FOUND;\r
244 \r
245                                                                 var serviceInstanceId = response.instanceId;\r
246 \r
247                                                                 for (var i = 0; i < response.control.length; i++) {\r
248                                                                         if (response.control[i].id == COMPONENT.SUBSCRIBER_NAME) {\r
249                                                                                 subscriberId = response.control[i].value;\r
250                                                                         } else if (response.control[i].id == FIELD.ID.SERVICE_TYPE) {\r
251                                                                                 serviceType = response.control[i].value;\r
252                                                                         }\r
253                                                                 }\r
254 \r
255 \r
256                                                                 $scope.refreshSubs(subscriberId,serviceType,serviceInstanceId);\r
257 \r
258                                                 }\r
259                                             }\r
260                                         });\r
261                                 }, function (response) {\r
262                                         console.log("Error: " + response);\r
263                                 });\r
264                 };\r
265                 \r
266                 $scope.tableData=[];\r
267                 var oldData=[];\r
268                 $scope.loadPreviousVersionData=function(invariantUUID , name, version){\r
269                         $scope.tableData =[];\r
270                         oldData=[];\r
271                         for(var i=0;i<wholeData.length;i++){\r
272                                 if(wholeData[i].invariantUUID == invariantUUID && wholeData[i].name == name && version!=wholeData[i].version){\r
273                                         oldData.push(wholeData[i]);\r
274                                 }\r
275                         }\r
276                         $scope.tableData = oldData;\r
277                         $scope.createType = "Previous Version";\r
278                         var broadcastType = "createTableComponent";\r
279                         $scope.componentName = name;\r
280                         $scope.$broadcast(broadcastType, {\r
281                             componentId : COMPONENT.OLDVERSION,\r
282                             callbackFunction : function(response) {\r
283                             }\r
284                         });\r
285                 };\r
286 \r
287                 $scope.refreshSubs = function(subscriberId, serviceType, serviceInstanceId) {\r
288                         $scope.status = FIELD.STATUS.FETCHING_SUBSCRIBER_LIST_AAI;\r
289                         $scope.init();\r
290                         $http.get( FIELD.ID.AAI_REFRESH_FULL_SUBSCRIBERS, {\r
291 \r
292                         },{\r
293                                 timeout: $scope.responseTimeoutMsec\r
294                         }).then(function(response){\r
295                                 \r
296                                 if (response.data.status < 200 || response.data.status > 202) {\r
297                                         $scope.showError(FIELD.ERROR.MSO);\r
298                                         return;\r
299                                 }\r
300 \r
301                                 $scope.customer = response.data.customer; // get data from json\r
302 \r
303                                 $scope.customerList = [];\r
304 \r
305                                 $scope.serviceInstanceToCustomer = [];\r
306                                 \r
307                                 angular.forEach($scope.customer, function(subVal, subKey) {\r
308                                         var cust = { "globalCustomerId": subVal[FIELD.ID.GLOBAL_CUSTOMER_ID], "subscriberName": subVal[FIELD.ID.SUBNAME] };\r
309                                         $scope.customerList.push(cust);\r
310                                         if (subVal[FIELD.ID.SERVICE_SUBSCRIPTIONS] != null) {\r
311                                                         angular.forEach(subVal[FIELD.ID.SERVICE_SUBSCRIPTIONS][FIELD.ID.SERVICE_SUBSCRIPTION], function(serviceSubscription, key) {\r
312                                                                 $scope.serviceInstanceId = [];\r
313                                                                 if (serviceSubscription[FIELD.ID.SERVICETYPE] != null) {\r
314                                                                         $scope.serviceType = serviceSubscription[FIELD.ID.SERVICETYPE];\r
315                                                                 } else {\r
316                                                                         $scope.serviceType = FIELD.STATUS.NO_SERVICE_SUBSCRIPTION_FOUND;\r
317                                                                 }\r
318                                                                 if (serviceSubscription[FIELD.ID.SERVICE_INSTANCES] != null) {\r
319                                                                         angular.forEach(serviceSubscription[FIELD.ID.SERVICE_INSTANCES][FIELD.ID.SERVICE_INSTANCE], function(instValue, instKey) {\r
320                                                                                 var foo = { "serviceInstanceId": instValue[FIELD.ID.SERVICE_INSTANCE_ID], \r
321                                                                                                 "globalCustomerId": subVal[FIELD.ID.GLOBAL_CUSTOMER_ID],\r
322                                                                                                 "subscriberName": subVal[FIELD.ID.SUBNAME] };\r
323                                                                                 $scope.serviceInstanceToCustomer.push(foo);\r
324                                                                         });\r
325                                                                 }\r
326                                                         });\r
327                                         }\r
328                                 });     \r
329                                 DataService.setServiceInstanceToCustomer($scope.serviceInstanceToCustomer);\r
330                                 var serviceIdList = [];\r
331                                 $http.get( FIELD.ID.AAI_GET_SERVICES, {\r
332                                 },{\r
333                                         timeout: $scope.responseTimeoutMsec\r
334                                 }).then(function(response) {\r
335                                         angular.forEach(response.data, function(value, key) {\r
336                                                 angular.forEach(value, function(subVal, key) {\r
337                                                         var newVal = { "id" : subVal[FIELD.ID.SERVICE_ID], "description" : subVal[FIELD.ID.SERVICE_DESCRIPTION] ,"isPermitted" : subVal[FIELD.ID.IS_PERMITTED] };\r
338                                                         serviceIdList.push(newVal);\r
339                                                         DataService.setServiceIdList(serviceIdList);\r
340                                                         \r
341                                                         $location.search({\r
342                                                                 "subscriberId": subscriberId,\r
343                                                                 "serviceType": serviceType,\r
344                                                                 "serviceInstanceId": serviceInstanceId,\r
345                                                                 "isPermitted": newVal.isPermitted.toString()\r
346                                                         });\r
347                                                         \r
348                                                         $location.path(COMPONENT.INSTANTIATE_PATH);\r
349                                                 });\r
350                                         });\r
351                                 });     \r
352                         })\r
353                         ["catch"]($scope.handleServerError);\r
354                 };\r
355         });\r
356 })();\r