2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 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============================================
38 package org.onap.portalapp.portal.service;
40 import java.util.Date;
41 import java.util.HashMap;
42 import java.util.HashSet;
43 import java.util.List;
47 import org.hibernate.SessionFactory;
48 import org.onap.portalapp.portal.domain.EPUser;
49 import org.onap.portalapp.portal.domain.EPUserNotification;
50 import org.onap.portalapp.portal.domain.EcompAppRole;
51 import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
52 import org.onap.portalapp.portal.transport.EpNotificationItem;
53 import org.onap.portalapp.portal.transport.EpNotificationItemVO;
54 import org.onap.portalapp.portal.transport.EpRoleNotificationItem;
55 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
56 import org.onap.portalsdk.core.service.DataAccessService;
57 import org.springframework.beans.factory.annotation.Autowired;
58 import org.springframework.context.annotation.EnableAspectJAutoProxy;
59 import org.springframework.stereotype.Service;
61 @Service("userNotificationService")
62 @org.springframework.context.annotation.Configuration
63 @EnableAspectJAutoProxy
65 public class UserNotificationServiceImpl implements UserNotificationService {
66 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuServiceImpl.class);
69 private DataAccessService dataAccessService;
71 private SessionFactory sessionFactory;
76 * @see org.onap.portalapp.portal.service.UserNotificationService#
77 * getNotifications(java.lang.Long)
80 public List<EpNotificationItem> getNotifications(Long userId) {
81 Map<String, String> params = new HashMap<String, String>();
82 params.put("user_id", userId.toString());
83 @SuppressWarnings("unchecked")
84 List<EpNotificationItem> notificationList = dataAccessService.executeNamedQuery("getNotifications", params,
86 // set the roles to null for pure retrieval of all notifications
87 for (EpNotificationItem item : notificationList) {
90 return notificationList;
96 * @see org.onap.portalapp.portal.service.UserNotificationService#
97 * getNotificationHistoryVO(java.lang.Long)
100 public List<EpNotificationItemVO> getNotificationHistoryVO(Long userId) {
101 Map<String, String> params = new HashMap<String, String>();
102 params.put("user_id", userId.toString());
103 @SuppressWarnings("unchecked")
104 List<EpNotificationItemVO> notificationList = dataAccessService.executeNamedQuery("getNotificationHistoryVO",
106 return notificationList;
112 * @see org.onap.portalapp.portal.service.UserNotificationService#
113 * getAdminNotificationVOS()
116 public List<EpNotificationItemVO> getAdminNotificationVOS(Long userId) {
117 Map<String, String> params = new HashMap<String, String>();
118 params.put("user_id", userId.toString());
119 @SuppressWarnings("unchecked")
120 List<EpNotificationItemVO> notificationList = dataAccessService
121 .executeNamedQuery("getAdminNotificationHistoryVO", params, null);
122 return notificationList;
128 * @see org.onap.portalapp.portal.service.UserNotificationService#
129 * getNotificationRoles(java.lang.Long)
132 public List<EpRoleNotificationItem> getNotificationRoles(Long notificationId) {
133 Map<String, String> params = new HashMap<String, String>();
134 params.put("notificationId", Long.toString(notificationId));
135 @SuppressWarnings("unchecked")
136 List<EpRoleNotificationItem> roleNotifList = dataAccessService.executeNamedQuery("getNotificationRoles", params,
138 return roleNotifList;
144 * @see org.onap.portalapp.portal.service.UserNotificationService#
147 @SuppressWarnings("unchecked")
149 public List<EcompAppRole> getAppRoleList() {
150 List<EcompAppRole> appRoleList = (List<EcompAppRole>) dataAccessService
151 .executeNamedQuery("getEpNotificationAppRoles", null, null);
158 * @see org.onap.portalapp.portal.service.UserNotificationService#
159 * setNotificationsRead(java.lang.Long, int)
162 public void setNotificationRead(Long notificationId, int userId) {
163 EPUserNotification userNotification = new EPUserNotification();
164 userNotification.setNotificationId(notificationId);
165 userNotification.setUpdateTime(new Date());
166 userNotification.setViewed("Y");
167 userNotification.setUserId((long) userId);
168 getDataAccessService().saveDomainObject(userNotification, null);
174 * @see org.onap.portalapp.portal.service.UserNotificationService#
175 * saveNotification(org.onap.portalapp.portal.transport.
176 * EpNotificationItem)
179 public String saveNotification(EpNotificationItem notificationItem) throws Exception {
182 if (notificationItem.getRoleIds() != null && !notificationItem.getIsForAllRoles().equals("Y")) {
183 if (notificationItem.getRoles() == null) {
184 Set<EpRoleNotificationItem> roleSet = new HashSet<EpRoleNotificationItem>();
185 notificationItem.setRoles(roleSet);
187 for (Long roleId : notificationItem.getRoleIds()) {
188 EpRoleNotificationItem roleItem = new EpRoleNotificationItem();
189 roleItem.setNotificationId(notificationItem.getNotificationId());
190 roleItem.setRoleId(roleId.intValue());
191 notificationItem.getRoles().add(roleItem);
195 // for updates fetch roles and then save
196 if (notificationItem.getNotificationId() != null) {
197 EpNotificationItem updateNotificationItem = (EpNotificationItem) getDataAccessService()
198 .getDomainObject(EpNotificationItem.class, notificationItem.getNotificationId(), null);
199 if(updateNotificationItem != null) {
200 notificationItem.setRoles(updateNotificationItem.getRoles());
203 if (notificationItem.msgSource == null) {
204 notificationItem.setMsgSource("EP");
206 getDataAccessService().saveDomainObject(notificationItem, null);
212 public List<EPUser> getUsersByOrgIds(List<String> OrgIds) {
213 Map<String, Object> params = new HashMap<String, Object>();
214 params.put("OrgIds", OrgIds);
215 @SuppressWarnings("unchecked")
216 List<EPUser> userList = dataAccessService.executeNamedQuery("getUsersByOrgIdsNotifications", params, null);
221 public List<String> getMessageRecipients(Long notificationId) {
222 Map<String, String> params = new HashMap<>();
223 params.put("notificationId", Long.toString(notificationId));
224 @SuppressWarnings("unchecked")
225 List<String> activeUsers = dataAccessService.executeNamedQuery("messageRecipients", params, null);
229 public DataAccessService getDataAccessService() {
230 return dataAccessService;
233 public void setDataAccessService(DataAccessService dataAccessService) {
234 this.dataAccessService = dataAccessService;
237 public SessionFactory getSessionFactory() {
238 return sessionFactory;
241 public void setSessionFactory(SessionFactory sessionFactory) {
242 this.sessionFactory = sessionFactory;
246 public void deleteNotificationsFromEpNotificationTable() {
247 Map<String, String> params = new HashMap<String, String>();
248 dataAccessService.executeNamedQuery("deleteNotificationsFromEpNotificationTable", params, null);
252 public void deleteNotificationsFromEpUserNotificationTable() {
253 Map<String, String> params = new HashMap<String, String>();
254 dataAccessService.executeNamedQuery("deleteNotificationsFromEpUserNotificationTable", params, null);
259 public void deleteNotificationsFromEpRoleNotificationTable() {
260 Map<String, String> params = new HashMap<String, String>();
261 dataAccessService.executeNamedQuery("deleteNotificationsFromEpRoleNotificationTable", params, null);