Hibernate db fix
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / fn / FnMenuFunctional.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.GeneratedValue;
49 import javax.persistence.GenerationType;
50 import javax.persistence.Id;
51 import javax.persistence.Index;
52 import javax.persistence.JoinColumn;
53 import javax.persistence.JoinTable;
54 import javax.persistence.ManyToMany;
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_functional` (
72   `menu_id` int(11) NOT NULL AUTO_INCREMENT,
73   `column_num` int(2) NOT NULL,
74   `text` varchar(100) NOT NULL,
75   `parent_menu_id` int(11) DEFAULT NULL,
76   `url` varchar(128) NOT NULL DEFAULT '',
77   `active_yn` varchar(1) NOT NULL DEFAULT 'y',
78   `image_src` varchar(100) DEFAULT NULL,
79   PRIMARY KEY (`menu_id`),
80   KEY `fk_fn_menu_func_parent_menu_id_idx` (`parent_menu_id`),
81   CONSTRAINT `fk_fn_menu_func_parent_menu_id` FOREIGN KEY (`parent_menu_id`) REFERENCES `fn_menu_functional` (`menu_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
82 )
83 */
84
85 @Table(name = "fn_menu_functional", indexes = {@Index(columnList = "parent_menu_id", name = "fk_fn_menu_func_parent_menu_id_idx")
86 })
87 @NoArgsConstructor
88 @AllArgsConstructor
89 @Getter
90 @Setter
91 @Entity
92 public class FnMenuFunctional {
93        @Id
94        @GeneratedValue(strategy = GenerationType.AUTO)
95        @Column(name = "menu_id", nullable = false, length = 11)
96        @Digits(integer = 11, fraction = 0)
97        private Long menuId;
98        @Column(name = "column_num", nullable = false, length = 2)
99        @Digits(integer = 2, fraction = 0)
100        private Long columnNum;
101        @Column(name = "text", length = 100, nullable = false)
102        @Size(max = 100)
103        @SafeHtml
104        @NotNull
105        private String text;
106        @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
107        @JoinColumn(name = "parent_menu_id")
108        @Valid
109        private FnMenuFunctional parentMenuId;
110        @Column(name = "url", length = 128, nullable = false, columnDefinition = "varchar(128) default ''")
111        @Size(max = 128)
112        @SafeHtml
113        @NotNull
114        //TODO URL
115        @URL
116        private String url;
117        @Column(name = "active_yn", length = 1, columnDefinition = "varchar(1) default 'Y'", nullable = false)
118        @Pattern(regexp = "[YNyn]")
119        @Size(max = 1)
120        @NotNull
121        @SafeHtml
122        private String activeYn;
123        @Column(name = "image_src", length = 100, columnDefinition = "varchar(100) default null")
124        @Size(max = 100)
125        @SafeHtml
126        private String imageSrc;
127        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
128        @JoinTable(
129                name = "fn_menu_favorites",
130                joinColumns = {@JoinColumn(name = "menu_id", referencedColumnName = "menu_id")},
131                inverseJoinColumns = {@JoinColumn(name = "role_Id", referencedColumnName = "user_id")},
132                indexes = {
133                        @Index(name = "sys_c0014619", columnList = "menu_id")
134                }
135        )
136        private Set<FnUser> fnUsers;
137        @OneToMany(
138                targetEntity = FnMenuFunctionalAncestors.class,
139                mappedBy = "menuId",
140                cascade = CascadeType.ALL,
141                fetch = FetchType.LAZY
142        )
143        private Set<FnMenuFunctionalAncestors> fnMenuFunctionalAncestorsMenuId;
144        @OneToMany(
145                targetEntity = FnMenuFunctionalAncestors.class,
146                mappedBy = "ancestorMenuId",
147                cascade = CascadeType.ALL,
148                fetch = FetchType.LAZY
149        )
150        private Set<FnMenuFunctionalAncestors> fnMenuFunctionalsAncestorMenuId;
151        @OneToMany(
152                targetEntity = FnMenuFunctionalRoles.class,
153                mappedBy = "menuId",
154                cascade = CascadeType.ALL,
155                fetch = FetchType.LAZY
156        )
157        private Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles;
158 }