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 NotificationService {
24 constructor($q, $log, $http, conf, uuid,utilsService) {
30 this.notificationCount = {count:0};
31 this.refreshCount = 0;
33 this.utilsService = utilsService;
35 getNotificationCount() {
36 return this.notificationCount;
38 setNotificationCount(count) {
39 this.notificationCount.count = count;
42 return this.refreshCount;
44 setRefreshCount(count){
45 this.refreshCount = count;
47 setMaxRefreshCount(count){
48 this.maxCount = count;
50 decrementRefreshCount(){
51 this.refreshCount = this.refreshCount - 1;
54 getNotificationRate() {
55 let deferred = this.$q.defer();
56 let url = this.conf.api.notificationUpdateRate;
62 'X-ECOMP-RequestID':this.uuid.generate()
65 // If response comes back as a redirected HTML page which IS NOT a success
66 if (Object.keys(res.data).length == 0) {
67 deferred.reject("ecomp::NotificationService::getNotificationRate Failed");
69 deferred.resolve(res.data);
72 deferred.reject(status);
74 return deferred.promise;
78 let deferred = this.$q.defer();
82 url: this.conf.api.getNotifications,
84 'X-ECOMP-RequestID':this.uuid.generate()
88 // If response comes back as a redirected HTML page which IS NOT a success
89 if (this.utilsService.isValidJSON(res)=== false) {
90 this.$log.error('NotificationService::getNotification Failed');
91 deferred.reject("NotificationService::getNotification Failed");
93 deferred.resolve(res);
97 this.$log.error('NotificationService::getNotification Failed', status);
98 deferred.reject(status);
101 return deferred.promise;
103 getNotificationHistory(){
104 let deferred = this.$q.defer();
108 url: this.conf.api.getNotificationHistory,
110 'X-ECOMP-RequestID':this.uuid.generate()
114 // If response comes back as a redirected HTML page which IS NOT a success
115 if (this.utilsService.isValidJSON(res)=== false) {
116 this.$log.error('NotificationService::getNotification Failed');
117 deferred.reject("NotificationService::getNotification Failed");
119 deferred.resolve(res);
123 this.$log.error('NotificationService::getNotification Failed', status);
124 deferred.reject(status);
127 return deferred.promise;
130 getAdminNotification(){
131 let deferred = this.$q.defer();
135 url: this.conf.api.getAdminNotifications,
137 'X-ECOMP-RequestID':this.uuid.generate()
141 // If response comes back as a redirected HTML page which IS NOT a success
142 if (this.utilsService.isValidJSON(res)=== false) {
143 this.$log.error('NotificationService::getAdminNotification Failed');
144 deferred.reject("NotificationService::getAdminNotification Failed");
146 deferred.resolve(res);
150 this.$log.error('NotificationService::getAdminNotification Failed', status);
151 deferred.reject(status);
154 return deferred.promise;
158 getMessageRecipients(notificationId){
159 let deferred = this.$q.defer();
163 url: this.conf.api.getMessageRecipients+"?notificationId="+notificationId,
165 'X-ECOMP-RequestID':this.uuid.generate()
169 // If response comes back as a redirected HTML page which IS NOT a success
170 if (this.utilsService.isValidJSON(res.data)=== false) {
171 this.$log.error('NotificationService::getMessageRecipients Failed');
172 deferred.reject("NotificationService::getMessageRecipients Failed");
174 deferred.resolve(res.data);
178 this.$log.error('NotificationService::getMappedRecipients Failed', status);
179 deferred.reject(status);
182 return deferred.promise;
186 let deferred = this.$q.defer();
190 url: this.conf.api.getAllAppRoleIds,
192 'X-ECOMP-RequestID':this.uuid.generate()
196 // If response comes back as a redirected HTML page which IS NOT a success
197 if (this.utilsService.isValidJSON(res)=== false) {
198 this.$log.error('NotificationService::getAppRoleIds Failed');
199 deferred.reject("NotificationService::getAppRoleIds Failed");
201 deferred.resolve(res);
205 this.$log.error('NotificationService::getAppRoleIds Failed', status);
206 deferred.reject(status);
208 return deferred.promise;
211 getNotificationRoles(notificationId){
212 let deferred = this.$q.defer();
216 url: this.conf.api.getNotificationRoles + '/'+notificationId+'/roles',
218 'X-ECOMP-RequestID':this.uuid.generate()
222 // If response comes back as a redirected HTML page which IS NOT a success
223 if (this.utilsService.isValidJSON(res)=== false) {
224 this.$log.error('NotificationService::getAdminNotification Failed');
225 deferred.reject("NotificationService::getAdminNotification Failed");
227 deferred.resolve(res);
231 this.$log.error('NotificationService::getAdminNotification Failed', status);
232 deferred.reject(status);
234 return deferred.promise;
237 addAdminNotification(newAdminNotif){
238 let deferred = this.$q.defer();
239 // this.$log.debug('applications-service::addOnboardingApp with:', newApp);
243 url: this.conf.api.saveNotification,
247 'X-ECOMP-RequestID':this.uuid.generate()
250 // If response comes back as a redirected HTML page which IS NOT a success
251 // But don't declare an empty list to be an error.
252 if (res == null || res.data == null) {
253 deferred.reject("NotificationService::addAdminNotification Failed");
255 // this.$log.info('NotificationService::addAdminNotification Succeeded');
256 deferred.resolve(res.data);
260 deferred.reject(status);
262 return deferred.promise;
265 updateAdminNotification(adminNotif){
266 let deferred = this.$q.defer();
269 url: this.conf.api.saveNotification,
273 'X-ECOMP-RequestID':this.uuid.generate()
276 // If response comes back as a redirected HTML page which IS NOT a success
277 // But don't declare an empty list to be an error.
278 if (res == null || res.data == null) {
279 deferred.reject("NotificationService::updateAdminNotification Failed");
281 // this.$log.info('NotificationService::updateAdminNotification Succeeded');
282 deferred.resolve(res.data);
286 deferred.reject(status);
288 return deferred.promise;
291 setNotificationRead(notificationId){
292 let deferred = this.$q.defer();
296 url: this.conf.api.notificationRead+"?notificationId="+notificationId,
298 'X-ECOMP-RequestID':this.uuid.generate()
302 // If response comes back as a redirected HTML page which IS NOT a success
303 if (this.utilsService.isValidJSON(res)=== false) {
304 this.$log.error('NotificationService::setNotificationRead Failed');
305 deferred.reject("NotificationService::setNotificationRead Failed");
307 deferred.resolve(res);
311 this.$log.error('NotificationService::setNotificationRead Failed', status);
312 deferred.reject(status);
315 return deferred.promise;
318 NotificationService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4','utilsService'];
319 angular.module('ecompApp').service('notificationService', NotificationService)