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.onap.portalapp.portal.domain.DomainVo;
83 import org.onap.portalapp.portal.domain.db.cr.CrReportFileHistory;
84 import org.onap.portalapp.portal.domain.db.ep.EpPersUserAppManSort;
85 import org.onap.portalapp.portal.domain.db.ep.EpPersUserWidgetPlacement;
86 import org.onap.portalapp.portal.domain.db.ep.EpPersUserWidgetSel;
87 import org.onap.portalapp.portal.domain.db.ep.EpUserNotification;
88 import org.onap.portalapp.portal.domain.db.ep.EpUserRolesRequest;
89 import org.onap.portalapp.portal.domain.db.ep.EpWidgetCatalogParameter;
90 import org.springframework.security.core.GrantedAuthority;
91 import org.springframework.security.core.authority.SimpleGrantedAuthority;
92 import org.springframework.security.core.userdetails.UserDetails;
95 CREATE TABLE `fn_user` (
96 `user_id` int(11) NOT NULL AUTO_INCREMENT,
97 `org_id` int(11) DEFAULT NULL,
98 `manager_id` int(11) DEFAULT NULL,
99 `first_name` varchar(50) DEFAULT NULL,
100 `middle_name` varchar(50) DEFAULT NULL,
101 `last_name` varchar(50) DEFAULT NULL,
102 `phone` varchar(25) DEFAULT NULL,
103 `fax` varchar(25) DEFAULT NULL,
104 `cellular` varchar(25) DEFAULT NULL,
105 `email` varchar(50) DEFAULT NULL,
106 `address_id` decimal(11,0) DEFAULT NULL,
107 `alert_method_cd` varchar(10) DEFAULT NULL,
108 `hrid` varchar(20) DEFAULT NULL,
109 `org_user_id` varchar(20) DEFAULT NULL,
110 `org_code` varchar(30) DEFAULT NULL,
111 `login_id` varchar(25) DEFAULT NULL,
112 `login_pwd` varchar(100) DEFAULT NULL,
113 `last_login_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
114 `active_yn` varchar(1) NOT NULL DEFAULT 'y',
115 `created_id` int(11) DEFAULT NULL,
116 `created_date` timestamp NOT NULL DEFAULT current_timestamp(),
117 `modified_id` int(11) DEFAULT NULL,
118 `modified_date` timestamp NOT NULL DEFAULT current_timestamp(),
119 `is_internal_yn` char(1) NOT NULL DEFAULT 'n',
120 `address_line_1` varchar(100) DEFAULT NULL,
121 `address_line_2` varchar(100) DEFAULT NULL,
122 `city` varchar(50) DEFAULT NULL,
123 `state_cd` varchar(3) DEFAULT NULL,
124 `zip_code` varchar(11) DEFAULT NULL,
125 `country_cd` varchar(3) DEFAULT NULL,
126 `location_clli` varchar(8) DEFAULT NULL,
127 `org_manager_userid` varchar(20) DEFAULT NULL,
128 `company` varchar(100) DEFAULT NULL,
129 `department_name` varchar(100) DEFAULT NULL,
130 `job_title` varchar(100) DEFAULT NULL,
131 `timezone` int(11) DEFAULT NULL,
132 `department` varchar(25) DEFAULT NULL,
133 `business_unit` varchar(25) DEFAULT NULL,
134 `business_unit_name` varchar(100) DEFAULT NULL,
135 `cost_center` varchar(25) DEFAULT NULL,
136 `fin_loc_code` varchar(10) DEFAULT NULL,
137 `silo_status` varchar(10) DEFAULT NULL,
138 `language_id` int(2) NOT NULL DEFAULT 1,
139 PRIMARY KEY (`user_id`),
140 UNIQUE KEY `fn_user_hrid` (`hrid`) USING BTREE,
141 UNIQUE KEY `fn_user_login_id` (`login_id`) USING BTREE,
142 KEY `fn_user_address_id` (`address_id`) USING BTREE,
143 KEY `fn_user_alert_method_cd` (`alert_method_cd`) USING BTREE,
144 KEY `fn_user_org_id` (`org_id`) USING BTREE,
145 KEY `fk_fn_user_ref_197_fn_user` (`manager_id`),
146 KEY `fk_fn_user_ref_198_fn_user` (`created_id`),
147 KEY `fk_fn_user_ref_199_fn_user` (`modified_id`),
148 KEY `fk_timezone` (`timezone`),
149 CONSTRAINT `fk_fn_user_ref_110_fn_org` FOREIGN KEY (`org_id`) REFERENCES `fn_org` (`org_id`),
150 CONSTRAINT `fk_fn_user_ref_123_fn_lu_al` FOREIGN KEY (`alert_method_cd`) REFERENCES `fn_lu_alert_method` (`alert_method_cd`),
151 CONSTRAINT `fk_fn_user_ref_197_fn_user` FOREIGN KEY (`manager_id`) REFERENCES `fn_user` (`user_id`),
152 CONSTRAINT `fk_fn_user_ref_198_fn_user` FOREIGN KEY (`created_id`) REFERENCES `fn_user` (`user_id`),
153 CONSTRAINT `fk_fn_user_ref_199_fn_user` FOREIGN KEY (`modified_id`) REFERENCES `fn_user` (`user_id`),
154 CONSTRAINT `fk_timezone` FOREIGN KEY (`timezone`) REFERENCES `fn_lu_timezone` (`timezone_id`)
158 @NamedNativeQueries({
160 name = "getUsersByOrgUserId",
161 query = "SELECT * FROM FnUser WHERE where org_user_id 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")
183 public class FnUser extends DomainVo implements UserDetails {
186 @GeneratedValue(strategy = GenerationType.AUTO)
187 @Column(name = "user_id", length = 11, nullable = false)
188 @Digits(integer = 11, fraction = 0)
190 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
191 @JoinColumn(name = "org_id", columnDefinition = "int(11) DEFAULT NULL")
194 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
195 @JoinColumn(name = "manager_id")
197 private FnUser managerId;
198 @Column(name = "first_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
201 private String firstName;
202 @Column(name = "middle_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
205 private String middleName;
206 @Column(name = "last_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
209 private String lastName;
210 @Column(name = "phone", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
213 private String phone;
214 @Column(name = "fax", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
218 @Column(name = "cellular", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
221 private String cellular;
222 @Column(name = "email", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
226 private String email;
227 @Column(name = "address_id", columnDefinition = "decimal(11,0) DEFAULT NULL")
228 @Digits(integer = 11, fraction = 0)
229 private Long addressId;
230 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
231 @JoinColumn(name = "alert_method_cd", columnDefinition = "varchar(10) DEFAULT NULL")
232 private FnLuAlertMethod alertMethodCd;
233 @Column(name = "hrid", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
237 @Column(name = "org_user_id", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
240 private String orgUserId;
241 @Column(name = "org_code", length = 30, columnDefinition = "varchar(30) DEFAULT NULL")
244 private String org_code;
245 @Column(name = "login_id", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
248 private String loginId;
249 @Column(name = "login_pwd", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
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", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false)
260 private String activeYn;
261 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
262 @JoinColumn(name = "created_id")
264 private FnUser createdId;
265 @Column(name = "created_date", columnDefinition = "datetime DEFAULT current_timestamp()", nullable = false)
267 protected LocalDateTime createdDate;
268 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
269 @JoinColumn(name = "modified_id")
271 private FnUser modifiedId;
272 @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
274 protected LocalDateTime modifiedDate;
275 @Column(name = "is_internal_yn", length = 1, columnDefinition = "character varying(1) default 'n'", nullable = false)
279 private String isInternalYn;
280 @Column(name = "address_line_1", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
283 private String addressLine1;
284 @Column(name = "address_line_2", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
287 private String addressLine2;
288 @Column(name = "city", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
292 @Column(name = "state_cd", length = 3, columnDefinition = "varchar(3) DEFAULT NULL")
295 private String stateCd;
296 @Column(name = "zip_code", length = 11, columnDefinition = "varchar(11) DEFAULT NULL")
299 private String zipCode;
300 @Column(name = "country_cd", length = 3, columnDefinition = "varchar(3) DEFAULT NULL")
303 private String countryCd;
304 @Column(name = "location_clli", length = 8, columnDefinition = "varchar(8) DEFAULT NULL")
307 private String locationClli;
308 @Column(name = "org_manager_userid", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
311 private String orgManagerUserId;
312 @Column(name = "company", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
315 private String company;
316 @Column(name = "department_name", length = 200, columnDefinition = "varchar(100) DEFAULT NULL")
319 private String departmentName;
320 @Column(name = "job_title", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
323 private String jobTitle;
324 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
325 @JoinColumn(name = "timezone", columnDefinition = "int(11) DEFAULT NULL")
327 private FnLuTimezone timezone;
328 @Column(name = "department", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
331 private String department;
332 @Column(name = "business_unit", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
335 private String businessUnit;
336 @Column(name = "business_unit_name", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
339 private String businessUnitName;
340 @Column(name = "cost_center", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
343 private String cost_center;
344 @Column(name = "fin_loc_code", length = 10, columnDefinition = "varchar(10) DEFAULT NULL")
347 private String finLocCode;
348 @Column(name = "silo_status", length = 10, columnDefinition = "varchar(10) DEFAULT NULL")
351 private String siloStatus;
352 @Column(name = "language_id", length = 2, columnDefinition = "int(2) default 1", nullable = false)
353 @Digits(integer = 2, fraction = 0)
355 private Long language_id;
356 @Column(name = "is_guest", columnDefinition = "boolean default 0", nullable = false)
358 private boolean guest;
359 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
360 private List<CrReportFileHistory> crReportFileHistorie = new ArrayList<>();
361 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
362 private List<FnRole> fnRoles = new ArrayList<>();
363 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
364 private List<FnMenuFunctional> fnRoleList = new ArrayList<>();
366 targetEntity = FnAuditLog.class,
368 cascade = CascadeType.ALL,
369 fetch = FetchType.LAZY
371 private List<FnAuditLog> fnAuditLogs = new ArrayList<>();
373 targetEntity = FnUser.class,
374 mappedBy = "createdId",
375 cascade = CascadeType.ALL,
376 fetch = FetchType.LAZY
378 private List<FnUser> fnUsersCreatedId = new ArrayList<>();
380 targetEntity = FnUser.class,
381 mappedBy = "managerId",
382 cascade = CascadeType.ALL,
383 fetch = FetchType.LAZY
385 private List<FnUser> fnUsersManagerId = new ArrayList<>();
387 targetEntity = FnUser.class,
388 mappedBy = "modifiedId",
389 cascade = CascadeType.ALL,
390 fetch = FetchType.LAZY
392 private List<FnUser> fnUsersModifiedId = new ArrayList<>();
394 targetEntity = EpUserRolesRequest.class,
396 cascade = CascadeType.ALL,
397 fetch = FetchType.LAZY
399 private List<EpUserRolesRequest> epUserRolesRequests = new ArrayList<>();
401 targetEntity = FnPersUserAppSel.class,
403 cascade = CascadeType.ALL,
404 fetch = FetchType.LAZY
406 private List<FnPersUserAppSel> persUserAppSels = new ArrayList<>();
408 targetEntity = EpPersUserAppManSort.class,
410 cascade = CascadeType.ALL,
411 fetch = FetchType.LAZY
413 private List<EpPersUserAppManSort> epPersUserAppManSorts = new ArrayList<>();
415 targetEntity = EpWidgetCatalogParameter.class,
417 cascade = CascadeType.ALL,
418 fetch = FetchType.LAZY
420 private List<EpWidgetCatalogParameter> epWidgetCatalogParameters = new ArrayList<>();
422 targetEntity = EpPersUserWidgetPlacement.class,
424 cascade = CascadeType.ALL,
425 fetch = FetchType.LAZY
427 private List<EpPersUserWidgetPlacement> epPersUserWidgetPlacements = new ArrayList<>();
429 targetEntity = EpPersUserWidgetSel.class,
431 cascade = CascadeType.ALL,
432 fetch = FetchType.LAZY
434 private List<EpPersUserWidgetSel> epPersUserWidgetSels = new ArrayList<>();
436 targetEntity = FnUserRole.class,
438 cascade = CascadeType.ALL,
439 fetch = FetchType.LAZY
441 private List<FnUserRole> fnUserRoles = new ArrayList<>();
443 targetEntity = EpUserNotification.class,
445 cascade = CascadeType.ALL,
446 fetch = FetchType.LAZY
448 private List<EpUserNotification> epUserNotifications = new ArrayList<>();
451 public Collection<? extends GrantedAuthority> getAuthorities() {
454 .map(fnRole -> new SimpleGrantedAuthority("ROLE_" + fnRole.getRoleName()))
455 .collect(Collectors.toList());
459 public String getPassword() {
460 return this.getLoginPwd();
464 public String getUsername() {
465 return this.getLoginId();
469 public boolean isAccountNonExpired() {
474 public boolean isAccountNonLocked() {
479 public boolean isCredentialsNonExpired() {
484 public boolean isEnabled() {
488 public String getFullName() {
489 return this.firstName + " " + this.lastName;