Transport DTO up
[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.time.LocalDateTime;
44 import java.util.Collection;
45 import java.util.Set;
46 import java.util.stream.Collectors;
47 import javax.persistence.CascadeType;
48 import javax.persistence.Column;
49 import javax.persistence.Entity;
50 import javax.persistence.FetchType;
51 import javax.persistence.GeneratedValue;
52 import javax.persistence.GenerationType;
53 import javax.persistence.Id;
54 import javax.persistence.Index;
55 import javax.persistence.JoinColumn;
56 import javax.persistence.ManyToMany;
57 import javax.persistence.ManyToOne;
58 import javax.persistence.NamedQueries;
59 import javax.persistence.NamedQuery;
60 import javax.persistence.OneToMany;
61 import javax.persistence.SequenceGenerator;
62 import javax.persistence.Table;
63 import javax.persistence.UniqueConstraint;
64 import javax.validation.constraints.Digits;
65 import javax.validation.constraints.Email;
66 import javax.validation.constraints.NotNull;
67 import javax.validation.constraints.PastOrPresent;
68 import javax.validation.constraints.Size;
69 import lombok.AllArgsConstructor;
70 import lombok.Getter;
71 import lombok.NoArgsConstructor;
72 import lombok.Setter;
73 import org.hibernate.annotations.DynamicUpdate;
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.springframework.security.core.GrantedAuthority;
82 import org.springframework.security.core.authority.SimpleGrantedAuthority;
83 import org.springframework.security.core.userdetails.UserDetails;
84
85 /*
86 CREATE TABLE `fn_user` (
87         `user_id` int(11) NOT NULL AUTO_INCREMENT,
88         `org_id` int(11) DEFAULT NULL,
89         `manager_id` int(11) DEFAULT NULL,
90         `first_name` varchar(50) DEFAULT NULL,
91         `middle_name` varchar(50) DEFAULT NULL,
92         `last_name` varchar(50) DEFAULT NULL,
93         `phone` varchar(25) DEFAULT NULL,
94         `fax` varchar(25) DEFAULT NULL,
95         `cellular` varchar(25) DEFAULT NULL,
96         `email` varchar(50) DEFAULT NULL,
97         `address_id` decimal(11,0) DEFAULT NULL,
98         `alert_method_cd` varchar(10) DEFAULT NULL,
99         `hrid` varchar(20) DEFAULT NULL,
100         `org_user_id` varchar(20) DEFAULT NULL,
101         `org_code` varchar(30) DEFAULT NULL,
102         `login_id` varchar(25) DEFAULT NULL,
103         `login_pwd` varchar(100) DEFAULT NULL,
104         `last_login_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
105         `active_yn` varchar(1) NOT NULL DEFAULT 'y',
106         `created_id` int(11) DEFAULT NULL,
107         `created_date` timestamp NOT NULL DEFAULT current_timestamp(),
108         `modified_id` int(11) DEFAULT NULL,
109         `modified_date` timestamp NOT NULL DEFAULT current_timestamp(),
110         `is_internal_yn` char(1) NOT NULL DEFAULT 'n',
111         `address_line_1` varchar(100) DEFAULT NULL,
112         `address_line_2` varchar(100) DEFAULT NULL,
113         `city` varchar(50) DEFAULT NULL,
114         `state_cd` varchar(3) DEFAULT NULL,
115         `zip_code` varchar(11) DEFAULT NULL,
116         `country_cd` varchar(3) DEFAULT NULL,
117         `location_clli` varchar(8) DEFAULT NULL,
118         `org_manager_userid` varchar(20) DEFAULT NULL,
119         `company` varchar(100) DEFAULT NULL,
120         `department_name` varchar(100) DEFAULT NULL,
121         `job_title` varchar(100) DEFAULT NULL,
122         `timezone` int(11) DEFAULT NULL,
123         `department` varchar(25) DEFAULT NULL,
124         `business_unit` varchar(25) DEFAULT NULL,
125         `business_unit_name` varchar(100) DEFAULT NULL,
126         `cost_center` varchar(25) DEFAULT NULL,
127         `fin_loc_code` varchar(10) DEFAULT NULL,
128         `silo_status` varchar(10) DEFAULT NULL,
129         `language_id` int(2) NOT NULL DEFAULT 1,
130         PRIMARY KEY (`user_id`),
131         UNIQUE KEY `fn_user_hrid` (`hrid`) USING BTREE,
132         UNIQUE KEY `fn_user_login_id` (`login_id`) USING BTREE,
133         KEY `fn_user_address_id` (`address_id`) USING BTREE,
134         KEY `fn_user_alert_method_cd` (`alert_method_cd`) USING BTREE,
135         KEY `fn_user_org_id` (`org_id`) USING BTREE,
136         KEY `fk_fn_user_ref_197_fn_user` (`manager_id`),
137         KEY `fk_fn_user_ref_198_fn_user` (`created_id`),
138         KEY `fk_fn_user_ref_199_fn_user` (`modified_id`),
139         KEY `fk_timezone` (`timezone`),
140         CONSTRAINT `fk_fn_user_ref_110_fn_org` FOREIGN KEY (`org_id`) REFERENCES `fn_org` (`org_id`),
141         CONSTRAINT `fk_fn_user_ref_123_fn_lu_al` FOREIGN KEY (`alert_method_cd`) REFERENCES `fn_lu_alert_method` (`alert_method_cd`),
142         CONSTRAINT `fk_fn_user_ref_197_fn_user` FOREIGN KEY (`manager_id`) REFERENCES `fn_user` (`user_id`),
143         CONSTRAINT `fk_fn_user_ref_198_fn_user` FOREIGN KEY (`created_id`) REFERENCES `fn_user` (`user_id`),
144         CONSTRAINT `fk_fn_user_ref_199_fn_user` FOREIGN KEY (`modified_id`) REFERENCES `fn_user` (`user_id`),
145         CONSTRAINT `fk_timezone` FOREIGN KEY (`timezone`) REFERENCES `fn_lu_timezone` (`timezone_id`)
146         )
147 */
148
149 @NamedQueries({
150         @NamedQuery(
151                 name = "FnUser.getUserWithOrgUserId",
152                 query = "FROM FnUser WHERE orgUserId = :orgId"),
153         @NamedQuery(
154                 name = "FnUser.getActiveUsers",
155                 query = "FROM FnUser WHERE activeYn = 'Y'"),
156         @NamedQuery(
157                 name = "FnUser.getUsersByOrgIds",
158                 query = "FROM FnUser WHERE orgUserId IN :orgIds"
159         )
160 })
161 @Table(name = "fn_user", indexes = {
162         @Index(name = "fn_user_address_id", columnList = "address_id"),
163         @Index(name = "fn_user_alert_method_cd", columnList = "alert_method_cd"),
164         @Index(name = "fn_user_org_id", columnList = "org_id"),
165         @Index(name = "fk_fn_user_ref_197_fn_user", columnList = "manager_id"),
166         @Index(name = "fk_fn_user_ref_198_fn_user", columnList = "created_id"),
167         @Index(name = "fk_fn_user_ref_199_fn_user", columnList = "modified_id"),
168         @Index(name = "fk_timezone", columnList = "timezone")
169 },
170         uniqueConstraints = {
171                 @UniqueConstraint(name = "fn_user_hrid", columnNames = "hrid"),
172                 @UniqueConstraint(name = "fn_user_login_id", columnNames = "login_id")
173
174         })
175
176 @Getter
177 @Setter
178 @Entity
179 @NoArgsConstructor
180 @AllArgsConstructor
181 @DynamicUpdate
182 @SequenceGenerator(name = "seq", initialValue = 1000, allocationSize = 100000)
183 public class FnUser implements UserDetails {
184
185        @Id
186        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
187        @Column(name = "user_id", length = 11, nullable = false)
188        @Digits(integer = 11, fraction = 0)
189        private Long userId;
190        @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
191        @JoinColumn(name = "org_id", columnDefinition = "int(11) DEFAULT NULL")
192        private FnOrg orgId;
193        @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
194        @JoinColumn(name = "manager_id")
195        private FnUser managerId;
196        @Column(name = "first_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
197        @Size(max = 50)
198        @SafeHtml
199        private String firstName;
200        @Column(name = "middle_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
201        @Size(max = 50)
202        @SafeHtml
203        private String middleName;
204        @Column(name = "last_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
205        @Size(max = 50)
206        @SafeHtml
207        private String lastName;
208        @Column(name = "phone", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
209        @Size(max = 25)
210        @SafeHtml
211        private String phone;
212        @Column(name = "fax", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
213        @Size(max = 25)
214        @SafeHtml
215        private String fax;
216        @Column(name = "cellular", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
217        @Size(max = 25)
218        @SafeHtml
219        private String cellular;
220        @Column(name = "email", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
221        @Size(max = 50)
222        @Email
223        @SafeHtml
224        private String email;
225        @Column(name = "address_id", columnDefinition = "decimal(11,0) DEFAULT NULL")
226        @Digits(integer = 11, fraction = 0)
227        private Long addressId;
228        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
229        @JoinColumn(name = "alert_method_cd", columnDefinition = "varchar(10) DEFAULT NULL")
230        private FnLuAlertMethod alertMethodCd;
231        @Column(name = "hrid", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
232        @Size(max = 20)
233        @SafeHtml
234        private String hrid;
235        @Column(name = "org_user_id", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
236        @Size(max = 20)
237        @SafeHtml
238        private String orgUserId;
239        @Column(name = "org_code", length = 30, columnDefinition = "varchar(30) DEFAULT NULL")
240        @Size(max = 30)
241        @SafeHtml
242        private String org_code;
243        @Column(name = "login_id", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
244        @Size(max = 25)
245        @SafeHtml
246        private String loginId;
247        @Column(name = "login_pwd", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
248        @Size(max = 100)
249        @SafeHtml
250        private String loginPwd;
251        @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
252        @PastOrPresent
253        protected LocalDateTime lastLoginDate;
254        @Column(name = "active_yn", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false)
255        @Size(max = 1)
256        @SafeHtml
257        @NotNull(message = "activeYn must not be null")
258        private String activeYn;
259        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
260        @JoinColumn(name = "created_id")
261        private FnUser createdId;
262        @Column(name = "created_date", columnDefinition = "datetime DEFAULT current_timestamp()", nullable = false)
263        @PastOrPresent
264        protected LocalDateTime createdDate;
265        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
266        @JoinColumn(name = "modified_id")
267        private FnUser modifiedId;
268        @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
269        @PastOrPresent
270        protected LocalDateTime modifiedDate;
271        @Column(name = "is_internal_yn", length = 1, columnDefinition = "character varying(1) default 'n'", nullable = false)
272        @Size(max = 1)
273        @SafeHtml
274        @NotNull(message = "isInternalYn must not be null")
275        private String isInternalYn;
276        @Column(name = "address_line_1", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
277        @Size(max = 100)
278        @SafeHtml
279        private String addressLine1;
280        @Column(name = "address_line_2", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
281        @Size(max = 100)
282        @SafeHtml
283        private String addressLine2;
284        @Column(name = "city", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
285        @Size(max = 50)
286        @SafeHtml
287        private String city;
288        @Column(name = "state_cd", length = 3, columnDefinition = "varchar(3) DEFAULT NULL")
289        @Size(max = 3)
290        @SafeHtml
291        private String stateCd;
292        @Column(name = "zip_code", length = 11, columnDefinition = "varchar(11) DEFAULT NULL")
293        @Size(max = 11)
294        @SafeHtml
295        private String zipCode;
296        @Column(name = "country_cd", length = 3, columnDefinition = "varchar(3) DEFAULT NULL")
297        @Size(max = 3)
298        @SafeHtml
299        private String countryCd;
300        @Column(name = "location_clli", length = 8, columnDefinition = "varchar(8) DEFAULT NULL")
301        @Size(max = 8)
302        @SafeHtml
303        private String locationClli;
304        @Column(name = "org_manager_userid", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
305        @Size(max = 20)
306        @SafeHtml
307        private String orgManagerUserId;
308        @Column(name = "company", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
309        @Size(max = 100)
310        @SafeHtml
311        private String company;
312        @Column(name = "department_name", length = 200, columnDefinition = "varchar(100) DEFAULT NULL")
313        @Size(max = 200)
314        @SafeHtml
315        private String departmentName;
316        @Column(name = "job_title", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
317        @Size(max = 100)
318        @SafeHtml
319        private String jobTitle;
320        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
321        @JoinColumn(name = "timezone", columnDefinition = "int(11) DEFAULT NULL")
322        private FnLuTimezone timezone;
323        @Column(name = "department", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
324        @Size(max = 25)
325        @SafeHtml
326        private String department;
327        @Column(name = "business_unit", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
328        @Size(max = 25)
329        @SafeHtml
330        private String businessUnit;
331        @Column(name = "business_unit_name", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
332        @Size(max = 100)
333        @SafeHtml
334        private String businessUnitName;
335        @Column(name = "cost_center", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
336        @Size(max = 25)
337        @SafeHtml
338        private String cost_center;
339        @Column(name = "fin_loc_code", length = 10, columnDefinition = "varchar(10) DEFAULT NULL")
340        @Size(max = 10)
341        @SafeHtml
342        private String finLocCode;
343        @Column(name = "silo_status", length = 10, columnDefinition = "varchar(10) DEFAULT NULL")
344        @Size(max = 10)
345        @SafeHtml
346        private String siloStatus;
347        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
348        @JoinColumn(name = "language_id", nullable = false, columnDefinition = "int(11) DEFAULT 1")
349        @NotNull(message = "languageId must not be null")
350        private FnLanguage languageId;
351        @Column(name = "is_guest", columnDefinition = "boolean default 0", nullable = false)
352        @NotNull(message = "guest must not be null")
353        private boolean guest;
354        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList")
355        private Set<CrReportFileHistory> crReportFileHistorie;
356        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
357        private Set<FnRole> fnRoles;
358        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
359        private Set<FnMenuFunctional> fnRoleList;
360        @OneToMany(
361                targetEntity = FnAuditLog.class,
362                mappedBy = "userId",
363                cascade = CascadeType.ALL,
364                fetch = FetchType.LAZY
365        )
366        private Set<FnAuditLog> fnAuditLogs;
367        @OneToMany(
368                targetEntity = FnUser.class,
369                mappedBy = "createdId",
370                cascade = CascadeType.ALL,
371                fetch = FetchType.LAZY
372        )
373        private Set<FnUser> fnUsersCreatedId;
374        @OneToMany(
375                targetEntity = FnUser.class,
376                mappedBy = "managerId",
377                cascade = CascadeType.ALL,
378                fetch = FetchType.LAZY
379        )
380        private Set<FnUser> fnUsersManagerId;
381        @OneToMany(
382                targetEntity = FnUser.class,
383                mappedBy = "modifiedId",
384                cascade = CascadeType.ALL,
385                fetch = FetchType.LAZY
386        )
387        private Set<FnUser> fnUsersModifiedId;
388        @OneToMany(
389                targetEntity = EpUserRolesRequest.class,
390                mappedBy = "userId",
391                cascade = CascadeType.ALL,
392                fetch = FetchType.LAZY
393        )
394        private Set<EpUserRolesRequest> epUserRolesRequests;
395        @OneToMany(
396                targetEntity = FnPersUserAppSel.class,
397                mappedBy = "userId",
398                cascade = CascadeType.ALL,
399                fetch = FetchType.LAZY
400        )
401        private Set<FnPersUserAppSel> persUserAppSels;
402        @OneToMany(
403                targetEntity = EpWidgetCatalogParameter.class,
404                mappedBy = "userId",
405                cascade = CascadeType.ALL,
406                fetch = FetchType.LAZY
407        )
408        private Set<EpWidgetCatalogParameter> epWidgetCatalogParameters;
409        @OneToMany(
410                targetEntity = EpPersUserWidgetPlacement.class,
411                mappedBy = "userId",
412                cascade = CascadeType.ALL,
413                fetch = FetchType.LAZY
414        )
415        private Set<EpPersUserWidgetPlacement> epPersUserWidgetPlacements;
416        @OneToMany(
417                targetEntity = EpPersUserWidgetSel.class,
418                mappedBy = "userId",
419                cascade = CascadeType.ALL,
420                fetch = FetchType.LAZY
421        )
422        private Set<EpPersUserWidgetSel> epPersUserWidgetSels;
423        @OneToMany(
424                targetEntity = FnUserRole.class,
425                mappedBy = "userId",
426                cascade = CascadeType.ALL,
427                fetch = FetchType.LAZY
428        )
429        private Set<FnUserRole> fnUserRoles;
430        @OneToMany(
431                targetEntity = EpUserNotification.class,
432                mappedBy = "userId",
433                cascade = CascadeType.ALL,
434                fetch = FetchType.LAZY
435        )
436        private Set<EpUserNotification> epUserNotifications;
437
438        @Override
439        public Collection<? extends GrantedAuthority> getAuthorities() {
440               return fnRoles
441                       .stream()
442                       .map(fnRole -> new SimpleGrantedAuthority("ROLE_" + fnRole.getRoleName()))
443                       .collect(Collectors.toList());
444        }
445
446        @Override
447        public String getPassword() {
448               return this.getLoginPwd();
449        }
450
451        @Override
452        public String getUsername() {
453               return this.getLoginId();
454        }
455
456        @Override
457        public boolean isAccountNonExpired() {
458               return true;
459        }
460
461        @Override
462        public boolean isAccountNonLocked() {
463               return true;
464        }
465
466        @Override
467        public boolean isCredentialsNonExpired() {
468               return true;
469        }
470
471        @Override
472        public boolean isEnabled() {
473               return true;
474        }
475
476        public String getFullName() {
477               return this.firstName + " " + this.lastName;
478        }
479
480 }