2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
20 package org.openecomp.portalapp.portal.service;
\r
22 import java.util.Date;
\r
23 import java.util.HashMap;
\r
24 import java.util.HashSet;
\r
25 import java.util.List;
\r
26 import java.util.Map;
\r
27 import java.util.Set;
\r
29 import org.hibernate.SessionFactory;
\r
30 import org.openecomp.portalapp.portal.domain.EPUser;
\r
31 import org.openecomp.portalapp.portal.domain.EPUserNotification;
\r
32 import org.openecomp.portalapp.portal.domain.EcompAppRole;
\r
33 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
\r
34 import org.openecomp.portalapp.portal.transport.EpNotificationItem;
\r
35 import org.openecomp.portalapp.portal.transport.EpNotificationItemVO;
\r
36 import org.openecomp.portalapp.portal.transport.EpRoleNotificationItem;
\r
37 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
38 import org.openecomp.portalsdk.core.service.DataAccessService;
\r
39 import org.springframework.beans.factory.annotation.Autowired;
\r
40 import org.springframework.context.annotation.EnableAspectJAutoProxy;
\r
41 import org.springframework.stereotype.Service;
\r
43 @Service("userNotificationService")
\r
44 @org.springframework.context.annotation.Configuration
\r
45 @EnableAspectJAutoProxy
\r
47 public class UserNotificationServiceImpl implements UserNotificationService {
\r
48 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuServiceImpl.class);
\r
51 private DataAccessService dataAccessService;
\r
53 private SessionFactory sessionFactory;
\r
57 * @see org.openecomp.portalapp.portal.service.UserNotificationService#getNotifications(java.lang.Long)
\r
60 public List<EpNotificationItem> getNotifications(Long userId) {
\r
61 Map<String, String> params = new HashMap<String, String>();
\r
62 params.put("user_id", userId.toString());
\r
63 @SuppressWarnings("unchecked")
\r
64 List<EpNotificationItem> notificationList = dataAccessService.executeNamedQuery("getNotifications", params,
\r
66 // set the roles to null for pure retrieval of all notifications
\r
67 for (EpNotificationItem item : notificationList) {
\r
68 item.setRoles(null);
\r
70 return notificationList;
\r
75 * @see org.openecomp.portalapp.portal.service.UserNotificationService#getNotificationHistoryVO(java.lang.Long)
\r
78 public List<EpNotificationItemVO> getNotificationHistoryVO(Long userId) {
\r
79 Map<String, String> params = new HashMap<String, String>();
\r
80 params.put("user_id", userId.toString());
\r
81 @SuppressWarnings("unchecked")
\r
82 List<EpNotificationItemVO> notificationList = dataAccessService.executeNamedQuery("getNotificationHistoryVO",
\r
84 return notificationList;
\r
89 * @see org.openecomp.portalapp.portal.service.UserNotificationService#getAdminNotificationVOS()
\r
92 public List<EpNotificationItemVO> getAdminNotificationVOS() {
\r
93 Map<String, String> params = new HashMap<String, String>();
\r
94 @SuppressWarnings("unchecked")
\r
95 List<EpNotificationItemVO> notificationList = dataAccessService
\r
96 .executeNamedQuery("getAdminNotificationHistoryVO", params, null);
\r
97 return notificationList;
\r
102 * @see org.openecomp.portalapp.portal.service.UserNotificationService#getNotificationRoles(java.lang.Long)
\r
105 public List<EpRoleNotificationItem> getNotificationRoles(Long notificationId) {
\r
106 Map<String, String> params = new HashMap<String, String>();
\r
107 params.put("notificationId", Long.toString(notificationId));
\r
108 @SuppressWarnings("unchecked")
\r
109 List<EpRoleNotificationItem> roleNotifList = dataAccessService.executeNamedQuery("getNotificationRoles", params,
\r
111 return roleNotifList;
\r
116 * @see org.openecomp.portalapp.portal.service.UserNotificationService#getAppRoleList()
\r
118 @SuppressWarnings("unchecked")
\r
120 public List<EcompAppRole> getAppRoleList() {
\r
121 List<EcompAppRole> appRoleList = (List<EcompAppRole>) dataAccessService.executeNamedQuery("getEpNotificationAppRoles", null, null);
\r
122 return appRoleList;
\r
128 * @see org.openecomp.portalapp.portal.service.UserNotificationService#
\r
129 * setNotificationsRead(java.lang.Long, int)
\r
132 public void setNotificationRead(Long notificationId, int userId) {
\r
133 EPUserNotification userNotification = new EPUserNotification();
\r
134 userNotification.setNotificationId(notificationId);
\r
135 userNotification.setUpdateTime(new Date());
\r
136 userNotification.setViewed("Y");
\r
137 userNotification.setUserId((long) userId);
\r
138 getDataAccessService().saveDomainObject(userNotification, null);
\r
143 * @see org.openecomp.portalapp.portal.service.UserNotificationService#saveNotification(org.openecomp.portalapp.portal.transport.EpNotificationItem)
\r
146 public String saveNotification(EpNotificationItem notificationItem) throws Exception {
\r
148 // gather the roles
\r
149 if (notificationItem.getRoleIds() != null && !notificationItem.getIsForAllRoles().equals("Y")) {
\r
150 if (notificationItem.getRoles() == null) {
\r
151 Set<EpRoleNotificationItem> roleSet = new HashSet<EpRoleNotificationItem>();
\r
152 notificationItem.setRoles(roleSet);
\r
154 for (Long roleId : notificationItem.getRoleIds()) {
\r
155 EpRoleNotificationItem roleItem = new EpRoleNotificationItem();
\r
156 roleItem.setNotificationId(notificationItem.getNotificationId());
\r
157 roleItem.setRoleId(roleId.intValue());
\r
158 notificationItem.getRoles().add(roleItem);
\r
163 // for updates fetch roles and then save
\r
164 if (notificationItem.getNotificationId() != null) {
\r
165 EpNotificationItem updateNotificationItem = (EpNotificationItem) getDataAccessService()
\r
166 .getDomainObject(EpNotificationItem.class, notificationItem.getNotificationId(), null);
\r
167 notificationItem.setRoles(updateNotificationItem.getRoles());
\r
169 if(notificationItem.msgSource == null)
\r
171 notificationItem.setMsgSource("EP");
\r
173 getDataAccessService().saveDomainObject(notificationItem, null);
\r
178 public List<EPUser> getUsersByOrgIds(List<String> OrgIds) {
\r
179 Map<String, Object> params = new HashMap<String, Object>();
\r
180 params.put("OrgIds", OrgIds);
\r
181 @SuppressWarnings("unchecked")
\r
182 List<EPUser> userList = dataAccessService.executeNamedQuery("getUsersByOrgIdsNotifications", params, null);
\r
187 public List<String> getMessageRecipients(Long notificationId) {
\r
188 Map<String, String> params = new HashMap<>();
\r
189 params.put("notificationId", Long.toString(notificationId));
\r
190 @SuppressWarnings("unchecked")
\r
191 List<String> activeUsers = dataAccessService.executeNamedQuery("messageRecipients", params, null);
\r
192 return activeUsers;
\r
195 public DataAccessService getDataAccessService() {
\r
196 return dataAccessService;
\r
199 public void setDataAccessService(DataAccessService dataAccessService) {
\r
200 this.dataAccessService = dataAccessService;
\r
203 public SessionFactory getSessionFactory() {
\r
204 return sessionFactory;
\r
207 public void setSessionFactory(SessionFactory sessionFactory) {
\r
208 this.sessionFactory = sessionFactory;
\r