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