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 @SequenceGenerator(name = "seq", initialValue = 1000, allocationSize = 100000)
187 public class FnUser extends DomainVo implements UserDetails, Serializable {
190 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
191 @Column(name = "user_id", length = 11, nullable = false)
192 @Digits(integer = 11, fraction = 0)
194 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
195 @JoinColumn(name = "org_id")
197 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
198 @JoinColumn(name = "manager_id")
199 private FnUser managerId;
200 @Column(name = "first_name", length = 50)
203 private String firstName;
204 @Column(name = "middle_name", length = 50)
207 private String middleName;
208 @Column(name = "last_name", length = 50)
211 private String lastName;
212 @Column(name = "phone", length = 25)
215 private String phone;
216 @Column(name = "fax", length = 25)
220 @Column(name = "cellular", length = 25)
223 private String cellular;
224 @Column(name = "email", length = 50)
228 private String email;
229 @Column(name = "address_id")
230 @Digits(integer = 11, fraction = 0)
231 private Long addressId;
232 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
233 @JoinColumn(name = "alert_method_cd")
234 private FnLuAlertMethod alertMethodCd;
235 @Column(name = "hrid", length = 20)
239 @Column(name = "org_user_id", length = 20)
242 private String orgUserId;
243 @Column(name = "org_code", length = 30)
246 private String org_code;
247 @Column(name = "login_id", length = 25)
250 private String loginId;
251 @Column(name = "login_pwd", length = 100)
254 private String loginPwd;
255 @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
257 protected LocalDateTime lastLoginDate;
258 @Column(name = "active_yn", nullable = false)
259 private Boolean activeYn;
260 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
261 @JoinColumn(name = "created_id")
262 private FnUser createdId;
263 @Column(name = "created_date", columnDefinition = "datetime DEFAULT current_timestamp()", nullable = false)
265 protected LocalDateTime createdDate;
266 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
267 @JoinColumn(name = "modified_id")
268 private FnUser modifiedId;
269 @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
271 protected LocalDateTime modifiedDate;
272 @Column(name = "is_internal_yn", nullable = false, columnDefinition = "bit DEFAULT 0")
273 private Boolean isInternalYn;
274 @Column(name = "address_line_1", length = 100)
277 private String addressLine1;
278 @Column(name = "address_line_2", length = 100)
281 private String addressLine2;
282 @Column(name = "city", length = 50)
286 @Column(name = "state_cd", length = 3)
289 private String stateCd;
290 @Column(name = "zip_code", length = 11)
293 private String zipCode;
294 @Column(name = "country_cd", length = 3)
297 private String countryCd;
298 @Column(name = "location_clli", length = 8)
301 private String locationClli;
302 @Column(name = "org_manager_userid", length = 20)
305 private String orgManagerUserId;
306 @Column(name = "company", length = 100)
309 private String company;
310 @Column(name = "department_name", length = 200)
313 private String departmentName;
314 @Column(name = "job_title", length = 100)
317 private String jobTitle;
318 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
319 @JoinColumn(name = "timezone")
320 private FnLuTimezone timezone;
321 @Column(name = "department", length = 25)
324 private String department;
325 @Column(name = "business_unit", length = 25)
328 private String businessUnit;
329 @Column(name = "business_unit_name", length = 100)
332 private String businessUnitName;
333 @Column(name = "cost_center", length = 25)
336 private String cost_center;
337 @Column(name = "fin_loc_code", length = 10)
340 private String finLocCode;
341 @Column(name = "silo_status", length = 10)
344 private String siloStatus;
345 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
346 @JoinColumn(name = "language_id", nullable = false, columnDefinition = "int(11) DEFAULT 1")
347 @NotNull(message = "languageId must not be null")
348 private FnLanguage languageId;
349 @Column(name = "is_guest", nullable = false, columnDefinition = "bit DEFAULT 0")
350 @NotNull(message = "guest must not be null")
351 private Boolean guest;
352 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
353 private Set<CrReportFileHistory> crReportFileHistorie;
354 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
355 private Set<FnRole> fnRoles;
356 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
357 private Set<FnMenuFunctional> fnRoleList;
359 targetEntity = FnAuditLog.class,
361 cascade = CascadeType.ALL,
362 fetch = FetchType.LAZY
364 private Set<FnAuditLog> fnAuditLogs;
366 targetEntity = FnUser.class,
367 mappedBy = "createdId",
368 cascade = CascadeType.ALL,
369 fetch = FetchType.LAZY
371 private Set<FnUser> fnUsersCreatedId;
373 targetEntity = FnUser.class,
374 mappedBy = "managerId",
375 cascade = CascadeType.ALL,
376 fetch = FetchType.LAZY
378 private Set<FnUser> fnUsersManagerId;
380 targetEntity = FnUser.class,
381 mappedBy = "modifiedId",
382 cascade = CascadeType.ALL,
383 fetch = FetchType.LAZY
385 private Set<FnUser> fnUsersModifiedId;
387 targetEntity = EpUserRolesRequest.class,
389 cascade = CascadeType.ALL,
390 fetch = FetchType.LAZY
392 private Set<EpUserRolesRequest> epUserRolesRequests;
394 targetEntity = FnPersUserAppSel.class,
396 cascade = CascadeType.ALL,
397 fetch = FetchType.LAZY
399 private Set<FnPersUserAppSel> persUserAppSels;
401 targetEntity = EpWidgetCatalogParameter.class,
403 cascade = CascadeType.ALL,
404 fetch = FetchType.LAZY
406 private Set<EpWidgetCatalogParameter> epWidgetCatalogParameters;
408 targetEntity = EpPersUserWidgetPlacement.class,
410 cascade = CascadeType.ALL,
411 fetch = FetchType.LAZY
413 private Set<EpPersUserWidgetPlacement> epPersUserWidgetPlacements;
415 targetEntity = EpPersUserWidgetSel.class,
417 cascade = CascadeType.ALL,
418 fetch = FetchType.LAZY
420 private Set<EpPersUserWidgetSel> epPersUserWidgetSels;
422 targetEntity = FnUserRole.class,
424 cascade = CascadeType.ALL,
425 fetch = FetchType.LAZY
427 private Set<FnUserRole> fnUserRoles;
429 targetEntity = EpUserNotification.class,
431 cascade = CascadeType.ALL,
432 fetch = FetchType.LAZY
434 private Set<EpUserNotification> epUserNotifications;
437 public Collection<? extends GrantedAuthority> getAuthorities() {
440 .map(fnRole -> new SimpleGrantedAuthority("ROLE_" + fnRole.getRoleName()))
441 .collect(Collectors.toList());
445 public String getPassword() {
446 return this.getLoginPwd();
450 public String getUsername() {
451 return this.getLoginId();
455 public boolean isAccountNonExpired() {
460 public boolean isAccountNonLocked() {
465 public boolean isCredentialsNonExpired() {
470 public boolean isEnabled() {
474 public String getFullName() {
475 return this.firstName + " " + this.lastName;