2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
41 package org.onap.portal.service;
43 import java.util.List;
44 import javax.persistence.EntityManager;
45 import javax.transaction.Transactional;
46 import org.onap.portal.domain.dto.transport.EpNotificationItemVO;
47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.stereotype.Service;
52 public class EpNotificationItemVOService {
54 private final EntityManager entityManager;
56 private final String notificationHistoryVOResult =
58 + "\t\t\tnotificationId, isForOnlineUsers, isForAllRoles, msgHeader,\tmsgDescription,msgSource,\n"
59 + "\t\t\tstartTime, endTime, priority, createdDate,notificationHyperlink,creatorId, loginId,\tactiveYn \n"
62 + "\t\t\t\t\tselect distinct \n"
63 + "\t\t\t\t\ta.notification_ID AS notificationId, \n"
64 + "\t\t\t\t\tis_for_online_users AS isForOnlineUsers, \n"
65 + "\t\t\t\t\tis_for_all_roles AS isForAllRoles, \n"
66 + "\t\t\t\t\tmsg_header AS msgHeader, \n"
67 + "\t\t\t\t\tmsg_description AS msgDescription,\n"
68 + "\t\t\t\t\tmsg_source AS msgSource, \n"
69 + "\t\t\t\t\tstart_Time AS startTime, \n"
70 + "\t\t\t\t\tend_time AS endTime, \n"
71 + "\t\t\t\t\tpriority,\n"
72 + "\t\t\t\t\tcreated_date AS createdDate, \n"
73 + "\t\t\t\t\tcreator_ID AS creatorId,\n"
74 + "\t\t\t\t\tnotification_hyperlink AS notificationHyperlink,\n"
75 + "\t\t\t\t\tlogin_id AS loginId,\n"
76 + "\t\t\t\t\tactive_YN AS activeYn, \n"
77 + "\t\t\t\t\tif (is_viewed is null, 'N', is_viewed)\n"
81 + "\t\t\t\t\tuser_id, login_id,notification_id, is_for_online_users, is_for_all_roles, \n"
82 + "\t\t\t\t\tmsg_header, msg_description,msg_source, start_Time, end_time, priority, created_date, \n"
83 + "\t\t\t\t\tcreator_ID,notification_hyperlink,active_YN\n"
86 + "\t\t\t\t\tselect a.notification_ID,a.is_for_online_users,a.is_for_all_roles,a.active_YN,\n"
87 + "\t\t\t\t\ta.msg_header,a.msg_description,a.msg_source,a.start_time,a.end_time,a.priority,a.creator_ID,a.notification_hyperlink,a.created_date, \n"
88 + "\t\t\t\t\t b.role_id,CASE WHEN a.creator_ID IS NOT NULL THEN u.org_user_id\n"
91 + " END AS login_id,b.recv_user_id \n"
92 + "\t\t\t\tfrom ep_notification a, ep_role_notification b,fn_user u\n"
93 + "\t\t\t\twhere a.notification_id = b.notification_id and (u.user_id=a.creator_ID OR a.creator_ID IS NULL)\n"
94 + "\t\t\t\tand a.is_for_all_roles = 'N'\n"
96 + "\t\t\t\t(start_time is null and end_time is null and a.created_date >= DATE_ADD(curdate(),INTERVAL-31 DAY))\n"
98 + "\t\t\t\t(start_time is not null and end_time is null and start_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n"
100 + "\t\t\t\t(start_time is null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n"
102 + "\t\t\t\t(start_time is not null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n"
106 + "\t\t\t\tselect distinct a.user_id, c.role_id, c.app_id, d.APP_NAME\n"
107 + "\t\t\t\tfrom fn_user a, fn_user_role b, fn_role c, fn_app d\n"
108 + "\t\t\t\twhere COALESCE(c.app_id,1) = d.app_id\n"
109 + " \t\tand a.user_id = b.user_id\n"
110 + "\t\t\t\tand a.user_id = :user_id\n"
111 + "\t\t\t\tand b.role_id = c.role_id\n"
112 + " \t\t\tand (d.enabled='Y' or d.app_id=1)\n"
116 + "\t\t\t\ta.role_id = b.role_id\n"
120 + "\t\t\t\t\t:user_id, login_id,notification_id, is_for_online_users, is_for_all_roles, \n"
121 + "\t\t\t\t\tmsg_header, msg_description,msg_source, start_Time, end_time, priority, created_date, \n"
122 + "\t\t\t\t\tcreator_ID,notification_hyperlink,active_YN\n"
125 + "\t\t\t\t\tselect a.notification_ID,a.is_for_online_users,a.is_for_all_roles,a.active_YN,\n"
126 + "\t\t\t\t\ta.msg_header,a.msg_description,a.msg_source,a.start_time,a.end_time,a.priority,a.creator_ID,a.created_date,a.notification_hyperlink, \n"
127 + "\t\t\t\t\t b.role_id,CASE WHEN a.creator_ID IS NOT NULL THEN u.org_user_id\n"
130 + " END AS login_id,b.recv_user_id \n"
131 + "\t\t\t\tfrom ep_notification a, ep_role_notification b,fn_user u\n"
132 + "\t\t\t\twhere a.notification_id = b.notification_id and (u.user_id=a.creator_ID OR a.creator_ID IS NULL)\n"
133 + "\t\t\t\tand a.is_for_all_roles = 'N'\n"
135 + "\t\t\t\t(start_time is null and end_time is null and a.created_date >= DATE_ADD(curdate(),INTERVAL-31 DAY))\n"
137 + "\t\t\t\t(start_time is not null and end_time is null and start_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n"
139 + "\t\t\t\t(start_time is null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n"
141 + "\t\t\t\t(start_time is not null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n"
146 + "\t\t a.recv_user_id=:user_id\n"
150 + "\t\t\t\tselect \n"
151 + "\t\t\t\t\t:user_id user_id, b.login_id,notification_id, is_for_online_users, is_for_all_roles,\n"
152 + "\t\t\t\t\tmsg_header, msg_description,msg_source, start_Time, end_time, priority, a.created_date, \n"
153 + "\t\t\t\t\tcreator_ID, a.notification_hyperlink,a.active_YN\n"
154 + "\t\t\t\tfrom ep_notification a JOIN fn_user b on b.user_id=a.creator_ID\n"
155 + "\t\t\t\twhere a.notification_id\n"
156 + "\t\t\t\tand a.is_for_all_roles = 'Y'\n"
158 + "\t\t\t\t(start_time is null and end_time is null and a.created_date >= DATE_ADD(curdate(),INTERVAL-31 DAY))\n"
160 + "\t\t\t\t(start_time is not null and end_time is null and start_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n"
162 + "\t\t\t\t(start_time is null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n"
164 + "\t\t\t\t(start_time is not null and end_time is not null and end_time >= DATE_ADD(curdate(),INTERVAL -31 DAY))\n"
167 + "\t\t\t\t) a left outer join (\n"
168 + "\t\t\t\tselect m.notification_ID, m.is_viewed from ep_user_notification m where user_id = :user_id\n"
170 + "\t\t\t\ton a.notification_id = m.notification_ID\n"
172 + "\t\t\t\tactive_YN = 'Y'\n"
174 + "\t\t\t\torder by start_Time desc,end_time desc\n"
176 + " (SELECT @rn /*'*/:=/*'*/ 0) t2 where startTime<=SYSDATE() ";
179 public EpNotificationItemVOService(EntityManager entityManager) {
180 this.entityManager = entityManager;
183 public List<EpNotificationItemVO> getNotificationHistoryVO(Long id) {
184 return entityManager.createQuery(notificationHistoryVOResult, EpNotificationItemVO.class).setParameter("user_id", id).getResultList();