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;
158 saveAppsSortTypeManual(appsSortManual){
159 let deferred = this.$q.defer();
160 if (appsSortManual== undefined
161 || appsSortManual == null
162 || appsSortManual.length == 0) {
163 this.$log.error('ApplicationsService::saveAppsSortTypeManual: Apps Sort Manual received empty string!');
164 return deferred.reject('Apps Sort Manual received empty string ');
169 url: this.conf.api.saveUserAppsSortingManual,
170 data: appsSortManual,
173 'X-ECOMP-RequestID':this.uuid.generate()
176 // If response comes back as a redirected HTML page which IS
178 // But don't declare an empty list to be an error.
179 if (res == null || res.data == null) {
180 deferred.reject("ApplicationsService::saveAppsSortTypeManual Failed");
182 // this.$log.info('ApplicationsService::saveAppsSortTypeManual
184 deferred.resolve(res.data);
188 deferred.reject(status);
190 return deferred.promise;
193 saveAppsSortTypePreference(appsSortPreference){
194 let deferred = this.$q.defer();
196 if (appsSortPreference== undefined
197 || appsSortPreference == null
198 || appsSortPreference.length == 0){
199 this.$log.error('ApplicationsService::saveAppsSortTypePreference: Apps Sort type Preference received empty string!');
200 return deferred.reject('Apps Sort type Preference received empty string ');
204 url: this.conf.api.saveUserAppsSortingPreference,
205 data: appsSortPreference,
208 'X-ECOMP-RequestID':this.uuid.generate()
211 // If response comes back as a redirected HTML page which IS NOT a success
212 // But don't declare an empty list to be an error.
213 if (res == null || res.data == null || _this2.utilsService.isValidJSON(res) == false) {
214 deferred.reject("ApplicationsService::saveAppsSortTypePreference Failed");
216 // this.$log.info('ApplicationsService::saveAppsSortTypePreference Succeeded');
217 deferred.resolve(res.data);
221 deferred.reject(status);
223 return deferred.promise;
226 getUserAppsSortTypePreference() {
227 let deferred = this.$q.defer();
231 url: this.conf.api.userAppsSortTypePreference,
234 'X-ECOMP-RequestID':this.uuid.generate()
238 if (res == null || res.data == null || _this3.utilsService.isValidJSON(res) == false) {
239 deferred.reject("ApplicationsService::getSortTypePreference Failed");
241 // this.$log.info('ApplicationsService::getUserAppsSortTypePreference Succeeded');
242 deferred.resolve(res.data);
246 deferred.reject(status);
248 return deferred.promise;
251 saveWidgetsSortManual(widgetsSortManual){
252 let deferred = this.$q.defer();
254 if (widgetsSortManual== undefined
255 || widgetsSortManual == null
256 || widgetsSortManual.length == 0){
257 this.$log.error('ApplicationsService::saveWidgetsSortManual: Widegts Sort type Preference received empty string!');
258 return deferred.reject('Widgets Sort Manual received empty string ');
262 url: this.conf.api.saveUserWidgetsSortManual,
263 data: widgetsSortManual,
266 'X-ECOMP-RequestID':this.uuid.generate()
269 if (res == null || res.data == null || _this4.utilsService.isValidJSON(res) == false) {
270 deferred.reject("ApplicationsService::saveWidgetsSortManual Failed");
272 // this.$log.info('ApplicationsService::saveWidgetsSortManual
274 deferred.resolve(res.data);
278 deferred.reject(status);
280 return deferred.promise;
283 delWidgetsSortPref(widgetsData){
284 let deferred = this.$q.defer();
287 if (widgetsData== undefined
288 || widgetsData == null
289 || widgetsData.length == 0){
290 this.$log.error('ApplicationsService::delWidgetsSortPref: While deleting, widgets received empty string!');
291 return deferred.reject('Widgets received empty string ');
296 url: this.conf.api.updateWidgetsSortPref,
300 'X-ECOMP-RequestID':this.uuid.generate()
303 if (res == null || res.data == null || _this5.utilsService.isValidJSON(res) == false) {
304 deferred.reject("ApplicationsService::delWidgetsSortPref Failed");
306 // this.$log.info('ApplicationsService::delWidgetsSortPref
308 deferred.resolve(res.data);
312 deferred.reject(status);
314 return deferred.promise;
318 let deferred = this.$q.defer();
320 // this.$log.info('ApplicationsService::getAvailableApps');
325 url: this.conf.api.availableApps,
328 'X-ECOMP-RequestID':this.uuid.generate()
332 if (res == null || res.data == null || _this6.utilsService.isValidJSON(res) == false) {
333 deferred.reject("ApplicationsService::getAvailableApps Failed");
335 // this.$log.info('ApplicationsService::getAvailableApps Succeeded');
336 deferred.resolve(res.data);
340 deferred.reject(status);
343 return deferred.promise;
348 let canceller = this.$q.defer();
349 let isActive = false;
353 this.$log.debug('ApplicationsService::getAdminApps: canceling the request');
358 let promise = () => {
360 let deferred = this.$q.defer();
361 // this.$log.info('ApplicationsService::getAdminApps: starting');
362 this.$http({method: "GET",
363 url: this.conf.api.adminApps,
365 timeout: canceller.promise,
367 'X-ECOMP-RequestID':this.uuid.generate()
371 if (res == null || res.data == null || _this7.utilsService.isValidJSON(res) == false) {
372 deferred.reject("ApplicationsService::adminApps Failed");
374 // this.$log.info('ApplicationsService::adminApps Succeeded');
375 deferred.resolve(res.data);
380 deferred.reject(status);
382 return deferred.promise;
392 let deferred = this.$q.defer();
394 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin');
395 this.$http({method: "GET",
396 url: this.conf.api.leftmenuItems,
399 'X-ECOMP-RequestID':this.uuid.generate()
402 // If response comes back as a redirected HTML page which IS NOT a success
403 // But don't declare an empty list to be an error.
404 this.$log.debug('getLeftMenuItems::getAdminApps: canceling the request',res);
406 if (res == null || res.data == null || _this8.utilsService.isValidJSON(res) == false) {
407 deferred.reject("ApplicationsService::getLeftMenuItems Failed");
409 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin Succeeded');
410 deferred.resolve(res.data);
414 deferred.reject(status);
416 return deferred.promise;
419 getAppsForSuperAdminAndAccountAdmin(){
420 let deferred = this.$q.defer();
422 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin');
423 this.$http({method: "GET",
424 url: this.conf.api.appsForSuperAdminAndAccountAdmin,
427 'X-ECOMP-RequestID':this.uuid.generate()
430 // If response comes back as a redirected HTML page which IS NOT a success
431 // But don't declare an empty list to be an error.
432 if (res == null || res.data == null || _this9.utilsService.isValidJSON(res) == false) {
433 deferred.reject("ApplicationsService::getAppsForSuperAdminAndAccountAdmin Failed");
435 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin Succeeded');
436 deferred.resolve(res.data);
440 deferred.reject(status);
442 return deferred.promise;
445 getAdminAppsSimpler(){
446 let deferred = this.$q.defer();
448 // this.$log.info('ApplicationsService::getAdminAppsSimpler');
449 this.$http({method: "GET",
450 url: this.conf.api.adminApps,
453 'X-ECOMP-RequestID':this.uuid.generate()
456 // If response comes back as a redirected HTML page which IS NOT a success
457 // But don't declare an empty list to be an error.
458 if (res == null || res.data == null || _this10.utilsService.isValidJSON(res.data) == false) {
459 deferred.reject("ApplicationsService::getAdminAppsSimpler Failed");
461 // this.$log.info('ApplicationsService::getAdminAppsSimpler Succeeded');
462 deferred.resolve(res.data);
466 deferred.reject(status);
468 return deferred.promise;
472 let deferred = this.$q.defer();
474 // this.$log.debug('applications-service::getOnboardingApps');
475 this.$http.get(this.conf.api.onboardingApps,
479 'X-ECOMP-RequestID':this.uuid.generate()
483 // If response comes back as a redirected HTML page which IS NOT a success
484 // But don't declare an empty list to be an error.
485 if (res == null || res.data == null || _this11.utilsService.isValidJSON(res.data) == false) {
486 deferred.reject("ApplicationsService::getOnboardingApps Failed");
488 // this.$log.info('ApplicationsService::getOnboardingApps Succeeded');
489 deferred.resolve(res.data);
493 deferred.reject(status);
496 return deferred.promise;
499 addOnboardingApp(newApp){
500 let deferred = this.$q.defer();
501 // this.$log.debug('applications-service::addOnboardingApp with:', newApp);
504 url: this.conf.api.onboardingApps,
508 'X-ECOMP-RequestID':this.uuid.generate()
511 // If response comes back as a redirected HTML page which IS NOT a success
512 // But don't declare an empty list to be an error.
513 if (res == null || res.data == null) {
514 deferred.reject("ApplicationsService::addOnboardingApp Failed");
516 // this.$log.info('ApplicationsService::addOnboardingApp Succeeded');
517 deferred.resolve(res.data);
521 deferred.reject(status);
523 return deferred.promise;
526 updateOnboardingApp(appData){
527 let deferred = this.$q.defer();
528 // this.$log.info('ApplicationsService::addOnboardingApp');
530 this.$log.error('ApplicationsService::addOnboardingApp: App id not found!');
531 return deferred.reject('App id not found');
536 url: this.conf.api.onboardingApps,
540 'X-ECOMP-RequestID':this.uuid.generate()
543 // If response comes back as a redirected HTML page which IS NOT a success
544 // But don't declare an empty list to be an error.
545 if (res == null || res.data == null) {
546 deferred.reject("ApplicationsService::updateOnboardingApp Failed");
548 // this.$log.info('ApplicationsService::updateOnboardingApp Succeeded');
549 deferred.resolve(res.data);
553 deferred.reject(status);
555 return deferred.promise;
558 saveUserAppsRoles(UserAppRolesRequest) {
559 let deferred = this.$q.defer();
561 if (UserAppRolesRequest== undefined
562 || UserAppRolesRequest == null
563 || UserAppRolesRequest.length == 0){
564 this.$log.error('ApplicationsService::saveAppsSortTypeManual: Apps Sort Manual received empty string!');
565 return deferred.reject('Apps Sort Manual received empty string ');
567 // var manualAppsJson = angular.toJson(appsSortManual);
569 // console.log(manual_jsonData);
572 url: this.conf.api.saveUserAppRoles,
573 data: UserAppRolesRequest,
576 'X-ECOMP-RequestID':this.uuid.generate()
579 // If response comes back as a redirected HTML page which IS
581 // But don't declare an empty list to be an error.
582 if (res == null || res.data == null) {
583 deferred.reject("ApplicationsService::saveAppsSortTypeManual Failed");
585 // this.$log.info('ApplicationsService::saveAppsSortTypeManual
587 deferred.resolve(res.data);
591 deferred.reject(status);
593 return deferred.promise;
598 deleteOnboardingApp(appId) {
599 let deferred = this.$q.defer();
600 let url = this.conf.api.onboardingApps + '/' + appId;
601 // this.$log.info('applications.service::deleteOnboardingApp' +appId);
609 'X-ECOMP-RequestID':this.uuid.generate()
612 // If response comes back as a redirected HTML page which IS NOT a success
613 // But don't declare an empty list to be an error.
614 if (res == null || res.data == null) {
615 deferred.reject("applications.service::deleteOnboardingApp Failed");
617 // this.$log.info('applications.service::deleteOnboardingApp succeeded: ');
618 deferred.resolve(res.data);
622 deferred.reject(errRes);
624 return deferred.promise;
627 syncRolesEcompFromExtAuthSystem(appId){
628 let deferred = this.$q.defer();
629 let url = this.conf.api.syncRolesFromExternalAuthSystem;
637 'X-ECOMP-RequestID':this.uuid.generate()
640 // If response comes back as a redirected HTML page which IS NOT a success
641 // But don't declare an empty list to be an error.
642 if (res == null || res.data == null || _this13.utilsService.isValidJSON(res.data) == false || res.data.status == 'ERROR') {
643 deferred.reject("ApplicationsService::syncRolesEcompFromExtAuthSystem Failed" + res.data.message);
645 deferred.resolve(res);
649 deferred.reject(status);
651 return deferred.promise;
654 syncFunctionsFromExternalAuthSystem(appId){
655 let deferred = this.$q.defer();
656 let url = this.conf.api.syncFunctionsFromExternalAuthSystem;
664 'X-ECOMP-RequestID':this.uuid.generate()
667 // If response comes back as a redirected HTML page which IS NOT a success
668 // But don't declare an empty list to be an error.
669 if (res == null || res.data == null || _this13.utilsService.isValidJSON(res.data) == false) {
670 deferred.reject("ApplicationsService::syncFunctionsFromExternalAuthSystem Failed");
672 deferred.resolve(res);
676 deferred.reject(status);
678 return deferred.promise;
681 getTopMenuData(selectedApp) {
682 let deferred = this.$q.defer();
683 // this.$log.info('ApplicationsService:getTopMenuData');
684 this.$log.debug('ApplicationsService:getTopMenuData with:', selectedApp);
688 let deferred = this.$q.defer();
689 // this.$log.info('ApplicationsService::ping: ');
690 this.$http.get(this.conf.api.ping,
694 'X-ECOMP-RequestID':this.uuid.generate()
698 // If response comes back as a redirected HTML page which IS NOT a success
699 if (Object.keys(res).length == 0) {
700 deferred.reject("ApplicationsService::ping: Failed");
702 // this.$log.info('ApplicationsService::ping: Succeeded');
703 deferred.resolve(res);
707 deferred.reject(status);
710 return deferred.promise;
713 ApplicationsService.$inject = ['$q', '$log', '$http', 'conf','uuid4','utilsService'];
714 angular.module('ecompApp').service('applicationsService', ApplicationsService)