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