2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
28 * https://creativecommons.org/licenses/by/4.0/
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.
36 * ============LICENSE_END============================================
41 package org.onap.portal.domain.db.fn;
43 import java.io.Serializable;
44 import java.time.LocalDateTime;
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;
68 import lombok.NoArgsConstructor;
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;
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
93 name = "FnRole.retrieveAppRolesByRoleNameAndByAppId",
94 query = "FROM FnRole where roleName =:roleName and appId =:appId"),
96 name = "FnRole.retrieveAppRolesByAppId",
97 query = "FROM FnRole where appId =:appId"),
99 name = "FnRole.retrieveAppRolesWhereAppIdIsNull",
100 query = "FROM FnRole where appId is null"),
102 name = "FnRole.retrieveAppRoleByRoleIdWhereAppIdIsNull",
103 query = "FROM FnRole where id =:roleId and appId is null"),
105 name = "FnRole.retrieveAppRoleByAppRoleIdAndByAppId",
106 query = "FROM FnRole where appRoleId =:appRoleId and appId =:appId"),
108 name = "FnRole.retrieveAppRoleByRoleIdAndAppId",
109 query = "FROM FnRole where id =:roleId and appId =:appId"),
111 name = "FnRole.retrieveAppRolesByRoleNameAndWhereAppIdIsNull",
112 query = "FROM FnRole where roleName =:roleName and appId is null"),
114 name = "FnRole.retrieveActiveRolesOfApplication",
115 query = "from FnRole where activeYn = 'Y' and appId=:appId"),
117 name = "FnRole.getUserRoleOnUserIdAndAppId",
120 + " FnUserRole fur\n"
122 + " fr.id = fur.roleId\n"
123 + " AND fur.userId = :userId"
124 + " AND fur.fnAppId.id = :appId\n"
125 + " AND fr.activeYn = 'y'"),
127 name = "FnRole.getGlobalRolesOfPortal",
131 + " roleName like 'global_%'"
132 + " and appId is null"
133 + " and activeYn = 'Y'"),
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"
140 @Table(name = "fn_role")
145 public class FnRole extends Role {
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)
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")},
156 @Index(name = "fk_pseudo_role_user_id", columnList = "user_id")
159 private Set<FnUser> fnUsers;
160 @ManyToMany(cascade = CascadeType.MERGE,
161 fetch = FetchType.LAZY, mappedBy = "role")
162 private Set<FnRoleFunction> roleFunctions;
164 targetEntity = EpRoleNotification.class,
165 mappedBy = "notificationId",
166 cascade = CascadeType.MERGE,
167 fetch = FetchType.LAZY
169 private Set<EpRoleNotification> epRoleNotifications;
171 targetEntity = FnMenuFunctionalRoles.class,
173 cascade = CascadeType.MERGE,
174 fetch = FetchType.LAZY
176 private Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles;
178 targetEntity = EpWidgetCatalogRole.class,
180 cascade = CascadeType.MERGE,
181 fetch = FetchType.LAZY
183 private Set<EpWidgetCatalogRole> epWidgetCatalogRoles;
185 targetEntity = EpAppRoleFunction.class,
187 cascade = CascadeType.MERGE,
188 fetch = FetchType.LAZY
190 private Set<EpAppRoleFunction> epAppRoleFunctions;
192 targetEntity = EpUserRolesRequestDet.class,
193 mappedBy = "requestedRoleId",
194 cascade = CascadeType.MERGE,
195 fetch = FetchType.LAZY
197 private Set<EpUserRolesRequestDet> epUserRolesRequestDets;
199 targetEntity = FnUserRole.class,
201 cascade = CascadeType.MERGE,
202 fetch = FetchType.LAZY
204 private Set<FnUserRole> fnUserRoles;
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;