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 * ================================================================================
21 * Created by wl849v on 12/14/2016.
25 class NotificationService {
26 constructor($q, $log, $http, conf, uuid,utilsService) {
32 this.notificationCount = {count:0};
33 this.refreshCount = 0;
35 this.utilsService = utilsService;
37 getNotificationCount() {
38 return this.notificationCount;
40 setNotificationCount(count) {
41 this.notificationCount.count = count;
44 return this.refreshCount;
46 setRefreshCount(count){
47 this.refreshCount = count;
49 setMaxRefreshCount(count){
50 this.maxCount = count;
52 decrementRefreshCount(){
53 this.refreshCount = this.refreshCount - 1;
56 getNotificationRate() {
57 let deferred = this.$q.defer();
58 let url = this.conf.api.notificationUpdateRate;
64 'X-ECOMP-RequestID':this.uuid.generate()
67 // If response comes back as a redirected HTML page which IS NOT a success
68 if (Object.keys(res.data).length == 0) {
69 deferred.reject("ecomp::NotificationService::getNotificationRate Failed");
71 deferred.resolve(res.data);
74 deferred.reject(status);
76 return deferred.promise;
80 let deferred = this.$q.defer();
84 url: this.conf.api.getNotifications,
86 'X-ECOMP-RequestID':this.uuid.generate()
90 // If response comes back as a redirected HTML page which IS NOT a success
91 if (this.utilsService.isValidJSON(res)=== false) {
92 this.$log.error('NotificationService::getNotification Failed');
93 deferred.reject("NotificationService::getNotification Failed");
95 deferred.resolve(res);
99 this.$log.error('NotificationService::getNotification Failed', status);
100 deferred.reject(status);
103 return deferred.promise;
105 getNotificationHistory(){
106 let deferred = this.$q.defer();
110 url: this.conf.api.getNotificationHistory,
112 'X-ECOMP-RequestID':this.uuid.generate()
116 // If response comes back as a redirected HTML page which IS NOT a success
117 if (this.utilsService.isValidJSON(res)=== false) {
118 this.$log.error('NotificationService::getNotification Failed');
119 deferred.reject("NotificationService::getNotification Failed");
121 deferred.resolve(res);
125 this.$log.error('NotificationService::getNotification Failed', status);
126 deferred.reject(status);
129 return deferred.promise;
132 getAdminNotification(){
133 let deferred = this.$q.defer();
137 url: this.conf.api.getAdminNotifications,
139 'X-ECOMP-RequestID':this.uuid.generate()
143 // If response comes back as a redirected HTML page which IS NOT a success
144 if (this.utilsService.isValidJSON(res)=== false) {
145 this.$log.error('NotificationService::getAdminNotification Failed');
146 deferred.reject("NotificationService::getAdminNotification Failed");
148 deferred.resolve(res);
152 this.$log.error('NotificationService::getAdminNotification Failed', status);
153 deferred.reject(status);
156 return deferred.promise;
160 getMessageRecipients(notificationId){
161 let deferred = this.$q.defer();
165 url: this.conf.api.getMessageRecipients+"?notificationId="+notificationId,
167 'X-ECOMP-RequestID':this.uuid.generate()
171 // If response comes back as a redirected HTML page which IS NOT a success
172 if (this.utilsService.isValidJSON(res.data)=== false) {
173 this.$log.error('NotificationService::getMessageRecipients Failed');
174 deferred.reject("NotificationService::getMessageRecipients Failed");
176 deferred.resolve(res.data);
180 this.$log.error('NotificationService::getMappedRecipients Failed', status);
181 deferred.reject(status);
184 return deferred.promise;
188 let deferred = this.$q.defer();
192 url: this.conf.api.getAllAppRoleIds,
194 'X-ECOMP-RequestID':this.uuid.generate()
198 // If response comes back as a redirected HTML page which IS NOT a success
199 if (this.utilsService.isValidJSON(res)=== false) {
200 this.$log.error('NotificationService::getAppRoleIds Failed');
201 deferred.reject("NotificationService::getAppRoleIds Failed");
203 deferred.resolve(res);
207 this.$log.error('NotificationService::getAppRoleIds Failed', status);
208 deferred.reject(status);
210 return deferred.promise;
213 getNotificationRoles(notificationId){
214 let deferred = this.$q.defer();
218 url: this.conf.api.getNotificationRoles + '/'+notificationId+'/roles',
220 'X-ECOMP-RequestID':this.uuid.generate()
224 // If response comes back as a redirected HTML page which IS NOT a success
225 if (this.utilsService.isValidJSON(res)=== false) {
226 this.$log.error('NotificationService::getAdminNotification Failed');
227 deferred.reject("NotificationService::getAdminNotification Failed");
229 deferred.resolve(res);
233 this.$log.error('NotificationService::getAdminNotification Failed', status);
234 deferred.reject(status);
236 return deferred.promise;
239 addAdminNotification(newAdminNotif){
240 let deferred = this.$q.defer();
241 // this.$log.debug('applications-service::addOnboardingApp with:', newApp);
245 url: this.conf.api.saveNotification,
249 'X-ECOMP-RequestID':this.uuid.generate()
252 // If response comes back as a redirected HTML page which IS NOT a success
253 // But don't declare an empty list to be an error.
254 if (res == null || res.data == null) {
255 deferred.reject("NotificationService::addAdminNotification Failed");
257 // this.$log.info('NotificationService::addAdminNotification Succeeded');
258 deferred.resolve(res.data);
262 deferred.reject(status);
264 return deferred.promise;
267 updateAdminNotification(adminNotif){
268 let deferred = this.$q.defer();
271 url: this.conf.api.saveNotification,
275 'X-ECOMP-RequestID':this.uuid.generate()
278 // If response comes back as a redirected HTML page which IS NOT a success
279 // But don't declare an empty list to be an error.
280 if (res == null || res.data == null) {
281 deferred.reject("NotificationService::updateAdminNotification Failed");
283 // this.$log.info('NotificationService::updateAdminNotification Succeeded');
284 deferred.resolve(res.data);
288 deferred.reject(status);
290 return deferred.promise;
293 setNotificationRead(notificationId){
294 let deferred = this.$q.defer();
298 url: this.conf.api.notificationRead+"?notificationId="+notificationId,
300 'X-ECOMP-RequestID':this.uuid.generate()
304 // If response comes back as a redirected HTML page which IS NOT a success
305 if (this.utilsService.isValidJSON(res)=== false) {
306 this.$log.error('NotificationService::setNotificationRead Failed');
307 deferred.reject("NotificationService::setNotificationRead Failed");
309 deferred.resolve(res);
313 this.$log.error('NotificationService::setNotificationRead Failed', status);
314 deferred.reject(status);
317 return deferred.promise;
320 NotificationService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4','utilsService'];
321 angular.module('ecompApp').service('notificationService', NotificationService)