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