Fixed health check issue
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / ep / EpNotification.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.domain.db.ep;
42
43 import java.io.Serializable;
44 import java.time.LocalDateTime;
45 import java.util.List;
46 import java.util.Set;
47 import javax.persistence.CascadeType;
48 import javax.persistence.Column;
49 import javax.persistence.ColumnResult;
50 import javax.persistence.ConstructorResult;
51 import javax.persistence.Entity;
52 import javax.persistence.FetchType;
53 import javax.persistence.GeneratedValue;
54 import javax.persistence.GenerationType;
55 import javax.persistence.Id;
56 import javax.persistence.NamedNativeQueries;
57 import javax.persistence.NamedNativeQuery;
58 import javax.persistence.NamedQueries;
59 import javax.persistence.NamedQuery;
60 import javax.persistence.OneToMany;
61 import javax.persistence.SequenceGenerator;
62 import javax.persistence.SqlResultSetMapping;
63 import javax.persistence.Table;
64 import javax.persistence.Transient;
65 import javax.validation.constraints.Digits;
66 import javax.validation.constraints.FutureOrPresent;
67 import javax.validation.constraints.NotNull;
68 import javax.validation.constraints.PastOrPresent;
69 import javax.validation.constraints.Pattern;
70 import javax.validation.constraints.Size;
71 import lombok.AllArgsConstructor;
72 import lombok.Getter;
73 import lombok.NoArgsConstructor;
74 import lombok.Setter;
75 import org.hibernate.validator.constraints.SafeHtml;
76 import org.onap.portal.domain.db.fn.FnUser;
77 import org.onap.portal.domain.dto.transport.EpNotificationItemVO;
78
79 /*
80 CREATE TABLE `ep_notification` (
81         `notification_ID` int(11) NOT NULL AUTO_INCREMENT,
82         `is_for_online_users` char(1) DEFAULT 'N',
83         `is_for_all_roles` char(1) DEFAULT 'N',
84         `active_YN` char(1) DEFAULT 'Y',
85         `msg_header` varchar(100) DEFAULT NULL,
86         `msg_description` varchar(2000) DEFAULT NULL,
87         `msg_source` varchar(50) DEFAULT 'EP',
88         `start_time` timestamp NOT NULL DEFAULT current_timestamp(),
89         `end_time` timestamp NULL DEFAULT NULL,
90         `priority` int(11) DEFAULT NULL,
91         `creator_ID` int(11) DEFAULT NULL,
92         `created_date` timestamp NULL DEFAULT NULL,
93         `notification_hyperlink` varchar(512) DEFAULT NULL,
94         PRIMARY KEY (`notification_ID`)
95         )
96 */
97
98 @NamedNativeQueries({
99     @NamedNativeQuery(
100         name = "EpNotification.getNotifications",
101         query = "select rowId, notification_ID, is_for_online_users,is_for_all_roles, msg_header, msg_description,msg_source, start_Time, end_time, priority, created_date, creator_ID,notification_hyperlink, active_YN from\n"
102         + "( \n"
103         + "select notification_ID, is_for_online_users, is_for_all_roles, msg_header, msg_description, msg_source,start_Time, end_time, priority,created_date, creator_ID,notification_hyperlink,active_YN\n"
104         + "from\n"
105         + "    (\n"
106         + "    select user_id, notification_id, is_for_online_users, is_for_all_roles, msg_header, msg_description,msg_source,start_Time, end_time, priority, created_date,notification_hyperlink, creator_ID,active_YN\n"
107         + "    from\n"
108         + "    (\n"
109         + "    select a.notification_ID,a.is_for_online_users,a.is_for_all_roles,a.active_YN,\n"
110         + "        a.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,b.role_id,b.recv_user_id \n"
111         + "    from ep_notification a, ep_role_notification b\n"
112         + "    where a.notification_id = b.notification_id\n"
113         + "    and (end_time is null ||  SYSDATE() <= end_time )\n"
114         + "    and (start_time is null ||  SYSDATE() >= start_time)\n"
115         + "    and a.is_for_all_roles = 'N'\n"
116         + "    ) a,\n"
117         + "    (\n"
118         + "    select distinct a.user_id, c.role_id, c.app_id, d.APP_NAME\n"
119         + "    from fn_user a, fn_user_role b, fn_role c, fn_app d\n"
120         + "    where COALESCE(c.app_id,1) = d.app_id\n"
121         + "       and a.user_id = b.user_id\n"
122         + "    and a.user_id = :user_id\n"
123         + "    and b.role_id = c.role_id\n"
124         + "      and (d.enabled='Y' or d.app_id=1)\n"
125         + "    )b\n"
126         + "    where\n"
127         + "    (\n"
128         + "    a.role_id = b.role_id\n"
129         + "    )\n"
130         + "    union\n"
131         + "    select :user_id, notification_id, is_for_online_users, is_for_all_roles, msg_header, msg_description,msg_source,start_Time, end_time, priority, created_date,notification_hyperlink, creator_ID,active_YN\n"
132         + "    from\n"
133         + "    (\n"
134         + "    select a.notification_ID,a.is_for_online_users,a.is_for_all_roles,a.active_YN,\n"
135         + "        a.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,b.role_id,b.recv_user_id \n"
136         + "    from ep_notification a, ep_role_notification b\n"
137         + "    where a.notification_id = b.notification_id\n"
138         + "    and (end_time is null ||  SYSDATE() <= end_time )\n"
139         + "    and (start_time is null ||  SYSDATE() >= start_time)\n"
140         + "    and a.is_for_all_roles = 'N'\n"
141         + "    ) a\n"
142         + "    where\n"
143         + "    (\n"
144         + "    a.recv_user_id=:user_id\n"
145         + "    )\n"
146         + "    union\n"
147         + "    (\n"
148         + "    select :user_id user_id, notification_id, is_for_online_users, is_for_all_roles, msg_header, msg_description, msg_source,start_Time, end_time, priority, created_date,notification_hyperlink, creator_ID,active_YN\n"
149         + "    from ep_notification a\n"
150         + "    where a.notification_id\n"
151         + "    and (end_time is null ||  SYSDATE() <= end_time )\n"
152         + "    and (start_time is null ||  SYSDATE() >= start_time)\n"
153         + "    and a.is_for_all_roles = 'Y'\n"
154         + "    )\n"
155         + "    ) a\n"
156         + "    where\n"
157         + "        active_YN = 'Y'\n"
158         + "    and\n"
159         + "        not exists\n"
160         + "    (\n"
161         + "    select ID,User_ID,notification_ID,is_viewed,updated_time from ep_user_notification m where user_id = :user_id and m.notification_id = a.notification_id and is_viewed = 'Y'\n"
162         + "    )\n"
163         + "    order by priority desc, created_date desc,start_Time desc\n"
164         + "\n"
165         + "\n"
166         + " ) t,\n")}
167 )
168
169 @Table(name = "ep_notification")
170 @NoArgsConstructor
171 @AllArgsConstructor
172 @Getter
173 @Setter
174 @Entity
175 public class EpNotification implements Serializable {
176        @Id
177        @GeneratedValue(strategy = GenerationType.AUTO)
178        @Column(name = "notification_ID", length = 11, nullable = false)
179        @Digits(integer = 11, fraction = 0)
180        private Long notificationId;
181        @Column(name = "is_for_online_users")
182        private Boolean isForOnlineUsers = false;
183        @Column(name = "is_for_all_roles")
184        private Boolean isForAllRoles = false;
185        @Column(name = "active_yn")
186        private Boolean activeYn = true;
187        @Column(name = "msg_header", length = 100)
188        @Size(max = 100)
189        @SafeHtml
190        private String msgHeader;
191        @Column(name = "msg_description", length = 2000)
192        @Size(max = 2000)
193        @SafeHtml
194        private String msgDescription;
195        @Column(name = "msg_source", length = 50, columnDefinition = "varchar(50) default 'EP'")
196        @Size(max = 50)
197        @SafeHtml
198        private String msgSource;
199        @Column(name = "start_time", nullable = false, columnDefinition = "datetime default now()")
200        @PastOrPresent
201        @NotNull
202        private LocalDateTime startTime;
203        @Column(name = "end_time")
204        @FutureOrPresent
205        private LocalDateTime endTime;
206        @Column(name = "priority", length = 11)
207        @Digits(integer = 11, fraction = 0)
208        private Long priority;
209        @Column(name = "creator_Id", length = 11)
210        @Digits(integer = 11, fraction = 0)
211        private FnUser creatorId;
212        @Column(name = "created_date")
213        @FutureOrPresent
214        private LocalDateTime createdDate;
215        @Column(name = "notification_hyperlink", length = 512)
216        @Size(max = 512)
217        @SafeHtml
218        private String notificationHyperlink;
219        @Transient
220        private List<Long> roleIds;
221        @OneToMany(
222                targetEntity = EpRoleNotification.class,
223                mappedBy = "notificationId",
224                cascade = CascadeType.MERGE,
225                fetch = FetchType.LAZY
226        )
227        private Set<EpRoleNotification> epRoleNotifications;
228        @OneToMany(
229                targetEntity = EpUserNotification.class,
230                mappedBy = "notificationId",
231                cascade = CascadeType.MERGE,
232                fetch = FetchType.LAZY
233        )
234        private Set<EpUserNotification> epUserNotifications;
235 }