2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.portal.controller;
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.List;
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpServletResponse;
48 import org.springframework.beans.factory.annotation.Autowired;
49 import org.springframework.context.annotation.EnableAspectJAutoProxy;
50 import org.springframework.web.bind.annotation.PathVariable;
51 import org.springframework.web.bind.annotation.RequestBody;
52 import org.springframework.web.bind.annotation.RequestMapping;
53 import org.springframework.web.bind.annotation.RequestMethod;
54 import org.springframework.web.bind.annotation.RequestParam;
55 import org.springframework.web.bind.annotation.RestController;
57 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
58 import org.openecomp.portalsdk.core.util.SystemProperties;
59 import org.openecomp.portalsdk.core.web.support.UserUtils;
60 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
61 import org.openecomp.portalapp.portal.domain.EPUser;
62 import org.openecomp.portalapp.portal.domain.EcompAppRole;
63 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
64 import org.openecomp.portalapp.portal.service.FunctionalMenuService;
65 import org.openecomp.portalapp.portal.service.UserNotificationService;
66 import org.openecomp.portalapp.portal.transport.EpNotificationItem;
67 import org.openecomp.portalapp.portal.transport.EpNotificationItemVO;
68 import org.openecomp.portalapp.portal.transport.EpRoleNotificationItem;
69 import org.openecomp.portalapp.portal.transport.FunctionalMenuRole;
70 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
71 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
72 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
73 import org.openecomp.portalapp.util.EPUserUtils;
76 @org.springframework.context.annotation.Configuration
77 @EnableAspectJAutoProxy
79 public class UserNotificationController extends EPRestrictedBaseController {
82 FunctionalMenuService functionalMenuService;
85 UserNotificationService userNotificationService;
87 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserNotificationController.class);
89 @RequestMapping(value = {
90 "/portalApi/getFunctionalMenuRole" }, method = RequestMethod.GET, produces = "application/json")
91 public List<FunctionalMenuRole> getMenuIdRoleId(HttpServletRequest request, HttpServletResponse response) {
92 // EPUser user = EPUserUtils.getUserSession(request);
93 List<FunctionalMenuRole> menuRoleList = null;
94 menuRoleList = functionalMenuService.getFunctionalMenuRole();
98 @RequestMapping(value = {
99 "/portalApi/getNotifications" }, method = RequestMethod.GET, produces = "application/json")
100 public PortalRestResponse<List<EpNotificationItem>> getNotifications(HttpServletRequest request,
101 HttpServletResponse response) {
102 EPUser user = EPUserUtils.getUserSession(request);
103 PortalRestResponse<List<EpNotificationItem>> portalRestResponse = null;
105 List<EpNotificationItem> notificationList = userNotificationService.getNotifications(user.getId());
106 portalRestResponse = new PortalRestResponse<List<EpNotificationItem>>(PortalRestStatusEnum.OK, "success",
108 } catch (Exception e) {
109 logger.error(EELFLoggerDelegate.errorLogger, "getAllAppsAndContacts failed", e);
110 portalRestResponse = new PortalRestResponse<List<EpNotificationItem>>(PortalRestStatusEnum.ERROR,
111 e.getMessage(), null);
113 return portalRestResponse;
116 @RequestMapping(value = {
117 "/portalApi/getAdminNotifications" }, method = RequestMethod.GET, produces = "application/json")
118 public List<EpNotificationItemVO> getAdminNotifications(HttpServletRequest request, HttpServletResponse response) {
119 List<EpNotificationItemVO> adminNotificationList = null;
120 EPUser user = EPUserUtils.getUserSession(request);
121 adminNotificationList = userNotificationService.getAdminNotificationVOS(user.getId());
122 return adminNotificationList;
125 @RequestMapping(value = "/portalApi/saveNotification", method = RequestMethod.POST, produces = "application/json")
126 public PortalRestResponse<String> save(HttpServletRequest request, HttpServletResponse response,
127 @RequestBody EpNotificationItem notificationItem) {
129 if (notificationItem == null || notificationItem.getMsgHeader() == null)
130 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE",
131 "Notification Header cannot be null or empty");
132 if (notificationItem.getEndTime().compareTo(notificationItem.getStartTime()) < 0) {
133 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE",
134 "End Time should be greater than start time");
137 if ((notificationItem.getIsForAllRoles() == "N") && notificationItem.getRoleIds().isEmpty()) {
138 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE",
139 "No Roles Ids Exist for the selected Roles");
142 Long creatorId = UserUtils.getUserIdAsLong(request);
143 notificationItem.setCreatorId(creatorId);
145 // Front-end date picker does not accept a time value, so all
146 // values are the start of the chosen day in the local time zone.
147 // Move the end time value to the very end of the chosen day.
148 // Avoid Calendar.getDefault() which uses the server's locale.
149 Long endTime = notificationItem.getEndTime().getTime();
150 endTime += (23 * 3600 + 59 * 60 + 59) * 1000;
151 notificationItem.getEndTime().setTime(endTime);
154 userNotificationService.saveNotification(notificationItem);
155 } catch (Exception e) {
156 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE", e.getMessage());
158 return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "SUCCESS", "");
161 @RequestMapping(value = {
162 "/portalApi/notificationUpdateRate" }, method = RequestMethod.GET, produces = "application/json")
163 public PortalRestResponse<Map<String, String>> getNotificationUpdateRate(HttpServletRequest request) {
165 String updateRate = SystemProperties.getProperty(EPCommonSystemProperties.NOTIFICATION_UPDATE_RATE);
166 String updateDuration = SystemProperties.getProperty(EPCommonSystemProperties.NOTIFICATION_UPDATE_DURATION);
167 Integer rateInMiliSec = Integer.valueOf(updateRate) * 1000;
168 Integer durationInMiliSec = Integer.valueOf(updateDuration) * 1000;
169 Map<String, String> results = new HashMap<String, String>();
170 results.put("updateRate", String.valueOf(rateInMiliSec));
171 results.put("updateDuration", String.valueOf(durationInMiliSec));
172 return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);
173 } catch (Exception e) {
174 logger.error(EELFLoggerDelegate.errorLogger, "getNotificationUpdateRate failed", e);
175 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);
179 @RequestMapping(value = {
180 "/portalApi/notificationRead" }, method = RequestMethod.GET, produces = "application/json")
181 public PortalRestResponse<Map<String, String>> notificationRead(
182 @RequestParam("notificationId") String notificationID, HttpServletRequest request) {
184 userNotificationService.setNotificationRead(Long.parseLong(notificationID), UserUtils.getUserId(request));
185 return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", null);
186 } catch (Exception e) {
187 logger.error(EELFLoggerDelegate.errorLogger, "notificationRead failed", e);
188 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);
192 @RequestMapping(value = {
193 "/portalApi/getNotificationHistory" }, method = RequestMethod.GET, produces = "application/json")
194 public List<EpNotificationItemVO> getNotificationHistory(HttpServletRequest request, HttpServletResponse response) {
195 EPUser user = EPUserUtils.getUserSession(request);
196 List<EpNotificationItemVO> notificationList = null;
197 notificationList = userNotificationService.getNotificationHistoryVO(user.getId());
198 return notificationList;
201 @RequestMapping(value = { "/portalApi/notificationRole/{notificationId}/roles" }, method = {
202 RequestMethod.GET }, produces = "application/json")
203 public List<Integer> testGetRoles(HttpServletRequest request, @PathVariable("notificationId") Long notificationId) {
204 List<EpRoleNotificationItem> NotifRoles = userNotificationService.getNotificationRoles(notificationId);
205 ArrayList<Integer> rolesList = new ArrayList<Integer>();
206 for (EpRoleNotificationItem notifRole : NotifRoles) {
207 rolesList.add(notifRole.roleId);
212 @RequestMapping(value = { "/portalApi/getNotificationAppRoles" }, method = {
213 RequestMethod.GET }, produces = "application/json")
214 public List<EcompAppRole> getNotificationAppRoles(HttpServletRequest request, HttpServletResponse response) {
215 List<EcompAppRole> epAppRoleList = null;
217 epAppRoleList = userNotificationService.getAppRoleList();
218 } catch (Exception e) {
219 logger.error(EELFLoggerDelegate.errorLogger,
220 "Exception occurred while performing UserNofiticationController.getNotificationAppRoles. Details: ",
223 return epAppRoleList;
226 @RequestMapping(value = {
227 "/portalApi/getMessageRecipients" }, method = RequestMethod.GET, produces = "application/json")
228 public List<String> getMessageRecipients(@RequestParam("notificationId") Long notificationID) {
229 // EPUser user = EPUserUtils.getUserSession(request);
230 List<String> messageUserRecipients = null;
231 messageUserRecipients = userNotificationService.getMessageRecipients(notificationID);
232 return messageUserRecipients;