275ce1e37cdec6fe849ad78b34a02dc19cb087c0
[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.io.Serializable;
44 import java.util.Set;
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.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 import org.onap.portal.domain.dto.DomainVo;
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 appRoleId =:appRoleId and appId =: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         @NamedQuery(
115                 name = "FnRole.getUserRoleOnUserIdAndAppId",
116                 query = " FROM"
117                         + "  FnRole fr,\n"
118                         + "  FnUserRole fur\n"
119                         + " WHERE\n"
120                         + "  fr.roleId = fur.roleId\n"
121                         + "  AND fur.userId = :userId"
122                         + "  AND fur.appId = :appId\n"
123                         + "  AND fr.activeYn = 'y'")
124         })
125
126 @Table(name = "fn_role", indexes = {
127         @Index(name = "fn_role_name_app_id_idx", columnList = "role_name, app_id", unique = true)
128 })
129 @NoArgsConstructor
130 @AllArgsConstructor
131 @Getter
132 @Setter
133 @Entity
134 public class FnRole extends DomainVo implements Serializable {
135
136        @Id
137        @GeneratedValue(strategy = GenerationType.AUTO)
138        @Column(name = "role_id", length = 11, nullable = false)
139        @Digits(integer = 11, fraction = 0)
140        private Long roleId;
141        @Column(name = "role_name", length = 300, nullable = false)
142        @Size(max = 300)
143        @NotNull
144        @SafeHtml
145        private String roleName;
146        @Column(name = "active_yn", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false)
147        @NotNull
148        private Boolean activeYn;
149        @Column(name = "priority", length = 4, columnDefinition = "decimal(4,0) DEFAULT NULL")
150        @Digits(integer = 4, fraction = 0)
151        private Long priority;
152        @Column(name = "app_Id", length = 11, columnDefinition = "int(11) default null")
153        @Digits(integer = 11, fraction = 0)
154        private Long appId;
155        @Column(name = "app_role_id", length = 11, columnDefinition = "int(11) default null")
156        @Digits(integer = 11, fraction = 0)
157        private Long appRoleId;
158        @OneToMany(
159                targetEntity = FnRoleFunction.class,
160                mappedBy = "roleId",
161                cascade = CascadeType.ALL,
162                fetch = FetchType.LAZY
163        )
164        private Set<FnRoleFunction> fnRoleFunctions;
165        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
166        @JoinTable(
167                name = "fn_user_pseudo_role",
168                joinColumns = {@JoinColumn(name = "pseudo_role_Id", referencedColumnName = "role_id")},
169                inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "user_id")},
170                indexes = {
171                        @Index(name = "fk_pseudo_role_user_id", columnList = "user_id")
172                }
173        )
174        private Set<FnUser> fnUsers;
175        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
176        @JoinTable(
177                name = "fn_role_composite",
178                joinColumns = {@JoinColumn(name = "parent_role_id", referencedColumnName = "role_id")},
179                inverseJoinColumns = {@JoinColumn(name = "child_role_id", referencedColumnName = "role_id")},
180                indexes = {
181                        @Index(name = "fk_fn_role_composite_child", columnList = "child_role_id")
182                }
183        )
184        private Set<FnRole> fnRoles;
185        @ManyToMany(cascade = CascadeType.ALL,
186                fetch = FetchType.LAZY)
187        private Set<FnRole> fnRoleList;
188        @OneToMany(
189                targetEntity = EpRoleNotification.class,
190                mappedBy = "notificationID",
191                cascade = CascadeType.ALL,
192                fetch = FetchType.LAZY
193        )
194        private Set<EpRoleNotification> epRoleNotifications;
195        @OneToMany(
196                targetEntity = FnMenuFunctionalRoles.class,
197                mappedBy = "roleId",
198                cascade = CascadeType.ALL,
199                fetch = FetchType.LAZY
200        )
201        private Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles;
202        @OneToMany(
203                targetEntity = EpWidgetCatalogRole.class,
204                mappedBy = "roleId",
205                cascade = CascadeType.ALL,
206                fetch = FetchType.LAZY
207        )
208        private Set<EpWidgetCatalogRole> epWidgetCatalogRoles;
209        @OneToMany(
210                targetEntity = EpAppRoleFunction.class,
211                mappedBy = "fnRole",
212                cascade = CascadeType.ALL,
213                fetch = FetchType.LAZY
214        )
215        private Set<EpAppRoleFunction> epAppRoleFunctions;
216        @OneToMany(
217                targetEntity = EpUserRolesRequestDet.class,
218                mappedBy = "requestedRoleId",
219                cascade = CascadeType.ALL,
220                fetch = FetchType.LAZY
221        )
222        private Set<EpUserRolesRequestDet> epUserRolesRequestDets;
223        @OneToMany(
224                targetEntity = FnUserRole.class,
225                mappedBy = "roleId",
226                cascade = CascadeType.ALL,
227                fetch = FetchType.LAZY
228        )
229        private Set<FnUserRole> fnUserRoles;
230 }