actually adding the files to the initial commit
[vid.git] / vid / src / main / webapp / app / vid / scripts / services / aaiService.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 "use strict";
22
23 var AaiService = function($http, $log, PropertyService, UtilityService) {
24     return {
25                 getSubscriptionServiceTypeList : function(globalCustomerId,
26                         successCallbackFunction) {
27                     $log
28                             .debug("AaiService:getSubscriptionServiceTypeList: globalCustomerId: "
29                                     + globalCustomerId);
30                     $http.get(
31                             PropertyService.getAaiBaseUrl()
32                                     + "/aai_sub_details/"
33                                     + globalCustomerId + "?r=" + Math.random(),
34                             {
35                                 timeout : PropertyService
36                                         .getServerResponseTimeoutMsec()
37                             }).then(function(response) {
38                                 if (response.data && response.data["service-subscriptions"]) {
39                                         var serviceTypes = [];
40                                         var serviceSubscriptions = response.data["service-subscriptions"]["service-subscription"];
41                                         
42                                         for (var i = 0; i < serviceSubscriptions.length; i++) {
43                                                 serviceTypes.push(serviceSubscriptions[i]["service-type"]);
44                                         }
45                                         
46                                         successCallbackFunction(serviceTypes);
47                                 } else {
48                                         successCallbackFunction([]);
49                                 }
50                             })["catch"]
51                             (UtilityService.runHttpErrorHandler);
52                 },
53                 getLcpCloudRegionTenantList : function(globalCustomerId, serviceType,
54                                 successCallbackFunction) {
55                             $log
56                                     .debug("AaiService:getLcpCloudRegionTenantList: globalCustomerId: "
57                                             + globalCustomerId);
58                             var url =   PropertyService.getAaiBaseUrl()
59                             + "/aai_get_tenants/"
60                             + globalCustomerId + "/" + serviceType + "?r=" + Math.random();
61                 
62                             $http.get(url,
63                                     {
64                                         timeout : PropertyService
65                                                 .getServerResponseTimeoutMsec()
66                                     }).then(function(response) {
67                                         var lcpCloudRegionTenants = [];
68                                         var aaiLcpCloudRegionTenants = response.data;
69                                         
70                                         lcpCloudRegionTenants.push({
71                                                 "cloudRegionId": "",
72                                                 "tenantName": "Please choose a region",
73                                                 "tenantId": ""
74                                         });
75                                         
76                                         for (var i = 0; i < aaiLcpCloudRegionTenants.length; i++) {
77                                                 lcpCloudRegionTenants.push({
78                                                         "cloudRegionId": aaiLcpCloudRegionTenants[i]["cloudRegionID"],
79                                                         "tenantName": aaiLcpCloudRegionTenants[i]["tenantName"],
80                                                         "tenantId": aaiLcpCloudRegionTenants[i]["tenantID"]
81                                                 });
82                                         }
83                                         
84                                         successCallbackFunction(lcpCloudRegionTenants);
85                                     })["catch"]
86                                     (UtilityService.runHttpErrorHandler);
87                 },
88                 getSubscribers : function(successCallbackFunction) {
89                             $log
90                                     .debug("AaiService:getSubscribers");
91                             var url =   PropertyService.getAaiBaseUrl()
92                             + "/aai_get_subscribers?r=" + Math.random();
93                 
94                             $http.get(url,
95                                     {
96                                         timeout : PropertyService
97                                                 .getServerResponseTimeoutMsec()
98                                     }).then(function(response) {
99                                         if (response.data) {
100                                                 successCallbackFunction(response.data.customer);
101                                         } else {
102                                                 successCallbackFunction([]);
103                                         }
104                                     })["catch"]
105                                     (UtilityService.runHttpErrorHandler);
106                 }
107     }
108 }
109
110 app.factory("AaiService", [ "$http", "$log", "PropertyService",
111         "UtilityService", AaiService ]);