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