[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / services / functionalMenu / functionalMenu.service.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
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  * ================================================================================
19  */
20 'use strict';
21
22 (function () {
23     class FunctionalMenuService {
24         constructor($q, $log, $http, conf, uuid, utilsService) {
25             this.$q = $q;
26             this.$log = $log;
27             this.$http = $http;
28             this.conf = conf;
29             this.uuid = uuid;
30             this.utilsService = utilsService;
31         }
32
33
34         getManagedRolesMenu( appId )
35         {
36             let deferred = this.$q.defer();
37             this.$log.info('FunctionalMenuService::getManagedRolesMenu');
38             let url = this.conf.api.appRoles.replace(':appId', appId);
39             this.$log.info('FunctionalMenuService::getManagedRolesMenu url: '+url);
40
41             this.$http({
42                 method: 'GET',
43                 url: url,
44                 cache: false,
45                 headers: {
46                     'X-ECOMP-RequestID':this.uuid.generate()
47                 }
48             }).then(res => {
49                     // If response comes back as a redirected HTML page which IS NOT a success
50                     if (this.utilsService.isValidJSON(res)== false) {
51                         deferred.reject('functionalMenu.service::getManagedRolesMenu Failed');
52                     } else {
53                         this.$log.info('functionalMenu.service::getManagedRolesMenu succeeded: ');
54                         deferred.resolve(res.data);
55                     }
56                 })
57                 .catch(status => {
58                     deferred.reject(status);
59                 });
60             return deferred.promise;
61         }
62
63         getAvailableApplications()
64         {
65             let deferred = this.$q.defer();
66             this.$log.info('FunctionalMenuService::getManagedRolesMenu:getAvailableApplications');
67
68             this.$http({
69                 method: 'GET',
70 //                url: this.conf.api.availableApps,
71                 url: this.conf.api.allAvailableApps,
72                 cache: false,
73                 headers: {
74                     'X-ECOMP-RequestID':this.uuid.generate()
75                 }
76             }).then(res => {
77                     // If response comes back as a redirected HTML page which IS NOT a success
78                     if (this.utilsService.isValidJSON(res)== false) {
79                         deferred.reject('FunctionalMenuService::getManagedRolesMenu:getAvailableApplications Failed');
80                     } else {
81                         this.$log.info('FunctionalMenuService::getManagedRolesMenu:getAvailableApplications succeeded: ');
82                         deferred.resolve(res.data);
83                     }
84                 })
85                 .catch(status => {
86                     deferred.reject(status);
87                 });
88             return deferred.promise;
89         }
90         getMenuDetails( menuId )
91         {
92             let deferred = this.$q.defer();
93             this.$log.info('FunctionalMenuService::getMenuDetails:getMenuDetails');
94             let url = this.conf.api.functionalMenuItemDetails.replace(':menuId',menuId);
95             this.$log.info('FunctionalMenuService::getMenuDetails url: '+url);
96
97
98             this.$http({
99                 method: 'GET',
100                 url: url,
101                 cache: false,
102                 headers: {
103                     'X-ECOMP-RequestID':this.uuid.generate()
104                 }
105             }).then(res => {
106                     // If response comes back as a redirected HTML page which IS NOT a success
107                 if (this.utilsService.isValidJSON(res)== false) {
108                         deferred.reject('FunctionalMenuService::getMenuDetails:getMenuDetails Failed');
109                     } else {
110                         this.$log.info('FunctionalMenuService::getMenuDetails:getMenuDetails succeeded: ');
111                         deferred.resolve(res.data);
112                     }
113                 })
114                 .catch(status => {
115                     deferred.reject(status);
116                 });
117             return deferred.promise;
118         }
119
120
121         getManagedFunctionalMenu() {
122             let deferred = this.$q.defer();
123             this.$log.info('FunctionalMenuService::getMenuDetails:getManagedFunctionalMenu');
124
125             this.$http({
126                 method: 'GET',
127 //                url: this.conf.api.functionalMenuForAuthUser,
128                 url: this.conf.api.functionalMenuForEditing,
129                 cache: false,
130                 headers: {
131                     'X-ECOMP-RequestID':this.uuid.generate()
132                 }
133             }).then(res => {
134                     // If response comes back as a redirected HTML page which IS NOT a success
135                     if (this.utilsService.isValidJSON(res)== false) {
136                         deferred.reject('FunctionalMenuService::getManagedFunctionalMenu Failed');
137                     } else {
138                         this.$log.info('FunctionalMenuService::getManagedFunctionalMenu succeeded: ');
139                         deferred.resolve(res.data);
140                     }
141                 })
142                 .catch(status => {
143                     deferred.reject(status);
144                 });
145             return deferred.promise;
146         }
147         
148         getManagedFunctionalMenuForNotificationTree() {
149             let deferred = this.$q.defer();
150             this.$log.info('FunctionalMenuService::getMenuDetails:getManagedFunctionalMenuForNotificationTree');
151             this.$http({
152                 method: 'GET',
153                 url: this.conf.api.functionalMenuForNotificationTree,
154                 cache: false,
155                 headers: {
156                     'X-ECOMP-RequestID':this.uuid.generate()
157                 }
158             }).then(res => {
159                     // If response comes back as a redirected HTML page which IS NOT a success
160                     if (this.utilsService.isValidJSON(res)== false) {
161                         deferred.reject('FunctionalMenuService::getManagedFunctionalMenuForNotificationTree Failed');
162                         
163                     } else {
164                         this.$log.info('FunctionalMenuService::getManagedFunctionalMenuForNotificationTree succeeded: ');
165                         deferred.resolve(res.data);
166                     }
167                 })
168                 .catch(status => {
169                     deferred.reject(status);
170                 });
171             return deferred.promise;
172         }
173
174
175         regenerateFunctionalMenuAncestors() {
176             let deferred = this.$q.defer();
177             this.$log.info('FunctionalMenuService::regenerateFunctionalMenuAncestors');
178
179             this.$http({
180                 method: 'GET',
181                 url: this.conf.api.regenerateFunctionalMenuAncestors,
182                 cache: false,
183                 headers: {
184                     'X-ECOMP-RequestID':this.uuid.generate()
185                 }
186             }).then(res => {
187                     // If response comes back as a redirected HTML page which IS NOT a success
188                     if (this.utilsService.isValidJSON(res)== false) {
189                         deferred.reject('FunctionalMenuService::regenerateFunctionalMenuAncestors Failed');
190                     } else {
191                         this.$log.info('FunctionalMenuService::regenerateFunctionalMenuAncestors succeeded: ');
192                         deferred.resolve(res.data);
193                     }
194                 })
195                 .catch(status => {
196                     deferred.reject(status);
197                 });
198             return deferred.promise;
199         }
200
201         saveEditedMenuItem(menuData) {
202             let deferred = this.$q.defer();
203             this.$log.info('FunctionalMenuService::saveEditedMenuItem: ' + menuData);
204         
205             let url = this.conf.api.functionalMenuItem;
206             this.$http({
207                 method: 'PUT',
208                 url: url,
209                 cache: false,
210                 data: menuData,
211                 headers: {
212                     'X-ECOMP-RequestID':this.uuid.generate()
213                 }
214             }).then(res => {
215                 // If response comes back as a redirected HTML page which IS NOT a success
216                 if (this.utilsService.isValidJSON(res)== false) {
217                     deferred.reject('FunctionalMenuService::saveEditedMenuItem Failed');
218                 } else {
219                     this.$log.info('FunctionalMenuService::saveEditedMenuItem succeeded: ');
220                     deferred.resolve(res.data);
221                 }
222                 })
223                 .catch(errRes => {
224                     deferred.reject(errRes);
225                 });
226             return deferred.promise;
227         }
228         
229         saveMenuItem(menuData) {
230             let deferred = this.$q.defer();
231             this.$log.info('FunctionalMenuService::saveMenuItem: ' + JSON.stringify(menuData));
232
233             let url = this.conf.api.functionalMenuItem;
234             this.$http({
235                 method: 'POST',
236                 url: url,
237                 cache: false,
238                 headers: {
239                     'X-ECOMP-RequestID':this.uuid.generate()
240                 },
241                 data: menuData
242             }).then(res => {
243                     // If response comes back as a redirected HTML page which IS NOT a success
244                     if (this.utilsService.isValidJSON(res)== false) {
245                         deferred.reject('FunctionalMenuService::saveMenuItem:  Failed');
246                     } else {
247                         this.$log.info('FunctionalMenuService::saveMenuItem:  succeeded: ');
248                         deferred.resolve(res.data);
249                     }
250                 })
251                 .catch(errRes => {
252                     deferred.reject(errRes);
253                 });
254             return deferred.promise;
255         }
256
257
258         deleteMenuItem(menuId) {
259             let deferred = this.$q.defer();
260             let url = this.conf.api.functionalMenuItem + '/' + menuId;
261
262             this.$log.info('FunctionalMenuService::deleteMenuItem: ' +menuId);
263
264             this.$http({
265                 method: 'DELETE',
266                 url: url,
267                 cache: false,
268                 data:'',
269                 headers: {
270                     'X-ECOMP-RequestID':this.uuid.generate()
271                 }
272             }).then(res => {
273                     // If response comes back as a redirected HTML page which IS NOT a success
274                     if (this.utilsService.isValidJSON(res)== false) {
275                         deferred.reject('FunctionalMenuService::deleteMenuItem Failed');
276                     } else {
277                         this.$log.info('FunctionalMenuService::deleteMenuItem succeeded: ');
278                         deferred.resolve(res.data);
279                     }
280                 })
281                 .catch(errRes => {
282                     deferred.reject(errRes);
283                 });
284             return deferred.promise;
285         }
286
287
288         getFunctionalMenuRole()
289         {
290             let deferred = this.$q.defer();
291             this.$log.info('FunctionalMenuService::getFunctionalMenuRole');
292
293             this.$http({
294                 method: 'GET',
295                 url: this.conf.api.getFunctionalMenuRole,
296                 cache: false,
297                 headers: {
298                     'X-ECOMP-RequestID':this.uuid.generate()
299                 }
300             }).then(res => {
301                     // If response comes back as a redirected HTML page which IS NOT a success
302                     if (this.utilsService.isValidJSON(res)== false) {
303                         deferred.reject('FunctionalMenuService::getFunctionalMenuRole Failed');
304                     } else {
305                         this.$log.info('FunctionalMenuService::getFunctionalMenuRole succeeded: ');
306                         deferred.resolve(res.data);
307                     }
308                 })
309                 .catch(status => {
310                     deferred.reject(status);
311                 });
312             return deferred.promise;
313         }
314
315 }
316     FunctionalMenuService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
317     angular.module('ecompApp').service('functionalMenuService', FunctionalMenuService)
318 })();