[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / controller / UserNotificationController.java
index 777fb91..24b698e 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
-package org.openecomp.portalapp.portal.controller;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.context.annotation.EnableAspectJAutoProxy;\r
-import org.springframework.web.bind.annotation.PathVariable;\r
-import org.springframework.web.bind.annotation.RequestBody;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RequestMethod;\r
-import org.springframework.web.bind.annotation.RequestParam;\r
-import org.springframework.web.bind.annotation.RestController;\r
-\r
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
-import org.openecomp.portalsdk.core.util.SystemProperties;\r
-import org.openecomp.portalsdk.core.web.support.UserUtils;\r
-import org.openecomp.portalapp.controller.EPRestrictedBaseController;\r
-import org.openecomp.portalapp.portal.domain.EPUser;\r
-import org.openecomp.portalapp.portal.domain.EcompAppRole;\r
-import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;\r
-import org.openecomp.portalapp.portal.service.FunctionalMenuService;\r
-import org.openecomp.portalapp.portal.service.UserNotificationService;\r
-import org.openecomp.portalapp.portal.transport.EpNotificationItem;\r
-import org.openecomp.portalapp.portal.transport.EpNotificationItemVO;\r
-import org.openecomp.portalapp.portal.transport.EpRoleNotificationItem;\r
-import org.openecomp.portalapp.portal.transport.FunctionalMenuRole;\r
-import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;\r
-import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;\r
-import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;\r
-import org.openecomp.portalapp.util.EPUserUtils;\r
-\r
-@RestController\r
-@org.springframework.context.annotation.Configuration\r
-@EnableAspectJAutoProxy\r
-@EPAuditLog\r
-public class UserNotificationController extends EPRestrictedBaseController {\r
-\r
-       @Autowired\r
-       FunctionalMenuService functionalMenuService;\r
-\r
-       @Autowired\r
-       UserNotificationService userNotificationService;\r
-\r
-       EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserNotificationController.class);\r
-\r
-       @RequestMapping(value = {\r
-                       "/portalApi/getFunctionalMenuRole" }, method = RequestMethod.GET, produces = "application/json")\r
-       public List<FunctionalMenuRole> getMenuIdRoleId(HttpServletRequest request, HttpServletResponse response) {\r
-               // EPUser user = EPUserUtils.getUserSession(request);\r
-               List<FunctionalMenuRole> menuRoleList = null;\r
-               menuRoleList = functionalMenuService.getFunctionalMenuRole();\r
-               return menuRoleList;\r
-       }\r
-\r
-       @RequestMapping(value = {\r
-                       "/portalApi/getNotifications" }, method = RequestMethod.GET, produces = "application/json")\r
-       public PortalRestResponse<List<EpNotificationItem>> getNotifications(HttpServletRequest request,\r
-                       HttpServletResponse response) {\r
-               EPUser user = EPUserUtils.getUserSession(request);\r
-               PortalRestResponse<List<EpNotificationItem>> portalRestResponse = null;\r
-               try {\r
-                       List<EpNotificationItem> notificationList = userNotificationService.getNotifications(user.getId());\r
-                       portalRestResponse = new PortalRestResponse<List<EpNotificationItem>>(PortalRestStatusEnum.OK, "success",\r
-                                       notificationList);\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "getAllAppsAndContacts failed", e);\r
-                       portalRestResponse = new PortalRestResponse<List<EpNotificationItem>>(PortalRestStatusEnum.ERROR,\r
-                                       e.getMessage(), null);\r
-               }\r
-               return portalRestResponse;\r
-       }\r
-\r
-       @RequestMapping(value = {\r
-                       "/portalApi/getAdminNotifications" }, method = RequestMethod.GET, produces = "application/json")\r
-       public List<EpNotificationItemVO> getAdminNotifications(HttpServletRequest request, HttpServletResponse response) {\r
-               List<EpNotificationItemVO> adminNotificationList = null;\r
-               adminNotificationList = userNotificationService.getAdminNotificationVOS();\r
-               return adminNotificationList;\r
-       }\r
-\r
-       @RequestMapping(value = "/portalApi/saveNotification", method = RequestMethod.POST, produces = "application/json")\r
-       public PortalRestResponse<String> save(HttpServletRequest request, HttpServletResponse response,\r
-                       @RequestBody EpNotificationItem notificationItem) {\r
-\r
-               if (notificationItem == null || notificationItem.getMsgHeader() == null)\r
-                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE",\r
-                                       "Notification Header cannot be null or empty");\r
-               if (notificationItem.getEndTime().compareTo(notificationItem.getStartTime()) < 0) {\r
-                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE",\r
-                                       "End Time should be greater than  start time");\r
-               }\r
-\r
-               if ((notificationItem.getIsForAllRoles() == "N") && notificationItem.getRoleIds().isEmpty()) {\r
-                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE",\r
-                                       "No Roles Ids Exist for the selected Roles");\r
-               }\r
-\r
-               Long creatorId = UserUtils.getUserIdAsLong(request);\r
-               notificationItem.setCreatorId(creatorId);\r
-\r
-               // Front-end date picker does not accept a time value, so all\r
-               // values are the start of the chosen day in the local time zone.\r
-               // Move the end time value to the very end of the chosen day.\r
-               // Avoid Calendar.getDefault() which uses the server's locale.\r
-               Long endTime = notificationItem.getEndTime().getTime();\r
-               endTime += (23 * 3600 + 59 * 60 + 59) * 1000;\r
-               notificationItem.getEndTime().setTime(endTime);\r
-\r
-               try {\r
-                       userNotificationService.saveNotification(notificationItem);\r
-               } catch (Exception e) {\r
-                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE", e.getMessage());\r
-               }\r
-               return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "SUCCESS", "");\r
-       }\r
-\r
-       @RequestMapping(value = {\r
-                       "/portalApi/notificationUpdateRate" }, method = RequestMethod.GET, produces = "application/json")\r
-       public PortalRestResponse<Map<String, String>> getNotificationUpdateRate(HttpServletRequest request) {\r
-               try {\r
-                       String updateRate = SystemProperties.getProperty(EPCommonSystemProperties.NOTIFICATION_UPDATE_RATE);\r
-                       String updateDuration = SystemProperties.getProperty(EPCommonSystemProperties.NOTIFICATION_UPDATE_DURATION);\r
-                       Integer rateInMiliSec = Integer.valueOf(updateRate) * 1000;\r
-                       Integer durationInMiliSec = Integer.valueOf(updateDuration) * 1000;\r
-                       Map<String, String> results = new HashMap<String, String>();\r
-                       results.put("updateRate", String.valueOf(rateInMiliSec));\r
-                       results.put("updateDuration", String.valueOf(durationInMiliSec));\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "getNotificationUpdateRate failed", e);\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);\r
-               }\r
-       }\r
-\r
-       @RequestMapping(value = {\r
-                       "/portalApi/notificationRead" }, method = RequestMethod.GET, produces = "application/json")\r
-       public PortalRestResponse<Map<String, String>> notificationRead(\r
-                       @RequestParam("notificationId") String notificationID, HttpServletRequest request) {\r
-               try {\r
-                       userNotificationService.setNotificationRead(Long.parseLong(notificationID), UserUtils.getUserId(request));\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", null);\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "notificationRead failed", e);\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);\r
-               }\r
-       }\r
-\r
-       @RequestMapping(value = {\r
-                       "/portalApi/getNotificationHistory" }, method = RequestMethod.GET, produces = "application/json")\r
-       public List<EpNotificationItemVO> getNotificationHistory(HttpServletRequest request, HttpServletResponse response) {\r
-               EPUser user = EPUserUtils.getUserSession(request);\r
-               List<EpNotificationItemVO> notificationList = null;\r
-               notificationList = userNotificationService.getNotificationHistoryVO(user.getId());\r
-               return notificationList;\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/notificationRole/{notificationId}/roles" }, method = {\r
-                       RequestMethod.GET }, produces = "application/json")\r
-       public List<Integer> testGetRoles(HttpServletRequest request, @PathVariable("notificationId") Long notificationId) {\r
-               List<EpRoleNotificationItem> NotifRoles = userNotificationService.getNotificationRoles(notificationId);\r
-               ArrayList<Integer> rolesList = new ArrayList<Integer>();\r
-               for (EpRoleNotificationItem notifRole : NotifRoles) {\r
-                       rolesList.add(notifRole.roleId);\r
-               }\r
-               return rolesList;\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/getNotificationAppRoles" }, method = {\r
-                       RequestMethod.GET }, produces = "application/json")\r
-       public List<EcompAppRole> getNotificationAppRoles(HttpServletRequest request, HttpServletResponse response) {\r
-               List<EcompAppRole> epAppRoleList = null;\r
-               try {\r
-                       epAppRoleList = userNotificationService.getAppRoleList();\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger,\r
-                                       "Exception occurred while performing UserNofiticationController.getNotificationAppRoles. Details: ",\r
-                                       e);\r
-               }\r
-               return epAppRoleList;\r
-       }\r
-       \r
-       @RequestMapping(value = {\r
-                       "/portalApi/getMessageRecipients" }, method = RequestMethod.GET, produces = "application/json")\r
-       public List<String> getMessageRecipients(@RequestParam("notificationId") Long notificationID) {\r
-               // EPUser user = EPUserUtils.getUserSession(request);\r
-               List<String> messageUserRecipients = null;\r
-               messageUserRecipients = userNotificationService.getMessageRecipients(notificationID);\r
-               return messageUserRecipients;\r
-       }\r
-\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.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.controller;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.openecomp.portalsdk.core.web.support.UserUtils;
+import org.openecomp.portalapp.controller.EPRestrictedBaseController;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.domain.EcompAppRole;
+import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
+import org.openecomp.portalapp.portal.service.FunctionalMenuService;
+import org.openecomp.portalapp.portal.service.UserNotificationService;
+import org.openecomp.portalapp.portal.transport.EpNotificationItem;
+import org.openecomp.portalapp.portal.transport.EpNotificationItemVO;
+import org.openecomp.portalapp.portal.transport.EpRoleNotificationItem;
+import org.openecomp.portalapp.portal.transport.FunctionalMenuRole;
+import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.util.EPUserUtils;
+
+@RestController
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+@EPAuditLog
+public class UserNotificationController extends EPRestrictedBaseController {
+
+       @Autowired
+       FunctionalMenuService functionalMenuService;
+
+       @Autowired
+       UserNotificationService userNotificationService;
+
+       EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserNotificationController.class);
+
+       @RequestMapping(value = {
+                       "/portalApi/getFunctionalMenuRole" }, method = RequestMethod.GET, produces = "application/json")
+       public List<FunctionalMenuRole> getMenuIdRoleId(HttpServletRequest request, HttpServletResponse response) {
+               // EPUser user = EPUserUtils.getUserSession(request);
+               List<FunctionalMenuRole> menuRoleList = null;
+               menuRoleList = functionalMenuService.getFunctionalMenuRole();
+               return menuRoleList;
+       }
+
+       @RequestMapping(value = {
+                       "/portalApi/getNotifications" }, method = RequestMethod.GET, produces = "application/json")
+       public PortalRestResponse<List<EpNotificationItem>> getNotifications(HttpServletRequest request,
+                       HttpServletResponse response) {
+               EPUser user = EPUserUtils.getUserSession(request);
+               PortalRestResponse<List<EpNotificationItem>> portalRestResponse = null;
+               try {
+                       List<EpNotificationItem> notificationList = userNotificationService.getNotifications(user.getId());
+                       portalRestResponse = new PortalRestResponse<List<EpNotificationItem>>(PortalRestStatusEnum.OK, "success",
+                                       notificationList);
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "getAllAppsAndContacts failed", e);
+                       portalRestResponse = new PortalRestResponse<List<EpNotificationItem>>(PortalRestStatusEnum.ERROR,
+                                       e.getMessage(), null);
+               }
+               return portalRestResponse;
+       }
+
+       @RequestMapping(value = {
+                       "/portalApi/getAdminNotifications" }, method = RequestMethod.GET, produces = "application/json")
+       public List<EpNotificationItemVO> getAdminNotifications(HttpServletRequest request, HttpServletResponse response) {
+               List<EpNotificationItemVO> adminNotificationList = null;
+               EPUser user = EPUserUtils.getUserSession(request);
+               adminNotificationList = userNotificationService.getAdminNotificationVOS(user.getId());
+               return adminNotificationList;
+       }
+
+       @RequestMapping(value = "/portalApi/saveNotification", method = RequestMethod.POST, produces = "application/json")
+       public PortalRestResponse<String> save(HttpServletRequest request, HttpServletResponse response,
+                       @RequestBody EpNotificationItem notificationItem) {
+
+               if (notificationItem == null || notificationItem.getMsgHeader() == null)
+                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE",
+                                       "Notification Header cannot be null or empty");
+               if (notificationItem.getEndTime().compareTo(notificationItem.getStartTime()) < 0) {
+                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE",
+                                       "End Time should be greater than  start time");
+               }
+
+               if ((notificationItem.getIsForAllRoles() == "N") && notificationItem.getRoleIds().isEmpty()) {
+                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE",
+                                       "No Roles Ids Exist for the selected Roles");
+               }
+
+               Long creatorId = UserUtils.getUserIdAsLong(request);
+               notificationItem.setCreatorId(creatorId);
+
+               // Front-end date picker does not accept a time value, so all
+               // values are the start of the chosen day in the local time zone.
+               // Move the end time value to the very end of the chosen day.
+               // Avoid Calendar.getDefault() which uses the server's locale.
+               Long endTime = notificationItem.getEndTime().getTime();
+               endTime += (23 * 3600 + 59 * 60 + 59) * 1000;
+               notificationItem.getEndTime().setTime(endTime);
+
+               try {
+                       userNotificationService.saveNotification(notificationItem);
+               } catch (Exception e) {
+                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE", e.getMessage());
+               }
+               return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "SUCCESS", "");
+       }
+
+       @RequestMapping(value = {
+                       "/portalApi/notificationUpdateRate" }, method = RequestMethod.GET, produces = "application/json")
+       public PortalRestResponse<Map<String, String>> getNotificationUpdateRate(HttpServletRequest request) {
+               try {
+                       String updateRate = SystemProperties.getProperty(EPCommonSystemProperties.NOTIFICATION_UPDATE_RATE);
+                       String updateDuration = SystemProperties.getProperty(EPCommonSystemProperties.NOTIFICATION_UPDATE_DURATION);
+                       Integer rateInMiliSec = Integer.valueOf(updateRate) * 1000;
+                       Integer durationInMiliSec = Integer.valueOf(updateDuration) * 1000;
+                       Map<String, String> results = new HashMap<String, String>();
+                       results.put("updateRate", String.valueOf(rateInMiliSec));
+                       results.put("updateDuration", String.valueOf(durationInMiliSec));
+                       return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "getNotificationUpdateRate failed", e);
+                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);
+               }
+       }
+
+       @RequestMapping(value = {
+                       "/portalApi/notificationRead" }, method = RequestMethod.GET, produces = "application/json")
+       public PortalRestResponse<Map<String, String>> notificationRead(
+                       @RequestParam("notificationId") String notificationID, HttpServletRequest request) {
+               try {
+                       userNotificationService.setNotificationRead(Long.parseLong(notificationID), UserUtils.getUserId(request));
+                       return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", null);
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "notificationRead failed", e);
+                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);
+               }
+       }
+
+       @RequestMapping(value = {
+                       "/portalApi/getNotificationHistory" }, method = RequestMethod.GET, produces = "application/json")
+       public List<EpNotificationItemVO> getNotificationHistory(HttpServletRequest request, HttpServletResponse response) {
+               EPUser user = EPUserUtils.getUserSession(request);
+               List<EpNotificationItemVO> notificationList = null;
+               notificationList = userNotificationService.getNotificationHistoryVO(user.getId());
+               return notificationList;
+       }
+
+       @RequestMapping(value = { "/portalApi/notificationRole/{notificationId}/roles" }, method = {
+                       RequestMethod.GET }, produces = "application/json")
+       public List<Integer> testGetRoles(HttpServletRequest request, @PathVariable("notificationId") Long notificationId) {
+               List<EpRoleNotificationItem> NotifRoles = userNotificationService.getNotificationRoles(notificationId);
+               ArrayList<Integer> rolesList = new ArrayList<Integer>();
+               for (EpRoleNotificationItem notifRole : NotifRoles) {
+                       rolesList.add(notifRole.roleId);
+               }
+               return rolesList;
+       }
+
+       @RequestMapping(value = { "/portalApi/getNotificationAppRoles" }, method = {
+                       RequestMethod.GET }, produces = "application/json")
+       public List<EcompAppRole> getNotificationAppRoles(HttpServletRequest request, HttpServletResponse response) {
+               List<EcompAppRole> epAppRoleList = null;
+               try {
+                       epAppRoleList = userNotificationService.getAppRoleList();
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger,
+                                       "Exception occurred while performing UserNofiticationController.getNotificationAppRoles. Details: ",
+                                       e);
+               }
+               return epAppRoleList;
+       }
+
+       @RequestMapping(value = {
+                       "/portalApi/getMessageRecipients" }, method = RequestMethod.GET, produces = "application/json")
+       public List<String> getMessageRecipients(@RequestParam("notificationId") Long notificationID) {
+               // EPUser user = EPUserUtils.getUserSession(request);
+               List<String> messageUserRecipients = null;
+               messageUserRecipients = userNotificationService.getMessageRecipients(notificationID);
+               return messageUserRecipients;
+       }
+
+}