Portal Spring Boot version Hibernate implementation
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / fn / FnAppContactUs.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.fn;
42
43 import java.io.Serializable;
44 import javax.persistence.CascadeType;
45 import javax.persistence.Column;
46 import javax.persistence.Entity;
47 import javax.persistence.EntityResult;
48 import javax.persistence.FetchType;
49 import javax.persistence.FieldResult;
50 import javax.persistence.Id;
51 import javax.persistence.JoinColumn;
52 import javax.persistence.MapsId;
53 import javax.persistence.NamedNativeQueries;
54 import javax.persistence.NamedNativeQuery;
55 import javax.persistence.OneToOne;
56 import javax.persistence.SqlResultSetMapping;
57 import javax.persistence.Table;
58 import javax.validation.Valid;
59 import javax.validation.constraints.Pattern;
60 import javax.validation.constraints.Size;
61 import lombok.AllArgsConstructor;
62 import lombok.EqualsAndHashCode;
63 import lombok.Getter;
64 import lombok.NoArgsConstructor;
65 import lombok.Setter;
66 import org.hibernate.validator.constraints.SafeHtml;
67 import org.hibernate.validator.constraints.URL;
68 import org.onap.portal.domain.dto.DomainVo;
69
70 /*
71 CREATE TABLE `fn_app_contact_us` (
72         `app_id` int(11) NOT NULL,
73         `contact_name` varchar(128) DEFAULT NULL,
74         `contact_email` varchar(128) DEFAULT NULL,
75         `url` varchar(256) DEFAULT NULL,
76         `active_yn` varchar(2) DEFAULT NULL,
77         `description` varchar(1024) DEFAULT NULL,
78         PRIMARY KEY (`app_id`),
79         CONSTRAINT `fk_fn_a_con__ref_202_fn_app` FOREIGN KEY (`app_id`) REFERENCES `fn_app` (`app_id`)
80         )
81 */
82
83 @SqlResultSetMapping(
84         name = "fnAppContactUsMapping",
85         entities = {
86                 @EntityResult(
87                         entityClass = FnAppContactUs.class,
88                         fields = {
89                                 @FieldResult(name = "appId", column = "app_Id"),
90                                 @FieldResult(name = "contactName", column = "contactName"),
91                                 @FieldResult(name = "contact_email", column = "contactEmail"),
92                                 @FieldResult(name = "description", column = "description"),
93                                 @FieldResult(name = "activeYN", column = "activeYN")
94                         }
95                 )
96         })
97
98 @NamedNativeQueries({
99         @NamedNativeQuery(
100                 name = "FnAppContactUs.getAppsAndContacts",
101                 query = "select "
102                         + "a.app_id as app_Id, a.app_name as appName,"
103                         + "c.contact_name as contactName, "
104                         + "c.contact_email as contactEmail, c.url, c.description, "
105                         + "c.active_yn as activeYN"
106                         + "from "
107                         + "fn_app a"
108                         + "left join "
109                         + "fn_app_contact_us c"
110                         + "on a.app_id = c.app_id"
111                         + "where "
112                         + "a.enabled = 'Y' and a.app_name is not null and a.app_name != '';",
113                 resultClass = FnAppContactUs.class,
114                 resultSetMapping = "fnAppContactUsMapping"),
115         @NamedNativeQuery(
116                 name = "FnAppContactUs.getAppContactUsItems",
117                 query = "select\n"
118                         + "  c.app_id as app_Id,\n"
119                         + "  c.contact_name as contact_name,\n"
120                         + "  c.contact_email as contact_email,\n"
121                         + "  c.url,\n"
122                         + "  c.description,\n"
123                         + "  c.active_yn as active_yn,\n"
124                         + "  a.app_name as appName\n"
125                         + "from\n"
126                         + "  fn_app_contact_us c\n"
127                         + "  left join fn_app a on a.app_id = c.app_id\n"
128                         + "where\n"
129                         + "  a.enabled = 'Y'\n"
130                         + "  and a.app_name is not null\n"
131                         + "  and a.app_name != ''",
132                 resultClass = FnAppContactUs.class,
133                 resultSetMapping = "fnAppContactUsMapping")
134 })
135
136 @Table(name = "fn_app_contact_us")
137 @NoArgsConstructor
138 @AllArgsConstructor
139 @EqualsAndHashCode(callSuper = true)
140 @Getter
141 @Setter
142 @Entity
143 public class FnAppContactUs extends DomainVo implements Serializable {
144        @Id
145        @Column(name = "app_id")
146        private Long appId;
147
148        @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
149        @JoinColumn(name = "app_id")
150        @MapsId
151        @Valid
152        private FnApp fnApp;
153        @Column(name = "contact_name", length = 128, columnDefinition = "varchar(128) default null")
154        @Size(max = 128)
155        @SafeHtml
156        private String contactName;
157        @Column(name = "contact_email", length = 128, columnDefinition = "varchar(128) default null")
158        @Size(max = 128)
159        @SafeHtml
160        private String contactEmail;
161        @Column(name = "url", length = 256, columnDefinition = "varchar(128) default null")
162        @Size(max = 256)
163        @SafeHtml
164        //TODO URL
165        @URL
166        private String url;
167        @Column(name = "active_yn", length = 1, columnDefinition = "varchar(1) default null")
168        @Pattern(regexp = "[YNyn]")
169        @Size(max = 1)
170        @SafeHtml
171        private String activeYn;
172        @Column(name = "description", length = 1024, columnDefinition = "varchar(1024) default null")
173        @Size(max = 1024)
174        @SafeHtml
175        private String description;
176
177 }