Security/ Package Name changes
[portal.git] / ecomp-portal-FE-common / client / app / services / functionalMenu / functionalMenu.service.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 'use strict';
39
40 (function () {
41     class FunctionalMenuService {
42         constructor($q, $log, $http, conf, uuid, utilsService) {
43             this.$q = $q;
44             this.$log = $log;
45             this.$http = $http;
46             this.conf = conf;
47             this.uuid = uuid;
48             this.utilsService = utilsService;
49         }
50
51
52         getManagedRolesMenu( appId )
53         {
54             let deferred = this.$q.defer();
55             this.$log.info('FunctionalMenuService::getManagedRolesMenu');
56             let url = this.conf.api.appRoles.replace(':appId', appId);
57             this.$log.info('FunctionalMenuService::getManagedRolesMenu url: '+url);
58
59             this.$http({
60                 method: 'GET',
61                 url: url,
62                 cache: false,
63                 headers: {
64                     'X-ECOMP-RequestID':this.uuid.generate()
65                 }
66             }).then(res => {
67                     // If response comes back as a redirected HTML page which IS NOT a success
68                     if (this.utilsService.isValidJSON(res)== false) {
69                         deferred.reject('functionalMenu.service::getManagedRolesMenu Failed');
70                     } else {
71                         this.$log.info('functionalMenu.service::getManagedRolesMenu succeeded: ');
72                         deferred.resolve(res.data);
73                     }
74                 })
75                 .catch(status => {
76                     deferred.reject(status);
77                 });
78             return deferred.promise;
79         }
80
81         getAvailableApplications()
82         {
83             let deferred = this.$q.defer();
84             this.$log.info('FunctionalMenuService::getManagedRolesMenu:getAvailableApplications');
85
86             this.$http({
87                 method: 'GET',
88 //                url: this.conf.api.availableApps,
89                 url: this.conf.api.allAvailableApps,
90                 cache: false,
91                 headers: {
92                     'X-ECOMP-RequestID':this.uuid.generate()
93                 }
94             }).then(res => {
95                     // If response comes back as a redirected HTML page which IS NOT a success
96                     if (this.utilsService.isValidJSON(res)== false) {
97                         deferred.reject('FunctionalMenuService::getManagedRolesMenu:getAvailableApplications Failed');
98                     } else {
99                         this.$log.info('FunctionalMenuService::getManagedRolesMenu:getAvailableApplications succeeded: ');
100                         deferred.resolve(res.data);
101                     }
102                 })
103                 .catch(status => {
104                     deferred.reject(status);
105                 });
106             return deferred.promise;
107         }
108         getMenuDetails( menuId )
109         {
110             let deferred = this.$q.defer();
111             this.$log.info('FunctionalMenuService::getMenuDetails:getMenuDetails');
112             let url = this.conf.api.functionalMenuItemDetails.replace(':menuId',menuId);
113             this.$log.info('FunctionalMenuService::getMenuDetails url: '+url);
114
115
116             this.$http({
117                 method: 'GET',
118                 url: url,
119                 cache: false,
120                 headers: {
121                     'X-ECOMP-RequestID':this.uuid.generate()
122                 }
123             }).then(res => {
124                     // If response comes back as a redirected HTML page which IS NOT a success
125                 if (this.utilsService.isValidJSON(res)== false) {
126                         deferred.reject('FunctionalMenuService::getMenuDetails:getMenuDetails Failed');
127                     } else {
128                         this.$log.info('FunctionalMenuService::getMenuDetails:getMenuDetails succeeded: ');
129                         deferred.resolve(res.data);
130                     }
131                 })
132                 .catch(status => {
133                     deferred.reject(status);
134                 });
135             return deferred.promise;
136         }
137
138
139         getManagedFunctionalMenu() {
140             let deferred = this.$q.defer();
141             this.$log.info('FunctionalMenuService::getMenuDetails:getManagedFunctionalMenu');
142
143             this.$http({
144                 method: 'GET',
145 //                url: this.conf.api.functionalMenuForAuthUser,
146                 url: this.conf.api.functionalMenuForEditing,
147                 cache: false,
148                 headers: {
149                     'X-ECOMP-RequestID':this.uuid.generate()
150                 }
151             }).then(res => {
152                     // If response comes back as a redirected HTML page which IS NOT a success
153                     if (this.utilsService.isValidJSON(res)== false) {
154                         deferred.reject('FunctionalMenuService::getManagedFunctionalMenu Failed');
155                     } else {
156                         this.$log.info('FunctionalMenuService::getManagedFunctionalMenu succeeded: ');
157                         deferred.resolve(res.data);
158                     }
159                 })
160                 .catch(status => {
161                     deferred.reject(status);
162                 });
163             return deferred.promise;
164         }
165         
166         getManagedFunctionalMenuForNotificationTree() {
167             let deferred = this.$q.defer();
168             this.$log.info('FunctionalMenuService::getMenuDetails:getManagedFunctionalMenuForNotificationTree');
169             this.$http({
170                 method: 'GET',
171                 url: this.conf.api.functionalMenuForNotificationTree,
172                 cache: false,
173                 headers: {
174                     'X-ECOMP-RequestID':this.uuid.generate()
175                 }
176             }).then(res => {
177                     // If response comes back as a redirected HTML page which IS NOT a success
178                     if (this.utilsService.isValidJSON(res)== false) {
179                         deferred.reject('FunctionalMenuService::getManagedFunctionalMenuForNotificationTree Failed');
180                         
181                     } else {
182                         this.$log.info('FunctionalMenuService::getManagedFunctionalMenuForNotificationTree succeeded: ');
183                         deferred.resolve(res.data);
184                     }
185                 })
186                 .catch(status => {
187                     deferred.reject(status);
188                 });
189             return deferred.promise;
190         }
191
192
193         regenerateFunctionalMenuAncestors() {
194             let deferred = this.$q.defer();
195             this.$log.info('FunctionalMenuService::regenerateFunctionalMenuAncestors');
196
197             this.$http({
198                 method: 'GET',
199                 url: this.conf.api.regenerateFunctionalMenuAncestors,
200                 cache: false,
201                 headers: {
202                     'X-ECOMP-RequestID':this.uuid.generate()
203                 }
204             }).then(res => {
205                     // If response comes back as a redirected HTML page which IS NOT a success
206                     if (this.utilsService.isValidJSON(res)== false) {
207                         deferred.reject('FunctionalMenuService::regenerateFunctionalMenuAncestors Failed');
208                     } else {
209                         this.$log.info('FunctionalMenuService::regenerateFunctionalMenuAncestors succeeded: ');
210                         deferred.resolve(res.data);
211                     }
212                 })
213                 .catch(status => {
214                     deferred.reject(status);
215                 });
216             return deferred.promise;
217         }
218
219         saveEditedMenuItem(menuData) {
220             let deferred = this.$q.defer();
221             this.$log.info('FunctionalMenuService::saveEditedMenuItem: ' + menuData);
222         
223             let url = this.conf.api.functionalMenuItem;
224             this.$http({
225                 method: 'PUT',
226                 url: url,
227                 cache: false,
228                 data: menuData,
229                 headers: {
230                     'X-ECOMP-RequestID':this.uuid.generate()
231                 }
232             }).then(res => {
233                 // If response comes back as a redirected HTML page which IS NOT a success
234                 if (this.utilsService.isValidJSON(res)== false) {
235                     deferred.reject('FunctionalMenuService::saveEditedMenuItem Failed');
236                 } else {
237                     this.$log.info('FunctionalMenuService::saveEditedMenuItem succeeded: ');
238                     deferred.resolve(res.data);
239                 }
240                 })
241                 .catch(errRes => {
242                     deferred.reject(errRes);
243                 });
244             return deferred.promise;
245         }
246         
247         saveMenuItem(menuData) {
248             let deferred = this.$q.defer();
249             this.$log.info('FunctionalMenuService::saveMenuItem: ' + JSON.stringify(menuData));
250
251             let url = this.conf.api.functionalMenuItem;
252             this.$http({
253                 method: 'POST',
254                 url: url,
255                 cache: false,
256                 headers: {
257                     'X-ECOMP-RequestID':this.uuid.generate()
258                 },
259                 data: menuData
260             }).then(res => {
261                     // If response comes back as a redirected HTML page which IS NOT a success
262                     if (this.utilsService.isValidJSON(res)== false) {
263                         deferred.reject('FunctionalMenuService::saveMenuItem:  Failed');
264                     } else {
265                         this.$log.info('FunctionalMenuService::saveMenuItem:  succeeded: ');
266                         deferred.resolve(res.data);
267                     }
268                 })
269                 .catch(errRes => {
270                     deferred.reject(errRes);
271                 });
272             return deferred.promise;
273         }
274
275
276         deleteMenuItem(menuId) {
277             let deferred = this.$q.defer();
278             let url = this.conf.api.functionalMenuItem + '/' + menuId;
279
280             this.$log.info('FunctionalMenuService::deleteMenuItem: ' +menuId);
281
282             this.$http({
283                 method: 'DELETE',
284                 url: url,
285                 cache: false,
286                 data:'',
287                 headers: {
288                     'X-ECOMP-RequestID':this.uuid.generate()
289                 }
290             }).then(res => {
291                     // If response comes back as a redirected HTML page which IS NOT a success
292                     if (this.utilsService.isValidJSON(res)== false) {
293                         deferred.reject('FunctionalMenuService::deleteMenuItem Failed');
294                     } else {
295                         this.$log.info('FunctionalMenuService::deleteMenuItem succeeded: ');
296                         deferred.resolve(res.data);
297                     }
298                 })
299                 .catch(errRes => {
300                     deferred.reject(errRes);
301                 });
302             return deferred.promise;
303         }
304
305
306         getFunctionalMenuRole()
307         {
308             let deferred = this.$q.defer();
309             this.$log.info('FunctionalMenuService::getFunctionalMenuRole');
310
311             this.$http({
312                 method: 'GET',
313                 url: this.conf.api.getFunctionalMenuRole,
314                 cache: false,
315                 headers: {
316                     'X-ECOMP-RequestID':this.uuid.generate()
317                 }
318             }).then(res => {
319                     // If response comes back as a redirected HTML page which IS NOT a success
320                     if (this.utilsService.isValidJSON(res)== false) {
321                         deferred.reject('FunctionalMenuService::getFunctionalMenuRole Failed');
322                     } else {
323                         this.$log.info('FunctionalMenuService::getFunctionalMenuRole succeeded: ');
324                         deferred.resolve(res.data);
325                     }
326                 })
327                 .catch(status => {
328                     deferred.reject(status);
329                 });
330             return deferred.promise;
331         }
332
333 }
334     FunctionalMenuService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
335     angular.module('ecompApp').service('functionalMenuService', FunctionalMenuService)
336 })();