Portal Spring Boot version Hibernate implementation
[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.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;
71 import lombok.Getter;
72 import lombok.NoArgsConstructor;
73 import lombok.Setter;
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;
93
94 /*
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`)
155         )
156 */
157
158 @NamedNativeQueries({
159         @NamedNativeQuery(
160                 name = "getUsersByOrgUserId",
161                 query = "SELECT * FROM FnUser WHERE where org_user_id in :orgIds"
162         )
163 })
164
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")
173 },
174         uniqueConstraints = {
175                 @UniqueConstraint(name = "fn_user_hrid", columnNames = "hrid"),
176                 @UniqueConstraint(name = "fn_user_login_id", columnNames = "login_id")
177         })
178 @NoArgsConstructor
179 @AllArgsConstructor
180 @Getter
181 @Setter
182 @Entity
183 public class FnUser extends DomainVo implements UserDetails {
184
185        @Id
186        @GeneratedValue(strategy = GenerationType.AUTO)
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.EAGER)
191        @JoinColumn(name = "org_id", columnDefinition = "int(11) DEFAULT NULL")
192        @Valid
193        private FnOrg orgId;
194        @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
195        @JoinColumn(name = "manager_id")
196        @Valid
197        private FnUser managerId;
198        @Column(name = "first_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
199        @Size(max = 50)
200        @SafeHtml
201        private String firstName;
202        @Column(name = "middle_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
203        @Size(max = 50)
204        @SafeHtml
205        private String middleName;
206        @Column(name = "last_name", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
207        @Size(max = 50)
208        @SafeHtml
209        private String lastName;
210        @Column(name = "phone", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
211        @Size(max = 25)
212        @SafeHtml
213        private String phone;
214        @Column(name = "fax", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
215        @Size(max = 25)
216        @SafeHtml
217        private String fax;
218        @Column(name = "cellular", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
219        @Size(max = 25)
220        @SafeHtml
221        private String cellular;
222        @Column(name = "email", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
223        @Size(max = 50)
224        @Email
225        @SafeHtml
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")
234        @Size(max = 20)
235        @SafeHtml
236        private String hrid;
237        @Column(name = "org_user_id", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
238        @Size(max = 20)
239        @SafeHtml
240        private String orgUserId;
241        @Column(name = "org_code", length = 30, columnDefinition = "varchar(30) DEFAULT NULL")
242        @Size(max = 30)
243        @SafeHtml
244        private String org_code;
245        @Column(name = "login_id", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
246        @Size(max = 25)
247        @SafeHtml
248        private String loginId;
249        @Column(name = "login_pwd", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
250        @Size(max = 100)
251        @SafeHtml
252        private String loginPwd;
253        @Column(name = "last_login_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
254        @PastOrPresent
255        protected LocalDateTime lastLoginDate;
256        @Column(name = "active_yn", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false)
257        @Size(max = 1)
258        @SafeHtml
259        @NotNull
260        private String activeYn;
261        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
262        @JoinColumn(name = "created_id")
263        @Valid
264        private FnUser createdId;
265        @Column(name = "created_date", columnDefinition = "datetime DEFAULT current_timestamp()", nullable = false)
266        @PastOrPresent
267        protected LocalDateTime createdDate;
268        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
269        @JoinColumn(name = "modified_id")
270        @Valid
271        private FnUser modifiedId;
272        @Column(name = "modified_date", nullable = false, columnDefinition = "datetime default now()")
273        @PastOrPresent
274        protected LocalDateTime modifiedDate;
275        @Column(name = "is_internal_yn", length = 1, columnDefinition = "character varying(1) default 'n'", nullable = false)
276        @Size(max = 1)
277        @SafeHtml
278        @NotNull
279        private String isInternalYn;
280        @Column(name = "address_line_1", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
281        @Size(max = 100)
282        @SafeHtml
283        private String addressLine1;
284        @Column(name = "address_line_2", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
285        @Size(max = 100)
286        @SafeHtml
287        private String addressLine2;
288        @Column(name = "city", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
289        @Size(max = 50)
290        @SafeHtml
291        private String city;
292        @Column(name = "state_cd", length = 3, columnDefinition = "varchar(3) DEFAULT NULL")
293        @Size(max = 3)
294        @SafeHtml
295        private String stateCd;
296        @Column(name = "zip_code", length = 11, columnDefinition = "varchar(11) DEFAULT NULL")
297        @Size(max = 11)
298        @SafeHtml
299        private String zipCode;
300        @Column(name = "country_cd", length = 3, columnDefinition = "varchar(3) DEFAULT NULL")
301        @Size(max = 3)
302        @SafeHtml
303        private String countryCd;
304        @Column(name = "location_clli", length = 8, columnDefinition = "varchar(8) DEFAULT NULL")
305        @Size(max = 8)
306        @SafeHtml
307        private String locationClli;
308        @Column(name = "org_manager_userid", length = 20, columnDefinition = "varchar(20) DEFAULT NULL")
309        @Size(max = 20)
310        @SafeHtml
311        private String orgManagerUserId;
312        @Column(name = "company", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
313        @Size(max = 100)
314        @SafeHtml
315        private String company;
316        @Column(name = "department_name", length = 200, columnDefinition = "varchar(100) DEFAULT NULL")
317        @Size(max = 200)
318        @SafeHtml
319        private String departmentName;
320        @Column(name = "job_title", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
321        @Size(max = 100)
322        @SafeHtml
323        private String jobTitle;
324        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
325        @JoinColumn(name = "timezone", columnDefinition = "int(11) DEFAULT NULL")
326        @Valid
327        private FnLuTimezone timezone;
328        @Column(name = "department", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
329        @Size(max = 25)
330        @SafeHtml
331        private String department;
332        @Column(name = "business_unit", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
333        @Size(max = 25)
334        @SafeHtml
335        private String businessUnit;
336        @Column(name = "business_unit_name", length = 100, columnDefinition = "varchar(100) DEFAULT NULL")
337        @Size(max = 100)
338        @SafeHtml
339        private String businessUnitName;
340        @Column(name = "cost_center", length = 25, columnDefinition = "varchar(25) DEFAULT NULL")
341        @Size(max = 25)
342        @SafeHtml
343        private String cost_center;
344        @Column(name = "fin_loc_code", length = 10, columnDefinition = "varchar(10) DEFAULT NULL")
345        @Size(max = 10)
346        @SafeHtml
347        private String finLocCode;
348        @Column(name = "silo_status", length = 10, columnDefinition = "varchar(10) DEFAULT NULL")
349        @Size(max = 10)
350        @SafeHtml
351        private String siloStatus;
352        @Column(name = "language_id", length = 2, columnDefinition = "int(2) default 1", nullable = false)
353        @Digits(integer = 2, fraction = 0)
354        @NotNull
355        private Long language_id;
356        @Column(name = "is_guest", columnDefinition = "boolean default 0", nullable = false)
357        @NotNull
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<>();
365        @OneToMany(
366                targetEntity = FnAuditLog.class,
367                mappedBy = "userId",
368                cascade = CascadeType.ALL,
369                fetch = FetchType.LAZY
370        )
371        private List<FnAuditLog> fnAuditLogs = new ArrayList<>();
372        @OneToMany(
373                targetEntity = FnUser.class,
374                mappedBy = "createdId",
375                cascade = CascadeType.ALL,
376                fetch = FetchType.LAZY
377        )
378        private List<FnUser> fnUsersCreatedId = new ArrayList<>();
379        @OneToMany(
380                targetEntity = FnUser.class,
381                mappedBy = "managerId",
382                cascade = CascadeType.ALL,
383                fetch = FetchType.LAZY
384        )
385        private List<FnUser> fnUsersManagerId = new ArrayList<>();
386        @OneToMany(
387                targetEntity = FnUser.class,
388                mappedBy = "modifiedId",
389                cascade = CascadeType.ALL,
390                fetch = FetchType.LAZY
391        )
392        private List<FnUser> fnUsersModifiedId = new ArrayList<>();
393        @OneToMany(
394                targetEntity = EpUserRolesRequest.class,
395                mappedBy = "userId",
396                cascade = CascadeType.ALL,
397                fetch = FetchType.LAZY
398        )
399        private List<EpUserRolesRequest> epUserRolesRequests = new ArrayList<>();
400        @OneToMany(
401                targetEntity = FnPersUserAppSel.class,
402                mappedBy = "userId",
403                cascade = CascadeType.ALL,
404                fetch = FetchType.LAZY
405        )
406        private List<FnPersUserAppSel> persUserAppSels = new ArrayList<>();
407        @OneToMany(
408                targetEntity = EpPersUserAppManSort.class,
409                mappedBy = "userId",
410                cascade = CascadeType.ALL,
411                fetch = FetchType.LAZY
412        )
413        private List<EpPersUserAppManSort> epPersUserAppManSorts = new ArrayList<>();
414        @OneToMany(
415                targetEntity = EpWidgetCatalogParameter.class,
416                mappedBy = "userId",
417                cascade = CascadeType.ALL,
418                fetch = FetchType.LAZY
419        )
420        private List<EpWidgetCatalogParameter> epWidgetCatalogParameters = new ArrayList<>();
421        @OneToMany(
422                targetEntity = EpPersUserWidgetPlacement.class,
423                mappedBy = "userId",
424                cascade = CascadeType.ALL,
425                fetch = FetchType.LAZY
426        )
427        private List<EpPersUserWidgetPlacement> epPersUserWidgetPlacements = new ArrayList<>();
428        @OneToMany(
429                targetEntity = EpPersUserWidgetSel.class,
430                mappedBy = "userId",
431                cascade = CascadeType.ALL,
432                fetch = FetchType.LAZY
433        )
434        private List<EpPersUserWidgetSel> epPersUserWidgetSels = new ArrayList<>();
435        @OneToMany(
436                targetEntity = FnUserRole.class,
437                mappedBy = "userId",
438                cascade = CascadeType.ALL,
439                fetch = FetchType.LAZY
440        )
441        private List<FnUserRole> fnUserRoles = new ArrayList<>();
442        @OneToMany(
443                targetEntity = EpUserNotification.class,
444                mappedBy = "userId",
445                cascade = CascadeType.ALL,
446                fetch = FetchType.LAZY
447        )
448        private List<EpUserNotification> epUserNotifications = new ArrayList<>();
449
450        @Override
451        public Collection<? extends GrantedAuthority> getAuthorities() {
452               return fnRoles
453                       .stream()
454                       .map(fnRole -> new SimpleGrantedAuthority("ROLE_" + fnRole.getRoleName()))
455                       .collect(Collectors.toList());
456        }
457
458        @Override
459        public String getPassword() {
460               return this.getLoginPwd();
461        }
462
463        @Override
464        public String getUsername() {
465               return this.getLoginId();
466        }
467
468        @Override
469        public boolean isAccountNonExpired() {
470               return true;
471        }
472
473        @Override
474        public boolean isAccountNonLocked() {
475               return true;
476        }
477
478        @Override
479        public boolean isCredentialsNonExpired() {
480               return true;
481        }
482
483        @Override
484        public boolean isEnabled() {
485               return true;
486        }
487
488        public String getFullName() {
489               return this.firstName + " " + this.lastName;
490        }
491
492 }