getAppRolesForUser() method up in UserRolesController
[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.Embeddable;
48 import javax.persistence.Entity;
49 import javax.persistence.FetchType;
50 import javax.persistence.GeneratedValue;
51 import javax.persistence.GenerationType;
52 import javax.persistence.Id;
53 import javax.persistence.IdClass;
54 import javax.persistence.Index;
55 import javax.persistence.JoinColumn;
56 import javax.persistence.JoinTable;
57 import javax.persistence.ManyToMany;
58 import javax.persistence.NamedQueries;
59 import javax.persistence.NamedQuery;
60 import javax.persistence.OneToMany;
61 import javax.persistence.Table;
62 import javax.validation.constraints.Digits;
63 import javax.validation.constraints.NotNull;
64 import javax.validation.constraints.Size;
65 import lombok.AllArgsConstructor;
66 import lombok.Builder;
67 import lombok.Getter;
68 import lombok.NoArgsConstructor;
69 import lombok.Setter;
70 import org.hibernate.validator.constraints.SafeHtml;
71 import org.onap.portal.domain.db.ep.EpAppRoleFunction;
72 import org.onap.portal.domain.db.ep.EpRoleNotification;
73 import org.onap.portal.domain.db.ep.EpUserRolesRequestDet;
74 import org.onap.portal.domain.db.ep.EpWidgetCatalogRole;
75 import org.onap.portal.domain.dto.DomainVo;
76
77 /*
78 CREATE TABLE `fn_role` (
79         `role_id` int(11) NOT NULL AUTO_INCREMENT,
80         `role_name` varchar(300) NOT NULL,
81         `active_yn` varchar(1) NOT NULL DEFAULT 'y',
82         `priority` decimal(4,0) DEFAULT NULL,
83         `app_id` int(11) DEFAULT NULL,
84         `app_role_id` int(11) DEFAULT NULL,
85         PRIMARY KEY (`role_id`),
86         UNIQUE KEY `fn_role_name_app_id_idx` (`role_name`,`app_id`) USING BTREE
87         )
88 */
89
90 @NamedQueries({
91     @NamedQuery(
92         name = "FnRole.retrieveAppRolesByRoleNameAndByAppId",
93         query = "FROM FnRole where roleName =:roleName and appId =:appId"),
94     @NamedQuery(
95         name = "FnRole.retrieveAppRolesByAppId",
96         query = "FROM FnRole where appId =:appId"),
97     @NamedQuery(
98         name = "FnRole.retrieveAppRolesWhereAppIdIsNull",
99         query = "FROM FnRole where appId is null"),
100     @NamedQuery(
101         name = "FnRole.retrieveAppRoleByRoleIdWhereAppIdIsNull",
102         query = "FROM FnRole where roleId =:roleId and appId is null"),
103     @NamedQuery(
104         name = "FnRole.retrieveAppRoleByAppRoleIdAndByAppId",
105         query = "FROM FnRole where appRoleId =:appRoleId and appId =:appId"),
106     @NamedQuery(
107         name = "FnRole.retrieveAppRoleByRoleIdAndAppId",
108         query = "FROM FnRole where roleId =:roleId and appId =:appId"),
109     @NamedQuery(
110         name = "FnRole.retrieveAppRolesByRoleNameAndWhereAppIdIsNull",
111         query = "FROM FnRole where roleName =:roleName and appId is null"),
112     @NamedQuery(
113         name = "FnRole.retrieveActiveRolesOfApplication",
114         query = "from FnRole where activeYn = 'Y' and appId=:appId"),
115     @NamedQuery(
116         name = "FnRole.getUserRoleOnUserIdAndAppId",
117         query = " FROM"
118             + "  FnRole fr,\n"
119             + "  FnUserRole fur\n"
120             + " WHERE\n"
121             + "  fr.roleId = fur.roleId\n"
122             + "  AND fur.userId = :userId"
123             + "  AND fur.appId = :appId\n"
124             + "  AND fr.activeYn = 'y'"),
125     @NamedQuery(
126         name = "FnRole.getGlobalRolesOfPortal",
127         query = "from"
128             + "  FnRole"
129             + " where"
130             + "  roleName like 'global_%'"
131             + "  and appId is null"
132             + "  and activeYn = 'Y'"
133     )
134 })
135
136 @Table(name = "fn_role", indexes = {
137     @Index(name = "fn_role_name_app_id_idx", columnList = "role_name, app_id", unique = true)
138 })
139 @NoArgsConstructor
140 @AllArgsConstructor
141 @Builder
142 @Getter
143 @Setter
144 @Entity
145 public class FnRole extends DomainVo implements Serializable {
146
147   @Id
148   @GeneratedValue(strategy = GenerationType.AUTO)
149   @Column(name = "role_id", length = 11, nullable = false)
150   @Digits(integer = 11, fraction = 0)
151   private Long roleId;
152   @Column(name = "role_name", length = 300, nullable = false)
153   @Size(max = 300)
154   @NotNull
155   @SafeHtml
156   private String roleName;
157   @Column(name = "active_yn", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false)
158   @NotNull
159   private Boolean activeYn;
160   @Column(name = "priority", length = 4, columnDefinition = "decimal(4,0) DEFAULT NULL")
161   @Digits(integer = 4, fraction = 0)
162   private Integer priority;
163   @Column(name = "app_Id", length = 11, columnDefinition = "int(11) default null")
164   @Digits(integer = 11, fraction = 0)
165   private Long appId;
166   @Column(name = "app_role_id", length = 11, columnDefinition = "int(11) default null")
167   @Digits(integer = 11, fraction = 0)
168   private Long appRoleId;
169   @OneToMany(
170       targetEntity = FnRoleFunction.class,
171       mappedBy = "roleId",
172       cascade = CascadeType.ALL,
173       fetch = FetchType.LAZY
174   )
175   private Set<FnRoleFunction> fnRoleFunctions;
176   @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
177   @JoinTable(
178       name = "fn_user_pseudo_role",
179       joinColumns = {@JoinColumn(name = "pseudo_role_Id", referencedColumnName = "role_id")},
180       inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "user_id")},
181       indexes = {
182           @Index(name = "fk_pseudo_role_user_id", columnList = "user_id")
183       }
184   )
185   private Set<FnUser> fnUsers;
186   @OneToMany(
187       targetEntity = FnRoleComposite.class,
188       mappedBy = "childRoles",
189       cascade = CascadeType.ALL,
190       fetch = FetchType.LAZY
191   )
192   private Set<FnRoleComposite> childRoles;
193   @OneToMany(
194       targetEntity = FnRoleComposite.class,
195       mappedBy = "parentRoles",
196       cascade = CascadeType.ALL,
197       fetch = FetchType.LAZY
198   )
199   private Set<FnRoleComposite> parentRoles;
200   @ManyToMany(cascade = CascadeType.ALL,
201       fetch = FetchType.LAZY)
202   private Set<FnRoleFunction> roleFunctions;
203   @OneToMany(
204       targetEntity = EpRoleNotification.class,
205       mappedBy = "notificationID",
206       cascade = CascadeType.ALL,
207       fetch = FetchType.LAZY
208   )
209   private Set<EpRoleNotification> epRoleNotifications;
210   @OneToMany(
211       targetEntity = FnMenuFunctionalRoles.class,
212       mappedBy = "roleId",
213       cascade = CascadeType.ALL,
214       fetch = FetchType.LAZY
215   )
216   private Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles;
217   @OneToMany(
218       targetEntity = EpWidgetCatalogRole.class,
219       mappedBy = "roleId",
220       cascade = CascadeType.ALL,
221       fetch = FetchType.LAZY
222   )
223   private Set<EpWidgetCatalogRole> epWidgetCatalogRoles;
224   @OneToMany(
225       targetEntity = EpAppRoleFunction.class,
226       mappedBy = "fnRole",
227       cascade = CascadeType.ALL,
228       fetch = FetchType.LAZY
229   )
230   private Set<EpAppRoleFunction> epAppRoleFunctions;
231   @OneToMany(
232       targetEntity = EpUserRolesRequestDet.class,
233       mappedBy = "requestedRoleId",
234       cascade = CascadeType.ALL,
235       fetch = FetchType.LAZY
236   )
237   private Set<EpUserRolesRequestDet> epUserRolesRequestDets;
238   @OneToMany(
239       targetEntity = FnUserRole.class,
240       mappedBy = "roleId",
241       cascade = CascadeType.ALL,
242       fetch = FetchType.LAZY
243   )
244   private Set<FnUserRole> fnUserRoles;
245
246   public FnRole(Long roleId, String roleName, Boolean activeYn, Integer priority,
247       Set<FnRoleFunction> fnRoleFunctions, Set<FnRoleComposite> childRoles,
248       Set<FnRoleComposite> parentRoles) {
249     this.roleId = roleId;
250     this.roleName = roleName;
251     this.activeYn = activeYn;
252     this.priority = priority;
253     this.fnRoleFunctions = fnRoleFunctions;
254     this.childRoles = childRoles;
255     this.parentRoles = parentRoles;
256   }
257 }