[VID-3] Updating pom w/ dav plugin
[vid.git] / vid / src / main / webapp / app / vid / scripts / controller / ServiceModelController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 (function () {
22         'use strict';
23
24         app.controller("ServiceModelController", function ($scope, $http, $location, COMPONENT, DataService, vidService,
25                         PropertyService) {
26
27                 $scope.popup = {};
28                 var re = /.*?:\/\/.*?:.*?\/(.*?)\//g;
29                 var baseEndpoint = re.exec($location.absUrl())[1];
30                 
31                 $scope.getServiceModels = function() {
32                         $scope.status = "Fetching service catalog from ASDC.  Please wait.";
33                         $http.get('/' + baseEndpoint + '/rest/models/services?distributionStatus=DISTRIBUTED')
34                         .then(function(response) {
35                                 $scope.services = [];
36                                 if (angular.isArray(response.data)) {
37                                         $scope.services = response.data;
38                                         $scope.viewPerPage=10;
39                                         $scope.totalPage=$scope.services.length/$scope.viewPerPage;
40                                         $scope.sortBy="name";
41                                         $scope.scrollViewPerPage=2;
42                                         $scope.currentPage=1;
43                                         $scope.searchCategory;
44                                         $scope.searchString="";
45                                         $scope.currentPageNum=1;
46                                         $scope.isSpinnerVisible = false;
47                                         $scope.isProgressVisible = false;
48                                 } else {
49                                         $scope.status = "Failed to get service models from ASDC.";
50                                         $scope.error = true;
51                                         $scope.isSpinnerVisible = false;
52                                 }
53                         }, function (response) {
54                                 console.log("Error: " + response);
55                         });
56                 }
57                 $scope.init = function() {
58                 // takes a default value, retrieves the prop value from the file system and sets it
59                 var msecs = PropertyService.retrieveMsoMaxPollingIntervalMsec(1000);
60                 PropertyService.setMsoMaxPollingIntervalMsec(msecs);
61                 
62                 // takes a default value, retrieves the prop value from the file system and sets it
63                 var polls = PropertyService.retrieveMsoMaxPolls(7);
64                 PropertyService.setMsoMaxPolls(polls);
65                 
66                 //PropertyService.setMsoBaseUrl("testmso");
67                 PropertyService.setServerResponseTimeoutMsec(10000);
68         }
69                 
70                 $scope.prevPage = function() {
71                         $scope.currentPage--;
72                 }
73                 
74                 $scope.nextPage = function() {
75                         $scope.currentPage++;
76                 }
77                 
78                 $scope.deployService = function(service) {
79
80                         console.log("Instantiating ASDC service " + service.uuid);
81                         
82                         $http.get('/' + baseEndpoint + '/rest/models/services/' + service.uuid)
83                                 .then(function successCallback(getServiceResponse) {
84                                         
85                                         var serviceModel = getServiceResponse.data;
86                                         DataService.setServiceName(serviceModel.service.name);
87                                         
88                                         DataService.setModelInfo(COMPONENT.SERVICE, {
89                                                 "modelInvariantId": serviceModel.service.invariantUuid,
90                                                 "modelVersion": serviceModel.service.version,
91                                                 "modelNameVersionId": serviceModel.service.uuid,
92                                                 "modelName": serviceModel.service.name,
93                                                 "description": serviceModel.service.description,
94                                                 "category":serviceModel.service.category
95                                         });
96                                         
97                                         $scope.$broadcast("createComponent", {
98                                             componentId : COMPONENT.SERVICE,
99                                             callbackFunction : function(response) {
100                                                 if (response.isSuccessful) {
101                                                                 vidService.setModel(serviceModel);
102                                                                 
103                                                                 var subscriberId = "Not Found";
104                                                                 var serviceType = "Not Found";
105                                                                 
106                                                                 var serviceInstanceId = response.instanceId;
107                                                                 
108                                                                 for (var i = 0; i < response.control.length; i++) {
109                                                                         if (response.control[i].id == "subscriberName") {
110                                                                                 subscriberId = response.control[i].value;
111                                                                         } else if (response.control[i].id == "serviceType") {
112                                                                                 serviceType = response.control[i].value;
113                                                                         }
114                                                                 }
115                                                                 
116                                                                 
117                                                                 $scope.refreshSubs(subscriberId,serviceType,serviceInstanceId);
118                                                         
119                                                 }
120                                             }
121                                         });
122                                         
123                                 }, function errorCallback(response) {
124                                         console.log("Error: " + response);
125                                 });
126                 };
127                 
128                 $scope.refreshSubs = function(subscriberId, serviceType, serviceInstanceId) {
129                         $scope.status = "Fetching subscriber list from A&AI...";
130                         $scope.init();
131                         $http.get(  PropertyService.getAaiBaseUrl() + "/aai_refresh_full_subscribers", {
132
133                         },{
134                                 timeout: $scope.responseTimeoutMsec
135                         }).then(function(response){
136                                 
137                                 if (response.data.status < 200 || response.data.status > 202) {
138                                         $scope.showError("MSO failure - see log below for details")
139                                         return;
140                                 }
141
142                                 $scope.customer = response.data.customer; // get data from json
143                                 
144                                 $scope.customerList = [];
145
146                                 $scope.serviceInstanceToCustomer = [];
147                                 
148                                 angular.forEach($scope.customer, function(subVal, subKey) {
149                                         var cust = { "globalCustomerId": subVal["global-customer-id"], "subscriberName": subVal["subscriber-name"] };
150                                         $scope.customerList.push(cust);
151                                         if (subVal["service-subscriptions"] != null) {
152                                                         angular.forEach(subVal["service-subscriptions"]["service-subscription"], function(serviceSubscription, key) {
153                                                                 $scope.serviceInstanceId = [];
154                                                                 if (serviceSubscription["service-type"] != null) {
155                                                                         $scope.serviceType = serviceSubscription["service-type"];
156                                                                 } else {
157                                                                         $scope.serviceType = "No Service Subscription Found";
158                                                                 }
159                                                                 if (serviceSubscription["service-instances"] != null) {
160                                                                         angular.forEach(serviceSubscription["service-instances"]["service-instance"], function(instValue, instKey) {
161                                                                                 var foo = { "serviceInstanceId": instValue["service-instance-id"], 
162                                                                                                 "globalCustomerId": subVal["global-customer-id"],
163                                                                                                 "subscriberName": subVal["subscriber-name"] };
164                                                                                 $scope.serviceInstanceToCustomer.push(foo);
165                                                                         });
166                                                                 }
167                                                         });
168                                         }
169                                 });     
170                                 DataService.setServiceInstanceToCustomer($scope.serviceInstanceToCustomer);
171                                 var serviceIdList = [];
172                                 $http.get(PropertyService.getAaiBaseUrl() + "/aai_get_services", {
173                                 },{
174                                         timeout: $scope.responseTimeoutMsec
175                                 }).then(function(response) {
176                                 angular.forEach(response.data, function(value, key) {
177                                         angular.forEach(value, function(subVal, key) {
178                                                 var newVal = { "id" : subVal["service-id"], "description" : subVal["service-description"] };
179                                                 serviceIdList.push(newVal);
180                                                 DataService.setServiceIdList(serviceIdList);
181                                                 
182                                                 $location.search({
183                                                         "subscriberId": subscriberId,
184                                                         "serviceType": serviceType,
185                                                         "serviceInstanceId": serviceInstanceId
186                                                 });
187                                                 
188                                                 $location.path("/instantiate");
189                                         });
190                                         });
191                                 });
192                         })
193                         ["catch"]($scope.handleServerError);
194                 };
195         });
196 })();