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;
46 import java.util.HashSet;
48 import java.util.stream.Collectors;
49 import javax.persistence.CascadeType;
50 import javax.persistence.Column;
51 import javax.persistence.Entity;
52 import javax.persistence.FetchType;
53 import javax.persistence.GeneratedValue;
54 import javax.persistence.GenerationType;
55 import javax.persistence.Id;
56 import javax.persistence.Index;
57 import javax.persistence.JoinColumn;
58 import javax.persistence.ManyToMany;
59 import javax.persistence.ManyToOne;
60 import javax.persistence.NamedQueries;
61 import javax.persistence.NamedQuery;
62 import javax.persistence.OneToMany;
63 import javax.persistence.SequenceGenerator;
64 import javax.persistence.Table;
65 import javax.persistence.UniqueConstraint;
66 import javax.validation.constraints.Digits;
67 import javax.validation.constraints.Email;
68 import javax.validation.constraints.NotNull;
69 import javax.validation.constraints.PastOrPresent;
70 import javax.validation.constraints.Size;
71 import lombok.AllArgsConstructor;
72 import lombok.Builder;
74 import lombok.NoArgsConstructor;
76 import org.hibernate.annotations.DynamicUpdate;
77 import org.hibernate.validator.constraints.SafeHtml;
78 import org.onap.portal.domain.db.cr.CrReportFileHistory;
79 import org.onap.portal.domain.db.ep.EpPersUserWidgetPlacement;
80 import org.onap.portal.domain.db.ep.EpPersUserWidgetSel;
81 import org.onap.portal.domain.db.ep.EpUserNotification;
82 import org.onap.portal.domain.db.ep.EpUserRolesRequest;
83 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
84 import org.onap.portal.domain.dto.DomainVo;
85 import org.springframework.security.core.GrantedAuthority;
86 import org.springframework.security.core.authority.SimpleGrantedAuthority;
87 import org.springframework.security.core.userdetails.UserDetails;
90 CREATE TABLE `fn_user` (
91 `user_id` int(11) NOT NULL AUTO_INCREMENT,
92 `org_id` int(11) DEFAULT NULL,
93 `manager_id` int(11) DEFAULT NULL,
94 `first_name` varchar(50) DEFAULT NULL,
95 `middle_name` varchar(50) DEFAULT NULL,
96 `last_name` varchar(50) DEFAULT NULL,
97 `phone` varchar(25) DEFAULT NULL,
98 `fax` varchar(25) DEFAULT NULL,
99 `cellular` varchar(25) DEFAULT NULL,
100 `email` varchar(50) DEFAULT NULL,
101 `address_id` decimal(11,0) DEFAULT NULL,
102 `alert_method_cd` varchar(10) DEFAULT NULL,
103 `hrid` varchar(20) DEFAULT NULL,
104 `org_user_id` varchar(20) DEFAULT NULL,
105 `org_code` varchar(30) DEFAULT NULL,
106 `login_id` varchar(25) DEFAULT NULL,
107 `login_pwd` varchar(100) DEFAULT NULL,
108 `last_login_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
109 `active_yn` varchar(1) NOT NULL DEFAULT 'y',
110 `created_id` int(11) DEFAULT NULL,
111 `created_date` timestamp NOT NULL DEFAULT current_timestamp(),
112 `modified_id` int(11) DEFAULT NULL,
113 `modified_date` timestamp NOT NULL DEFAULT current_timestamp(),
114 `is_internal_yn` char(1) NOT NULL DEFAULT 'n',
115 `address_line_1` varchar(100) DEFAULT NULL,
116 `address_line_2` varchar(100) DEFAULT NULL,
117 `city` varchar(50) DEFAULT NULL,
118 `state_cd` varchar(3) DEFAULT NULL,
119 `zip_code` varchar(11) DEFAULT NULL,
120 `country_cd` varchar(3) DEFAULT NULL,
121 `location_clli` varchar(8) DEFAULT NULL,
122 `org_manager_userid` varchar(20) DEFAULT NULL,
123 `company` varchar(100) DEFAULT NULL,
124 `department_name` varchar(100) DEFAULT NULL,
125 `job_title` varchar(100) DEFAULT NULL,
126 `timezone` int(11) DEFAULT NULL,
127 `department` varchar(25) DEFAULT NULL,
128 `business_unit` varchar(25) DEFAULT NULL,
129 `business_unit_name` varchar(100) DEFAULT NULL,
130 `cost_center` varchar(25) DEFAULT NULL,
131 `fin_loc_code` varchar(10) DEFAULT NULL,
132 `silo_status` varchar(10) DEFAULT NULL,
133 `language_id` int(2) NOT NULL DEFAULT 1,
134 PRIMARY KEY (`user_id`),
135 UNIQUE KEY `fn_user_hrid` (`hrid`) USING BTREE,
136 UNIQUE KEY `fn_user_login_id` (`login_id`) USING BTREE,
137 KEY `fn_user_address_id` (`address_id`) USING BTREE,
138 KEY `fn_user_alert_method_cd` (`alert_method_cd`) USING BTREE,
139 KEY `fn_user_org_id` (`org_id`) USING BTREE,
140 KEY `fk_fn_user_ref_197_fn_user` (`manager_id`),
141 KEY `fk_fn_user_ref_198_fn_user` (`created_id`),
142 KEY `fk_fn_user_ref_199_fn_user` (`modified_id`),
143 KEY `fk_timezone` (`timezone`),
144 CONSTRAINT `fk_fn_user_ref_110_fn_org` FOREIGN KEY (`org_id`) REFERENCES `fn_org` (`org_id`),
145 CONSTRAINT `fk_fn_user_ref_123_fn_lu_al` FOREIGN KEY (`alert_method_cd`) REFERENCES `fn_lu_alert_method` (`alert_method_cd`),
146 CONSTRAINT `fk_fn_user_ref_197_fn_user` FOREIGN KEY (`manager_id`) REFERENCES `fn_user` (`user_id`),
147 CONSTRAINT `fk_fn_user_ref_198_fn_user` FOREIGN KEY (`created_id`) REFERENCES `fn_user` (`user_id`),
148 CONSTRAINT `fk_fn_user_ref_199_fn_user` FOREIGN KEY (`modified_id`) REFERENCES `fn_user` (`user_id`),
149 CONSTRAINT `fk_timezone` FOREIGN KEY (`timezone`) REFERENCES `fn_lu_timezone` (`timezone_id`)
155 name = "FnUser.getUserWithOrgUserId",
156 query = "FROM FnUser WHERE orgUserId = :orgId"),
158 name = "FnUser.getActiveUsers",
159 query = "FROM FnUser WHERE activeYn = 'Y'"),
161 name = "FnUser.getUsersByOrgIds",
162 query = "FROM FnUser WHERE orgUserId IN :orgIds"
165 @Table(name = "fn_user", indexes = {
166 @Index(name = "fn_user_address_id", columnList = "address_id"),
167 @Index(name = "fn_user_alert_method_cd", columnList = "alert_method_cd"),
168 @Index(name = "fn_user_org_id", columnList = "org_id"),
169 @Index(name = "fk_fn_user_ref_197_fn_user", columnList = "manager_id"),
170 @Index(name = "fk_fn_user_ref_198_fn_user", columnList = "created_id"),
171 @Index(name = "fk_fn_user_ref_199_fn_user", columnList = "modified_id"),
172 @Index(name = "fk_timezone", columnList = "timezone")
174 uniqueConstraints = {
175 @UniqueConstraint(name = "fn_user_hrid", columnNames = "hrid"),
176 @UniqueConstraint(name = "fn_user_login_id", columnNames = "login_id")
187 public class FnUser extends DomainVo implements UserDetails, Serializable {
190 @GeneratedValue(strategy = GenerationType.IDENTITY)
191 @Column(name = "user_id", nullable = false)
193 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
194 @JoinColumn(name = "org_id")
196 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
197 @JoinColumn(name = "manager_id")
198 private FnUser managerId;
199 @Column(name = "first_name", length = 50)
202 private String firstName;
203 @Column(name = "middle_name", length = 50)
206 private String middleName;
207 @Column(name = "last_name", length = 50)
210 private String lastName;
211 @Column(name = "phone", length = 25)
214 private String phone;
215 @Column(name = "fax", length = 25)
219 @Column(name = "cellular", length = 25)
222 private String cellular;
223 @Column(name = "email", length = 50)
227 private String email;
228 @Column(name = "address_id")
229 @Digits(integer = 11, fraction = 0)
230 private Long addressId;
231 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
232 @JoinColumn(name = "alert_method_cd")
233 private FnLuAlertMethod alertMethodCd;
234 @Column(name = "hrid", length = 20)
238 @Column(name = "org_user_id", length = 20)
241 private String orgUserId;
242 @Column(name = "org_code", length = 30)
245 private String org_code;
246 @Column(name = "login_id", length = 25)
249 private String loginId;
250 @Column(name = "login_pwd", length = 100)
253 private String loginPwd;
254 @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
256 protected LocalDateTime lastLoginDate;
257 @Column(name = "active_yn", nullable = false)
258 private Boolean activeYn;
259 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
260 @JoinColumn(name = "created_id")
261 private FnUser createdId;
262 @Column(name = "created_date", columnDefinition = "datetime DEFAULT current_timestamp()", nullable = false)
264 protected LocalDateTime createdDate;
265 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
266 @JoinColumn(name = "modified_id")
267 private FnUser modifiedId;
268 @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
270 protected LocalDateTime modifiedDate;
271 @Column(name = "is_internal_yn", nullable = false, columnDefinition = "bit DEFAULT 0")
272 private Boolean isInternalYn;
273 @Column(name = "address_line_1", length = 100)
276 private String addressLine1;
277 @Column(name = "address_line_2", length = 100)
280 private String addressLine2;
281 @Column(name = "city", length = 50)
285 @Column(name = "state_cd", length = 3)
288 private String stateCd;
289 @Column(name = "zip_code", length = 11)
292 private String zipCode;
293 @Column(name = "country_cd", length = 3)
296 private String countryCd;
297 @Column(name = "location_clli", length = 8)
300 private String locationClli;
301 @Column(name = "org_manager_userid", length = 20)
304 private String orgManagerUserId;
305 @Column(name = "company", length = 100)
308 private String company;
309 @Column(name = "department_name", length = 200)
312 private String departmentName;
313 @Column(name = "job_title", length = 100)
316 private String jobTitle;
317 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
318 @JoinColumn(name = "timezone")
319 private FnLuTimezone timezone;
320 @Column(name = "department", length = 25)
323 private String department;
324 @Column(name = "business_unit", length = 25)
327 private String businessUnit;
328 @Column(name = "business_unit_name", length = 100)
331 private String businessUnitName;
332 @Column(name = "cost_center", length = 25)
335 private String cost_center;
336 @Column(name = "fin_loc_code", length = 10)
339 private String finLocCode;
340 @Column(name = "silo_status", length = 10)
343 private String siloStatus;
344 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
345 @JoinColumn(name = "language_id", nullable = false, columnDefinition = "bigint DEFAULT 1")
346 @NotNull(message = "languageId must not be null")
347 private FnLanguage languageId;
348 @Column(name = "is_guest", nullable = false, columnDefinition = "bit DEFAULT 0")
349 @NotNull(message = "guest must not be null")
350 private Boolean guest;
351 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
352 private Set<CrReportFileHistory> crReportFileHistorie;
353 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
354 private Set<FnRole> fnRoles;
355 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
356 private Set<FnMenuFunctional> fnRoleList;
358 targetEntity = FnAuditLog.class,
360 cascade = CascadeType.ALL,
361 fetch = FetchType.LAZY
363 private Set<FnAuditLog> fnAuditLogs;
365 targetEntity = FnUser.class,
366 mappedBy = "createdId",
367 cascade = CascadeType.ALL,
368 fetch = FetchType.LAZY
370 private Set<FnUser> fnUsersCreatedId;
372 targetEntity = FnUser.class,
373 mappedBy = "managerId",
374 cascade = CascadeType.ALL,
375 fetch = FetchType.LAZY
377 private Set<FnUser> fnUsersManagerId;
379 targetEntity = FnUser.class,
380 mappedBy = "modifiedId",
381 cascade = CascadeType.ALL,
382 fetch = FetchType.LAZY
384 private Set<FnUser> fnUsersModifiedId;
386 targetEntity = EpUserRolesRequest.class,
388 cascade = CascadeType.ALL,
389 fetch = FetchType.LAZY
391 private Set<EpUserRolesRequest> epUserRolesRequests;
393 targetEntity = FnPersUserAppSel.class,
395 cascade = CascadeType.ALL,
396 fetch = FetchType.LAZY
398 private Set<FnPersUserAppSel> persUserAppSels;
400 targetEntity = EpWidgetCatalogParameter.class,
402 cascade = CascadeType.ALL,
403 fetch = FetchType.LAZY
405 private Set<EpWidgetCatalogParameter> epWidgetCatalogParameters;
407 targetEntity = EpPersUserWidgetPlacement.class,
409 cascade = CascadeType.ALL,
410 fetch = FetchType.LAZY
412 private Set<EpPersUserWidgetPlacement> epPersUserWidgetPlacements;
414 targetEntity = EpPersUserWidgetSel.class,
416 cascade = CascadeType.ALL,
417 fetch = FetchType.LAZY
419 private Set<EpPersUserWidgetSel> epPersUserWidgetSels;
421 targetEntity = FnUserRole.class,
423 cascade = CascadeType.ALL,
424 fetch = FetchType.LAZY
426 private Set<FnUserRole> fnUserRoles;
428 targetEntity = EpUserNotification.class,
430 cascade = CascadeType.ALL,
431 fetch = FetchType.LAZY
433 private Set<EpUserNotification> epUserNotifications;
436 public Collection<? extends GrantedAuthority> getAuthorities() {
439 .map(fnRole -> new SimpleGrantedAuthority("ROLE_" + fnRole.getRoleName()))
440 .collect(Collectors.toList());
444 public String getPassword() {
445 return this.getLoginPwd();
449 public String getUsername() {
450 return this.getLoginId();
454 public boolean isAccountNonExpired() {
459 public boolean isAccountNonLocked() {
464 public boolean isCredentialsNonExpired() {
469 public boolean isEnabled() {
473 public String getFullName() {
474 return this.firstName + " " + this.lastName;