2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
23 class ApplicationsService {
24 constructor($q, $log, $http, conf, uuid, utilsService) {
30 this.utilsService = utilsService
34 let deferred = this.$q.defer();
36 // this.$log.info('ApplicationsService::getPersUserApps');
37 this.$http.get(this.conf.api.persUserApps,
41 'X-ECOMP-RequestID':this.uuid.generate()
45 // If response comes back as a redirected HTML page which IS NOT a success
46 // But don't declare an empty list to be an error.
47 if (res == null || res.data == null || _this0.utilsService.isValidJSON(res.data) == false) {
48 deferred.reject("ApplicationsService::getPersUserApps Failed");
50 deferred.resolve(res.data);
54 deferred.reject(status);
56 return deferred.promise;
59 getAppsOrderBySortPref(userAppSortTypePref) {
60 let deferred = this.$q.defer();
62 // this.$log.info('ApplicationsService::getAppsOrderBySortPref');
63 this.$http.get(this.conf.api.userAppsOrderBySortPref,
66 params:{'mparams':userAppSortTypePref},
68 'X-ECOMP-RequestID':this.uuid.generate()
72 // If response comes back as a redirected HTML page which IS NOT a success
73 // But don't declare an empty list to be an error.
74 if (res == null || res.data == null || _this1.utilsService.isValidJSON(res.data)== false) {
75 deferred.reject("ApplicationsService::getAppsOrderBySortPref Failed");
77 // this.$log.info('ApplicationsService::getAppsOrderBySortPref Succeeded');
78 deferred.resolve(res.data);
82 deferred.reject(status);
85 return deferred.promise;
88 saveAppsSortTypeManual(appsSortManual){
89 let deferred = this.$q.defer();
90 if (appsSortManual== undefined
91 || appsSortManual == null
92 || appsSortManual.length == 0) {
93 this.$log.error('ApplicationsService::saveAppsSortTypeManual: Apps Sort Manual received empty string!');
94 return deferred.reject('Apps Sort Manual received empty string ');
99 url: this.conf.api.saveUserAppsSortingManual,
100 data: appsSortManual,
103 'X-ECOMP-RequestID':this.uuid.generate()
106 // If response comes back as a redirected HTML page which IS
108 // But don't declare an empty list to be an error.
109 if (res == null || res.data == null) {
110 deferred.reject("ApplicationsService::saveAppsSortTypeManual Failed");
112 // this.$log.info('ApplicationsService::saveAppsSortTypeManual
114 deferred.resolve(res.data);
118 deferred.reject(status);
120 return deferred.promise;
123 saveAppsSortTypePreference(appsSortPreference){
124 let deferred = this.$q.defer();
126 if (appsSortPreference== undefined
127 || appsSortPreference == null
128 || appsSortPreference.length == 0){
129 this.$log.error('ApplicationsService::saveAppsSortTypePreference: Apps Sort type Preference received empty string!');
130 return deferred.reject('Apps Sort type Preference received empty string ');
134 url: this.conf.api.saveUserAppsSortingPreference,
135 data: appsSortPreference,
138 'X-ECOMP-RequestID':this.uuid.generate()
141 // If response comes back as a redirected HTML page which IS NOT a success
142 // But don't declare an empty list to be an error.
143 if (res == null || res.data == null || _this2.utilsService.isValidJSON(res) == false) {
144 deferred.reject("ApplicationsService::saveAppsSortTypePreference Failed");
146 // this.$log.info('ApplicationsService::saveAppsSortTypePreference Succeeded');
147 deferred.resolve(res.data);
151 deferred.reject(status);
153 return deferred.promise;
156 getUserAppsSortTypePreference() {
157 let deferred = this.$q.defer();
161 url: this.conf.api.userAppsSortTypePreference,
164 'X-ECOMP-RequestID':this.uuid.generate()
168 if (res == null || res.data == null || _this3.utilsService.isValidJSON(res) == false) {
169 deferred.reject("ApplicationsService::getSortTypePreference Failed");
171 // this.$log.info('ApplicationsService::getUserAppsSortTypePreference Succeeded');
172 deferred.resolve(res.data);
176 deferred.reject(status);
178 return deferred.promise;
181 saveWidgetsSortManual(widgetsSortManual){
182 let deferred = this.$q.defer();
184 if (widgetsSortManual== undefined
185 || widgetsSortManual == null
186 || widgetsSortManual.length == 0){
187 this.$log.error('ApplicationsService::saveWidgetsSortManual: Widegts Sort type Preference received empty string!');
188 return deferred.reject('Widgets Sort Manual received empty string ');
192 url: this.conf.api.saveUserWidgetsSortManual,
193 data: widgetsSortManual,
196 'X-ECOMP-RequestID':this.uuid.generate()
199 if (res == null || res.data == null || _this4.utilsService.isValidJSON(res) == false) {
200 deferred.reject("ApplicationsService::saveWidgetsSortManual Failed");
202 // this.$log.info('ApplicationsService::saveWidgetsSortManual
204 deferred.resolve(res.data);
208 deferred.reject(status);
210 return deferred.promise;
213 delWidgetsSortPref(widgetsData){
214 let deferred = this.$q.defer();
217 if (widgetsData== undefined
218 || widgetsData == null
219 || widgetsData.length == 0){
220 this.$log.error('ApplicationsService::delWidgetsSortPref: While deleting, widgets received empty string!');
221 return deferred.reject('Widgets received empty string ');
226 url: this.conf.api.updateWidgetsSortPref,
230 'X-ECOMP-RequestID':this.uuid.generate()
233 if (res == null || res.data == null || _this5.utilsService.isValidJSON(res) == false) {
234 deferred.reject("ApplicationsService::delWidgetsSortPref Failed");
236 // this.$log.info('ApplicationsService::delWidgetsSortPref
238 deferred.resolve(res.data);
242 deferred.reject(status);
244 return deferred.promise;
248 let deferred = this.$q.defer();
250 // this.$log.info('ApplicationsService::getAvailableApps');
255 url: this.conf.api.availableApps,
258 'X-ECOMP-RequestID':this.uuid.generate()
262 if (res == null || res.data == null || _this6.utilsService.isValidJSON(res) == false) {
263 deferred.reject("ApplicationsService::getAvailableApps Failed");
265 // this.$log.info('ApplicationsService::getAvailableApps Succeeded');
266 deferred.resolve(res.data);
270 deferred.reject(status);
273 return deferred.promise;
278 let canceller = this.$q.defer();
279 let isActive = false;
283 this.$log.debug('ApplicationsService::getAdminApps: canceling the request');
288 let promise = () => {
290 let deferred = this.$q.defer();
291 // this.$log.info('ApplicationsService::getAdminApps: starting');
292 this.$http({method: "GET",
293 url: this.conf.api.adminApps,
295 timeout: canceller.promise,
297 'X-ECOMP-RequestID':this.uuid.generate()
301 if (res == null || res.data == null || _this7.utilsService.isValidJSON(res) == false) {
302 deferred.reject("ApplicationsService::adminApps Failed");
304 // this.$log.info('ApplicationsService::adminApps Succeeded');
305 deferred.resolve(res.data);
310 deferred.reject(status);
312 return deferred.promise;
322 let deferred = this.$q.defer();
324 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin');
325 this.$http({method: "GET",
326 url: this.conf.api.leftmenuItems,
329 'X-ECOMP-RequestID':this.uuid.generate()
332 // If response comes back as a redirected HTML page which IS NOT a success
333 // But don't declare an empty list to be an error.
334 this.$log.debug('getLeftMenuItems::getAdminApps: canceling the request',res);
336 if (res == null || res.data == null || _this8.utilsService.isValidJSON(res) == false) {
337 deferred.reject("ApplicationsService::getLeftMenuItems Failed");
339 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin Succeeded');
340 deferred.resolve(res.data);
344 deferred.reject(status);
346 return deferred.promise;
349 getAppsForSuperAdminAndAccountAdmin(){
350 let deferred = this.$q.defer();
352 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin');
353 this.$http({method: "GET",
354 url: this.conf.api.appsForSuperAdminAndAccountAdmin,
357 'X-ECOMP-RequestID':this.uuid.generate()
360 // If response comes back as a redirected HTML page which IS NOT a success
361 // But don't declare an empty list to be an error.
362 if (res == null || res.data == null || _this9.utilsService.isValidJSON(res) == false) {
363 deferred.reject("ApplicationsService::getAppsForSuperAdminAndAccountAdmin Failed");
365 // this.$log.info('ApplicationsService::getAppsForSuperAdminAndAccountAdmin Succeeded');
366 deferred.resolve(res.data);
370 deferred.reject(status);
372 return deferred.promise;
375 getAdminAppsSimpler(){
376 let deferred = this.$q.defer();
378 // this.$log.info('ApplicationsService::getAdminAppsSimpler');
379 this.$http({method: "GET",
380 url: this.conf.api.adminApps,
383 'X-ECOMP-RequestID':this.uuid.generate()
386 // If response comes back as a redirected HTML page which IS NOT a success
387 // But don't declare an empty list to be an error.
388 if (res == null || res.data == null || _this10.utilsService.isValidJSON(res.data) == false) {
389 deferred.reject("ApplicationsService::getAdminAppsSimpler Failed");
391 // this.$log.info('ApplicationsService::getAdminAppsSimpler Succeeded');
392 deferred.resolve(res.data);
396 deferred.reject(status);
398 return deferred.promise;
402 let deferred = this.$q.defer();
404 // this.$log.debug('applications-service::getOnboardingApps');
405 this.$http.get(this.conf.api.onboardingApps,
409 'X-ECOMP-RequestID':this.uuid.generate()
413 // If response comes back as a redirected HTML page which IS NOT a success
414 // But don't declare an empty list to be an error.
415 if (res == null || res.data == null || _this11.utilsService.isValidJSON(res.data) == false) {
416 deferred.reject("ApplicationsService::getOnboardingApps Failed");
418 // this.$log.info('ApplicationsService::getOnboardingApps Succeeded');
419 deferred.resolve(res.data);
423 deferred.reject(status);
426 return deferred.promise;
429 addOnboardingApp(newApp){
430 let deferred = this.$q.defer();
431 // this.$log.debug('applications-service::addOnboardingApp with:', newApp);
434 url: this.conf.api.onboardingApps,
438 'X-ECOMP-RequestID':this.uuid.generate()
441 // If response comes back as a redirected HTML page which IS NOT a success
442 // But don't declare an empty list to be an error.
443 if (res == null || res.data == null) {
444 deferred.reject("ApplicationsService::addOnboardingApp Failed");
446 // this.$log.info('ApplicationsService::addOnboardingApp Succeeded');
447 deferred.resolve(res.data);
451 deferred.reject(status);
453 return deferred.promise;
456 updateOnboardingApp(appData){
457 let deferred = this.$q.defer();
458 // this.$log.info('ApplicationsService::addOnboardingApp');
460 this.$log.error('ApplicationsService::addOnboardingApp: App id not found!');
461 return deferred.reject('App id not found');
466 url: this.conf.api.onboardingApps,
470 'X-ECOMP-RequestID':this.uuid.generate()
473 // If response comes back as a redirected HTML page which IS NOT a success
474 // But don't declare an empty list to be an error.
475 if (res == null || res.data == null) {
476 deferred.reject("ApplicationsService::updateOnboardingApp Failed");
478 // this.$log.info('ApplicationsService::updateOnboardingApp Succeeded');
479 deferred.resolve(res.data);
483 deferred.reject(status);
485 return deferred.promise;
488 saveUserAppsRoles(UserAppRolesRequest) {
489 let deferred = this.$q.defer();
491 if (UserAppRolesRequest== undefined
492 || UserAppRolesRequest == null
493 || UserAppRolesRequest.length == 0){
494 this.$log.error('ApplicationsService::saveAppsSortTypeManual: Apps Sort Manual received empty string!');
495 return deferred.reject('Apps Sort Manual received empty string ');
497 // var manualAppsJson = angular.toJson(appsSortManual);
499 // console.log(manual_jsonData);
502 url: this.conf.api.saveUserAppRoles,
503 data: UserAppRolesRequest,
506 'X-ECOMP-RequestID':this.uuid.generate()
509 // If response comes back as a redirected HTML page which IS
511 // But don't declare an empty list to be an error.
512 if (res == null || res.data == null) {
513 deferred.reject("ApplicationsService::saveAppsSortTypeManual Failed");
515 // this.$log.info('ApplicationsService::saveAppsSortTypeManual
517 deferred.resolve(res.data);
521 deferred.reject(status);
523 return deferred.promise;
528 deleteOnboardingApp(appId) {
529 let deferred = this.$q.defer();
530 let url = this.conf.api.onboardingApps + '/' + appId;
531 // this.$log.info('applications.service::deleteOnboardingApp' +appId);
539 'X-ECOMP-RequestID':this.uuid.generate()
542 // If response comes back as a redirected HTML page which IS NOT a success
543 // But don't declare an empty list to be an error.
544 if (res == null || res.data == null) {
545 deferred.reject("applications.service::deleteOnboardingApp Failed");
547 // this.$log.info('applications.service::deleteOnboardingApp succeeded: ');
548 deferred.resolve(res.data);
552 deferred.reject(errRes);
554 return deferred.promise;
557 getTopMenuData(selectedApp) {
558 let deferred = this.$q.defer();
559 // this.$log.info('ApplicationsService:getTopMenuData');
560 this.$log.debug('ApplicationsService:getTopMenuData with:', selectedApp);
564 let deferred = this.$q.defer();
565 // this.$log.info('ApplicationsService::ping: ');
566 this.$http.get(this.conf.api.ping,
570 'X-ECOMP-RequestID':this.uuid.generate()
574 // If response comes back as a redirected HTML page which IS NOT a success
575 if (Object.keys(res).length == 0) {
576 deferred.reject("ApplicationsService::ping: Failed");
578 // this.$log.info('ApplicationsService::ping: Succeeded');
579 deferred.resolve(res);
583 deferred.reject(status);
586 return deferred.promise;
589 ApplicationsService.$inject = ['$q', '$log', '$http', 'conf','uuid4','utilsService'];
590 angular.module('ecompApp').service('applicationsService', ApplicationsService)