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 NotificationService {
42 constructor($q, $log, $http, conf, uuid,utilsService) {
48 this.notificationCount = {count:0};
49 this.refreshCount = 0;
51 this.utilsService = utilsService;
53 getNotificationCount() {
54 return this.notificationCount;
56 setNotificationCount(count) {
57 this.notificationCount.count = count;
60 return this.refreshCount;
62 setRefreshCount(count){
63 this.refreshCount = count;
65 setMaxRefreshCount(count){
66 this.maxCount = count;
68 decrementRefreshCount(){
69 this.refreshCount = this.refreshCount - 1;
72 getNotificationRate() {
73 let deferred = this.$q.defer();
74 let url = this.conf.api.notificationUpdateRate;
80 'X-ECOMP-RequestID':this.uuid.generate()
83 // If response comes back as a redirected HTML page which IS NOT a success
84 if (Object.keys(res.data).length == 0) {
85 deferred.reject("ecomp::NotificationService::getNotificationRate Failed");
87 deferred.resolve(res.data);
90 deferred.reject(status);
92 return deferred.promise;
96 let deferred = this.$q.defer();
100 url: this.conf.api.getNotifications,
102 'X-ECOMP-RequestID':this.uuid.generate()
106 // If response comes back as a redirected HTML page which IS NOT a success
107 if (this.utilsService.isValidJSON(res)=== false) {
108 this.$log.error('NotificationService::getNotification Failed');
109 deferred.reject("NotificationService::getNotification Failed");
111 deferred.resolve(res);
115 this.$log.error('NotificationService::getNotification Failed', status);
116 deferred.reject(status);
119 return deferred.promise;
121 getNotificationHistory(){
122 let deferred = this.$q.defer();
126 url: this.conf.api.getNotificationHistory,
128 'X-ECOMP-RequestID':this.uuid.generate()
132 // If response comes back as a redirected HTML page which IS NOT a success
133 if (this.utilsService.isValidJSON(res)=== false) {
134 this.$log.error('NotificationService::getNotification Failed');
135 deferred.reject("NotificationService::getNotification Failed");
137 deferred.resolve(res);
141 this.$log.error('NotificationService::getNotification Failed', status);
142 deferred.reject(status);
145 return deferred.promise;
148 getAdminNotification(){
149 let deferred = this.$q.defer();
153 url: this.conf.api.getAdminNotifications,
155 'X-ECOMP-RequestID':this.uuid.generate()
159 // If response comes back as a redirected HTML page which IS NOT a success
160 if (this.utilsService.isValidJSON(res)=== false) {
161 this.$log.error('NotificationService::getAdminNotification Failed');
162 deferred.reject("NotificationService::getAdminNotification Failed");
164 deferred.resolve(res);
168 this.$log.error('NotificationService::getAdminNotification Failed', status);
169 deferred.reject(status);
172 return deferred.promise;
176 getMessageRecipients(notificationId){
177 let deferred = this.$q.defer();
181 url: this.conf.api.getMessageRecipients+"?notificationId="+notificationId,
183 'X-ECOMP-RequestID':this.uuid.generate()
187 // If response comes back as a redirected HTML page which IS NOT a success
188 if (this.utilsService.isValidJSON(res.data)=== false) {
189 this.$log.error('NotificationService::getMessageRecipients Failed');
190 deferred.reject("NotificationService::getMessageRecipients Failed");
192 deferred.resolve(res.data);
196 this.$log.error('NotificationService::getMappedRecipients Failed', status);
197 deferred.reject(status);
200 return deferred.promise;
204 let deferred = this.$q.defer();
208 url: this.conf.api.getAllAppRoleIds,
210 'X-ECOMP-RequestID':this.uuid.generate()
214 // If response comes back as a redirected HTML page which IS NOT a success
215 if (this.utilsService.isValidJSON(res)=== false) {
216 this.$log.error('NotificationService::getAppRoleIds Failed');
217 deferred.reject("NotificationService::getAppRoleIds Failed");
219 deferred.resolve(res);
223 this.$log.error('NotificationService::getAppRoleIds Failed', status);
224 deferred.reject(status);
226 return deferred.promise;
229 getNotificationRoles(notificationId){
230 let deferred = this.$q.defer();
234 url: this.conf.api.getNotificationRoles + '/'+notificationId+'/roles',
236 'X-ECOMP-RequestID':this.uuid.generate()
240 // If response comes back as a redirected HTML page which IS NOT a success
241 if (this.utilsService.isValidJSON(res)=== false) {
242 this.$log.error('NotificationService::getAdminNotification Failed');
243 deferred.reject("NotificationService::getAdminNotification Failed");
245 deferred.resolve(res);
249 this.$log.error('NotificationService::getAdminNotification Failed', status);
250 deferred.reject(status);
252 return deferred.promise;
255 addAdminNotification(newAdminNotif){
256 let deferred = this.$q.defer();
257 // this.$log.debug('applications-service::addOnboardingApp with:', newApp);
261 url: this.conf.api.saveNotification,
265 'X-ECOMP-RequestID':this.uuid.generate()
268 // If response comes back as a redirected HTML page which IS NOT a success
269 // But don't declare an empty list to be an error.
270 if (res == null || res.data == null) {
271 deferred.reject("NotificationService::addAdminNotification Failed");
273 // this.$log.info('NotificationService::addAdminNotification Succeeded');
274 deferred.resolve(res.data);
278 deferred.reject(status);
280 return deferred.promise;
283 updateAdminNotification(adminNotif){
284 let deferred = this.$q.defer();
287 url: this.conf.api.saveNotification,
291 'X-ECOMP-RequestID':this.uuid.generate()
294 // If response comes back as a redirected HTML page which IS NOT a success
295 // But don't declare an empty list to be an error.
296 if (res == null || res.data == null) {
297 deferred.reject("NotificationService::updateAdminNotification Failed");
299 // this.$log.info('NotificationService::updateAdminNotification Succeeded');
300 deferred.resolve(res.data);
304 deferred.reject(status);
306 return deferred.promise;
309 setNotificationRead(notificationId){
310 let deferred = this.$q.defer();
314 url: this.conf.api.notificationRead+"?notificationId="+notificationId,
316 'X-ECOMP-RequestID':this.uuid.generate()
320 // If response comes back as a redirected HTML page which IS NOT a success
321 if (this.utilsService.isValidJSON(res)=== false) {
322 this.$log.error('NotificationService::setNotificationRead Failed');
323 deferred.reject("NotificationService::setNotificationRead Failed");
325 deferred.resolve(res);
329 this.$log.error('NotificationService::setNotificationRead Failed', status);
330 deferred.reject(status);
333 return deferred.promise;
336 NotificationService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4','utilsService'];
337 angular.module('ecompApp').service('notificationService', NotificationService)