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