[VID-6] Initial rebase push
[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 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 (function () {\r
22         'use strict';\r
23 \r
24         appDS2.controller("ServiceModelController", function ($scope, $http, $location, COMPONENT, VIDCONFIGURATION, FIELD, DataService, vidService,\r
25                         PropertyService, UtilityService) {\r
26 \r
27                 $scope.popup = {};\r
28                 \r
29         //      var baseEndpoint = "vid";\r
30                 var pathQuery = COMPONENT.SERVICES_DIST_STATUS_PATH + VIDCONFIGURATION.ASDC_MODEL_STATUS;\r
31                 \r
32                 if ( VIDCONFIGURATION.ASDC_MODEL_STATUS === FIELD.STATUS.ALL) {\r
33                         pathQuery = COMPONENT.SERVICES_PATH;\r
34                 }\r
35                 \r
36                 $scope.getServiceModels = function() {\r
37                         $scope.status = FIELD.STATUS.FETCHING_SERVICE_CATALOG_ASDC;\r
38 \r
39                         $http.get(pathQuery)\r
40                         .then(function successCallback(response) {\r
41                                 $scope.services = [];\r
42                                 if (angular.isArray(response.data)) {\r
43                                         $scope.services = response.data;\r
44                                         $scope.viewPerPage=10;\r
45                                         $scope.totalPage=$scope.services.length/$scope.viewPerPage;\r
46                                         $scope.sortBy=COMPONENT.NAME;\r
47                                         $scope.scrollViewPerPage=2;\r
48                                         $scope.currentPage=1;\r
49                                         $scope.searchCategory;\r
50                                         $scope.searchString="";\r
51                                         $scope.currentPageNum=1;\r
52                                         $scope.isSpinnerVisible = false;\r
53                                         $scope.isProgressVisible = false;\r
54                                 } else {\r
55                                         $scope.status = FIELD.STATUS.FAILED_SERVICE_MODELS_ASDC;\r
56                                         $scope.error = true;\r
57                                         $scope.isSpinnerVisible = false;\r
58                                 }\r
59                         }, function errorCallback(response) {\r
60                                 console.log("Error: " + response);\r
61                         });\r
62                 }\r
63                 \r
64                 $scope.init = function() {\r
65                 var msecs = PropertyService.retrieveMsoMaxPollingIntervalMsec();\r
66                 PropertyService.setMsoMaxPollingIntervalMsec(msecs);\r
67                 \r
68                 var polls = PropertyService.retrieveMsoMaxPolls();\r
69                 PropertyService.setMsoMaxPolls(polls);\r
70                 \r
71                 //PropertyService.setMsoBaseUrl("testmso");\r
72                 PropertyService.setServerResponseTimeoutMsec(10000);\r
73         }\r
74                 \r
75                 $scope.prevPage = function() {\r
76                         $scope.currentPage--;\r
77                 }\r
78                 \r
79                 $scope.nextPage = function() {\r
80                         $scope.currentPage++;\r
81                 }\r
82                 \r
83                 $scope.createType = COMPONENT.A_LA_CARTE;\r
84                 $scope.deployService = function(service) {\r
85                         \r
86                         \r
87                         console.log("Instantiating SDC service " + service.uuid);\r
88                         \r
89                         $http.get(COMPONENT.SERVICES_PATH + service.uuid)\r
90                                 .then(function successCallback(getServiceResponse) {\r
91                                         \r
92                                         var serviceModel = getServiceResponse.data;\r
93                                         DataService.setServiceName(serviceModel.service.name);\r
94                                         \r
95                                         DataService.setModelInfo(COMPONENT.SERVICE, {\r
96                                                 "modelInvariantId": serviceModel.service.invariantUuid,\r
97                                                 "modelVersion": serviceModel.service.version,\r
98                                                 "modelNameVersionId": serviceModel.service.uuid,\r
99                                                 "modelName": serviceModel.service.name,\r
100                                                 "description": serviceModel.service.description,\r
101                                                 "category":serviceModel.service.category\r
102                                         });\r
103                                         DataService.setALaCarte (true);\r
104                                         $scope.createType = COMPONENT.A_LA_CARTE;\r
105                                         var broadcastType = COMPONENT.CREATE_COMPONENT;\r
106                                         \r
107                                         if (UtilityService.arrayContains (VIDCONFIGURATION.MACRO_SERVICES, serviceModel.service.invariantUuid )) {\r
108                                                 DataService.setALaCarte (false);\r
109                                                 $scope.createType = COMPONENT.MACRO;\r
110                                                 var convertedAsdcModel = UtilityService.convertModel(serviceModel);\r
111                                                 \r
112                                                 //console.log ("display inputs "); \r
113                                                 //console.log (JSON.stringify ( convertedAsdcModel.completeDisplayInputs));\r
114                                                 \r
115                                                 DataService.setModelInfo(COMPONENT.SERVICE, {\r
116                                                         "modelInvariantId": serviceModel.service.invariantUuid,\r
117                                                         "modelVersion": serviceModel.service.version,\r
118                                                         "modelNameVersionId": serviceModel.service.uuid,\r
119                                                         "modelName": serviceModel.service.name,\r
120                                                         "description": serviceModel.service.description,\r
121                                                         "category":serviceModel.service.category,\r
122                                                         "serviceEcompNaming": serviceModel.service.serviceEcompNaming,\r
123                                                         "inputs": serviceModel.service.inputs,\r
124                                                         "displayInputs": convertedAsdcModel.completeDisplayInputs\r
125                                                 });\r
126                                         };\r
127                                         \r
128                                         $scope.$broadcast(broadcastType, {\r
129                                             componentId : COMPONENT.SERVICE,\r
130                                             callbackFunction : function(response) {\r
131                                                 if (response.isSuccessful) {\r
132                                                                 vidService.setModel(serviceModel);\r
133                                                                 \r
134                                                                 var subscriberId = FIELD.STATUS.NOT_FOUND;\r
135                                                                 var serviceType = FIELD.STATUS.NOT_FOUND;\r
136                                                                 \r
137                                                                 var serviceInstanceId = response.instanceId;\r
138                                                                 \r
139                                                                 for (var i = 0; i < response.control.length; i++) {\r
140                                                                         if (response.control[i].id == COMPONENT.SUBSCRIBER_NAME) {\r
141                                                                                 subscriberId = response.control[i].value;\r
142                                                                         } else if (response.control[i].id == "service-type") {\r
143                                                                                 serviceType = response.control[i].value;\r
144                                                                         }\r
145                                                                 }\r
146                                                                 \r
147                                                                 \r
148                                                                 $scope.refreshSubs(subscriberId,serviceType,serviceInstanceId);\r
149                                                         \r
150                                                 }\r
151                                             }\r
152                                         });\r
153                                         \r
154                                 }, function errorCallback(response) {\r
155                                         console.log("Error: " + response);\r
156                                 });\r
157                 };\r
158                 \r
159                 $scope.refreshSubs = function(subscriberId, serviceType, serviceInstanceId) {\r
160                         $scope.status = FIELD.STATUS.FETCHING_SUBSCRIBER_LIST_AAI;\r
161                         $scope.init();\r
162                         $http.get( FIELD.ID.AAI_REFRESH_FULL_SUBSCRIBERS, {\r
163 \r
164                         },{\r
165                                 timeout: $scope.responseTimeoutMsec\r
166                         }).then(function(response){\r
167                                 \r
168                                 if (response.data.status < 200 || response.data.status > 202) {\r
169                                         $scope.showError(FIELD.ERROR.MSO)\r
170                                         return;\r
171                                 }\r
172 \r
173                                 $scope.customer = response.data.customer; // get data from json\r
174 \r
175                                 $scope.customerList = [];\r
176 \r
177                                 $scope.serviceInstanceToCustomer = [];\r
178                                 \r
179                                 angular.forEach($scope.customer, function(subVal, subKey) {\r
180                                         var cust = { "globalCustomerId": subVal[FIELD.ID.GLOBAL_CUSTOMER_ID], "subscriberName": subVal[FIELD.ID.SUBNAME] };\r
181                                         $scope.customerList.push(cust);\r
182                                         if (subVal[FIELD.ID.SERVICE_SUBSCRIPTIONS] != null) {\r
183                                                         angular.forEach(subVal[FIELD.ID.SERVICE_SUBSCRIPTIONS][FIELD.ID.SERVICE_SUBSCRIPTION], function(serviceSubscription, key) {\r
184                                                                 $scope.serviceInstanceId = [];\r
185                                                                 if (serviceSubscription[FIELD.ID.SERVICE_TYPE] != null) {\r
186                                                                         $scope.serviceType = serviceSubscription[FIELD.ID.SERVICE_TYPE];\r
187                                                                 } else {\r
188                                                                         $scope.serviceType = FIELD.STATUS.NO_SERVICE_SUBSCRIPTION_FOUND;\r
189                                                                 }\r
190                                                                 if (serviceSubscription[FIELD.ID.SERVICE_INSTANCES] != null) {\r
191                                                                         angular.forEach(serviceSubscription[FIELD.ID.SERVICE_INSTANCES][FIELD.ID.SERVICE_INSTANCE], function(instValue, instKey) {\r
192                                                                                 var foo = { "serviceInstanceId": instValue[FIELD.ID.SERVICE_INSTANCE_ID], \r
193                                                                                                 "globalCustomerId": subVal[FIELD.ID.GLOBAL_CUSTOMER_ID],\r
194                                                                                                 "subscriberName": subVal[FIELD.ID.SUBNAME] };\r
195                                                                                 $scope.serviceInstanceToCustomer.push(foo);\r
196                                                                         });\r
197                                                                 }\r
198                                                         });\r
199                                         }\r
200                                 });     \r
201                                 DataService.setServiceInstanceToCustomer($scope.serviceInstanceToCustomer);\r
202                                 var serviceIdList = [];\r
203                                 $http.get( FIELD.ID.AAI_GET_SERVICES, {\r
204                                 },{\r
205                                         timeout: $scope.responseTimeoutMsec\r
206                                 }).then(function(response) {\r
207                                         angular.forEach(response.data, function(value, key) {\r
208                                                 angular.forEach(value, function(subVal, key) {\r
209                                                         var newVal = { "id" : subVal[FIELD.ID.SERVICE_ID], "description" : subVal[FIELD.ID.SERVICE_DESCRIPTION] };\r
210                                                         serviceIdList.push(newVal);\r
211                                                         DataService.setServiceIdList(serviceIdList);\r
212                                                         \r
213                                                         $location.search({\r
214                                                                 "subscriberId": subscriberId,\r
215                                                                 "serviceType": serviceType,\r
216                                                                 "serviceInstanceId": serviceInstanceId\r
217                                                         });\r
218                                                         \r
219                                                         $location.path(COMPONENT.INSTANTIATE_PATH);\r
220                                                 });\r
221                                         });\r
222                                 });     \r
223                         })\r
224                         ["catch"]($scope.handleServerError);\r
225                 };\r
226         });\r
227 })();\r