a3c9c4819640cf53b8de23db151c8f0594093fef
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / domain / EPUser.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 package org.onap.portalapp.portal.domain;
39
40 import java.util.Date;
41 import java.util.Iterator;
42 import java.util.SortedSet;
43 import java.util.TreeSet;
44
45 import javax.validation.Valid;
46 import org.hibernate.validator.constraints.SafeHtml;
47 import org.onap.portalapp.portal.utils.PortalConstants;
48 import org.onap.portalsdk.core.domain.User;
49 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
50
51 import com.fasterxml.jackson.annotation.JsonIgnore;
52
53 public class EPUser extends User {
54             
55             private Long   orgId;
56             private Long   managerId;
57             @SafeHtml
58             private String firstName;
59             @SafeHtml
60             private String middleInitial;
61             @SafeHtml
62             private String lastName;
63             @SafeHtml
64             private String phone;
65             @SafeHtml
66             private String fax;
67             @SafeHtml
68             private String cellular;
69             @SafeHtml
70             private String email;
71             private Long   addressId;
72             @SafeHtml
73             private String alertMethodCd;
74             @SafeHtml
75             private String hrid;
76             @SafeHtml
77             private String orgUserId;
78             @SafeHtml
79             private String orgCode;
80             @SafeHtml
81             private String address1;
82             @SafeHtml
83             private String address2;
84             @SafeHtml
85             private String city;
86             @SafeHtml
87             private String state;
88             @SafeHtml
89             private String zipCode;
90             @SafeHtml
91             private String country;
92             @SafeHtml
93             private String orgManagerUserId;
94             @SafeHtml
95             private String locationClli;
96             @SafeHtml
97             private String businessCountryCode;
98             @SafeHtml
99             private String businessCountryName;
100             @SafeHtml
101             private String businessUnit;
102             @SafeHtml
103             private String businessUnitName;
104             @SafeHtml
105             private String department;
106             @SafeHtml
107             private String departmentName;
108             @SafeHtml
109             private String companyCode;
110             @SafeHtml
111             private String company;
112             @SafeHtml
113             private String zipCodeSuffix;
114             @SafeHtml
115             private String jobTitle;
116             @SafeHtml
117             private String commandChain;
118             @SafeHtml
119             private String siloStatus;
120             @SafeHtml
121             private String costCenter;
122             @SafeHtml
123             private String financialLocCode;
124             
125             
126             @SafeHtml
127             private String loginId;
128             @SafeHtml
129             private String loginPwd;
130             private Date   lastLoginDate;
131             private boolean active;
132             private boolean internal;
133             private Long    selectedProfileId;
134             private Long timeZoneId;
135             private boolean online;
136             @SafeHtml
137             private String chatId;
138             private boolean systemUser;
139             private Integer languageId;
140             private static final long serialVersionUID = 1L;
141
142
143             private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPUser.class);
144                 private static final String ECOMP_PORTAL_NAME = "ECOMP";
145                 private boolean isGuest = false;
146                 @Valid
147                 private SortedSet<EPUserApp> userApps = new TreeSet<EPUserApp>();
148                 @Valid
149                 private SortedSet<EPRole> pseudoRoles = new TreeSet<EPRole>();
150
151             public EPUser() {}
152
153             public Long getAddressId() {
154                 return addressId;
155             }
156
157             public String getAlertMethodCd() {
158                 return alertMethodCd;
159             }
160
161             public String getCellular() {
162                 return cellular;
163             }
164
165             public String getEmail() {
166                 return email;
167             }
168
169             public String getFax() {
170                 return fax;
171             }
172
173             public String getFirstName() {
174                 return firstName;
175             }
176
177             public String getHrid() {
178                 return hrid;
179             }
180
181             public Date getLastLoginDate() {
182                 return lastLoginDate;
183             }
184
185             public String getLastName() {
186                 return lastName;
187             }
188
189             @JsonIgnore
190             public String getFullName() {
191                 return getFirstName() + " " + getLastName();    
192             }
193             
194             public String getLoginId() {
195                 return loginId;
196             }
197
198             public String getLoginPwd() {
199                 return loginPwd;
200             }
201
202             public Long getManagerId() {
203                 return managerId;
204             }
205
206             public String getMiddleInitial() {
207                 return middleInitial;
208             }
209
210             public String getOrgCode() {
211                 return orgCode;
212             }
213
214             public Long getOrgId() {
215                 return orgId;
216             }
217
218             public String getPhone() {
219                 return phone;
220             }
221
222             public String getOrgUserId() {
223                 return orgUserId;
224             }
225
226             public boolean getActive() {
227                 return active;
228             }
229
230             public boolean getInternal() {
231                 return internal;
232             }
233
234             public String getAddress1() {
235                 return address1;
236             }
237
238             public String getAddress2() {
239                 return address2;
240             }
241
242             public String getCity() {
243                 return city;
244             }
245
246             public String getCountry() {
247                 return country;
248             }
249
250             public String getState() {
251                 return state;
252             }
253
254             public String getZipCode() {
255                 return zipCode;
256             }
257
258             public String getBusinessCountryCode() {
259                 return businessCountryCode;
260             }
261
262             public String getCommandChain() {
263                 return commandChain;
264             }
265
266             public String getCompany() {
267                 return company;
268             }
269
270             public String getCompanyCode() {
271                 return companyCode;
272             }
273
274             public String getDepartment() {
275                 return department;
276             }
277
278             public String getJobTitle() {
279                 return jobTitle;
280             }
281
282             public String getLocationClli() {
283                 return locationClli;
284             }
285
286             public String getOrgManagerUserId() {
287                 return orgManagerUserId;
288             }
289
290             public String getZipCodeSuffix() {
291                 return zipCodeSuffix;
292             }
293
294             public String getBusinessCountryName() {
295                 return businessCountryName;
296             }
297
298             public Long getSelectedProfileId() {
299                 return selectedProfileId;
300             }
301
302             public void setAddressId(Long addressId) {
303                 this.addressId = addressId;
304             }
305
306             public void setAlertMethodCd(String alertMethodCd) {
307                 this.alertMethodCd = alertMethodCd;
308             }
309
310             public void setCellular(String cellular) {
311                 this.cellular = cellular;
312             }
313
314             public void setEmail(String email) {
315                 this.email = email;
316             }
317
318             public void setFax(String fax) {
319                 this.fax = fax;
320             }
321
322             public void setFirstName(String firstName) {
323                 this.firstName = firstName;
324             }
325
326             public void setHrid(String hrid) {
327                 this.hrid = hrid;
328             }
329
330             public void setLastLoginDate(Date lastLoginDate) {
331                 this.lastLoginDate = lastLoginDate;
332             }
333
334             public void setLastName(String lastName) {
335                 this.lastName = lastName;
336             }
337
338             public void setLoginId(String loginId) {
339                 this.loginId = loginId;
340             }
341
342             public void setLoginPwd(String loginPwd) {
343                 this.loginPwd = loginPwd;
344             }
345
346             public void setManagerId(Long managerId) {
347                 this.managerId = managerId;
348             }
349
350             public void setMiddleInitial(String middleInitial) {
351                 this.middleInitial = middleInitial;
352             }
353
354             public void setOrgCode(String orgCode) {
355                 this.orgCode = orgCode;
356             }
357
358             public void setOrgId(Long orgId) {
359                 this.orgId = orgId;
360             }
361
362             public void setPhone(String phone) {
363                 this.phone = phone;
364             }
365
366             public void setOrgUserId(String orgUserId) {
367                 this.orgUserId = orgUserId;
368             }
369
370             public void setActive(boolean active) {
371                 this.active = active;
372             }
373
374             public void setInternal(boolean internal) {
375                 this.internal = internal;
376             }
377
378             public void setAddress1(String address1) {
379                 this.address1 = address1;
380             }
381
382             public void setAddress2(String address2) {
383                 this.address2 = address2;
384             }
385
386             public void setCity(String city) {
387                 this.city = city;
388             }
389
390             public void setCountry(String country) {
391                 this.country = country;
392             }
393
394             public void setState(String state) {
395                 this.state = state;
396             }
397
398             public void setZipCode(String zipCode) {
399                 this.zipCode = zipCode;
400             }
401
402             public void setBusinessCountryCode(String businessCountryCode) {
403                 this.businessCountryCode = businessCountryCode;
404             }
405
406             public void setCommandChain(String commandChain) {
407                 this.commandChain = commandChain;
408             }
409
410             public void setCompany(String company) {
411                 this.company = company;
412             }
413
414             public void setCompanyCode(String companyCode) {
415                 this.companyCode = companyCode;
416             }
417
418             public void setDepartment(String department) {
419                 this.department = department;
420             }
421
422             public void setJobTitle(String jobTitle) {
423                 this.jobTitle = jobTitle;
424             }
425
426             public void setLocationClli(String locationClli) {
427                 this.locationClli = locationClli;
428             }
429
430             public void setOrgManagerUserId(String orgManagerUserId) {
431                 this.orgManagerUserId = orgManagerUserId;
432             }
433
434             public void setZipCodeSuffix(String zipCodeSuffix) {
435                 this.zipCodeSuffix = zipCodeSuffix;
436             }
437
438             public void setBusinessCountryName(String businessCountryName) {
439                 this.businessCountryName = businessCountryName;
440             }
441
442             public SortedSet<EPRole> getPseudoRoles() {
443                         return pseudoRoles;
444                 }
445             
446             public void setPseudoRoles(SortedSet<EPRole> pseudoRoles) {
447                 this.pseudoRoles = pseudoRoles;
448             }
449
450             public void setSelectedProfileId(Long selectedProfileId) {
451                 this.selectedProfileId = selectedProfileId;
452             }
453             
454                 public Long getTimeZoneId() {
455                         return timeZoneId;
456                 }
457
458                 public void setTimeZoneId(Long timeZoneId) {
459                         this.timeZoneId = timeZoneId;
460                 }
461
462                 public String getBusinessUnit() {
463                         return businessUnit;
464                 }
465
466                 public void setBusinessUnit(String businessUnit) {
467                         this.businessUnit = businessUnit;
468                 }
469
470                 public String getSiloStatus() {
471                         return siloStatus;
472                 }
473
474                 public void setSiloStatus(String siloStatus) {
475                         this.siloStatus = siloStatus;
476                 }
477
478                 public String getCostCenter() {
479                         return costCenter;
480                 }
481
482                 public void setCostCenter(String costCenter) {
483                         this.costCenter = costCenter;
484                 }
485
486                 public String getFinancialLocCode() {
487                         return financialLocCode;
488                 }
489
490                 public void setFinancialLocCode(String financialLocCode) {
491                         this.financialLocCode = financialLocCode;
492                 }
493                 
494                 public String getBusinessUnitName() {
495                         return businessUnitName;
496                 }
497
498                 public void setBusinessUnitName(String businessUnitName) {
499                         this.businessUnitName = businessUnitName;
500                 }
501
502                 public String getDepartmentName() {
503                         return departmentName;
504                 }
505
506                 public void setDepartmentName(String departmentName) {
507                         this.departmentName = departmentName;
508                 }
509
510                 public int compareTo(Object obj){
511               EPUser user = (EPUser)obj;
512
513               String c1 = getLastName() + getFirstName() + getMiddleInitial();
514               String c2 = user.getLastName() + user.getFirstName() + user.getMiddleInitial();
515
516               return c1.compareTo(c2);
517             }
518
519                 public boolean isOnline() {
520                         return online;
521                 }
522
523                 public void setOnline(boolean online) {
524                         this.online = online;
525                 }
526
527                 public String getChatId() {
528                         return chatId;
529                 }
530
531                 public void setChatId(String chatId) {
532                         this.chatId = chatId;
533                 }
534                 
535                 
536                 public Integer getLanguageId() {
537                         return languageId;
538                 }
539
540                 public void setLanguageId(Integer languageId) {
541                         this.languageId = languageId;
542                 }
543
544         public void setPseudoEPRoles(SortedSet<EPRole> pseudoRoles) {
545                 this.pseudoRoles = pseudoRoles;
546         }
547         
548         public SortedSet<EPUserApp> getEPUserApps() {
549                 return userApps;
550         }
551
552         public void setEPUserApps(SortedSet<EPUserApp> userApps) {
553                 this.userApps = userApps;
554         }
555
556         public void addUserApp(EPUserApp userApp) {
557                 userApps.add(userApp);
558         }
559         
560         public void addAppRoles(EPApp app, SortedSet<EPRole> roles) {
561                 if (roles != null) {
562                         // add all
563                         SortedSet<EPUserApp> userApps = new TreeSet<EPUserApp>();
564                         // this.userApps.removeAll(this.userApps);
565                         Iterator<EPRole> itr = roles.iterator();
566                         while (itr.hasNext()) {
567                                 EPRole role = (EPRole) itr.next();
568                                 EPUserApp userApp = new EPUserApp();
569                                 userApp.setUserId(this.id);
570                                 userApp.setApp(app);
571                                 userApp.setRole(role);
572                                 userApps.add(userApp);
573                         }
574                         setEPUserApps(userApps);
575                 } else {
576                         // remove all
577                         setEPUserApps(null);
578                 }
579
580         }
581
582         public SortedSet<EPRole> getAppEPRoles(EPApp app) {
583                 
584                 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - app = {}", app.getName());
585                 
586                 SortedSet<EPRole> roles = new TreeSet<EPRole>();
587                 SortedSet<EPUserApp> userAppRoles = getEPUserApps();
588                 
589                 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - userApps = {} ", userAppRoles.size());
590
591                 Iterator<EPUserApp> userAppRolesIterator = userAppRoles.iterator();
592
593                 EPUserApp userAppRole = null;
594                 // getting default app
595                 while (userAppRolesIterator.hasNext()) {
596                         EPUserApp tempUserApp = (EPUserApp) userAppRolesIterator.next();
597                         if (tempUserApp.getApp().getId().equals(app.getId())) {
598
599                                 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - for user {}, found application {}", this.getFullName(), app.getName());
600                                 
601                                 userAppRole = tempUserApp;
602                                 
603                                 EPRole role = userAppRole.getRole();
604                                 if(role.getActive()){
605                                         logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - Role {} is active - adding for user {} and app {}", role.getName(), this.getFullName(), app.getName());
606                                         roles.add((EPRole) role);
607                                 }
608                                 else{
609                                         logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - Role {} is NOT active - NOT adding for user {} and app {}", role.getName(), this.getFullName(), app.getName());
610                                 }                               
611                         }
612                 }
613                 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - roles = {}" , roles.size());
614
615                 return roles;
616         }
617
618         
619         /**
620          * Attention! Not for use in ONAP
621          */
622         public SortedSet<EPRole> getAppRoles(EPApp app) {
623                 SortedSet<EPRole> roles = new TreeSet<EPRole>();
624                 SortedSet<EPUserApp> apps = getEPUserApps();
625                 Iterator<EPUserApp> appsItr = apps.iterator();
626                 EPUserApp userApp = null;
627                 // getting default app
628                 while (appsItr.hasNext()) {
629                         EPUserApp tempUserApp = (EPUserApp) appsItr.next();
630                         if (tempUserApp.getApp().getId().equals(app.getId())) {
631                                 userApp = tempUserApp;
632                                 roles.add((EPRole) userApp.getRole());
633                         }
634                 }
635                 return roles;
636         }
637
638         
639
640         /**
641          * Attention! Not for use in ONAP
642          */
643         public SortedSet<EPRole> getEPRoles() {
644                 EPApp app = new EPApp();
645                 app.setId(new Long(PortalConstants.PORTAL_APP_ID));
646                 app.setName(ECOMP_PORTAL_NAME);
647                 return getAppEPRoles(app);
648         }
649
650         /**
651          * Attention! Not for use in ONAP
652          */
653         public void setEPRoles(SortedSet<EPRole> roles) {
654                 EPApp app = new EPApp();
655                 app.setId(new Long(PortalConstants.PORTAL_APP_ID));
656                 app.setName(ECOMP_PORTAL_NAME);
657                 addAppRoles(app, roles);
658         }
659
660         /**
661          * Attention! Not for use in ONAP
662          */
663         public void removeEPRole(Long roleId) {
664                 SortedSet<EPUserApp> apps = getEPUserApps();
665                 Iterator<EPUserApp> appsItr = apps.iterator();
666                 // getting default app
667                 while (appsItr.hasNext()) {
668                         EPUserApp tempUserApp = (EPUserApp) appsItr.next();
669                         if (tempUserApp.equals(new Long(PortalConstants.PORTAL_APP_ID)) && tempUserApp.getRole().getId().equals(roleId)) {
670                                 appsItr.remove();
671                         }
672                 }
673         }
674
675         /**
676          * Attention! Not for use in ONAP
677          */
678         public void addEPRole(EPRole role) {
679                 if (role != null) {
680                         SortedSet<EPRole> roles = getEPRoles();
681                         if (roles == null) {
682                                 roles = new TreeSet<EPRole>();
683                         }
684                         roles.add(role);
685                         setEPRoles(roles);
686                 }
687         }
688         
689         public boolean isGuest() {
690                 return isGuest;
691         }
692
693         public void setGuest(boolean isGuest) {
694                 this.isGuest = isGuest;
695         }
696         
697         public boolean isSystemUser() {
698                 return systemUser;
699         }
700
701         public void setSystemUser(boolean systemUser) {
702                 this.systemUser = systemUser;
703         }
704
705         @Override
706         public String toString() {
707                 return "EPUser [orgId=" + orgId + ", managerId=" + managerId + ", firstName=" + firstName + ", middleInitial="
708                                 + middleInitial + ", lastName=" + lastName + ", phone=" + phone + ", fax=" + fax + ", cellular="
709                                 + cellular + ", email=" + email + ", addressId=" + addressId + ", alertMethodCd=" + alertMethodCd
710                                 + ", hrid=" + hrid + ", orgUserId=" + orgUserId + ", orgCode=" + orgCode + ", address1=" + address1
711                                 + ", address2=" + address2 + ", city=" + city + ", state=" + state + ", zipCode=" + zipCode
712                                 + ", country=" + country + ", orgManagerUserId=" + orgManagerUserId + ", locationClli=" + locationClli
713                                 + ", businessCountryCode=" + businessCountryCode + ", businessCountryName=" + businessCountryName
714                                 + ", businessUnit=" + businessUnit + ", businessUnitName=" + businessUnitName + ", department="
715                                 + department + ", departmentName=" + departmentName + ", companyCode=" + companyCode + ", company="
716                                 + company + ", zipCodeSuffix=" + zipCodeSuffix + ", jobTitle=" + jobTitle + ", commandChain="
717                                 + commandChain + ", siloStatus=" + siloStatus + ", costCenter=" + costCenter + ", financialLocCode="
718                                 + financialLocCode + ", loginId=" + loginId + ", loginPwd=" + loginPwd + ", lastLoginDate="
719                                 + lastLoginDate + ", active=" + active + ", internal=" + internal + ", selectedProfileId="
720                                 + selectedProfileId + ", timeZoneId=" + timeZoneId + ", online=" + online + ", chatId=" + chatId
721                                 + ", isGuest=" + isGuest + ", userApps=" + userApps + ", pseudoRoles=" + pseudoRoles + "]";
722         }
723         
724         
725 }