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 ApplicationsService {
42 constructor($q, $log, $http, conf, uuid, utilsService) {
48 this.utilsService = utilsService
51 getSingleAppInfo(appName) {
52 let deferred = this.$q.defer();
54 this.$http.get(this.conf.api.singleAppInfo,
57 params:{'appParam':appName},
59 'X-ECOMP-RequestID':this.uuid.generate()
63 // If response comes back as a redirected HTML page which IS NOT a success
64 // But don't declare an empty list to be an error.
65 if (res == null || res.data == null || _this12.utilsService.isValidJSON(res.data) == false) {
66 deferred.reject("ApplicationsService::getSingleAppInfo Failed");
68 deferred.resolve(res.data);
72 deferred.reject(status);
74 return deferred.promise;
77 getSingleAppInfoById(appId) {
78 let deferred = this.$q.defer();
80 this.$http.get(this.conf.api.singleAppInfoById,
83 params:{'appParam':appId},
85 'X-ECOMP-RequestID':this.uuid.generate()
89 // If response comes back as a redirected HTML page which IS NOT a success
90 // But don't declare an empty list to be an error.
91 if (res == null || res.data == null || _this14.utilsService.isValidJSON(res.data) == false) {
92 deferred.reject("ApplicationsService::getSingleAppInfoById Failed");
94 deferred.resolve(res.data);
98 deferred.reject(status);
100 return deferred.promise;
104 let deferred = this.$q.defer();
106 // this.$log.info('ApplicationsService::getPersUserApps');
107 this.$http.get(this.conf.api.persUserApps,
111 'X-ECOMP-RequestID':this.uuid.generate()
115 // If response comes back as a redirected HTML page which IS NOT a success
116 // But don't declare an empty list to be an error.
117 if (res == null || res.data == null || _this0.utilsService.isValidJSON(res.data) == false) {
118 deferred.reject("ApplicationsService::getPersUserApps Failed");
120 deferred.resolve(res.data);
124 deferred.reject(status);
126 return deferred.promise;
129 getAppsOrderBySortPref(userAppSortTypePref) {
130 let deferred = this.$q.defer();
132 // this.$log.info('ApplicationsService::getAppsOrderBySortPref');
133 this.$http.get(this.conf.api.userAppsOrderBySortPref,
136 params:{'mparams':userAppSortTypePref},
138 'X-ECOMP-RequestID':this.uuid.generate()
142 // If response comes back as a redirected HTML page which IS NOT a success
143 // But don't declare an empty list to be an error.
144 if (res == null || res.data == null || _this1.utilsService.isValidJSON(res.data)== false) {
145 deferred.reject("ApplicationsService::getAppsOrderBySortPref Failed");
147 // this.$log.info('ApplicationsService::getAppsOrderBySortPref Succeeded');
148 deferred.resolve(res.data);
152 deferred.reject(status);
155 return deferred.promise;
157 checkIfUserIsSuperAdmin() {
158 let deferred = this.$q.defer();
160 // this.$log.info('ApplicationsService::getPersUserApps');
161 this.$http.get(this.conf.api.checkIfUserIsSuperAdmin,
165 'X-ECOMP-RequestID':this.uuid.generate()
169 // If response comes back as a redirected HTML page which IS NOT a success
170 // But don't declare an empty list to be an error.
171 if (res == null || res.data == null) {
172 deferred.reject("ApplicationsService::checkIfUserIsSuperAdmin Failed");
174 deferred.resolve(res.data);
178 deferred.reject(status);
180 return deferred.promise;
182 saveAppsSortTypeManual(appsSortManual){
183 let deferred = this.$q.defer();
184 if (appsSortManual== undefined
185 || appsSortManual == null
186 || appsSortManual.length == 0) {
187 this.$log.error('ApplicationsService::saveAppsSortTypeManual: Apps Sort Manual received empty string!');
188 return deferred.reject('Apps Sort Manual received empty string ');
193 url: this.conf.api.saveUserAppsSortingManual,
194 data: appsSortManual,
197 'X-ECOMP-RequestID':this.uuid.generate()
200 // If response comes back as a redirected HTML page which IS
202 // But don't declare an empty list to be an error.
203 if (res == null || res.data == null) {
204 deferred.reject("ApplicationsService::saveAppsSortTypeManual Failed");
206 // this.$log.info('ApplicationsService::saveAppsSortTypeManual
208 deferred.resolve(res.data);
212 deferred.reject(status);
214 return deferred.promise;
217 saveAppsSortTypePreference(appsSortPreference){
218 let deferred = this.$q.defer();
220 if (appsSortPreference== undefined
221 || appsSortPreference == null
222 || appsSortPreference.length == 0){
223 this.$log.error('ApplicationsService::saveAppsSortTypePreference: Apps Sort type Preference received empty string!');
224 return deferred.reject('Apps Sort type Preference received empty string ');
228 url: this.conf.api.saveUserAppsSortingPreference,
229 data: appsSortPreference,
232 'X-ECOMP-RequestID':this.uuid.generate()
235 // If response comes back as a redirected HTML page which IS NOT a success
236 // But don't declare an empty list to be an error.
237 if (res == null || res.data == null || _this2.utilsService.isValidJSON(res) == false) {
238 deferred.reject("ApplicationsService::saveAppsSortTypePreference Failed");
240 // this.$log.info('ApplicationsService::saveAppsSortTypePreference Succeeded');
241 deferred.resolve(res.data);
245 deferred.reject(status);
247 return deferred.promise;
250 getUserAppsSortTypePreference() {
251 let deferred = this.$q.defer();
255 url: this.conf.api.userAppsSortTypePreference,
258 'X-ECOMP-RequestID':this.uuid.generate()
262 if (res == null || res.data == null || _this3.utilsService.isValidJSON(res) == false) {
263 deferred.reject("ApplicationsService::getSortTypePreference Failed");
265 // this.$log.info('ApplicationsService::getUserAppsSortTypePreference Succeeded');
266 deferred.resolve(res.data);
270 deferred.reject(status);
272 return deferred.promise;
275 saveWidgetsSortManual(widgetsSortManual){
276 let deferred = this.$q.defer();
278 if (widgetsSortManual== undefined
279 || widgetsSortManual == null
280 || widgetsSortManual.length == 0){
281 this.$log.error('ApplicationsService::saveWidgetsSortManual: Widegts Sort type Preference received empty string!');
282 return deferred.reject('Widgets Sort Manual received empty string ');
286 url: this.conf.api.saveUserWidgetsSortManual,
287 data: widgetsSortManual,
290 'X-ECOMP-RequestID':this.uuid.generate()
293 if (res == null || res.data == null || _this4.utilsService.isValidJSON(res) == false) {
294 deferred.reject("ApplicationsService::saveWidgetsSortManual Failed");
296 // this.$log.info('ApplicationsService::saveWidgetsSortManual
298 deferred.resolve(res.data);
302 deferred.reject(status);
304 return deferred.promise;
307 delWidgetsSortPref(widgetsData){
308 let deferred = this.$q.defer();
311 if (widgetsData== undefined
312 || widgetsData == null
313 || widgetsData.length == 0){
314 this.$log.error('ApplicationsService::delWidgetsSortPref: While deleting, widgets received empty string!');
315 return deferred.reject('Widgets received empty string ');
320 url: this.conf.api.updateWidgetsSortPref,
324 'X-ECOMP-RequestID':this.uuid.generate()
327 if (res == null || res.data == null || _this5.utilsService.isValidJSON(res) == false) {
328 deferred.reject("ApplicationsService::delWidgetsSortPref Failed");
330 // this.$log.info('ApplicationsService::delWidgetsSortPref
332 deferred.resolve(res.data);
336 deferred.reject(status);
338 return deferred.promise;
342 let deferred = this.$q.defer();
344 // this.$log.info('ApplicationsService::getAvailableApps');
349 url: this.conf.api.availableApps,
352 'X-ECOMP-RequestID':this.uuid.generate()
356 if (res == null || res.data == null || _this6.utilsService.isValidJSON(res) == false) {
357 deferred.reject("ApplicationsService::getAvailableApps Failed");
359 // this.$log.info('ApplicationsService::getAvailableApps Succeeded');
360 deferred.resolve(res.data);
364 deferred.reject(status);
367 return deferred.promise;
372 let canceller = this.$q.defer();
373 let isActive = false;
377 this.$log.debug('ApplicationsService::getAdminApps: canceling the request');
382 let promise = () => {
384 let deferred = this.$q.defer();
385 // this.$log.info('ApplicationsService::getAdminApps: starting');
386 this.$http({method: "GET",
387 url: this.conf.api.adminApps,
389 timeout: canceller.promise,
391 'X-ECOMP-RequestID':this.uuid.generate()
395 if (res == null || res.data == null || _this7.utilsService.isValidJSON(res) == false) {
396 deferred.reject("ApplicationsService::adminApps Failed");
398 // this.$log.info('ApplicationsService::adminApps Succeeded');
399 deferred.resolve(res.data);
404 deferred.reject(status);
406 return deferred.promise;
416 let deferred = this.$q.defer();
418 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin');
419 this.$http({method: "GET",
420 url: this.conf.api.leftmenuItems,
423 'X-ECOMP-RequestID':this.uuid.generate()
426 // If response comes back as a redirected HTML page which IS NOT a success
427 // But don't declare an empty list to be an error.
428 this.$log.debug('getLeftMenuItems::getAdminApps: canceling the request',res);
430 if (res == null || res.data == null || _this8.utilsService.isValidJSON(res) == false) {
431 deferred.reject("ApplicationsService::getLeftMenuItems Failed");
433 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin Succeeded');
434 deferred.resolve(res.data);
438 deferred.reject(status);
440 return deferred.promise;
443 getAppsForSuperAdminAndAccountAdmin(){
444 let deferred = this.$q.defer();
446 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin');
447 this.$http({method: "GET",
448 url: this.conf.api.appsForSuperAdminAndAccountAdmin,
451 'X-ECOMP-RequestID':this.uuid.generate()
454 // If response comes back as a redirected HTML page which IS NOT a success
455 // But don't declare an empty list to be an error.
456 if (res == null || res.data == null || _this9.utilsService.isValidJSON(res) == false) {
457 deferred.reject("ApplicationsService::getAppsForSuperAdminAndAccountAdmin Failed");
459 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin Succeeded');
460 deferred.resolve(res.data);
464 deferred.reject(status);
466 return deferred.promise;
469 getAdminAppsSimpler(){
470 let deferred = this.$q.defer();
472 // this.$log.info('ApplicationsService::getAdminAppsSimpler');
473 this.$http({method: "GET",
474 url: this.conf.api.adminApps,
477 'X-ECOMP-RequestID':this.uuid.generate()
480 // If response comes back as a redirected HTML page which IS NOT a success
481 // But don't declare an empty list to be an error.
482 if (res == null || res.data == null || _this10.utilsService.isValidJSON(res.data) == false) {
483 deferred.reject("ApplicationsService::getAdminAppsSimpler Failed");
485 // this.$log.info('ApplicationsService::getAdminAppsSimpler Succeeded');
486 deferred.resolve(res.data);
490 deferred.reject(status);
492 return deferred.promise;
496 let deferred = this.$q.defer();
498 // this.$log.debug('applications-service::getOnboardingApps');
499 this.$http.get(this.conf.api.onboardingApps,
503 'X-ECOMP-RequestID':this.uuid.generate()
507 // If response comes back as a redirected HTML page which IS NOT a success
508 // But don't declare an empty list to be an error.
509 if (res == null || res.data == null || _this11.utilsService.isValidJSON(res.data) == false) {
510 deferred.reject("ApplicationsService::getOnboardingApps Failed");
512 // this.$log.info('ApplicationsService::getOnboardingApps Succeeded');
513 deferred.resolve(res.data);
517 deferred.reject(status);
520 return deferred.promise;
523 addOnboardingApp(newApp){
524 let deferred = this.$q.defer();
525 // this.$log.debug('applications-service::addOnboardingApp with:', newApp);
528 url: this.conf.api.onboardingApps,
532 'X-ECOMP-RequestID':this.uuid.generate()
535 // If response comes back as a redirected HTML page which IS NOT a success
536 // But don't declare an empty list to be an error.
537 if (res == null || res.data == null) {
538 deferred.reject("ApplicationsService::addOnboardingApp Failed");
540 // this.$log.info('ApplicationsService::addOnboardingApp Succeeded');
541 deferred.resolve(res.data);
545 deferred.reject(status);
547 return deferred.promise;
550 updateOnboardingApp(appData){
551 let deferred = this.$q.defer();
552 // this.$log.info('ApplicationsService::addOnboardingApp');
554 this.$log.error('ApplicationsService::addOnboardingApp: App id not found!');
555 return deferred.reject('App id not found');
560 url: this.conf.api.onboardingApps,
564 'X-ECOMP-RequestID':this.uuid.generate()
567 // If response comes back as a redirected HTML page which IS NOT a success
568 // But don't declare an empty list to be an error.
569 if (res == null || res.data == null) {
570 deferred.reject("ApplicationsService::updateOnboardingApp Failed");
572 // this.$log.info('ApplicationsService::updateOnboardingApp Succeeded');
573 deferred.resolve(res.data);
577 deferred.reject(status);
579 return deferred.promise;
582 saveUserAppsRoles(UserAppRolesRequest) {
583 let deferred = this.$q.defer();
585 if (UserAppRolesRequest== undefined
586 || UserAppRolesRequest == null
587 || UserAppRolesRequest.length == 0){
588 this.$log.error('ApplicationsService::saveAppsSortTypeManual: Apps Sort Manual received empty string!');
589 return deferred.reject('Apps Sort Manual received empty string ');
591 // var manualAppsJson = angular.toJson(appsSortManual);
593 // console.log(manual_jsonData);
596 url: this.conf.api.saveUserAppRoles,
597 data: UserAppRolesRequest,
600 'X-ECOMP-RequestID':this.uuid.generate()
603 // If response comes back as a redirected HTML page which IS
605 // But don't declare an empty list to be an error.
606 if (res == null || res.data == null) {
607 deferred.reject("ApplicationsService::saveAppsSortTypeManual Failed");
609 // this.$log.info('ApplicationsService::saveAppsSortTypeManual
611 deferred.resolve(res.data);
615 deferred.reject(status);
617 return deferred.promise;
622 deleteOnboardingApp(appId) {
623 let deferred = this.$q.defer();
624 let url = this.conf.api.onboardingApps + '/' + appId;
625 // this.$log.info('applications.service::deleteOnboardingApp' +appId);
633 'X-ECOMP-RequestID':this.uuid.generate()
636 // If response comes back as a redirected HTML page which IS NOT a success
637 // But don't declare an empty list to be an error.
638 if (res == null || res.data == null) {
639 deferred.reject("applications.service::deleteOnboardingApp Failed");
641 // this.$log.info('applications.service::deleteOnboardingApp succeeded: ');
642 deferred.resolve(res.data);
646 deferred.reject(errRes);
648 return deferred.promise;
651 syncRolesEcompFromExtAuthSystem(appId){
652 let deferred = this.$q.defer();
653 let url = this.conf.api.syncRolesFromExternalAuthSystem;
661 'X-ECOMP-RequestID':this.uuid.generate()
664 // If response comes back as a redirected HTML page which IS NOT a success
665 // But don't declare an empty list to be an error.
666 if (res == null || res.data == null || _this13.utilsService.isValidJSON(res.data) == false || res.data.status == 'ERROR') {
667 deferred.reject("ApplicationsService::syncRolesEcompFromExtAuthSystem Failed" + res.data.message);
669 deferred.resolve(res);
673 deferred.reject(status);
675 return deferred.promise;
678 syncFunctionsFromExternalAuthSystem(appId){
679 let deferred = this.$q.defer();
680 let url = this.conf.api.syncFunctionsFromExternalAuthSystem;
688 'X-ECOMP-RequestID':this.uuid.generate()
691 // If response comes back as a redirected HTML page which IS NOT a success
692 // But don't declare an empty list to be an error.
693 if (res == null || res.data == null || _this13.utilsService.isValidJSON(res.data) == false) {
694 deferred.reject("ApplicationsService::syncFunctionsFromExternalAuthSystem Failed");
696 deferred.resolve(res);
700 deferred.reject(status);
702 return deferred.promise;
705 getTopMenuData(selectedApp) {
706 let deferred = this.$q.defer();
707 // this.$log.info('ApplicationsService:getTopMenuData');
708 this.$log.debug('ApplicationsService:getTopMenuData with:', selectedApp);
712 let deferred = this.$q.defer();
713 // this.$log.info('ApplicationsService::ping: ');
714 this.$http.get(this.conf.api.ping,
718 'X-ECOMP-RequestID':this.uuid.generate()
722 // If response comes back as a redirected HTML page which IS NOT a success
723 if (Object.keys(res).length == 0) {
724 deferred.reject("ApplicationsService::ping: Failed");
726 // this.$log.info('ApplicationsService::ping: Succeeded');
727 deferred.resolve(res);
731 deferred.reject(status);
734 return deferred.promise;
737 ApplicationsService.$inject = ['$q', '$log', '$http', 'conf','uuid4','utilsService'];
738 angular.module('ecompApp').service('applicationsService', ApplicationsService)