HealthCheckController up
[portal.git] / portal-BE / src / main / java / org / onap / portal / service / EpNotificationItemVOService.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ===================================================================
9  *
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
14  *
15  *             http://www.apache.org/licenses/LICENSE-2.0
16  *
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.
22  *
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
27  *
28  *             https://creativecommons.org/licenses/by/4.0/
29  *
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.
35  *
36  * ============LICENSE_END============================================
37  *
38  *
39  */
40
41 package org.onap.portal.service;
42
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;
49
50 @Service
51 @Transactional
52 public class EpNotificationItemVOService {
53
54     private final EntityManager entityManager;
55
56     private final String notificationHistoryVOResult =
57         "\t\tSELECT\n"
58             + "\t\t\tnotificationId, isForOnlineUsers, isForAllRoles, msgHeader,\tmsgDescription,msgSource,\n"
59             + "\t\t\tstartTime, endTime, priority, createdDate,notificationHyperlink,creatorId, loginId,\tactiveYn \n"
60             + "\t\tFROM\n"
61             + "\t\t\t(\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"
78             + "\t\t\tfrom\n"
79             + "\t\t\t(\n"
80             + "\t\t\t\tselect \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"
84             + "\t\t\t\tfrom\n"
85             + "\t\t\t\t(\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"
89             + "                   \n"
90             + "                   ELSE NULL\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"
95             + "\t\t\t\tand (\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"
97             + "\t\t\t\tor\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"
99             + "\t\t\t\tor\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"
101             + "\t\t\t\tor\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"
103             + "\t\t\t\t)\n"
104             + "\t\t\t\t) a,\n"
105             + "\t\t\t\t(\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"
113             + "\t\t\t\t) b\n"
114             + "\t\t\t\twhere\n"
115             + "\t\t\t\t(\n"
116             + "\t\t\t\ta.role_id = b.role_id\n"
117             + "\t\t\t\t)\n"
118             + "\t\t\t\t   UNION\n"
119             + "        \t\tselect \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"
123             + "\t\t\t\tfrom\n"
124             + "\t\t\t\t(\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"
128             + "                   \n"
129             + "                   ELSE NULL\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"
134             + "\t\t\t\tand (\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"
136             + "\t\t\t\tor\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"
138             + "\t\t\t\tor\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"
140             + "\t\t\t\tor\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"
142             + "\t\t\t\t)\n"
143             + "\t\t\t\t) a\n"
144             + "\t\t        where\n"
145             + "\t\t        (\n"
146             + "\t\t        a.recv_user_id=:user_id\n"
147             + "\t\t        )\n"
148             + "\t\t\t\tunion\n"
149             + "\t\t\t\t(\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"
157             + "\t\t\t\tand (\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"
159             + "\t\t\t\tor\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"
161             + "\t\t\t\tor\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"
163             + "\t\t\t\tor\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"
165             + "\t\t\t\t)\n"
166             + "\t\t\t\t)\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"
169             + "\t\t\t\t) m\n"
170             + "\t\t\t\ton  a.notification_id = m.notification_ID\n"
171             + "\t\t\t\twhere\n"
172             + "\t\t\t\tactive_YN = 'Y'\n"
173             + "\t\t\t\t\n"
174             + "\t\t\t\torder by  start_Time desc,end_time desc\n"
175             + "\t\t\t) t,\n"
176             + "                     (SELECT @rn /*'*/:=/*'*/ 0) t2 where startTime<=SYSDATE() ";
177
178     @Autowired
179     public EpNotificationItemVOService(EntityManager entityManager) {
180         this.entityManager = entityManager;
181     }
182
183     public List<EpNotificationItemVO> getNotificationHistoryVO(Long id) {
184         return entityManager.createQuery(notificationHistoryVOResult, EpNotificationItemVO.class).setParameter("user_id", id).getResultList();
185     }
186 }