Hibernate db fix
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / fn / FnMenu.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.util.Set;
44 import javax.persistence.CascadeType;
45 import javax.persistence.Column;
46 import javax.persistence.Entity;
47 import javax.persistence.FetchType;
48 import javax.persistence.ForeignKey;
49 import javax.persistence.GeneratedValue;
50 import javax.persistence.GenerationType;
51 import javax.persistence.Id;
52 import javax.persistence.Index;
53 import javax.persistence.JoinColumn;
54 import javax.persistence.ManyToOne;
55 import javax.persistence.OneToMany;
56 import javax.persistence.Table;
57 import javax.validation.Valid;
58 import javax.validation.constraints.Digits;
59 import javax.validation.constraints.NotNull;
60 import javax.validation.constraints.Pattern;
61 import javax.validation.constraints.Size;
62 import lombok.AllArgsConstructor;
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
69 /*
70 CREATE TABLE `fn_menu` (
71         `menu_id` int(11) NOT NULL AUTO_INCREMENT,
72         `label` varchar(100) DEFAULT NULL,
73         `parent_id` int(11) DEFAULT NULL,
74         `sort_order` decimal(4,0) DEFAULT NULL,
75         `action` varchar(200) DEFAULT NULL,
76         `function_cd` varchar(30) DEFAULT NULL,
77         `active_yn` varchar(1) NOT NULL DEFAULT 'y',
78         `servlet` varchar(50) DEFAULT NULL,
79         `query_string` varchar(200) DEFAULT NULL,
80         `external_url` varchar(200) DEFAULT NULL,
81         `target` varchar(25) DEFAULT NULL,
82         `menu_set_cd` varchar(10) DEFAULT 'app',
83         `separator_yn` char(1) DEFAULT 'n',
84         `image_src` varchar(100) DEFAULT NULL,
85         PRIMARY KEY (`menu_id`),
86         KEY `fk_fn_menu_ref_196_fn_menu` (`parent_id`),
87         KEY `fk_fn_menu_menu_set_cd` (`menu_set_cd`),
88         KEY `idx_fn_menu_label` (`label`),
89         CONSTRAINT `fk_fn_menu_menu_set_cd` FOREIGN KEY (`menu_set_cd`) REFERENCES `fn_lu_menu_set` (`menu_set_cd`),
90         CONSTRAINT `fk_fn_menu_ref_196_fn_menu` FOREIGN KEY (`parent_id`) REFERENCES `fn_menu` (`menu_id`)
91         )
92 */
93
94 @Table(name = "fn_menu", indexes = {
95         @Index(name = "idx_fn_menu_label", columnList = "label"),
96         @Index(name = "fk_fn_menu_ref_196_fn_menu", columnList = "parent_id"),
97         @Index(name = "fk_fn_menu_menu_set_cd", columnList = "menu_set_cd")
98 })
99 @NoArgsConstructor
100 @AllArgsConstructor
101 @Getter
102 @Setter
103 @Entity
104 public class FnMenu {
105        @Id
106        @GeneratedValue(strategy = GenerationType.AUTO)
107        @Column(name = "menu_id", nullable = false, length = 11, columnDefinition = "int(11) auto_increment")
108        @Digits(integer = 11, fraction = 0)
109        private Integer menu_id;
110        @Column(name = "label", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
111        @Size(max = 100)
112        @SafeHtml
113        private String label;
114        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
115        @JoinColumn(name = "parent_Id", columnDefinition = "int(11) DEFAULT NULL")
116        @Valid
117        private FnMenu parentId;
118        @Column(name = "sort_order", length = 4, columnDefinition = "decimal(4,0) DEFAULT NULL")
119        @Digits(integer = 4, fraction = 0)
120        private Integer sortOrder;
121        @Column(name = "action", length = 200, columnDefinition = "varchar(200) DEFAULT NULL")
122        @Size(max = 200)
123        @SafeHtml
124        private String action;
125        @Column(name = "function_cd", length = 30, columnDefinition = "varchar(30) DEFAULT NULL")
126        @Size(max = 30)
127        @SafeHtml
128        private String functionCd;
129        @Column(name = "active_yn", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false)
130        @Pattern(regexp = "[YNyn]")
131        @Size(max = 1)
132        @NotNull
133        @SafeHtml
134        private String activeYn;
135        @Column(name = "servlet", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
136        @Size(max = 50)
137        @SafeHtml
138        private String servlet;
139        @Column(name = "query_string", length = 200, columnDefinition = "varchar(200) DEFAULT NULL")
140        @Size(max = 200)
141        @SafeHtml
142        private String queryString;
143        @Column(name = "external_url", length = 200, columnDefinition = "varchar(200) DEFAULT NULL")
144        @Size(max = 200)
145        @SafeHtml
146        @URL
147        //TODO url
148        private String externalUrl;
149        @Column(name = "target", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
150        @Size(max = 25)
151        @SafeHtml
152        private String target;
153        @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
154        @JoinColumn(name = "menu_set_cd", columnDefinition = "character varying(10) default 'app'", foreignKey = @ForeignKey(name = "fk_fn_menu_menu_set_cd"))
155        @Valid
156        private FnLuMenuSet menuSetCd;
157        @Column(name = "separator_yn", length = 1, columnDefinition = "character varying(1) default 'n'")
158        @Pattern(regexp = "[YNyn]")
159        @Size(max = 1)
160        @NotNull
161        @SafeHtml
162        private String separatorYn;
163        @Column(name = "image_src", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
164        @Size(max = 100)
165        @SafeHtml
166        private String imageSrc;
167        @OneToMany(
168                targetEntity = FnMenu.class,
169                mappedBy = "parentId",
170                cascade = CascadeType.ALL,
171                fetch = FetchType.LAZY
172        )
173        private Set<FnMenu> fnMenus;
174 }