ce28d0fd3c56a891bee6a2d1c2a20620db557f0b
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / fn / FnUser.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ===================================================================
9  *
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
14  *
15  *             http://www.apache.org/licenses/LICENSE-2.0
16  *
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.
22  *
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
27  *
28  *             https://creativecommons.org/licenses/by/4.0/
29  *
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.
35  *
36  * ============LICENSE_END============================================
37  *
38  *
39  */
40
41 package org.onap.portal.domain.db.fn;
42
43 import java.io.Serializable;
44 import java.time.LocalDateTime;
45 import java.util.Collection;
46 import java.util.Set;
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;
72 import lombok.Getter;
73 import lombok.NoArgsConstructor;
74 import lombok.Setter;
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;
87
88 /*
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`)
149         )
150 */
151
152 @NamedQueries({
153         @NamedQuery(
154                 name = "FnUser.getUserWithOrgUserId",
155                 query = "FROM FnUser WHERE orgUserId = :orgId"),
156         @NamedQuery(
157                 name = "FnUser.getActiveUsers",
158                 query = "FROM FnUser WHERE activeYn = 'Y'"),
159         @NamedQuery(
160                 name = "FnUser.getUsersByOrgIds",
161                 query = "FROM FnUser WHERE orgUserId IN :orgIds"
162         )
163 })
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")
172 },
173         uniqueConstraints = {
174                 @UniqueConstraint(name = "fn_user_hrid", columnNames = "hrid"),
175                 @UniqueConstraint(name = "fn_user_login_id", columnNames = "login_id")
176
177         })
178
179 @Getter
180 @Setter
181 @Entity
182 @Builder
183 @NoArgsConstructor
184 @AllArgsConstructor
185 @DynamicUpdate
186 @SequenceGenerator(name = "seq", initialValue = 1000, allocationSize = 100000)
187 public class FnUser extends DomainVo implements UserDetails, Serializable {
188
189        @Id
190        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
191        @Column(name = "user_id", length = 11, nullable = false)
192        @Digits(integer = 11, fraction = 0)
193        private Long userId;
194        @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
195        @JoinColumn(name = "org_id")
196        private FnOrg orgId;
197        @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
198        @JoinColumn(name = "manager_id")
199        private FnUser managerId;
200        @Column(name = "first_name", length = 50)
201        @Size(max = 50)
202        @SafeHtml
203        private String firstName;
204        @Column(name = "middle_name", length = 50)
205        @Size(max = 50)
206        @SafeHtml
207        private String middleName;
208        @Column(name = "last_name", length = 50)
209        @Size(max = 50)
210        @SafeHtml
211        private String lastName;
212        @Column(name = "phone", length = 25)
213        @Size(max = 25)
214        @SafeHtml
215        private String phone;
216        @Column(name = "fax", length = 25)
217        @Size(max = 25)
218        @SafeHtml
219        private String fax;
220        @Column(name = "cellular", length = 25)
221        @Size(max = 25)
222        @SafeHtml
223        private String cellular;
224        @Column(name = "email", length = 50)
225        @Size(max = 50)
226        @Email
227        @SafeHtml
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)
236        @Size(max = 20)
237        @SafeHtml
238        private String hrid;
239        @Column(name = "org_user_id", length = 20)
240        @Size(max = 20)
241        @SafeHtml
242        private String orgUserId;
243        @Column(name = "org_code", length = 30)
244        @Size(max = 30)
245        @SafeHtml
246        private String org_code;
247        @Column(name = "login_id", length = 25)
248        @Size(max = 25)
249        @SafeHtml
250        private String loginId;
251        @Column(name = "login_pwd", length = 100)
252        @Size(max = 100)
253        @SafeHtml
254        private String loginPwd;
255        @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
256        @PastOrPresent
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)
264        @PastOrPresent
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()")
270        @PastOrPresent
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)
275        @Size(max = 100)
276        @SafeHtml
277        private String addressLine1;
278        @Column(name = "address_line_2", length = 100)
279        @Size(max = 100)
280        @SafeHtml
281        private String addressLine2;
282        @Column(name = "city", length = 50)
283        @Size(max = 50)
284        @SafeHtml
285        private String city;
286        @Column(name = "state_cd", length = 3)
287        @Size(max = 3)
288        @SafeHtml
289        private String stateCd;
290        @Column(name = "zip_code", length = 11)
291        @Size(max = 11)
292        @SafeHtml
293        private String zipCode;
294        @Column(name = "country_cd", length = 3)
295        @Size(max = 3)
296        @SafeHtml
297        private String countryCd;
298        @Column(name = "location_clli", length = 8)
299        @Size(max = 8)
300        @SafeHtml
301        private String locationClli;
302        @Column(name = "org_manager_userid", length = 20)
303        @Size(max = 20)
304        @SafeHtml
305        private String orgManagerUserId;
306        @Column(name = "company", length = 100)
307        @Size(max = 100)
308        @SafeHtml
309        private String company;
310        @Column(name = "department_name", length = 200)
311        @Size(max = 200)
312        @SafeHtml
313        private String departmentName;
314        @Column(name = "job_title", length = 100)
315        @Size(max = 100)
316        @SafeHtml
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)
322        @Size(max = 25)
323        @SafeHtml
324        private String department;
325        @Column(name = "business_unit", length = 25)
326        @Size(max = 25)
327        @SafeHtml
328        private String businessUnit;
329        @Column(name = "business_unit_name", length = 100)
330        @Size(max = 100)
331        @SafeHtml
332        private String businessUnitName;
333        @Column(name = "cost_center", length = 25)
334        @Size(max = 25)
335        @SafeHtml
336        private String cost_center;
337        @Column(name = "fin_loc_code", length = 10)
338        @Size(max = 10)
339        @SafeHtml
340        private String finLocCode;
341        @Column(name = "silo_status", length = 10)
342        @Size(max = 10)
343        @SafeHtml
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;
358        @OneToMany(
359                targetEntity = FnAuditLog.class,
360                mappedBy = "userId",
361                cascade = CascadeType.ALL,
362                fetch = FetchType.LAZY
363        )
364        private Set<FnAuditLog> fnAuditLogs;
365        @OneToMany(
366                targetEntity = FnUser.class,
367                mappedBy = "createdId",
368                cascade = CascadeType.ALL,
369                fetch = FetchType.LAZY
370        )
371        private Set<FnUser> fnUsersCreatedId;
372        @OneToMany(
373                targetEntity = FnUser.class,
374                mappedBy = "managerId",
375                cascade = CascadeType.ALL,
376                fetch = FetchType.LAZY
377        )
378        private Set<FnUser> fnUsersManagerId;
379        @OneToMany(
380                targetEntity = FnUser.class,
381                mappedBy = "modifiedId",
382                cascade = CascadeType.ALL,
383                fetch = FetchType.LAZY
384        )
385        private Set<FnUser> fnUsersModifiedId;
386        @OneToMany(
387                targetEntity = EpUserRolesRequest.class,
388                mappedBy = "userId",
389                cascade = CascadeType.ALL,
390                fetch = FetchType.LAZY
391        )
392        private Set<EpUserRolesRequest> epUserRolesRequests;
393        @OneToMany(
394                targetEntity = FnPersUserAppSel.class,
395                mappedBy = "userId",
396                cascade = CascadeType.ALL,
397                fetch = FetchType.LAZY
398        )
399        private Set<FnPersUserAppSel> persUserAppSels;
400        @OneToMany(
401                targetEntity = EpWidgetCatalogParameter.class,
402                mappedBy = "userId",
403                cascade = CascadeType.ALL,
404                fetch = FetchType.LAZY
405        )
406        private Set<EpWidgetCatalogParameter> epWidgetCatalogParameters;
407        @OneToMany(
408                targetEntity = EpPersUserWidgetPlacement.class,
409                mappedBy = "userId",
410                cascade = CascadeType.ALL,
411                fetch = FetchType.LAZY
412        )
413        private Set<EpPersUserWidgetPlacement> epPersUserWidgetPlacements;
414        @OneToMany(
415                targetEntity = EpPersUserWidgetSel.class,
416                mappedBy = "userId",
417                cascade = CascadeType.ALL,
418                fetch = FetchType.LAZY
419        )
420        private Set<EpPersUserWidgetSel> epPersUserWidgetSels;
421        @OneToMany(
422                targetEntity = FnUserRole.class,
423                mappedBy = "userId",
424                cascade = CascadeType.ALL,
425                fetch = FetchType.LAZY
426        )
427        private Set<FnUserRole> fnUserRoles;
428        @OneToMany(
429                targetEntity = EpUserNotification.class,
430                mappedBy = "userId",
431                cascade = CascadeType.ALL,
432                fetch = FetchType.LAZY
433        )
434        private Set<EpUserNotification> epUserNotifications;
435
436        @Override
437        public Collection<? extends GrantedAuthority> getAuthorities() {
438               return fnRoles
439                       .stream()
440                       .map(fnRole -> new SimpleGrantedAuthority("ROLE_" + fnRole.getRoleName()))
441                       .collect(Collectors.toList());
442        }
443
444        @Override
445        public String getPassword() {
446               return this.getLoginPwd();
447        }
448
449        @Override
450        public String getUsername() {
451               return this.getLoginId();
452        }
453
454        @Override
455        public boolean isAccountNonExpired() {
456               return true;
457        }
458
459        @Override
460        public boolean isAccountNonLocked() {
461               return true;
462        }
463
464        @Override
465        public boolean isCredentialsNonExpired() {
466               return true;
467        }
468
469        @Override
470        public boolean isEnabled() {
471               return true;
472        }
473
474        public String getFullName() {
475               return this.firstName + " " + this.lastName;
476        }
477
478 }