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