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 CatalogService {
25 constructor($q, $log, $http, conf, uuid, utilsService) {
32 this.utilsService = utilsService;
36 let deferred = this.$q.defer();
39 url: this.conf.api.appCatalog,
42 'X-ECOMP-RequestID':this.uuid.generate()
47 this.$log.debug('CatalogService::getAppCatalog: result is ' + JSON.stringify(res));
48 // Res is always JSON, but the data object might be an HTML error page.
49 if (! this.utilsService.isValidJSON(res.data)) {
50 var msg = 'CatalogService::getAppCatalog: result data is not JSON';
56 this.$log.debug('CatalogService::getAppCatalog: success');
57 deferred.resolve(res.data);
61 this.$log.error('CatalogService:getAppCatalog failed: ' + status);
62 deferred.reject(status);
64 return deferred.promise;
67 // Expects an object with fields matching model class AppCatalogSelection:
68 // appId (number), select (boolean), pending (boolean).
69 updateAppCatalog(appData) {
70 let deferred = this.$q.defer();
71 // Validate the request, maybe this is overkill
72 if (appData == null || appData.appId == null || appData.select == null) {
73 var msg = 'CatalogService::updateAppCatalog: field appId and/or select not found';
75 return deferred.reject(msg);
79 url: this.conf.api.appCatalog,
82 'X-ECOMP-RequestID':this.uuid.generate()
85 // Detect missing result
86 if (res == null || res.data == null) {
87 deferred.reject("CatalogService::updateAppCatalog Failed");
89 deferred.resolve(res.data);
93 this.$log.error('CatalogService:updateAppCatalog failed: ' + status);
94 deferred.reject(status);
96 return deferred.promise;
99 // Expects an object with fields and used to update records for ep_pers_user_app_man_sort table:
100 // appId (number), select (boolean).
101 updateManualAppSort(appData) {
102 let deferred = this.$q.defer();
104 // Validate the request, maybe this is overkill
105 if (appData == null || appData.appId == null || appData.select == null) {
106 var msg = 'CatalogService::updateManualAppSort: field appId and/or select not found';
107 this.$log.error(msg);
108 return deferred.reject(msg);
112 url: this.conf.api.UpdateUserAppsSortManual,
115 'X-ECOMP-RequestID':this.uuid.generate()
118 // Detect missing result
119 if (res == null || res.data == null) {
120 deferred.reject("CatalogService::updateManualAppSort Failed");
122 deferred.resolve(res.data);
126 this.$log.error('CatalogService:updateManualAppSort failed: ' + status);
127 deferred.reject(status);
130 return deferred.promise;
133 getuserAppRolesCatalog(item) {
134 let deferred = this.$q.defer();
137 url: this.conf.api.appCatalogRoles,
138 params:{appName:item},
141 'X-ECOMP-RequestID':this.uuid.generate()
146 this.$log.debug('CatalogService::getAppCatalog: result is ' + JSON.stringify(res));
147 // Res is always JSON, but the data object might be an HTML error page.
148 if (! this.utilsService.isValidJSON(res.data)) {
149 var msg = 'CatalogService::getAppCatalog: result data is not JSON';
151 this.$log.debug(msg);
152 deferred.reject(msg);
155 this.$log.debug('CatalogService::getAppCatalog: success');
156 deferred.resolve(res.data);
160 this.$log.error('CatalogService:getAppCatalog failed: ' + status);
161 deferred.reject(status);
163 return deferred.promise;
167 let deferred = this.$q.defer();
170 url: this.conf.api.appsFullList,
173 'X-ECOMP-RequestID':this.uuid.generate()
178 this.$log.debug('CatalogService::getAppsFullList: result is ' + JSON.stringify(res));
179 // Res is always JSON, but the data object might be an HTML error page.
180 if (! this.utilsService.isValidJSON(res.data)) {
181 var msg = 'CatalogService::getAppsFullList: result data is not JSON';
183 this.$log.error(msg);
184 deferred.reject(msg);
187 this.$log.debug('CatalogService::getAppsFullList: success');
188 deferred.resolve(res.data);
192 this.$log.error('CatalogService:getAppsFullList failed: ' + status);
193 deferred.reject(status);
195 return deferred.promise;
200 CatalogService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
201 angular.module('ecompApp').service('catalogService', CatalogService)