2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
41 class FunctionalMenuService {
42 constructor($q, $log, $http, conf, uuid, utilsService) {
48 this.utilsService = utilsService;
52 getManagedRolesMenu( appId )
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);
64 'X-ECOMP-RequestID':this.uuid.generate()
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');
71 this.$log.info('functionalMenu.service::getManagedRolesMenu succeeded: ');
72 deferred.resolve(res.data);
76 deferred.reject(status);
78 return deferred.promise;
81 getAvailableApplications()
83 let deferred = this.$q.defer();
84 this.$log.info('FunctionalMenuService::getManagedRolesMenu:getAvailableApplications');
88 // url: this.conf.api.availableApps,
89 url: this.conf.api.allAvailableApps,
92 'X-ECOMP-RequestID':this.uuid.generate()
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');
99 this.$log.info('FunctionalMenuService::getManagedRolesMenu:getAvailableApplications succeeded: ');
100 deferred.resolve(res.data);
104 deferred.reject(status);
106 return deferred.promise;
108 getMenuDetails( menuId )
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);
121 'X-ECOMP-RequestID':this.uuid.generate()
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');
128 this.$log.info('FunctionalMenuService::getMenuDetails:getMenuDetails succeeded: ');
129 deferred.resolve(res.data);
133 deferred.reject(status);
135 return deferred.promise;
139 getManagedFunctionalMenu() {
140 let deferred = this.$q.defer();
141 this.$log.info('FunctionalMenuService::getMenuDetails:getManagedFunctionalMenu');
145 // url: this.conf.api.functionalMenuForAuthUser,
146 url: this.conf.api.functionalMenuForEditing,
149 'X-ECOMP-RequestID':this.uuid.generate()
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');
156 this.$log.info('FunctionalMenuService::getManagedFunctionalMenu succeeded: ');
157 deferred.resolve(res.data);
161 deferred.reject(status);
163 return deferred.promise;
166 getManagedFunctionalMenuForNotificationTree() {
167 let deferred = this.$q.defer();
168 this.$log.info('FunctionalMenuService::getMenuDetails:getManagedFunctionalMenuForNotificationTree');
171 url: this.conf.api.functionalMenuForNotificationTree,
174 'X-ECOMP-RequestID':this.uuid.generate()
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');
182 this.$log.info('FunctionalMenuService::getManagedFunctionalMenuForNotificationTree succeeded: ');
183 deferred.resolve(res.data);
187 deferred.reject(status);
189 return deferred.promise;
193 regenerateFunctionalMenuAncestors() {
194 let deferred = this.$q.defer();
195 this.$log.info('FunctionalMenuService::regenerateFunctionalMenuAncestors');
199 url: this.conf.api.regenerateFunctionalMenuAncestors,
202 'X-ECOMP-RequestID':this.uuid.generate()
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');
209 this.$log.info('FunctionalMenuService::regenerateFunctionalMenuAncestors succeeded: ');
210 deferred.resolve(res.data);
214 deferred.reject(status);
216 return deferred.promise;
219 saveEditedMenuItem(menuData) {
220 let deferred = this.$q.defer();
221 this.$log.info('FunctionalMenuService::saveEditedMenuItem: ' + menuData);
223 let url = this.conf.api.functionalMenuItem;
230 'X-ECOMP-RequestID':this.uuid.generate()
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');
237 this.$log.info('FunctionalMenuService::saveEditedMenuItem succeeded: ');
238 deferred.resolve(res.data);
242 deferred.reject(errRes);
244 return deferred.promise;
247 saveMenuItem(menuData) {
248 let deferred = this.$q.defer();
249 this.$log.info('FunctionalMenuService::saveMenuItem: ' + JSON.stringify(menuData));
251 let url = this.conf.api.functionalMenuItem;
257 'X-ECOMP-RequestID':this.uuid.generate()
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');
265 this.$log.info('FunctionalMenuService::saveMenuItem: succeeded: ');
266 deferred.resolve(res.data);
270 deferred.reject(errRes);
272 return deferred.promise;
276 deleteMenuItem(menuId) {
277 let deferred = this.$q.defer();
278 let url = this.conf.api.functionalMenuItem + '/' + menuId;
280 this.$log.info('FunctionalMenuService::deleteMenuItem: ' +menuId);
288 'X-ECOMP-RequestID':this.uuid.generate()
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');
295 this.$log.info('FunctionalMenuService::deleteMenuItem succeeded: ');
296 deferred.resolve(res.data);
300 deferred.reject(errRes);
302 return deferred.promise;
306 getFunctionalMenuRole()
308 let deferred = this.$q.defer();
309 this.$log.info('FunctionalMenuService::getFunctionalMenuRole');
313 url: this.conf.api.getFunctionalMenuRole,
316 'X-ECOMP-RequestID':this.uuid.generate()
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');
323 this.$log.info('FunctionalMenuService::getFunctionalMenuRole succeeded: ');
324 deferred.resolve(res.data);
328 deferred.reject(status);
330 return deferred.promise;
333 saveBulkRole(appId, appRole)
335 let canceller = this.$q.defer();
336 let isActive = false;
340 this.$log.debug('FunctionalMenuService::saveBulkRole: canceling the request');
345 let promise = () => {
346 let deferred = this.$q.defer();
347 let url = this.conf.api.saveRole.replace(':appId', appId);
354 'X-ECOMP-RequestID':this.uuid.generate()
357 if (this.utilsService.isValidJSON(res)== false) {
358 deferred.reject('UsersService::saveBulkRole: Failed');
360 deferred.resolve(res.data);
364 deferred.reject(status);
367 return deferred.promise;
376 saveBulkFunction(appId, appFunction)
378 let canceller = this.$q.defer();
379 let isActive = false;
383 this.$log.debug('FunctionalMenuService::saveRoleFunction: canceling the request');
388 let promise = () => {
389 let deferred = this.$q.defer();
390 let url = this.conf.api.saveRoleFunction.replace(':appId', appId);
397 'X-ECOMP-RequestID':this.uuid.generate()
400 if (this.utilsService.isValidJSON(res)== false) {
401 deferred.reject('UsersService::saveRoleFunction: Failed');
403 deferred.resolve(res.data);
407 deferred.reject(status);
410 return deferred.promise;
419 updateBulkRoleFunction(appId, roleFunction)
421 let canceller = this.$q.defer();
422 let isActive = false;
426 this.$log.debug('FunctionalMenuService::updateBulkRoleFunction: canceling the request');
431 let promise = () => {
432 let deferred = this.$q.defer();
433 let url = this.conf.api.uploadRoleFunction.replace(':appId', appId);
440 'X-ECOMP-RequestID':this.uuid.generate()
443 if (this.utilsService.isValidJSON(res)== false) {
444 deferred.reject('UsersService::updateBulkRoleFunction: Failed');
446 deferred.resolve(res.data);
450 deferred.reject(status);
453 return deferred.promise;
463 FunctionalMenuService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
464 angular.module('ecompApp').service('functionalMenuService', FunctionalMenuService)