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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
41 class CatalogService {
43 constructor($q, $log, $http, conf, uuid, utilsService) {
50 this.utilsService = utilsService;
54 let deferred = this.$q.defer();
57 url: this.conf.api.appCatalog,
60 'X-ECOMP-RequestID':this.uuid.generate()
65 this.$log.debug('CatalogService::getAppCatalog: result is ' + JSON.stringify(res));
66 // Res is always JSON, but the data object might be an HTML error page.
67 if (! this.utilsService.isValidJSON(res.data)) {
68 var msg = 'CatalogService::getAppCatalog: result data is not JSON';
74 this.$log.debug('CatalogService::getAppCatalog: success');
75 deferred.resolve(res.data);
79 this.$log.error('CatalogService:getAppCatalog failed: ' + status);
80 deferred.reject(status);
82 return deferred.promise;
85 // Expects an object with fields matching model class AppCatalogSelection:
86 // appId (number), select (boolean), pending (boolean).
87 updateAppCatalog(appData) {
88 let deferred = this.$q.defer();
89 // Validate the request, maybe this is overkill
90 if (appData == null || appData.appId == null || appData.select == null) {
91 var msg = 'CatalogService::updateAppCatalog: field appId and/or select not found';
93 return deferred.reject(msg);
97 url: this.conf.api.appCatalog,
100 'X-ECOMP-RequestID':this.uuid.generate()
103 // Detect missing result
104 if (res == null || res.data == null) {
105 deferred.reject("CatalogService::updateAppCatalog Failed");
107 deferred.resolve(res.data);
111 this.$log.error('CatalogService:updateAppCatalog failed: ' + status);
112 deferred.reject(status);
114 return deferred.promise;
117 // Expects an object with fields and used to update records for ep_pers_user_app_man_sort table:
118 // appId (number), select (boolean).
119 updateManualAppSort(appData) {
120 let deferred = this.$q.defer();
122 // Validate the request, maybe this is overkill
123 if (appData == null || appData.appId == null || appData.select == null) {
124 var msg = 'CatalogService::updateManualAppSort: field appId and/or select not found';
125 this.$log.error(msg);
126 return deferred.reject(msg);
130 url: this.conf.api.UpdateUserAppsSortManual,
133 'X-ECOMP-RequestID':this.uuid.generate()
136 // Detect missing result
137 if (res == null || res.data == null) {
138 deferred.reject("CatalogService::updateManualAppSort Failed");
140 deferred.resolve(res.data);
144 this.$log.error('CatalogService:updateManualAppSort failed: ' + status);
145 deferred.reject(status);
148 return deferred.promise;
151 getuserAppRolesCatalog(item) {
152 let deferred = this.$q.defer();
155 url: this.conf.api.appCatalogRoles,
156 params:{appName:item},
159 'X-ECOMP-RequestID':this.uuid.generate()
164 this.$log.debug('CatalogService::getAppCatalog: result is ' + JSON.stringify(res));
165 // Res is always JSON, but the data object might be an HTML error page.
166 if (! this.utilsService.isValidJSON(res.data)) {
167 var msg = 'CatalogService::getAppCatalog: result data is not JSON';
169 this.$log.debug(msg);
170 deferred.reject(msg);
173 this.$log.debug('CatalogService::getAppCatalog: success');
174 deferred.resolve(res.data);
178 this.$log.error('CatalogService:getAppCatalog failed: ' + status);
179 deferred.reject(status);
181 return deferred.promise;
185 let deferred = this.$q.defer();
188 url: this.conf.api.appsFullList,
191 'X-ECOMP-RequestID':this.uuid.generate()
196 this.$log.debug('CatalogService::getAppsFullList: result is ' + JSON.stringify(res));
197 // Res is always JSON, but the data object might be an HTML error page.
198 if (! this.utilsService.isValidJSON(res.data)) {
199 var msg = 'CatalogService::getAppsFullList: result data is not JSON';
201 this.$log.error(msg);
202 deferred.reject(msg);
205 this.$log.debug('CatalogService::getAppsFullList: success');
206 deferred.resolve(res.data);
210 this.$log.error('CatalogService:getAppsFullList failed: ' + status);
211 deferred.reject(status);
213 return deferred.promise;
218 CatalogService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
219 angular.module('ecompApp').service('catalogService', CatalogService)