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 * ================================================================================
20 package org.openecomp.portalapp.portal.service;
22 import java.util.Date;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.List;
29 import org.hibernate.SessionFactory;
30 import org.openecomp.portalapp.portal.domain.EPUser;
31 import org.openecomp.portalapp.portal.domain.EPUserNotification;
32 import org.openecomp.portalapp.portal.domain.EcompAppRole;
33 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
34 import org.openecomp.portalapp.portal.transport.EpNotificationItem;
35 import org.openecomp.portalapp.portal.transport.EpNotificationItemVO;
36 import org.openecomp.portalapp.portal.transport.EpRoleNotificationItem;
37 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
38 import org.openecomp.portalsdk.core.service.DataAccessService;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.context.annotation.EnableAspectJAutoProxy;
41 import org.springframework.stereotype.Service;
43 @Service("userNotificationService")
44 @org.springframework.context.annotation.Configuration
45 @EnableAspectJAutoProxy
47 public class UserNotificationServiceImpl implements UserNotificationService {
48 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuServiceImpl.class);
51 private DataAccessService dataAccessService;
53 private SessionFactory sessionFactory;
58 * @see org.openecomp.portalapp.portal.service.UserNotificationService#
59 * getNotifications(java.lang.Long)
62 public List<EpNotificationItem> getNotifications(Long userId) {
63 Map<String, String> params = new HashMap<String, String>();
64 params.put("user_id", userId.toString());
65 @SuppressWarnings("unchecked")
66 List<EpNotificationItem> notificationList = dataAccessService.executeNamedQuery("getNotifications", params,
68 // set the roles to null for pure retrieval of all notifications
69 for (EpNotificationItem item : notificationList) {
72 return notificationList;
78 * @see org.openecomp.portalapp.portal.service.UserNotificationService#
79 * getNotificationHistoryVO(java.lang.Long)
82 public List<EpNotificationItemVO> getNotificationHistoryVO(Long userId) {
83 Map<String, String> params = new HashMap<String, String>();
84 params.put("user_id", userId.toString());
85 @SuppressWarnings("unchecked")
86 List<EpNotificationItemVO> notificationList = dataAccessService.executeNamedQuery("getNotificationHistoryVO",
88 return notificationList;
94 * @see org.openecomp.portalapp.portal.service.UserNotificationService#
95 * getAdminNotificationVOS()
98 public List<EpNotificationItemVO> getAdminNotificationVOS(Long userId) {
99 Map<String, String> params = new HashMap<String, String>();
100 params.put("user_id", userId.toString());
101 @SuppressWarnings("unchecked")
102 List<EpNotificationItemVO> notificationList = dataAccessService
103 .executeNamedQuery("getAdminNotificationHistoryVO", params, null);
104 return notificationList;
110 * @see org.openecomp.portalapp.portal.service.UserNotificationService#
111 * getNotificationRoles(java.lang.Long)
114 public List<EpRoleNotificationItem> getNotificationRoles(Long notificationId) {
115 Map<String, String> params = new HashMap<String, String>();
116 params.put("notificationId", Long.toString(notificationId));
117 @SuppressWarnings("unchecked")
118 List<EpRoleNotificationItem> roleNotifList = dataAccessService.executeNamedQuery("getNotificationRoles", params,
120 return roleNotifList;
126 * @see org.openecomp.portalapp.portal.service.UserNotificationService#
129 @SuppressWarnings("unchecked")
131 public List<EcompAppRole> getAppRoleList() {
132 List<EcompAppRole> appRoleList = (List<EcompAppRole>) dataAccessService
133 .executeNamedQuery("getEpNotificationAppRoles", null, null);
140 * @see org.openecomp.portalapp.portal.service.UserNotificationService#
141 * setNotificationsRead(java.lang.Long, int)
144 public void setNotificationRead(Long notificationId, int userId) {
145 EPUserNotification userNotification = new EPUserNotification();
146 userNotification.setNotificationId(notificationId);
147 userNotification.setUpdateTime(new Date());
148 userNotification.setViewed("Y");
149 userNotification.setUserId((long) userId);
150 getDataAccessService().saveDomainObject(userNotification, null);
156 * @see org.openecomp.portalapp.portal.service.UserNotificationService#
157 * saveNotification(org.openecomp.portalapp.portal.transport.
158 * EpNotificationItem)
161 public String saveNotification(EpNotificationItem notificationItem) throws Exception {
164 if (notificationItem.getRoleIds() != null && !notificationItem.getIsForAllRoles().equals("Y")) {
165 if (notificationItem.getRoles() == null) {
166 Set<EpRoleNotificationItem> roleSet = new HashSet<EpRoleNotificationItem>();
167 notificationItem.setRoles(roleSet);
169 for (Long roleId : notificationItem.getRoleIds()) {
170 EpRoleNotificationItem roleItem = new EpRoleNotificationItem();
171 roleItem.setNotificationId(notificationItem.getNotificationId());
172 roleItem.setRoleId(roleId.intValue());
173 notificationItem.getRoles().add(roleItem);
177 // for updates fetch roles and then save
178 if (notificationItem.getNotificationId() != null) {
179 EpNotificationItem updateNotificationItem = (EpNotificationItem) getDataAccessService()
180 .getDomainObject(EpNotificationItem.class, notificationItem.getNotificationId(), null);
181 notificationItem.setRoles(updateNotificationItem.getRoles());
183 if (notificationItem.msgSource == null) {
184 notificationItem.setMsgSource("EP");
186 getDataAccessService().saveDomainObject(notificationItem, null);
192 public List<EPUser> getUsersByOrgIds(List<String> OrgIds) {
193 Map<String, Object> params = new HashMap<String, Object>();
194 params.put("OrgIds", OrgIds);
195 @SuppressWarnings("unchecked")
196 List<EPUser> userList = dataAccessService.executeNamedQuery("getUsersByOrgIdsNotifications", params, null);
201 public List<String> getMessageRecipients(Long notificationId) {
202 Map<String, String> params = new HashMap<>();
203 params.put("notificationId", Long.toString(notificationId));
204 @SuppressWarnings("unchecked")
205 List<String> activeUsers = dataAccessService.executeNamedQuery("messageRecipients", params, null);
209 public DataAccessService getDataAccessService() {
210 return dataAccessService;
213 public void setDataAccessService(DataAccessService dataAccessService) {
214 this.dataAccessService = dataAccessService;
217 public SessionFactory getSessionFactory() {
218 return sessionFactory;
221 public void setSessionFactory(SessionFactory sessionFactory) {
222 this.sessionFactory = sessionFactory;
226 public void deleteNotificationsFromEpNotificationTable() {
227 Map<String, String> params = new HashMap<String, String>();
228 dataAccessService.executeNamedUpdateQuery("deleteNotificationsFromEpNotificationTable", params, null);
232 public void deleteNotificationsFromEpUserNotificationTable() {
233 Map<String, String> params = new HashMap<String, String>();
234 dataAccessService.executeNamedUpdateQuery("deleteNotificationsFromEpUserNotificationTable", params, null);
239 public void deleteNotificationsFromEpRoleNotificationTable() {
240 Map<String, String> params = new HashMap<String, String>();
241 dataAccessService.executeNamedUpdateQuery("deleteNotificationsFromEpRoleNotificationTable", params, null);