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.time.LocalDateTime;
44 import java.util.ArrayList;
45 import java.util.Collection;
46 import java.util.List;
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.NamedNativeQueries;
60 import javax.persistence.NamedNativeQuery;
61 import javax.persistence.OneToMany;
62 import javax.persistence.Table;
63 import javax.persistence.UniqueConstraint;
64 import javax.validation.Valid;
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;
72 import lombok.NoArgsConstructor;
74 import org.hibernate.validator.constraints.SafeHtml;
75 import org.onap.portal.domain.db.cr.CrReportFileHistory;
76 import org.onap.portal.domain.db.ep.EpPersUserWidgetPlacement;
77 import org.onap.portal.domain.db.ep.EpPersUserWidgetSel;
78 import org.onap.portal.domain.db.ep.EpUserNotification;
79 import org.onap.portal.domain.db.ep.EpUserRolesRequest;
80 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
81 import org.onap.portal.domain.dto.DomainVo;
82 import org.springframework.security.core.GrantedAuthority;
83 import org.springframework.security.core.authority.SimpleGrantedAuthority;
84 import org.springframework.security.core.userdetails.UserDetails;
87 CREATE TABLE `fn_user` (
88 `user_id` int(11) NOT NULL AUTO_INCREMENT,
89 `org_id` int(11) DEFAULT NULL,
90 `manager_id` int(11) DEFAULT NULL,
91 `first_name` varchar(50) DEFAULT NULL,
92 `middle_name` varchar(50) DEFAULT NULL,
93 `last_name` varchar(50) DEFAULT NULL,
94 `phone` varchar(25) DEFAULT NULL,
95 `fax` varchar(25) DEFAULT NULL,
96 `cellular` varchar(25) DEFAULT NULL,
97 `email` varchar(50) DEFAULT NULL,
98 `address_id` decimal(11,0) DEFAULT NULL,
99 `alert_method_cd` varchar(10) DEFAULT NULL,
100 `hrid` varchar(20) DEFAULT NULL,
101 `org_user_id` varchar(20) DEFAULT NULL,
102 `org_code` varchar(30) DEFAULT NULL,
103 `login_id` varchar(25) DEFAULT NULL,
104 `login_pwd` varchar(100) DEFAULT NULL,
105 `last_login_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
106 `active_yn` varchar(1) NOT NULL DEFAULT 'y',
107 `created_id` int(11) DEFAULT NULL,
108 `created_date` timestamp NOT NULL DEFAULT current_timestamp(),
109 `modified_id` int(11) DEFAULT NULL,
110 `modified_date` timestamp NOT NULL DEFAULT current_timestamp(),
111 `is_internal_yn` char(1) NOT NULL DEFAULT 'n',
112 `address_line_1` varchar(100) DEFAULT NULL,
113 `address_line_2` varchar(100) DEFAULT NULL,
114 `city` varchar(50) DEFAULT NULL,
115 `state_cd` varchar(3) DEFAULT NULL,
116 `zip_code` varchar(11) DEFAULT NULL,
117 `country_cd` varchar(3) DEFAULT NULL,
118 `location_clli` varchar(8) DEFAULT NULL,
119 `org_manager_userid` varchar(20) DEFAULT NULL,
120 `company` varchar(100) DEFAULT NULL,
121 `department_name` varchar(100) DEFAULT NULL,
122 `job_title` varchar(100) DEFAULT NULL,
123 `timezone` int(11) DEFAULT NULL,
124 `department` varchar(25) DEFAULT NULL,
125 `business_unit` varchar(25) DEFAULT NULL,
126 `business_unit_name` varchar(100) DEFAULT NULL,
127 `cost_center` varchar(25) DEFAULT NULL,
128 `fin_loc_code` varchar(10) DEFAULT NULL,
129 `silo_status` varchar(10) DEFAULT NULL,
130 `language_id` int(2) NOT NULL DEFAULT 1,
131 PRIMARY KEY (`user_id`),
132 UNIQUE KEY `fn_user_hrid` (`hrid`) USING BTREE,
133 UNIQUE KEY `fn_user_login_id` (`login_id`) USING BTREE,
134 KEY `fn_user_address_id` (`address_id`) USING BTREE,
135 KEY `fn_user_alert_method_cd` (`alert_method_cd`) USING BTREE,
136 KEY `fn_user_org_id` (`org_id`) USING BTREE,
137 KEY `fk_fn_user_ref_197_fn_user` (`manager_id`),
138 KEY `fk_fn_user_ref_198_fn_user` (`created_id`),
139 KEY `fk_fn_user_ref_199_fn_user` (`modified_id`),
140 KEY `fk_timezone` (`timezone`),
141 CONSTRAINT `fk_fn_user_ref_110_fn_org` FOREIGN KEY (`org_id`) REFERENCES `fn_org` (`org_id`),
142 CONSTRAINT `fk_fn_user_ref_123_fn_lu_al` FOREIGN KEY (`alert_method_cd`) REFERENCES `fn_lu_alert_method` (`alert_method_cd`),
143 CONSTRAINT `fk_fn_user_ref_197_fn_user` FOREIGN KEY (`manager_id`) REFERENCES `fn_user` (`user_id`),
144 CONSTRAINT `fk_fn_user_ref_198_fn_user` FOREIGN KEY (`created_id`) REFERENCES `fn_user` (`user_id`),
145 CONSTRAINT `fk_fn_user_ref_199_fn_user` FOREIGN KEY (`modified_id`) REFERENCES `fn_user` (`user_id`),
146 CONSTRAINT `fk_timezone` FOREIGN KEY (`timezone`) REFERENCES `fn_lu_timezone` (`timezone_id`)
150 @NamedNativeQueries({
152 name = "getUsersByOrgUserId",
153 query = "SELECT * FROM FnUser WHERE where org_user_id in :orgIds"
157 @Table(name = "fn_user", indexes = {
158 @Index(name = "fn_user_address_id", columnList = "address_id"),
159 @Index(name = "fn_user_alert_method_cd", columnList = "alert_method_cd"),
160 @Index(name = "fn_user_org_id", columnList = "org_id"),
161 @Index(name = "fk_fn_user_ref_197_fn_user", columnList = "manager_id"),
162 @Index(name = "fk_fn_user_ref_198_fn_user", columnList = "created_id"),
163 @Index(name = "fk_fn_user_ref_199_fn_user", columnList = "modified_id"),
164 @Index(name = "fk_timezone", columnList = "timezone")
166 uniqueConstraints = {
167 @UniqueConstraint(name = "fn_user_hrid", columnNames = "hrid"),
168 @UniqueConstraint(name = "fn_user_login_id", columnNames = "login_id")
175 public class FnUser extends DomainVo implements UserDetails {
178 @GeneratedValue(strategy = GenerationType.AUTO)
179 @Column(name = "user_id", length = 11, nullable = false)
180 @Digits(integer = 11, fraction = 0)
182 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
183 @JoinColumn(name = "org_id", columnDefinition = "int(11) DEFAULT NULL")
186 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
187 @JoinColumn(name = "manager_id")
189 private FnUser managerId;
190 @Column(name = "first_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
193 private String firstName;
194 @Column(name = "middle_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
197 private String middleName;
198 @Column(name = "last_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
201 private String lastName;
202 @Column(name = "phone", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
205 private String phone;
206 @Column(name = "fax", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
210 @Column(name = "cellular", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
213 private String cellular;
214 @Column(name = "email", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
218 private String email;
219 @Column(name = "address_id", columnDefinition = "decimal(11,0) DEFAULT NULL")
220 @Digits(integer = 11, fraction = 0)
221 private Long addressId;
222 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
223 @JoinColumn(name = "alert_method_cd", columnDefinition = "varchar(10) DEFAULT NULL")
224 private FnLuAlertMethod alertMethodCd;
225 @Column(name = "hrid", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
229 @Column(name = "org_user_id", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
232 private String orgUserId;
233 @Column(name = "org_code", length = 30, columnDefinition = "varchar(30) DEFAULT NULL")
236 private String org_code;
237 @Column(name = "login_id", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
240 private String loginId;
241 @Column(name = "login_pwd", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
244 private String loginPwd;
245 @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
247 protected LocalDateTime lastLoginDate;
248 @Column(name = "active_yn", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false)
252 private String activeYn;
253 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
254 @JoinColumn(name = "created_id")
256 private FnUser createdId;
257 @Column(name = "created_date", columnDefinition = "datetime DEFAULT current_timestamp()", nullable = false)
259 protected LocalDateTime createdDate;
260 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
261 @JoinColumn(name = "modified_id")
263 private FnUser modifiedId;
264 @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
266 protected LocalDateTime modifiedDate;
267 @Column(name = "is_internal_yn", length = 1, columnDefinition = "character varying(1) default 'n'", nullable = false)
271 private String isInternalYn;
272 @Column(name = "address_line_1", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
275 private String addressLine1;
276 @Column(name = "address_line_2", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
279 private String addressLine2;
280 @Column(name = "city", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
284 @Column(name = "state_cd", length = 3, columnDefinition = "varchar(3) DEFAULT NULL")
287 private String stateCd;
288 @Column(name = "zip_code", length = 11, columnDefinition = "varchar(11) DEFAULT NULL")
291 private String zipCode;
292 @Column(name = "country_cd", length = 3, columnDefinition = "varchar(3) DEFAULT NULL")
295 private String countryCd;
296 @Column(name = "location_clli", length = 8, columnDefinition = "varchar(8) DEFAULT NULL")
299 private String locationClli;
300 @Column(name = "org_manager_userid", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
303 private String orgManagerUserId;
304 @Column(name = "company", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
307 private String company;
308 @Column(name = "department_name", length = 200, columnDefinition = "varchar(100) DEFAULT NULL")
311 private String departmentName;
312 @Column(name = "job_title", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
315 private String jobTitle;
316 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
317 @JoinColumn(name = "timezone", columnDefinition = "int(11) DEFAULT NULL")
319 private FnLuTimezone timezone;
320 @Column(name = "department", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
323 private String department;
324 @Column(name = "business_unit", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
327 private String businessUnit;
328 @Column(name = "business_unit_name", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
331 private String businessUnitName;
332 @Column(name = "cost_center", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
335 private String cost_center;
336 @Column(name = "fin_loc_code", length = 10, columnDefinition = "varchar(10) DEFAULT NULL")
339 private String finLocCode;
340 @Column(name = "silo_status", length = 10, columnDefinition = "varchar(10) DEFAULT NULL")
343 private String siloStatus;
344 @Column(name = "language_id", length = 2, columnDefinition = "int(2) default 1", nullable = false)
345 @Digits(integer = 2, fraction = 0)
347 private Long language_id;
348 @Column(name = "is_guest", columnDefinition = "boolean default 0", nullable = false)
350 private boolean guest;
351 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
352 private List<CrReportFileHistory> crReportFileHistorie = new ArrayList<>();
353 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
354 private List<FnRole> fnRoles = new ArrayList<>();
355 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
356 private List<FnMenuFunctional> fnRoleList = new ArrayList<>();
358 targetEntity = FnAuditLog.class,
360 cascade = CascadeType.ALL,
361 fetch = FetchType.LAZY
363 private List<FnAuditLog> fnAuditLogs = new ArrayList<>();
365 targetEntity = FnUser.class,
366 mappedBy = "createdId",
367 cascade = CascadeType.ALL,
368 fetch = FetchType.LAZY
370 private List<FnUser> fnUsersCreatedId = new ArrayList<>();
372 targetEntity = FnUser.class,
373 mappedBy = "managerId",
374 cascade = CascadeType.ALL,
375 fetch = FetchType.LAZY
377 private List<FnUser> fnUsersManagerId = new ArrayList<>();
379 targetEntity = FnUser.class,
380 mappedBy = "modifiedId",
381 cascade = CascadeType.ALL,
382 fetch = FetchType.LAZY
384 private List<FnUser> fnUsersModifiedId = new ArrayList<>();
386 targetEntity = EpUserRolesRequest.class,
388 cascade = CascadeType.ALL,
389 fetch = FetchType.LAZY
391 private List<EpUserRolesRequest> epUserRolesRequests = new ArrayList<>();
393 targetEntity = FnPersUserAppSel.class,
395 cascade = CascadeType.ALL,
396 fetch = FetchType.LAZY
398 private List<FnPersUserAppSel> persUserAppSels = new ArrayList<>();
400 targetEntity = EpWidgetCatalogParameter.class,
402 cascade = CascadeType.ALL,
403 fetch = FetchType.LAZY
405 private List<EpWidgetCatalogParameter> epWidgetCatalogParameters = new ArrayList<>();
407 targetEntity = EpPersUserWidgetPlacement.class,
409 cascade = CascadeType.ALL,
410 fetch = FetchType.LAZY
412 private List<EpPersUserWidgetPlacement> epPersUserWidgetPlacements = new ArrayList<>();
414 targetEntity = EpPersUserWidgetSel.class,
416 cascade = CascadeType.ALL,
417 fetch = FetchType.LAZY
419 private List<EpPersUserWidgetSel> epPersUserWidgetSels = new ArrayList<>();
421 targetEntity = FnUserRole.class,
423 cascade = CascadeType.ALL,
424 fetch = FetchType.LAZY
426 private List<FnUserRole> fnUserRoles = new ArrayList<>();
428 targetEntity = EpUserNotification.class,
430 cascade = CascadeType.ALL,
431 fetch = FetchType.LAZY
433 private List<EpUserNotification> epUserNotifications = new ArrayList<>();
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;