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;
45 import java.util.Collection;
47 import java.util.stream.Collectors;
48 import javax.persistence.CascadeType;
49 import javax.persistence.Column;
50 import javax.persistence.Entity;
51 import javax.persistence.FetchType;
52 import javax.persistence.GeneratedValue;
53 import javax.persistence.GenerationType;
54 import javax.persistence.Id;
55 import javax.persistence.Index;
56 import javax.persistence.JoinColumn;
57 import javax.persistence.ManyToMany;
58 import javax.persistence.ManyToOne;
59 import javax.persistence.NamedQueries;
60 import javax.persistence.NamedQuery;
61 import javax.persistence.OneToMany;
62 import javax.persistence.SequenceGenerator;
63 import javax.persistence.Table;
64 import javax.persistence.UniqueConstraint;
65 import javax.validation.constraints.Digits;
66 import javax.validation.constraints.Email;
67 import javax.validation.constraints.NotNull;
68 import javax.validation.constraints.PastOrPresent;
69 import javax.validation.constraints.Size;
70 import lombok.AllArgsConstructor;
71 import lombok.Builder;
73 import lombok.NoArgsConstructor;
75 import org.hibernate.annotations.DynamicUpdate;
76 import org.hibernate.validator.constraints.SafeHtml;
77 import org.onap.portal.domain.db.cr.CrReportFileHistory;
78 import org.onap.portal.domain.db.ep.EpPersUserWidgetPlacement;
79 import org.onap.portal.domain.db.ep.EpPersUserWidgetSel;
80 import org.onap.portal.domain.db.ep.EpUserNotification;
81 import org.onap.portal.domain.db.ep.EpUserRolesRequest;
82 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
83 import org.onap.portal.domain.dto.DomainVo;
84 import org.springframework.security.core.GrantedAuthority;
85 import org.springframework.security.core.authority.SimpleGrantedAuthority;
86 import org.springframework.security.core.userdetails.UserDetails;
89 CREATE TABLE `fn_user` (
90 `user_id` int(11) NOT NULL AUTO_INCREMENT,
91 `org_id` int(11) DEFAULT NULL,
92 `manager_id` int(11) DEFAULT NULL,
93 `first_name` varchar(50) DEFAULT NULL,
94 `middle_name` varchar(50) DEFAULT NULL,
95 `last_name` varchar(50) DEFAULT NULL,
96 `phone` varchar(25) DEFAULT NULL,
97 `fax` varchar(25) DEFAULT NULL,
98 `cellular` varchar(25) DEFAULT NULL,
99 `email` varchar(50) DEFAULT NULL,
100 `address_id` decimal(11,0) DEFAULT NULL,
101 `alert_method_cd` varchar(10) DEFAULT NULL,
102 `hrid` varchar(20) DEFAULT NULL,
103 `org_user_id` varchar(20) DEFAULT NULL,
104 `org_code` varchar(30) DEFAULT NULL,
105 `login_id` varchar(25) DEFAULT NULL,
106 `login_pwd` varchar(100) DEFAULT NULL,
107 `last_login_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
108 `active_yn` varchar(1) NOT NULL DEFAULT 'y',
109 `created_id` int(11) DEFAULT NULL,
110 `created_date` timestamp NOT NULL DEFAULT current_timestamp(),
111 `modified_id` int(11) DEFAULT NULL,
112 `modified_date` timestamp NOT NULL DEFAULT current_timestamp(),
113 `is_internal_yn` char(1) NOT NULL DEFAULT 'n',
114 `address_line_1` varchar(100) DEFAULT NULL,
115 `address_line_2` varchar(100) DEFAULT NULL,
116 `city` varchar(50) DEFAULT NULL,
117 `state_cd` varchar(3) DEFAULT NULL,
118 `zip_code` varchar(11) DEFAULT NULL,
119 `country_cd` varchar(3) DEFAULT NULL,
120 `location_clli` varchar(8) DEFAULT NULL,
121 `org_manager_userid` varchar(20) DEFAULT NULL,
122 `company` varchar(100) DEFAULT NULL,
123 `department_name` varchar(100) DEFAULT NULL,
124 `job_title` varchar(100) DEFAULT NULL,
125 `timezone` int(11) DEFAULT NULL,
126 `department` varchar(25) DEFAULT NULL,
127 `business_unit` varchar(25) DEFAULT NULL,
128 `business_unit_name` varchar(100) DEFAULT NULL,
129 `cost_center` varchar(25) DEFAULT NULL,
130 `fin_loc_code` varchar(10) DEFAULT NULL,
131 `silo_status` varchar(10) DEFAULT NULL,
132 `language_id` int(2) NOT NULL DEFAULT 1,
133 PRIMARY KEY (`user_id`),
134 UNIQUE KEY `fn_user_hrid` (`hrid`) USING BTREE,
135 UNIQUE KEY `fn_user_login_id` (`login_id`) USING BTREE,
136 KEY `fn_user_address_id` (`address_id`) USING BTREE,
137 KEY `fn_user_alert_method_cd` (`alert_method_cd`) USING BTREE,
138 KEY `fn_user_org_id` (`org_id`) USING BTREE,
139 KEY `fk_fn_user_ref_197_fn_user` (`manager_id`),
140 KEY `fk_fn_user_ref_198_fn_user` (`created_id`),
141 KEY `fk_fn_user_ref_199_fn_user` (`modified_id`),
142 KEY `fk_timezone` (`timezone`),
143 CONSTRAINT `fk_fn_user_ref_110_fn_org` FOREIGN KEY (`org_id`) REFERENCES `fn_org` (`org_id`),
144 CONSTRAINT `fk_fn_user_ref_123_fn_lu_al` FOREIGN KEY (`alert_method_cd`) REFERENCES `fn_lu_alert_method` (`alert_method_cd`),
145 CONSTRAINT `fk_fn_user_ref_197_fn_user` FOREIGN KEY (`manager_id`) REFERENCES `fn_user` (`user_id`),
146 CONSTRAINT `fk_fn_user_ref_198_fn_user` FOREIGN KEY (`created_id`) REFERENCES `fn_user` (`user_id`),
147 CONSTRAINT `fk_fn_user_ref_199_fn_user` FOREIGN KEY (`modified_id`) REFERENCES `fn_user` (`user_id`),
148 CONSTRAINT `fk_timezone` FOREIGN KEY (`timezone`) REFERENCES `fn_lu_timezone` (`timezone_id`)
154 name = "FnUser.getUserWithOrgUserId",
155 query = "FROM FnUser WHERE orgUserId = :orgId"),
157 name = "FnUser.getActiveUsers",
158 query = "FROM FnUser WHERE activeYn = 'Y'"),
160 name = "FnUser.getUsersByOrgIds",
161 query = "FROM FnUser WHERE orgUserId IN :orgIds"
164 @Table(name = "fn_user", indexes = {
165 @Index(name = "fn_user_address_id", columnList = "address_id"),
166 @Index(name = "fn_user_alert_method_cd", columnList = "alert_method_cd"),
167 @Index(name = "fn_user_org_id", columnList = "org_id"),
168 @Index(name = "fk_fn_user_ref_197_fn_user", columnList = "manager_id"),
169 @Index(name = "fk_fn_user_ref_198_fn_user", columnList = "created_id"),
170 @Index(name = "fk_fn_user_ref_199_fn_user", columnList = "modified_id"),
171 @Index(name = "fk_timezone", columnList = "timezone")
173 uniqueConstraints = {
174 @UniqueConstraint(name = "fn_user_hrid", columnNames = "hrid"),
175 @UniqueConstraint(name = "fn_user_login_id", columnNames = "login_id")
186 public class FnUser extends DomainVo implements UserDetails, Serializable {
189 @GeneratedValue(strategy = GenerationType.IDENTITY)
190 @Column(name = "user_id", nullable = false)
192 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
193 @JoinColumn(name = "org_id")
195 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
196 @JoinColumn(name = "manager_id")
197 private FnUser managerId;
198 @Column(name = "first_name", length = 50)
201 private String firstName;
202 @Column(name = "middle_name", length = 50)
205 private String middleName;
206 @Column(name = "last_name", length = 50)
209 private String lastName;
210 @Column(name = "phone", length = 25)
213 private String phone;
214 @Column(name = "fax", length = 25)
218 @Column(name = "cellular", length = 25)
221 private String cellular;
222 @Column(name = "email", length = 50)
226 private String email;
227 @Column(name = "address_id")
228 @Digits(integer = 11, fraction = 0)
229 private Long addressId;
230 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
231 @JoinColumn(name = "alert_method_cd")
232 private FnLuAlertMethod alertMethodCd;
233 @Column(name = "hrid", length = 20)
237 @Column(name = "org_user_id", length = 20)
240 private String orgUserId;
241 @Column(name = "org_code", length = 30)
244 private String org_code;
245 @Column(name = "login_id", length = 25)
248 private String loginId;
249 @Column(name = "login_pwd", length = 100)
252 private String loginPwd;
253 @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
255 protected LocalDateTime lastLoginDate;
256 @Column(name = "active_yn", nullable = false)
257 private Boolean activeYn;
258 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
259 @JoinColumn(name = "created_id")
260 private FnUser createdId;
261 @Column(name = "created_date", columnDefinition = "datetime DEFAULT current_timestamp()", nullable = false)
263 protected LocalDateTime createdDate;
264 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
265 @JoinColumn(name = "modified_id")
266 private FnUser modifiedId;
267 @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
269 protected LocalDateTime modifiedDate;
270 @Column(name = "is_internal_yn", nullable = false, columnDefinition = "bit DEFAULT 0")
271 private Boolean isInternalYn;
272 @Column(name = "address_line_1", length = 100)
275 private String addressLine1;
276 @Column(name = "address_line_2", length = 100)
279 private String addressLine2;
280 @Column(name = "city", length = 50)
284 @Column(name = "state_cd", length = 3)
287 private String stateCd;
288 @Column(name = "zip_code", length = 11)
291 private String zipCode;
292 @Column(name = "country_cd", length = 3)
295 private String countryCd;
296 @Column(name = "location_clli", length = 8)
299 private String locationClli;
300 @Column(name = "org_manager_userid", length = 20)
303 private String orgManagerUserId;
304 @Column(name = "company", length = 100)
307 private String company;
308 @Column(name = "department_name", length = 200)
311 private String departmentName;
312 @Column(name = "job_title", length = 100)
315 private String jobTitle;
316 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
317 @JoinColumn(name = "timezone")
318 private FnLuTimezone timezone;
319 @Column(name = "department", length = 25)
322 private String department;
323 @Column(name = "business_unit", length = 25)
326 private String businessUnit;
327 @Column(name = "business_unit_name", length = 100)
330 private String businessUnitName;
331 @Column(name = "cost_center", length = 25)
334 private String cost_center;
335 @Column(name = "fin_loc_code", length = 10)
338 private String finLocCode;
339 @Column(name = "silo_status", length = 10)
342 private String siloStatus;
343 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
344 @JoinColumn(name = "language_id", nullable = false, columnDefinition = "int(11) DEFAULT 1")
345 @NotNull(message = "languageId must not be null")
346 private FnLanguage languageId;
347 @Column(name = "is_guest", nullable = false, columnDefinition = "bit DEFAULT 0")
348 @NotNull(message = "guest must not be null")
349 private Boolean guest;
350 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
351 private Set<CrReportFileHistory> crReportFileHistorie;
352 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
353 private Set<FnRole> fnRoles;
354 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
355 private Set<FnMenuFunctional> fnRoleList;
357 targetEntity = FnAuditLog.class,
359 cascade = CascadeType.ALL,
360 fetch = FetchType.LAZY
362 private Set<FnAuditLog> fnAuditLogs;
364 targetEntity = FnUser.class,
365 mappedBy = "createdId",
366 cascade = CascadeType.ALL,
367 fetch = FetchType.LAZY
369 private Set<FnUser> fnUsersCreatedId;
371 targetEntity = FnUser.class,
372 mappedBy = "managerId",
373 cascade = CascadeType.ALL,
374 fetch = FetchType.LAZY
376 private Set<FnUser> fnUsersManagerId;
378 targetEntity = FnUser.class,
379 mappedBy = "modifiedId",
380 cascade = CascadeType.ALL,
381 fetch = FetchType.LAZY
383 private Set<FnUser> fnUsersModifiedId;
385 targetEntity = EpUserRolesRequest.class,
387 cascade = CascadeType.ALL,
388 fetch = FetchType.LAZY
390 private Set<EpUserRolesRequest> epUserRolesRequests;
392 targetEntity = FnPersUserAppSel.class,
394 cascade = CascadeType.ALL,
395 fetch = FetchType.LAZY
397 private Set<FnPersUserAppSel> persUserAppSels;
399 targetEntity = EpWidgetCatalogParameter.class,
401 cascade = CascadeType.ALL,
402 fetch = FetchType.LAZY
404 private Set<EpWidgetCatalogParameter> epWidgetCatalogParameters;
406 targetEntity = EpPersUserWidgetPlacement.class,
408 cascade = CascadeType.ALL,
409 fetch = FetchType.LAZY
411 private Set<EpPersUserWidgetPlacement> epPersUserWidgetPlacements;
413 targetEntity = EpPersUserWidgetSel.class,
415 cascade = CascadeType.ALL,
416 fetch = FetchType.LAZY
418 private Set<EpPersUserWidgetSel> epPersUserWidgetSels;
420 targetEntity = FnUserRole.class,
422 cascade = CascadeType.ALL,
423 fetch = FetchType.LAZY
425 private Set<FnUserRole> fnUserRoles;
427 targetEntity = EpUserNotification.class,
429 cascade = CascadeType.ALL,
430 fetch = FetchType.LAZY
432 private Set<EpUserNotification> epUserNotifications;
435 public Collection<? extends GrantedAuthority> getAuthorities() {
438 .map(fnRole -> new SimpleGrantedAuthority("ROLE_" + fnRole.getRoleName()))
439 .collect(Collectors.toList());
443 public String getPassword() {
444 return this.getLoginPwd();
448 public String getUsername() {
449 return this.getLoginId();
453 public boolean isAccountNonExpired() {
458 public boolean isAccountNonLocked() {
463 public boolean isCredentialsNonExpired() {
468 public boolean isEnabled() {
472 public String getFullName() {
473 return this.firstName + " " + this.lastName;