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.domain.db.ep;
43 import java.io.Serializable;
44 import java.time.LocalDateTime;
45 import java.util.List;
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;
73 import lombok.NoArgsConstructor;
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;
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`)
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"
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"
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"
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"
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"
128 + " a.role_id = b.role_id\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"
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"
144 + " a.recv_user_id=:user_id\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"
157 + " active_YN = 'Y'\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"
163 + " order by priority desc, created_date desc,start_Time desc\n"
169 @Table(name = "ep_notification")
175 public class EpNotification implements Serializable {
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)
190 private String msgHeader;
191 @Column(name = "msg_description", length = 2000)
194 private String msgDescription;
195 @Column(name = "msg_source", length = 50, columnDefinition = "varchar(50) default 'EP'")
198 private String msgSource;
199 @Column(name = "start_time", nullable = false, columnDefinition = "datetime default now()")
202 private LocalDateTime startTime;
203 @Column(name = "end_time")
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")
214 private LocalDateTime createdDate;
215 @Column(name = "notification_hyperlink", length = 512)
218 private String notificationHyperlink;
220 private List<Long> roleIds;
222 targetEntity = EpRoleNotification.class,
223 mappedBy = "notificationId",
224 cascade = CascadeType.MERGE,
225 fetch = FetchType.LAZY
227 private Set<EpRoleNotification> epRoleNotifications;
229 targetEntity = EpUserNotification.class,
230 mappedBy = "notificationId",
231 cascade = CascadeType.MERGE,
232 fetch = FetchType.LAZY
234 private Set<EpUserNotification> epUserNotifications;