2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
23 class CatalogService {
\r
25 constructor($q, $log, $http, conf, uuid, utilsService) {
\r
32 this.utilsService = utilsService;
\r
36 let deferred = this.$q.defer();
\r
39 url: this.conf.api.appCatalog,
\r
42 'X-ECOMP-RequestID':this.uuid.generate()
\r
47 this.$log.debug('CatalogService::getAppCatalog: result is ' + JSON.stringify(res));
\r
48 // Res is always JSON, but the data object might be an HTML error page.
\r
49 if (! this.utilsService.isValidJSON(res.data)) {
\r
50 var msg = 'CatalogService::getAppCatalog: result data is not JSON';
\r
52 this.$log.debug(msg);
\r
53 deferred.reject(msg);
\r
56 this.$log.debug('CatalogService::getAppCatalog: success');
\r
57 deferred.resolve(res.data);
\r
61 this.$log.error('CatalogService:getAppCatalog failed: ' + status);
\r
62 deferred.reject(status);
\r
64 return deferred.promise;
\r
67 // Expects an object with fields matching model class AppCatalogSelection:
\r
68 // appId (number), select (boolean), pending (boolean).
\r
69 updateAppCatalog(appData) {
\r
70 let deferred = this.$q.defer();
\r
71 // Validate the request, maybe this is overkill
\r
72 if (appData == null || appData.appId == null || appData.select == null) {
\r
73 var msg = 'CatalogService::updateAppCatalog: field appId and/or select not found';
\r
74 this.$log.error(msg);
\r
75 return deferred.reject(msg);
\r
79 url: this.conf.api.appCatalog,
\r
82 'X-ECOMP-RequestID':this.uuid.generate()
\r
85 // Detect missing result
\r
86 if (res == null || res.data == null) {
\r
87 deferred.reject("CatalogService::updateAppCatalog Failed");
\r
89 deferred.resolve(res.data);
\r
93 this.$log.error('CatalogService:updateAppCatalog failed: ' + status);
\r
94 deferred.reject(status);
\r
96 return deferred.promise;
\r
99 // Expects an object with fields and used to update records for ep_pers_user_app_man_sort table:
\r
100 // appId (number), select (boolean).
\r
101 updateManualAppSort(appData) {
\r
102 let deferred = this.$q.defer();
\r
104 // Validate the request, maybe this is overkill
\r
105 if (appData == null || appData.appId == null || appData.select == null) {
\r
106 var msg = 'CatalogService::updateManualAppSort: field appId and/or select not found';
\r
107 this.$log.error(msg);
\r
108 return deferred.reject(msg);
\r
112 url: this.conf.api.UpdateUserAppsSortManual,
\r
115 'X-ECOMP-RequestID':this.uuid.generate()
\r
118 // Detect missing result
\r
119 if (res == null || res.data == null) {
\r
120 deferred.reject("CatalogService::updateManualAppSort Failed");
\r
122 deferred.resolve(res.data);
\r
125 .catch( status => {
\r
126 this.$log.error('CatalogService:updateManualAppSort failed: ' + status);
\r
127 deferred.reject(status);
\r
130 return deferred.promise;
\r
133 getuserAppRolesCatalog(item) {
\r
134 let deferred = this.$q.defer();
\r
137 url: this.conf.api.appCatalogRoles,
\r
138 params:{appName:item},
\r
141 'X-ECOMP-RequestID':this.uuid.generate()
\r
146 this.$log.debug('CatalogService::getAppCatalog: result is ' + JSON.stringify(res));
\r
147 // Res is always JSON, but the data object might be an HTML error page.
\r
148 if (! this.utilsService.isValidJSON(res.data)) {
\r
149 var msg = 'CatalogService::getAppCatalog: result data is not JSON';
\r
151 this.$log.debug(msg);
\r
152 deferred.reject(msg);
\r
155 this.$log.debug('CatalogService::getAppCatalog: success');
\r
156 deferred.resolve(res.data);
\r
159 .catch( status => {
\r
160 this.$log.error('CatalogService:getAppCatalog failed: ' + status);
\r
161 deferred.reject(status);
\r
163 return deferred.promise;
\r
170 CatalogService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
\r
171 angular.module('ecompApp').service('catalogService', CatalogService)
\r