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