Hibernate db fix
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / fn / FnRole.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.NamedQueries;
56 import javax.persistence.NamedQuery;
57 import javax.persistence.OneToMany;
58 import javax.persistence.Table;
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.onap.portal.domain.db.ep.EpAppRoleFunction;
69 import org.onap.portal.domain.db.ep.EpRoleNotification;
70 import org.onap.portal.domain.db.ep.EpUserRolesRequestDet;
71 import org.onap.portal.domain.db.ep.EpWidgetCatalogRole;
72
73 /*
74 CREATE TABLE `fn_role` (
75         `role_id` int(11) NOT NULL AUTO_INCREMENT,
76         `role_name` varchar(300) NOT NULL,
77         `active_yn` varchar(1) NOT NULL DEFAULT 'y',
78         `priority` decimal(4,0) DEFAULT NULL,
79         `app_id` int(11) DEFAULT NULL,
80         `app_role_id` int(11) DEFAULT NULL,
81         PRIMARY KEY (`role_id`),
82         UNIQUE KEY `fn_role_name_app_id_idx` (`role_name`,`app_id`) USING BTREE
83         )
84 */
85
86 @NamedQueries({
87         @NamedQuery(
88                 name = "FnRole.retrieveAppRolesByRoleNameAndByAppId",
89                 query = "FROM FnRole where role_name =:roleName and app_id =:appId"),
90         @NamedQuery(
91                 name = "FnRole.retrieveAppRolesByAppId",
92                 query = "FROM FnRole where app_id =:appId"),
93         @NamedQuery(
94                 name = "FnRole.retrieveAppRolesWhereAppIdIsNull",
95                 query = "FROM FnRole where app_id is null"),
96         @NamedQuery(
97                 name = "FnRole.retrieveAppRoleByRoleIdWhereAppIdIsNull",
98                 query = "FROM FnRole where role_id =:roleId and app_id is null"),
99         @NamedQuery(
100                 name = "FnRole.retrieveAppRoleByAppRoleIdAndByAppId",
101                 query = "FROM FnRole where app_role_id =:appRoleId and app_id =:appId"),
102         @NamedQuery(
103                 name = "FnRole.retrieveAppRoleByRoleIdAndAppId",
104                 query = "FROM FnRole where role_id =:roleId and app_id =:appId"),
105         @NamedQuery(
106                 name = "FnRole.retrieveAppRolesByRoleNameAndWhereAppIdIsNull",
107                 query = "FROM FnRole where role_name =:roleName and app_id is null"),
108         @NamedQuery(
109                 name = "FnRole.retrieveActiveRolesOfApplication",
110                 query = "from FnRole where active_yn = 'Y' and app_id=:appId"),
111         @NamedQuery(name = "FnRole.retrieveRoleToUpdateInExternalAuthSystem",
112                 query = "FROM FnRole where role_name =:roleName and app_id =:appId")
113 })
114
115 @Table(name = "fn_role", indexes = {
116         @Index(name = "fn_role_name_app_id_idx", columnList = "role_name, app_id", unique = true)
117 })
118 @NoArgsConstructor
119 @AllArgsConstructor
120 @Getter
121 @Setter
122 @Entity
123 public class FnRole {
124
125        @Id
126        @GeneratedValue(strategy = GenerationType.AUTO)
127        @Column(name = "role_id", length = 11, nullable = false)
128        @Digits(integer = 11, fraction = 0)
129        private Long roleId;
130        @Column(name = "role_name", length = 300, nullable = false)
131        @Size(max = 300)
132        @NotNull
133        @SafeHtml
134        private String roleName;
135        @Column(name = "active_yn", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false)
136        @Pattern(regexp = "[YNyn]")
137        @Size(max = 1)
138        @NotNull
139        @SafeHtml
140        private String activeYn;
141        @Column(name = "priority", length = 4, columnDefinition = "decimal(4,0) DEFAULT NULL")
142        @Digits(integer = 4, fraction = 0)
143        private Long priority;
144        @Column(name = "app_Id", length = 11, columnDefinition = "int(11) default null")
145        @Digits(integer = 11, fraction = 0)
146        private Long appId;
147        @Column(name = "app_role_id", length = 11, columnDefinition = "int(11) default null")
148        @Digits(integer = 11, fraction = 0)
149        private Long appRoleId;
150        @OneToMany(
151                targetEntity = FnRoleFunction.class,
152                mappedBy = "roleId",
153                cascade = CascadeType.ALL,
154                fetch = FetchType.LAZY
155        )
156        private Set<FnRoleFunction> fnRoleFunctions;
157        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
158        @JoinTable(
159                name = "fn_user_pseudo_role",
160                joinColumns = {@JoinColumn(name = "pseudo_role_Id", referencedColumnName = "role_id")},
161                inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "user_id")},
162                indexes = {
163                        @Index(name = "fk_pseudo_role_user_id", columnList = "user_id")
164                }
165        )
166        private Set<FnUser> fnUsers;
167        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
168        @JoinTable(
169                name = "fn_role_composite",
170                joinColumns = {@JoinColumn(name = "parent_role_id", referencedColumnName = "role_id")},
171                inverseJoinColumns = {@JoinColumn(name = "child_role_id", referencedColumnName = "role_id")},
172                indexes = {
173                        @Index(name = "fk_fn_role_composite_child", columnList = "child_role_id")
174                }
175        )
176        private Set<FnRole> fnRoles;
177        @ManyToMany(cascade = CascadeType.ALL,
178                fetch = FetchType.LAZY)
179        private Set<FnRole> fnRoleList;
180        @OneToMany(
181                targetEntity = EpRoleNotification.class,
182                mappedBy = "notificationID",
183                cascade = CascadeType.ALL,
184                fetch = FetchType.LAZY
185        )
186        private Set<EpRoleNotification> epRoleNotifications;
187        @OneToMany(
188                targetEntity = FnMenuFunctionalRoles.class,
189                mappedBy = "roleId",
190                cascade = CascadeType.ALL,
191                fetch = FetchType.LAZY
192        )
193        private Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles;
194        @OneToMany(
195                targetEntity = EpWidgetCatalogRole.class,
196                mappedBy = "roleId",
197                cascade = CascadeType.ALL,
198                fetch = FetchType.LAZY
199        )
200        private Set<EpWidgetCatalogRole> epWidgetCatalogRoles;
201        @OneToMany(
202                targetEntity = EpAppRoleFunction.class,
203                mappedBy = "fnRole",
204                cascade = CascadeType.ALL,
205                fetch = FetchType.LAZY
206        )
207        private Set<EpAppRoleFunction> epAppRoleFunctions;
208        @OneToMany(
209                targetEntity = EpUserRolesRequestDet.class,
210                mappedBy = "requestedRoleId",
211                cascade = CascadeType.ALL,
212                fetch = FetchType.LAZY
213        )
214        private Set<EpUserRolesRequestDet> epUserRolesRequestDets;
215        @OneToMany(
216                targetEntity = FnUserRole.class,
217                mappedBy = "roleId",
218                cascade = CascadeType.ALL,
219                fetch = FetchType.LAZY
220        )
221        private Set<FnUserRole> fnUserRoles;
222 }