[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / services / notification / notification.service.js
index cf180e8..d7d4607 100644 (file)
-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-/**\r
- * Created by wl849v on 12/14/2016.\r
- */\r
-'use strict';\r
-(function () {\r
-    class NotificationService {\r
-       constructor($q, $log, $http, conf, uuid,utilsService) {\r
-            this.$q = $q;\r
-            this.$log = $log;\r
-            this.$http = $http;\r
-            this.conf = conf;\r
-            this.uuid = uuid;\r
-            this.notificationCount = {count:0};\r
-            this.refreshCount = 0;\r
-            this.maxCount = 0;\r
-            this.utilsService = utilsService;            \r
-        }      \r
-        getNotificationCount() {\r
-                return this.notificationCount;\r
-        }\r
-        setNotificationCount(count) {\r
-               this.notificationCount.count = count;\r
-        }\r
-        getRefreshCount() {\r
-            return this.refreshCount;\r
-        }\r
-        setRefreshCount(count){\r
-            this.refreshCount = count;\r
-        }\r
-        setMaxRefreshCount(count){\r
-            this.maxCount = count;\r
-        }\r
-        decrementRefreshCount(){\r
-            this.refreshCount = this.refreshCount - 1;\r
-        }\r
-        \r
-        getNotificationRate() {\r
-            let deferred = this.$q.defer();\r
-            let url = this.conf.api.notificationUpdateRate;\r
-            this.$http({\r
-                    method: "GET",\r
-                    url: url,\r
-                    cache: false,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                }).then( res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success\r
-                       if (Object.keys(res.data).length == 0) {\r
-                        deferred.reject("ecomp::NotificationService::getNotificationRate Failed");\r
-                    } else {\r
-                        deferred.resolve(res.data);\r
-                    }\r
-                }).catch( status => {\r
-                    deferred.reject(status);\r
-                });\r
-            return deferred.promise;\r
-        }\r
-        \r
-        getNotification(){\r
-               let deferred = this.$q.defer();\r
-            this.$http({\r
-                    method: "GET",\r
-                    cache: false,\r
-                    url: this.conf.api.getNotifications,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                })\r
-                .then( res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success                 \r
-                    if (this.utilsService.isValidJSON(res)=== false) {\r
-                       this.$log.error('NotificationService::getNotification Failed');\r
-                        deferred.reject("NotificationService::getNotification Failed");\r
-                    } else {\r
-                        deferred.resolve(res);\r
-                    }\r
-                })\r
-                .catch( status => {\r
-                       this.$log.error('NotificationService::getNotification Failed', status);\r
-                    deferred.reject(status);\r
-                });\r
-           \r
-            return deferred.promise;\r
-       }\r
-        getNotificationHistory(){\r
-               let deferred = this.$q.defer();\r
-            this.$http({\r
-                    method: "GET",\r
-                    cache: false,\r
-                    url: this.conf.api.getNotificationHistory,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                })\r
-                .then( res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success                 \r
-                    if (this.utilsService.isValidJSON(res)=== false) {\r
-                       this.$log.error('NotificationService::getNotification Failed');\r
-                        deferred.reject("NotificationService::getNotification Failed");\r
-                    } else {\r
-                        deferred.resolve(res);\r
-                    }\r
-                })\r
-                .catch( status => {\r
-                       this.$log.error('NotificationService::getNotification Failed', status);\r
-                    deferred.reject(status);\r
-                });\r
-           \r
-            return deferred.promise;\r
-       }\r
-        \r
-        getAdminNotification(){\r
-               let deferred = this.$q.defer();\r
-            this.$http({\r
-                    method: "GET",\r
-                    cache: false,\r
-                    url: this.conf.api.getAdminNotifications,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                })\r
-                .then( res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success                 \r
-                    if (this.utilsService.isValidJSON(res)=== false) {\r
-                       this.$log.error('NotificationService::getAdminNotification Failed');\r
-                        deferred.reject("NotificationService::getAdminNotification Failed");\r
-                    } else {\r
-                        deferred.resolve(res);\r
-                    }\r
-                })\r
-                .catch( status => {\r
-                       this.$log.error('NotificationService::getAdminNotification Failed', status);\r
-                    deferred.reject(status);\r
-                });\r
-           \r
-            return deferred.promise;\r
-       }\r
-\r
-        \r
-        getMessageRecipients(notificationId){\r
-               let deferred = this.$q.defer();\r
-            this.$http({\r
-                    method: "GET",\r
-                    cache: false,\r
-                   url: this.conf.api.getMessageRecipients+"?notificationId="+notificationId,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                })\r
-                .then( res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success                 \r
-                    if (this.utilsService.isValidJSON(res.data)=== false) {\r
-                       this.$log.error('NotificationService::getMessageRecipients Failed');\r
-                        deferred.reject("NotificationService::getMessageRecipients Failed");\r
-                    } else {\r
-                        deferred.resolve(res.data);\r
-                    }\r
-                })\r
-                .catch( status => {\r
-                       this.$log.error('NotificationService::getMappedRecipients Failed', status);\r
-                    deferred.reject(status);\r
-                });\r
-           \r
-            return deferred.promise;\r
-       }\r
-        \r
-        getAppRoleIds(){\r
-               let deferred = this.$q.defer();\r
-            this.$http({\r
-                    method: "GET",\r
-                    cache: false,\r
-                    url: this.conf.api.getAllAppRoleIds,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                })\r
-                .then( res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success                 \r
-                    if (this.utilsService.isValidJSON(res)=== false) {\r
-                       this.$log.error('NotificationService::getAppRoleIds Failed');\r
-                        deferred.reject("NotificationService::getAppRoleIds Failed");\r
-                    } else {\r
-                        deferred.resolve(res);\r
-                    }\r
-                })\r
-                .catch( status => {\r
-                       this.$log.error('NotificationService::getAppRoleIds Failed', status);\r
-                    deferred.reject(status);\r
-                });           \r
-            return deferred.promise;\r
-       }\r
-\r
-        getNotificationRoles(notificationId){\r
-               let deferred = this.$q.defer();\r
-            this.$http({\r
-                    method: "GET",\r
-                    cache: false,\r
-                    url: this.conf.api.getNotificationRoles + '/'+notificationId+'/roles',\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                })\r
-                .then( res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success                 \r
-                    if (this.utilsService.isValidJSON(res)=== false) {\r
-                       this.$log.error('NotificationService::getAdminNotification Failed');\r
-                        deferred.reject("NotificationService::getAdminNotification Failed");\r
-                    } else {\r
-                        deferred.resolve(res);\r
-                    }\r
-                })\r
-                .catch( status => {\r
-                       this.$log.error('NotificationService::getAdminNotification Failed', status);\r
-                    deferred.reject(status);\r
-                });           \r
-            return deferred.promise;\r
-       }\r
-\r
-        addAdminNotification(newAdminNotif){\r
-            let deferred = this.$q.defer();\r
-            // this.$log.debug('applications-service::addOnboardingApp with:', newApp);\r
-\r
-            this.$http({\r
-                method: "POST",\r
-                url: this.conf.api.saveNotification,\r
-                data: newAdminNotif,\r
-                cache: false,\r
-                headers: {\r
-                    'X-ECOMP-RequestID':this.uuid.generate()\r
-                }\r
-            }).then( res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success\r
-                       // But don't declare an empty list to be an error.\r
-                    if (res == null || res.data == null) {\r
-                        deferred.reject("NotificationService::addAdminNotification Failed");\r
-                    } else {\r
-                        // this.$log.info('NotificationService::addAdminNotification Succeeded');\r
-                        deferred.resolve(res.data);\r
-                    }\r
-                })\r
-                .catch( status => {\r
-                    deferred.reject(status);\r
-                });\r
-            return deferred.promise;\r
-        }\r
-\r
-        updateAdminNotification(adminNotif){\r
-            let deferred = this.$q.defer();\r
-            this.$http({\r
-                method: "POST",\r
-                url: this.conf.api.saveNotification,\r
-                data: adminNotif,\r
-                cache: false,\r
-                headers: {\r
-                    'X-ECOMP-RequestID':this.uuid.generate()\r
-                }\r
-            }).then( res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success\r
-                       // But don't declare an empty list to be an error.\r
-                    if (res == null || res.data == null) {\r
-                        deferred.reject("NotificationService::updateAdminNotification Failed");\r
-                    } else {\r
-                        // this.$log.info('NotificationService::updateAdminNotification Succeeded');\r
-                        deferred.resolve(res.data);\r
-                    }\r
-                })\r
-                .catch( status => {\r
-                    deferred.reject(status);\r
-                });\r
-            return deferred.promise;\r
-        }\r
-\r
-        setNotificationRead(notificationId){\r
-               let deferred = this.$q.defer();\r
-            this.$http({\r
-                    method: "GET",\r
-                    cache: false,\r
-                    url: this.conf.api.notificationRead+"?notificationId="+notificationId,\r
-                    headers: {\r
-                        'X-ECOMP-RequestID':this.uuid.generate()\r
-                    }\r
-                })\r
-                .then( res => {\r
-                    // If response comes back as a redirected HTML page which IS NOT a success\r
-                    if (this.utilsService.isValidJSON(res)=== false) {\r
-                       this.$log.error('NotificationService::setNotificationRead Failed');\r
-                        deferred.reject("NotificationService::setNotificationRead Failed");\r
-                    } else {\r
-                        deferred.resolve(res);\r
-                    }\r
-                })\r
-                .catch( status => {\r
-                       this.$log.error('NotificationService::setNotificationRead Failed', status);\r
-                    deferred.reject(status);\r
-                });\r
-           \r
-            return deferred.promise;   \r
-        }\r
-    }\r
-    NotificationService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4','utilsService'];\r
-    angular.module('ecompApp').service('notificationService', NotificationService)\r
-})();\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+/**
+ * Created by wl849v on 12/14/2016.
+ */
+'use strict';
+(function () {
+    class NotificationService {
+       constructor($q, $log, $http, conf, uuid,utilsService) {
+            this.$q = $q;
+            this.$log = $log;
+            this.$http = $http;
+            this.conf = conf;
+            this.uuid = uuid;
+            this.notificationCount = {count:0};
+            this.refreshCount = 0;
+            this.maxCount = 0;
+            this.utilsService = utilsService;            
+        }      
+        getNotificationCount() {
+                return this.notificationCount;
+        }
+        setNotificationCount(count) {
+               this.notificationCount.count = count;
+        }
+        getRefreshCount() {
+            return this.refreshCount;
+        }
+        setRefreshCount(count){
+            this.refreshCount = count;
+        }
+        setMaxRefreshCount(count){
+            this.maxCount = count;
+        }
+        decrementRefreshCount(){
+            this.refreshCount = this.refreshCount - 1;
+        }
+        
+        getNotificationRate() {
+            let deferred = this.$q.defer();
+            let url = this.conf.api.notificationUpdateRate;
+            this.$http({
+                    method: "GET",
+                    url: url,
+                    cache: false,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                }).then( res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success
+                       if (Object.keys(res.data).length == 0) {
+                        deferred.reject("ecomp::NotificationService::getNotificationRate Failed");
+                    } else {
+                        deferred.resolve(res.data);
+                    }
+                }).catch( status => {
+                    deferred.reject(status);
+                });
+            return deferred.promise;
+        }
+        
+        getNotification(){
+               let deferred = this.$q.defer();
+            this.$http({
+                    method: "GET",
+                    cache: false,
+                    url: this.conf.api.getNotifications,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                })
+                .then( res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success                 
+                    if (this.utilsService.isValidJSON(res)=== false) {
+                       this.$log.error('NotificationService::getNotification Failed');
+                        deferred.reject("NotificationService::getNotification Failed");
+                    } else {
+                        deferred.resolve(res);
+                    }
+                })
+                .catch( status => {
+                       this.$log.error('NotificationService::getNotification Failed', status);
+                    deferred.reject(status);
+                });
+           
+            return deferred.promise;
+       }
+        getNotificationHistory(){
+               let deferred = this.$q.defer();
+            this.$http({
+                    method: "GET",
+                    cache: false,
+                    url: this.conf.api.getNotificationHistory,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                })
+                .then( res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success                 
+                    if (this.utilsService.isValidJSON(res)=== false) {
+                       this.$log.error('NotificationService::getNotification Failed');
+                        deferred.reject("NotificationService::getNotification Failed");
+                    } else {
+                        deferred.resolve(res);
+                    }
+                })
+                .catch( status => {
+                       this.$log.error('NotificationService::getNotification Failed', status);
+                    deferred.reject(status);
+                });
+           
+            return deferred.promise;
+       }
+        
+        getAdminNotification(){
+               let deferred = this.$q.defer();
+            this.$http({
+                    method: "GET",
+                    cache: false,
+                    url: this.conf.api.getAdminNotifications,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                })
+                .then( res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success                 
+                    if (this.utilsService.isValidJSON(res)=== false) {
+                       this.$log.error('NotificationService::getAdminNotification Failed');
+                        deferred.reject("NotificationService::getAdminNotification Failed");
+                    } else {
+                        deferred.resolve(res);
+                    }
+                })
+                .catch( status => {
+                       this.$log.error('NotificationService::getAdminNotification Failed', status);
+                    deferred.reject(status);
+                });
+           
+            return deferred.promise;
+       }
+
+        
+        getMessageRecipients(notificationId){
+               let deferred = this.$q.defer();
+            this.$http({
+                    method: "GET",
+                    cache: false,
+                   url: this.conf.api.getMessageRecipients+"?notificationId="+notificationId,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                })
+                .then( res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success                 
+                    if (this.utilsService.isValidJSON(res.data)=== false) {
+                       this.$log.error('NotificationService::getMessageRecipients Failed');
+                        deferred.reject("NotificationService::getMessageRecipients Failed");
+                    } else {
+                        deferred.resolve(res.data);
+                    }
+                })
+                .catch( status => {
+                       this.$log.error('NotificationService::getMappedRecipients Failed', status);
+                    deferred.reject(status);
+                });
+           
+            return deferred.promise;
+       }
+        
+        getAppRoleIds(){
+               let deferred = this.$q.defer();
+            this.$http({
+                    method: "GET",
+                    cache: false,
+                    url: this.conf.api.getAllAppRoleIds,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                })
+                .then( res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success                 
+                    if (this.utilsService.isValidJSON(res)=== false) {
+                       this.$log.error('NotificationService::getAppRoleIds Failed');
+                        deferred.reject("NotificationService::getAppRoleIds Failed");
+                    } else {
+                        deferred.resolve(res);
+                    }
+                })
+                .catch( status => {
+                       this.$log.error('NotificationService::getAppRoleIds Failed', status);
+                    deferred.reject(status);
+                });           
+            return deferred.promise;
+       }
+
+        getNotificationRoles(notificationId){
+               let deferred = this.$q.defer();
+            this.$http({
+                    method: "GET",
+                    cache: false,
+                    url: this.conf.api.getNotificationRoles + '/'+notificationId+'/roles',
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                })
+                .then( res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success                 
+                    if (this.utilsService.isValidJSON(res)=== false) {
+                       this.$log.error('NotificationService::getAdminNotification Failed');
+                        deferred.reject("NotificationService::getAdminNotification Failed");
+                    } else {
+                        deferred.resolve(res);
+                    }
+                })
+                .catch( status => {
+                       this.$log.error('NotificationService::getAdminNotification Failed', status);
+                    deferred.reject(status);
+                });           
+            return deferred.promise;
+       }
+
+        addAdminNotification(newAdminNotif){
+            let deferred = this.$q.defer();
+            // this.$log.debug('applications-service::addOnboardingApp with:', newApp);
+
+            this.$http({
+                method: "POST",
+                url: this.conf.api.saveNotification,
+                data: newAdminNotif,
+                cache: false,
+                headers: {
+                    'X-ECOMP-RequestID':this.uuid.generate()
+                }
+            }).then( res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success
+                       // But don't declare an empty list to be an error.
+                    if (res == null || res.data == null) {
+                        deferred.reject("NotificationService::addAdminNotification Failed");
+                    } else {
+                        // this.$log.info('NotificationService::addAdminNotification Succeeded');
+                        deferred.resolve(res.data);
+                    }
+                })
+                .catch( status => {
+                    deferred.reject(status);
+                });
+            return deferred.promise;
+        }
+
+        updateAdminNotification(adminNotif){
+            let deferred = this.$q.defer();
+            this.$http({
+                method: "POST",
+                url: this.conf.api.saveNotification,
+                data: adminNotif,
+                cache: false,
+                headers: {
+                    'X-ECOMP-RequestID':this.uuid.generate()
+                }
+            }).then( res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success
+                       // But don't declare an empty list to be an error.
+                    if (res == null || res.data == null) {
+                        deferred.reject("NotificationService::updateAdminNotification Failed");
+                    } else {
+                        // this.$log.info('NotificationService::updateAdminNotification Succeeded');
+                        deferred.resolve(res.data);
+                    }
+                })
+                .catch( status => {
+                    deferred.reject(status);
+                });
+            return deferred.promise;
+        }
+
+        setNotificationRead(notificationId){
+               let deferred = this.$q.defer();
+            this.$http({
+                    method: "GET",
+                    cache: false,
+                    url: this.conf.api.notificationRead+"?notificationId="+notificationId,
+                    headers: {
+                        'X-ECOMP-RequestID':this.uuid.generate()
+                    }
+                })
+                .then( res => {
+                    // If response comes back as a redirected HTML page which IS NOT a success
+                    if (this.utilsService.isValidJSON(res)=== false) {
+                       this.$log.error('NotificationService::setNotificationRead Failed');
+                        deferred.reject("NotificationService::setNotificationRead Failed");
+                    } else {
+                        deferred.resolve(res);
+                    }
+                })
+                .catch( status => {
+                       this.$log.error('NotificationService::setNotificationRead Failed', status);
+                    deferred.reject(status);
+                });
+           
+            return deferred.promise;   
+        }
+    }
+    NotificationService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4','utilsService'];
+    angular.module('ecompApp').service('notificationService', NotificationService)
+})();