Merge "EpNotificationItem class DB constraints"
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / transport / EpNotificationItem.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 package org.onap.portalapp.portal.transport;
39
40 import java.util.Date;
41 import java.util.List;
42 import java.util.Set;
43
44 import javax.persistence.CascadeType;
45 import javax.persistence.Column;
46 import javax.persistence.Entity;
47 import javax.persistence.FetchType;
48 import javax.persistence.GeneratedValue;
49 import javax.persistence.GenerationType;
50 import javax.persistence.Id;
51 import javax.persistence.JoinColumn;
52 import javax.persistence.OneToMany;
53 import javax.persistence.Table;
54 import javax.persistence.Transient;
55 import javax.validation.constraints.Digits;
56 import javax.validation.constraints.Size;
57 import lombok.EqualsAndHashCode;
58 import lombok.Getter;
59 import lombok.NoArgsConstructor;
60 import lombok.Setter;
61 import org.hibernate.validator.constraints.SafeHtml;
62 import org.onap.portalsdk.core.domain.support.DomainVo;
63
64
65 /**
66  * This is to handle notifications in notification PopUp
67  */
68
69
70 @Entity
71 @Table(name = "ep_notification")
72 @NoArgsConstructor
73 @Getter
74 @Setter
75 @EqualsAndHashCode(callSuper = false)
76 public class EpNotificationItem extends DomainVo {
77         private static final long serialVersionUID = 1L;
78
79         @Id
80         @GeneratedValue(strategy = GenerationType.IDENTITY)
81         @Column(name = "notification_ID")
82         @Digits(integer = 11, fraction = 0)
83         public Long notificationId;
84
85         @Column(name = "is_for_online_users")
86         @Size(max = 1)
87         @SafeHtml
88         public String isForOnlineUsers;
89
90         @Column(name = "is_for_all_roles")
91         @Size(max = 1)
92         @SafeHtml
93         public String isForAllRoles;
94
95         @Column(name = "active_YN")
96         @Size(max = 1)
97         @SafeHtml
98         public String activeYn;
99
100         @Column(name = "msg_header")
101         @Size(max = 100)
102         @SafeHtml
103         public String msgHeader;
104
105         @Column(name = "msg_description")
106         @Size(max = 2000)
107         @SafeHtml
108         public String msgDescription;
109
110         @Column(name = "msg_source")
111         @Size(max = 50)
112         @SafeHtml
113         public String msgSource;
114
115         @Column(name = "start_time")
116         public Date startTime;
117
118         @Column(name = "end_time")
119         public Date endTime;
120
121         @Column(name = "priority")
122         @Digits(integer = 11, fraction = 0)
123         public Long priority;
124
125         @Column(name = "creator_ID")
126         @Digits(integer = 11, fraction = 0)
127         public Long creatorId;
128
129         @Column(name = "created_date")
130         public Date createdDate;
131
132         @Column(name = "notification_hyperlink")
133         @Size(max = 512)
134         @SafeHtml
135         public String notificationHyperlink;
136
137         @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}, orphanRemoval = true)
138         @JoinColumn(name="notification_ID")
139         private Set<EpRoleNotificationItem> roles;
140
141         @Transient
142         private List<Long> roleIds;
143
144         @Override
145         public String toString() {
146                 return "EpNotificationItem [notificationId=" + notificationId + ", isForOnlineUsers=" + isForOnlineUsers
147                                 + ", isForAllRoles=" + isForAllRoles + ", activeYn=" + activeYn + ", msgHeader=" + msgHeader
148                                 + ", msgDescription=" + msgDescription + ", msgSource=" + msgSource + ", startTime=" + startTime
149                                 + ", endTime=" + endTime + ", priority=" + priority + ", creatorId=" + creatorId + ", createdDate="
150                                 + createdDate + ", roles=" + roles + ", roleIds=" + roleIds + "]";
151         }
152
153 }