adding orchestration type to service models view
[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                 $scope.isShowOrchestrationType = function() {\r
93                         return featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_SHOW_ORCHESTRATION_TYPE);\r
94                 };\r
95 \r
96                 var wholeData=[];\r
97 \r
98                 $scope.filterDataWithHigherVersion = function(serviceData){\r
99                         var delimiter = '$$';\r
100                         var fiterDataServices = {};\r
101                         for(var i=0;i<serviceData.length;i++) {\r
102                                 var index = serviceData[i].invariantUUID.trim() + delimiter + serviceData[i].name.trim();\r
103                                 if(!fiterDataServices[index]) {\r
104                     var hasPreviousVersion = false;\r
105                     fiterDataServices[index] = {\r
106                         service: serviceData[i],\r
107                         hasPreviousVersion: false\r
108                     };\r
109                 }\r
110                 else {\r
111                     fiterDataServices[index].hasPreviousVersion = true;\r
112                     if(parseFloat(serviceData[i].version.trim())>parseFloat(fiterDataServices[index].service.version.trim())) {\r
113                         fiterDataServices[index].service = serviceData[i];\r
114                                         }\r
115                                 }\r
116                         }\r
117             return Object.keys(fiterDataServices).map(function(key) {\r
118                 var service = fiterDataServices[key].service;\r
119                 service.hasPreviousVersion = fiterDataServices[key].hasPreviousVersion;\r
120                 return  service;\r
121             });\r
122                 };\r
123 \r
124                 $scope.init = function() {\r
125                 var msecs = PropertyService.retrieveMsoMaxPollingIntervalMsec();\r
126                 PropertyService.setMsoMaxPollingIntervalMsec(msecs);\r
127                 \r
128                 var polls = PropertyService.retrieveMsoMaxPolls();\r
129                 PropertyService.setMsoMaxPolls(polls);\r
130         };\r
131                 \r
132                 $scope.prevPage = function() {\r
133                         $scope.currentPage--;\r
134                 };\r
135                 \r
136                 $scope.nextPage = function() {\r
137                         $scope.currentPage++;\r
138                 };\r
139 \r
140                 $scope.showReportWindow = function() {\r
141 \r
142                         const modalWindow = $uibModal.open({\r
143                                 templateUrl: 'app/vid/scripts/modals/report-modal/report-modal.html',\r
144                                 controller: 'reportModalController',\r
145                                 controllerAs: 'vm',\r
146                                 resolve: {\r
147                                         errorMsg: function () {\r
148                                                 return $scope.status;\r
149                                         }\r
150                                 }\r
151                         });\r
152 \r
153                 };\r
154 \r
155                 $scope.isShowErrorReport = function() {\r
156                         return featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_CREATE_ERROR_REPORTS);\r
157                 };\r
158                 \r
159                 $scope.createType = COMPONENT.A_LA_CARTE;\r
160                 $scope.deployService = function(service) {\r
161                         var searchKey = {\r
162                                 searchString: $scope.searchString,\r
163                 viewPerPage: $scope.viewPerPage,\r
164                 currentPage: $scope.currentPage\r
165                         };\r
166                         sessionStorage.setItem("searchKey",JSON.stringify(searchKey));\r
167 \r
168                         console.log("Instantiating SDC service " + service.uuid);\r
169 \r
170                         $http.get(COMPONENT.SERVICES_PATH + service.uuid)\r
171                                 .then(function (getServiceResponse) {\r
172 \r
173                                         var serviceModel = getServiceResponse.data;\r
174 \r
175                                         //VID-233 bug fix when models doesn't exists\r
176                                         if(typeof(serviceModel)==="string"){  //not an object\r
177                                                 $scope.status = FIELD.STATUS.FAILED_SERVICE_MODELS_ASDC;\r
178                                                 $scope.error = true;\r
179                                                 $scope.isSpinnerVisible = false;\r
180                                                 $scope.isProgressVisible = true;\r
181                                                 return;\r
182                                         } else{ //clean error message\r
183                                                 $scope.status = "";\r
184                                                 $scope.error = false;\r
185                                                 $scope.isSpinnerVisible = false;\r
186                                                 $scope.isProgressVisible = false;\r
187                                         }\r
188 \r
189                                         DataService.setServiceName(serviceModel.service.name);\r
190 \r
191                                         //VOLTE services need input list generated and macro style\r
192                                         DataService.setE2EService(false);\r
193                                         if(serviceModel.service.category === 'E2E Service') {\r
194                                                 DataService.setE2EService(true);\r
195                                                 DataService.setHideServiceFields(false);\r
196                                                 VIDCONFIGURATION.MACRO_SERVICES.push(serviceModel.service.invariantUuid);\r
197                                         }\r
198 \r
199                                         DataService.setModelInfo(COMPONENT.SERVICE, {\r
200                                                 "modelInvariantId": serviceModel.service.invariantUuid,\r
201                                                 "modelVersion": serviceModel.service.version,\r
202                                                 "serviceType" : serviceModel.service.serviceType,\r
203                                                 "serviceRole": serviceModel.service.serviceRole,\r
204                                                 "modelNameVersionId": serviceModel.service.uuid,\r
205                                                 "modelName": serviceModel.service.name,\r
206                                                 "description": serviceModel.service.description,\r
207                                                 "category":serviceModel.service.category\r
208                                         });\r
209 \r
210                     var shouldTakeTheAsyncInstantiationFlow = AsdcService.shouldTakeTheAsyncInstantiationFlow(serviceModel);\r
211                     DataService.setShouldIncludeInAsyncInstantiationFlow(shouldTakeTheAsyncInstantiationFlow);\r
212 \r
213                     DataService.setALaCarte (true);\r
214                     DataService.setPnf(!angular.equals(serviceModel.pnfs, {}));\r
215                                         $scope.createType = COMPONENT.A_LA_CARTE;\r
216                                         var broadcastType = COMPONENT.CREATE_COMPONENT;\r
217                     if (AsdcService.isMacro(serviceModel) || DataService.getE2EService()) {\r
218                         DataService.setALaCarte(false);\r
219                         if(!shouldTakeTheAsyncInstantiationFlow){\r
220                             $scope.createType = COMPONENT.MACRO;\r
221                             var convertedAsdcModel = UtilityService.convertModel(serviceModel);\r
222 \r
223                             DataService.setModelInfo(COMPONENT.SERVICE, {\r
224                                 "modelInvariantId": serviceModel.service.invariantUuid,\r
225                                 "modelVersion": serviceModel.service.version,\r
226                                 "modelNameVersionId": serviceModel.service.uuid,\r
227                                 "modelName": serviceModel.service.name,\r
228                                 "description": serviceModel.service.description,\r
229                                 "category": serviceModel.service.category,\r
230                                 "serviceEcompNaming": serviceModel.service.serviceEcompNaming,\r
231                                 "inputs": serviceModel.service.inputs,\r
232                                 "serviceType": serviceModel.service.serviceType,\r
233                                 "serviceRole": serviceModel.service.serviceRole,\r
234                                 "displayInputs": convertedAsdcModel.completeDisplayInputs\r
235                             });\r
236                         }\r
237                     }\r
238 \r
239                                         $scope.$broadcast(broadcastType, {\r
240                                             componentId : COMPONENT.SERVICE,\r
241                         modelNameVersionId: serviceModel.service.uuid,\r
242                                             callbackFunction : function(response) {\r
243                                                 if (response.isSuccessful) {\r
244                                                                 vidService.setModel(serviceModel);\r
245 \r
246                                                                 var subscriberId = FIELD.STATUS.NOT_FOUND;\r
247                                                                 var serviceType = FIELD.STATUS.NOT_FOUND;\r
248 \r
249                                                                 var serviceInstanceId = response.instanceId;\r
250 \r
251                                                                 for (var i = 0; i < response.control.length; i++) {\r
252                                                                         if (response.control[i].id == COMPONENT.SUBSCRIBER_NAME) {\r
253                                                                                 subscriberId = response.control[i].value;\r
254                                                                         } else if (response.control[i].id == FIELD.ID.SERVICE_TYPE) {\r
255                                                                                 serviceType = response.control[i].value;\r
256                                                                         }\r
257                                                                 }\r
258 \r
259 \r
260                                                                 $scope.refreshSubs(subscriberId,serviceType,serviceInstanceId);\r
261 \r
262                                                 }\r
263                                             }\r
264                                         });\r
265                                 }, function (response) {\r
266                                         console.log("Error: " + response);\r
267                                 });\r
268                 };\r
269                 \r
270                 $scope.tableData=[];\r
271                 var oldData=[];\r
272                 $scope.loadPreviousVersionData=function(invariantUUID , name, version){\r
273                         $scope.tableData =[];\r
274                         oldData=[];\r
275                         for(var i=0;i<wholeData.length;i++){\r
276                                 if(wholeData[i].invariantUUID == invariantUUID && wholeData[i].name == name && version!=wholeData[i].version){\r
277                                         oldData.push(wholeData[i]);\r
278                                 }\r
279                         }\r
280                         $scope.tableData = oldData;\r
281                         $scope.createType = "Previous Version";\r
282                         var broadcastType = "createTableComponent";\r
283                         $scope.componentName = name;\r
284                         $scope.$broadcast(broadcastType, {\r
285                             componentId : COMPONENT.OLDVERSION,\r
286                             callbackFunction : function(response) {\r
287                             }\r
288                         });\r
289                 };\r
290 \r
291                 $scope.refreshSubs = function(subscriberId, serviceType, serviceInstanceId) {\r
292                         $scope.status = FIELD.STATUS.FETCHING_SUBSCRIBER_LIST_AAI;\r
293                         $scope.init();\r
294                         $http.get( FIELD.ID.AAI_REFRESH_FULL_SUBSCRIBERS, {\r
295 \r
296                         },{\r
297                                 timeout: $scope.responseTimeoutMsec\r
298                         }).then(function(response){\r
299                                 \r
300                                 if (response.data.status < 200 || response.data.status > 202) {\r
301                                         $scope.showError(FIELD.ERROR.MSO);\r
302                                         return;\r
303                                 }\r
304 \r
305                                 $scope.customer = response.data.customer; // get data from json\r
306 \r
307                                 $scope.customerList = [];\r
308 \r
309                                 $scope.serviceInstanceToCustomer = [];\r
310                                 \r
311                                 angular.forEach($scope.customer, function(subVal, subKey) {\r
312                                         var cust = { "globalCustomerId": subVal[FIELD.ID.GLOBAL_CUSTOMER_ID], "subscriberName": subVal[FIELD.ID.SUBNAME] };\r
313                                         $scope.customerList.push(cust);\r
314                                         if (subVal[FIELD.ID.SERVICE_SUBSCRIPTIONS] != null) {\r
315                                                         angular.forEach(subVal[FIELD.ID.SERVICE_SUBSCRIPTIONS][FIELD.ID.SERVICE_SUBSCRIPTION], function(serviceSubscription, key) {\r
316                                                                 $scope.serviceInstanceId = [];\r
317                                                                 if (serviceSubscription[FIELD.ID.SERVICETYPE] != null) {\r
318                                                                         $scope.serviceType = serviceSubscription[FIELD.ID.SERVICETYPE];\r
319                                                                 } else {\r
320                                                                         $scope.serviceType = FIELD.STATUS.NO_SERVICE_SUBSCRIPTION_FOUND;\r
321                                                                 }\r
322                                                                 if (serviceSubscription[FIELD.ID.SERVICE_INSTANCES] != null) {\r
323                                                                         angular.forEach(serviceSubscription[FIELD.ID.SERVICE_INSTANCES][FIELD.ID.SERVICE_INSTANCE], function(instValue, instKey) {\r
324                                                                                 var foo = { "serviceInstanceId": instValue[FIELD.ID.SERVICE_INSTANCE_ID], \r
325                                                                                                 "globalCustomerId": subVal[FIELD.ID.GLOBAL_CUSTOMER_ID],\r
326                                                                                                 "subscriberName": subVal[FIELD.ID.SUBNAME] };\r
327                                                                                 $scope.serviceInstanceToCustomer.push(foo);\r
328                                                                         });\r
329                                                                 }\r
330                                                         });\r
331                                         }\r
332                                 });     \r
333                                 DataService.setServiceInstanceToCustomer($scope.serviceInstanceToCustomer);\r
334                                 var serviceIdList = [];\r
335                                 $http.get( FIELD.ID.AAI_GET_SERVICES, {\r
336                                 },{\r
337                                         timeout: $scope.responseTimeoutMsec\r
338                                 }).then(function(response) {\r
339                                         angular.forEach(response.data, function(value, key) {\r
340                                                 angular.forEach(value, function(subVal, key) {\r
341                                                         var newVal = { "id" : subVal[FIELD.ID.SERVICE_ID], "description" : subVal[FIELD.ID.SERVICE_DESCRIPTION] ,"isPermitted" : subVal[FIELD.ID.IS_PERMITTED] };\r
342                                                         serviceIdList.push(newVal);\r
343                                                         DataService.setServiceIdList(serviceIdList);\r
344                                                         \r
345                                                         $location.search({\r
346                                                                 "subscriberId": subscriberId,\r
347                                                                 "serviceType": serviceType,\r
348                                                                 "serviceInstanceId": serviceInstanceId,\r
349                                                                 "isPermitted": newVal.isPermitted.toString()\r
350                                                         });\r
351                                                         \r
352                                                         $location.path(COMPONENT.INSTANTIATE_PATH);\r
353                                                 });\r
354                                         });\r
355                                 });     \r
356                         })\r
357                         ["catch"]($scope.handleServerError);\r
358                 };\r
359         });\r
360 })();\r