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