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;
47 import java.util.Iterator;
49 import java.util.SortedSet;
50 import java.util.TreeSet;
51 import java.util.stream.Collectors;
52 import javax.persistence.CascadeType;
53 import javax.persistence.Column;
54 import javax.persistence.Entity;
55 import javax.persistence.FetchType;
56 import javax.persistence.GeneratedValue;
57 import javax.persistence.GenerationType;
58 import javax.persistence.Id;
59 import javax.persistence.Index;
60 import javax.persistence.JoinColumn;
61 import javax.persistence.ManyToMany;
62 import javax.persistence.ManyToOne;
63 import javax.persistence.NamedQueries;
64 import javax.persistence.NamedQuery;
65 import javax.persistence.OneToMany;
66 import javax.persistence.Table;
67 import javax.persistence.UniqueConstraint;
68 import javax.validation.constraints.Digits;
69 import javax.validation.constraints.Email;
70 import javax.validation.constraints.NotNull;
71 import javax.validation.constraints.PastOrPresent;
72 import javax.validation.constraints.Size;
73 import lombok.AllArgsConstructor;
74 import lombok.Builder;
76 import lombok.NoArgsConstructor;
78 import org.hibernate.annotations.DynamicUpdate;
79 import org.hibernate.validator.constraints.SafeHtml;
80 import org.onap.portal.domain.db.cr.CrReportFileHistory;
81 import org.onap.portal.domain.db.ep.EpPersUserWidgetPlacement;
82 import org.onap.portal.domain.db.ep.EpPersUserWidgetSel;
83 import org.onap.portal.domain.db.ep.EpUserNotification;
84 import org.onap.portal.domain.db.ep.EpUserRolesRequest;
85 import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter;
86 import org.onap.portal.domain.dto.DomainVo;
87 import org.onap.portalsdk.core.domain.App;
88 import org.onap.portalsdk.core.domain.Role;
89 import org.onap.portalsdk.core.domain.UserApp;
90 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
91 import org.springframework.security.core.GrantedAuthority;
92 import org.springframework.security.core.authority.SimpleGrantedAuthority;
93 import org.springframework.security.core.userdetails.UserDetails;
96 CREATE TABLE `fn_user` (
97 `user_id` int(11) NOT NULL AUTO_INCREMENT,
98 `org_id` int(11) DEFAULT NULL,
99 `manager_id` int(11) DEFAULT NULL,
100 `first_name` varchar(50) DEFAULT NULL,
101 `middle_name` varchar(50) DEFAULT NULL,
102 `last_name` varchar(50) DEFAULT NULL,
103 `phone` varchar(25) DEFAULT NULL,
104 `fax` varchar(25) DEFAULT NULL,
105 `cellular` varchar(25) DEFAULT NULL,
106 `email` varchar(50) DEFAULT NULL,
107 `address_id` decimal(11,0) DEFAULT NULL,
108 `alert_method_cd` varchar(10) DEFAULT NULL,
109 `hrid` varchar(20) DEFAULT NULL,
110 `org_user_id` varchar(20) DEFAULT NULL,
111 `org_code` varchar(30) DEFAULT NULL,
112 `login_id` varchar(25) DEFAULT NULL,
113 `login_pwd` varchar(100) DEFAULT NULL,
114 `last_login_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
115 `active_yn` varchar(1) NOT NULL DEFAULT 'y',
116 `created_id` int(11) DEFAULT NULL,
117 `created_date` timestamp NOT NULL DEFAULT current_timestamp(),
118 `modified_id` int(11) DEFAULT NULL,
119 `modified_date` timestamp NOT NULL DEFAULT current_timestamp(),
120 `is_internal_yn` char(1) NOT NULL DEFAULT 'n',
121 `address_line_1` varchar(100) DEFAULT NULL,
122 `address_line_2` varchar(100) DEFAULT NULL,
123 `city` varchar(50) DEFAULT NULL,
124 `state_cd` varchar(3) DEFAULT NULL,
125 `zip_code` varchar(11) DEFAULT NULL,
126 `country_cd` varchar(3) DEFAULT NULL,
127 `location_clli` varchar(8) DEFAULT NULL,
128 `org_manager_userid` varchar(20) DEFAULT NULL,
129 `company` varchar(100) DEFAULT NULL,
130 `department_name` varchar(100) DEFAULT NULL,
131 `job_title` varchar(100) DEFAULT NULL,
132 `timezone` int(11) DEFAULT NULL,
133 `department` varchar(25) DEFAULT NULL,
134 `business_unit` varchar(25) DEFAULT NULL,
135 `business_unit_name` varchar(100) DEFAULT NULL,
136 `cost_center` varchar(25) DEFAULT NULL,
137 `fin_loc_code` varchar(10) DEFAULT NULL,
138 `silo_status` varchar(10) DEFAULT NULL,
139 `language_id` int(2) NOT NULL DEFAULT 1,
140 PRIMARY KEY (`user_id`),
141 UNIQUE KEY `fn_user_hrid` (`hrid`) USING BTREE,
142 UNIQUE KEY `fn_user_login_id` (`login_id`) USING BTREE,
143 KEY `fn_user_address_id` (`address_id`) USING BTREE,
144 KEY `fn_user_alert_method_cd` (`alert_method_cd`) USING BTREE,
145 KEY `fn_user_org_id` (`org_id`) USING BTREE,
146 KEY `fk_fn_user_ref_197_fn_user` (`manager_id`),
147 KEY `fk_fn_user_ref_198_fn_user` (`created_id`),
148 KEY `fk_fn_user_ref_199_fn_user` (`modified_id`),
149 KEY `fk_timezone` (`timezone`),
150 CONSTRAINT `fk_fn_user_ref_110_fn_org` FOREIGN KEY (`org_id`) REFERENCES `fn_org` (`org_id`),
151 CONSTRAINT `fk_fn_user_ref_123_fn_lu_al` FOREIGN KEY (`alert_method_cd`) REFERENCES `fn_lu_alert_method` (`alert_method_cd`),
152 CONSTRAINT `fk_fn_user_ref_197_fn_user` FOREIGN KEY (`manager_id`) REFERENCES `fn_user` (`user_id`),
153 CONSTRAINT `fk_fn_user_ref_198_fn_user` FOREIGN KEY (`created_id`) REFERENCES `fn_user` (`user_id`),
154 CONSTRAINT `fk_fn_user_ref_199_fn_user` FOREIGN KEY (`modified_id`) REFERENCES `fn_user` (`user_id`),
155 CONSTRAINT `fk_timezone` FOREIGN KEY (`timezone`) REFERENCES `fn_lu_timezone` (`timezone_id`)
161 name = "FnUser.getUserWithOrgUserId",
162 query = "FROM FnUser WHERE orgUserId = :orgId"),
164 name = "FnUser.getActiveUsers",
165 query = "FROM FnUser WHERE activeYn = 'Y'"),
167 name = "FnUser.getUsersByOrgIds",
168 query = "FROM FnUser WHERE orgUserId IN :orgIds"
171 @Table(name = "fn_user", indexes = {
172 @Index(name = "fn_user_address_id", columnList = "address_id"),
173 @Index(name = "fn_user_alert_method_cd", columnList = "alert_method_cd"),
174 @Index(name = "fn_user_org_id", columnList = "org_id"),
175 @Index(name = "fk_fn_user_ref_197_fn_user", columnList = "manager_id"),
176 @Index(name = "fk_fn_user_ref_198_fn_user", columnList = "created_id"),
177 @Index(name = "fk_fn_user_ref_199_fn_user", columnList = "modified_id"),
178 @Index(name = "fk_timezone", columnList = "timezone")
180 uniqueConstraints = {
181 @UniqueConstraint(name = "fn_user_hrid", columnNames = "hrid"),
182 @UniqueConstraint(name = "fn_user_login_id", columnNames = "login_id")
193 public class FnUser extends DomainVo implements UserDetails, Serializable {
195 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnUser.class);
198 @GeneratedValue(strategy = GenerationType.IDENTITY)
199 @Column(name = "user_id", nullable = false)
201 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
202 @JoinColumn(name = "org_id")
204 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
205 @JoinColumn(name = "manager_id")
206 private FnUser managerId;
207 @Column(name = "first_name", length = 50)
210 private String firstName;
211 @Column(name = "middle_name", length = 50)
214 private String middleName;
215 @Column(name = "last_name", length = 50)
218 private String lastName;
219 @Column(name = "phone", length = 25)
222 private String phone;
223 @Column(name = "fax", length = 25)
227 @Column(name = "cellular", length = 25)
230 private String cellular;
231 @Column(name = "email", length = 50)
235 private String email;
236 @Column(name = "address_id")
237 @Digits(integer = 11, fraction = 0)
238 private Long addressId;
239 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
240 @JoinColumn(name = "alert_method_cd")
241 private FnLuAlertMethod alertMethodCd;
242 @Column(name = "hrid", length = 20)
246 @Column(name = "org_user_id", length = 20)
249 private String orgUserId;
250 @Column(name = "org_code", length = 30)
253 private String org_code;
254 @Column(name = "login_id", length = 25)
257 private String loginId;
258 @Column(name = "login_pwd", length = 100)
261 private String loginPwd;
262 @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
264 protected LocalDateTime lastLoginDate;
265 @Column(name = "active_yn", nullable = false)
266 private Boolean activeYn;
267 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
268 @JoinColumn(name = "created_id")
269 private FnUser createdId;
270 @Column(name = "created_date", columnDefinition = "datetime DEFAULT current_timestamp()", nullable = false)
272 protected LocalDateTime createdDate;
273 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
274 @JoinColumn(name = "modified_id")
275 private FnUser modifiedId;
276 @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
278 protected LocalDateTime modifiedDate;
279 @Column(name = "is_internal_yn", nullable = false, columnDefinition = "bit DEFAULT 0")
280 private Boolean isInternalYn;
281 @Column(name = "is_system_user", nullable = false, columnDefinition = "bit DEFAULT 0")
282 private Boolean isSystemUser;
283 @Column(name = "address_line_1", length = 100)
286 private String addressLine1;
287 @Column(name = "address_line_2", length = 100)
290 private String addressLine2;
291 @Column(name = "city", length = 50)
295 @Column(name = "state_cd", length = 3)
298 private String stateCd;
299 @Column(name = "zip_code", length = 11)
302 private String zipCode;
303 @Column(name = "country_cd", length = 3)
306 private String countryCd;
307 @Column(name = "location_clli", length = 8)
310 private String locationClli;
311 @Column(name = "org_manager_userid", length = 20)
314 private String orgManagerUserId;
315 @Column(name = "company", length = 100)
318 private String company;
319 @Column(name = "department_name", length = 200)
322 private String departmentName;
323 @Column(name = "job_title", length = 100)
326 private String jobTitle;
327 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
328 @JoinColumn(name = "timezone")
329 private FnLuTimezone timezone;
330 @Column(name = "department", length = 25)
333 private String department;
334 @Column(name = "business_unit", length = 25)
337 private String businessUnit;
338 @Column(name = "business_unit_name", length = 100)
341 private String businessUnitName;
342 @Column(name = "cost_center", length = 25)
345 private String cost_center;
346 @Column(name = "fin_loc_code", length = 10)
349 private String finLocCode;
350 @Column(name = "silo_status", length = 10)
353 private String siloStatus;
354 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
355 @JoinColumn(name = "language_id", nullable = false, columnDefinition = "bigint DEFAULT 1")
356 @NotNull(message = "languageId must not be null")
357 private FnLanguage languageId;
358 @Column(name = "is_guest", nullable = false, columnDefinition = "bit DEFAULT 0")
359 @NotNull(message = "guest must not be null")
360 private Boolean guest;
361 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
362 private Set<CrReportFileHistory> crReportFileHistorie;
363 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
364 private Set<FnRole> fnRoles;
365 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
366 private Set<FnMenuFunctional> fnRoleList;
368 targetEntity = FnAuditLog.class,
370 cascade = CascadeType.ALL,
371 fetch = FetchType.LAZY
373 private Set<FnAuditLog> fnAuditLogs;
375 targetEntity = FnUser.class,
376 mappedBy = "createdId",
377 cascade = CascadeType.ALL,
378 fetch = FetchType.LAZY
380 private Set<FnUser> fnUsersCreatedId;
382 targetEntity = FnUser.class,
383 mappedBy = "managerId",
384 cascade = CascadeType.ALL,
385 fetch = FetchType.LAZY
387 private Set<FnUser> fnUsersManagerId;
389 targetEntity = FnUser.class,
390 mappedBy = "modifiedId",
391 cascade = CascadeType.ALL,
392 fetch = FetchType.LAZY
394 private Set<FnUser> fnUsersModifiedId;
396 targetEntity = EpUserRolesRequest.class,
398 cascade = CascadeType.ALL,
399 fetch = FetchType.LAZY
401 private Set<EpUserRolesRequest> epUserRolesRequests;
403 targetEntity = FnPersUserAppSel.class,
405 cascade = CascadeType.ALL,
406 fetch = FetchType.LAZY
408 private Set<FnPersUserAppSel> persUserAppSels;
410 targetEntity = EpWidgetCatalogParameter.class,
412 cascade = CascadeType.ALL,
413 fetch = FetchType.LAZY
415 private Set<EpWidgetCatalogParameter> epWidgetCatalogParameters;
417 targetEntity = EpPersUserWidgetPlacement.class,
419 cascade = CascadeType.ALL,
420 fetch = FetchType.LAZY
422 private Set<EpPersUserWidgetPlacement> epPersUserWidgetPlacements;
424 targetEntity = EpPersUserWidgetSel.class,
426 cascade = CascadeType.ALL,
427 fetch = FetchType.LAZY
429 private Set<EpPersUserWidgetSel> epPersUserWidgetSels;
431 targetEntity = FnUserRole.class,
433 cascade = CascadeType.ALL,
434 fetch = FetchType.LAZY
436 private Set<FnUserRole> userApps;
438 targetEntity = EpUserNotification.class,
440 cascade = CascadeType.ALL,
441 fetch = FetchType.LAZY
443 private Set<EpUserNotification> epUserNotifications;
446 public Collection<? extends GrantedAuthority> getAuthorities() {
449 .map(fnRole -> new SimpleGrantedAuthority("ROLE_" + fnRole.getRoleName()))
450 .collect(Collectors.toList());
454 public String getPassword() {
455 return this.getLoginPwd();
459 public String getUsername() {
460 return this.getLoginId();
464 public boolean isAccountNonExpired() {
469 public boolean isAccountNonLocked() {
474 public boolean isCredentialsNonExpired() {
479 public boolean isEnabled() {
483 public String getFullName() {
484 return this.firstName + " " + this.lastName;
487 public SortedSet<FnRole> getAppEPRoles(FnApp app) {
489 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - app = {}", app.getAppName());
491 SortedSet<FnRole> roles = new TreeSet<>();
492 Set<FnUserRole> userAppRoles = getUserApps();
494 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - userApps = {} ", userAppRoles.size());
496 Iterator<FnUserRole> userAppRolesIterator = userAppRoles.iterator();
498 FnUserRole userAppRole;
499 // getting default app
500 while (userAppRolesIterator.hasNext()) {
501 FnUserRole tempUserApp = userAppRolesIterator.next();
502 if (tempUserApp.getAppId().getId().equals(app.getId())) {
504 logger.debug(EELFLoggerDelegate.debugLogger,
505 "In EPUser.getAppEPRoles() - for user {}, found application {}", this.getFullName(),
508 userAppRole = tempUserApp;
510 FnRole role = userAppRole.getRoleId();
511 if (role.getActiveYn()) {
512 logger.debug(EELFLoggerDelegate.debugLogger,
513 "In EPUser.getAppEPRoles() - Role {} is active - adding for user {} and app {}",
514 role.getRoleName(), this.getFullName(), app.getAppName());
517 logger.debug(EELFLoggerDelegate.debugLogger,
518 "In EPUser.getAppEPRoles() - Role {} is NOT active - NOT adding for user {} and app {}",
519 role.getRoleName(), this.getFullName(), app.getAppName());
523 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - roles = {}", roles.size());
528 public void setRoles(Set<FnRole> roles) {
529 FnApp app = new FnApp();
531 app.setAppName("Default");
532 this.addAppRoles(app, roles);
535 private void addAppRoles(FnApp app, Set<FnRole> roles) {
537 Set<FnUserRole> newUserApps = new HashSet<>();
538 for (FnRole role : roles) {
539 FnUserRole userApp = new FnUserRole();
540 userApp.setUserId(this);
541 userApp.setAppId(app);
542 userApp.setRoleId(role);
543 newUserApps.add(userApp);
546 this.setUserApps(newUserApps);
548 this.userApps.clear();