dff5601be98ecf48bcb6e72fd201ed32a2c16a09
[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 Integer languageId;
139             private static final long serialVersionUID = 1L;
140
141             private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPUser.class);
142                 private static final String ECOMP_PORTAL_NAME = "ECOMP";
143                 private boolean isGuest = false;
144                 @Valid
145                 private SortedSet<EPUserApp> userApps = new TreeSet<EPUserApp>();
146                 @Valid
147                 private SortedSet<EPRole> pseudoRoles = new TreeSet<EPRole>();
148
149             public EPUser() {}
150
151             public Long getAddressId() {
152                 return addressId;
153             }
154
155             public String getAlertMethodCd() {
156                 return alertMethodCd;
157             }
158
159             public String getCellular() {
160                 return cellular;
161             }
162
163             public String getEmail() {
164                 return email;
165             }
166
167             public String getFax() {
168                 return fax;
169             }
170
171             public String getFirstName() {
172                 return firstName;
173             }
174
175             public String getHrid() {
176                 return hrid;
177             }
178
179             public Date getLastLoginDate() {
180                 return lastLoginDate;
181             }
182
183             public String getLastName() {
184                 return lastName;
185             }
186
187             @JsonIgnore
188             public String getFullName() {
189                 return getFirstName() + " " + getLastName();    
190             }
191             
192             public String getLoginId() {
193                 return loginId;
194             }
195
196             public String getLoginPwd() {
197                 return loginPwd;
198             }
199
200             public Long getManagerId() {
201                 return managerId;
202             }
203
204             public String getMiddleInitial() {
205                 return middleInitial;
206             }
207
208             public String getOrgCode() {
209                 return orgCode;
210             }
211
212             public Long getOrgId() {
213                 return orgId;
214             }
215
216             public String getPhone() {
217                 return phone;
218             }
219
220             public String getOrgUserId() {
221                 return orgUserId;
222             }
223
224             public boolean getActive() {
225                 return active;
226             }
227
228             public boolean getInternal() {
229                 return internal;
230             }
231
232             public String getAddress1() {
233                 return address1;
234             }
235
236             public String getAddress2() {
237                 return address2;
238             }
239
240             public String getCity() {
241                 return city;
242             }
243
244             public String getCountry() {
245                 return country;
246             }
247
248             public String getState() {
249                 return state;
250             }
251
252             public String getZipCode() {
253                 return zipCode;
254             }
255
256             public String getBusinessCountryCode() {
257                 return businessCountryCode;
258             }
259
260             public String getCommandChain() {
261                 return commandChain;
262             }
263
264             public String getCompany() {
265                 return company;
266             }
267
268             public String getCompanyCode() {
269                 return companyCode;
270             }
271
272             public String getDepartment() {
273                 return department;
274             }
275
276             public String getJobTitle() {
277                 return jobTitle;
278             }
279
280             public String getLocationClli() {
281                 return locationClli;
282             }
283
284             public String getOrgManagerUserId() {
285                 return orgManagerUserId;
286             }
287
288             public String getZipCodeSuffix() {
289                 return zipCodeSuffix;
290             }
291
292             public String getBusinessCountryName() {
293                 return businessCountryName;
294             }
295
296             public Long getSelectedProfileId() {
297                 return selectedProfileId;
298             }
299
300             public void setAddressId(Long addressId) {
301                 this.addressId = addressId;
302             }
303
304             public void setAlertMethodCd(String alertMethodCd) {
305                 this.alertMethodCd = alertMethodCd;
306             }
307
308             public void setCellular(String cellular) {
309                 this.cellular = cellular;
310             }
311
312             public void setEmail(String email) {
313                 this.email = email;
314             }
315
316             public void setFax(String fax) {
317                 this.fax = fax;
318             }
319
320             public void setFirstName(String firstName) {
321                 this.firstName = firstName;
322             }
323
324             public void setHrid(String hrid) {
325                 this.hrid = hrid;
326             }
327
328             public void setLastLoginDate(Date lastLoginDate) {
329                 this.lastLoginDate = lastLoginDate;
330             }
331
332             public void setLastName(String lastName) {
333                 this.lastName = lastName;
334             }
335
336             public void setLoginId(String loginId) {
337                 this.loginId = loginId;
338             }
339
340             public void setLoginPwd(String loginPwd) {
341                 this.loginPwd = loginPwd;
342             }
343
344             public void setManagerId(Long managerId) {
345                 this.managerId = managerId;
346             }
347
348             public void setMiddleInitial(String middleInitial) {
349                 this.middleInitial = middleInitial;
350             }
351
352             public void setOrgCode(String orgCode) {
353                 this.orgCode = orgCode;
354             }
355
356             public void setOrgId(Long orgId) {
357                 this.orgId = orgId;
358             }
359
360             public void setPhone(String phone) {
361                 this.phone = phone;
362             }
363
364             public void setOrgUserId(String orgUserId) {
365                 this.orgUserId = orgUserId;
366             }
367
368             public void setActive(boolean active) {
369                 this.active = active;
370             }
371
372             public void setInternal(boolean internal) {
373                 this.internal = internal;
374             }
375
376             public void setAddress1(String address1) {
377                 this.address1 = address1;
378             }
379
380             public void setAddress2(String address2) {
381                 this.address2 = address2;
382             }
383
384             public void setCity(String city) {
385                 this.city = city;
386             }
387
388             public void setCountry(String country) {
389                 this.country = country;
390             }
391
392             public void setState(String state) {
393                 this.state = state;
394             }
395
396             public void setZipCode(String zipCode) {
397                 this.zipCode = zipCode;
398             }
399
400             public void setBusinessCountryCode(String businessCountryCode) {
401                 this.businessCountryCode = businessCountryCode;
402             }
403
404             public void setCommandChain(String commandChain) {
405                 this.commandChain = commandChain;
406             }
407
408             public void setCompany(String company) {
409                 this.company = company;
410             }
411
412             public void setCompanyCode(String companyCode) {
413                 this.companyCode = companyCode;
414             }
415
416             public void setDepartment(String department) {
417                 this.department = department;
418             }
419
420             public void setJobTitle(String jobTitle) {
421                 this.jobTitle = jobTitle;
422             }
423
424             public void setLocationClli(String locationClli) {
425                 this.locationClli = locationClli;
426             }
427
428             public void setOrgManagerUserId(String orgManagerUserId) {
429                 this.orgManagerUserId = orgManagerUserId;
430             }
431
432             public void setZipCodeSuffix(String zipCodeSuffix) {
433                 this.zipCodeSuffix = zipCodeSuffix;
434             }
435
436             public void setBusinessCountryName(String businessCountryName) {
437                 this.businessCountryName = businessCountryName;
438             }
439
440             public SortedSet<EPRole> getPseudoRoles() {
441                         return pseudoRoles;
442                 }
443             
444             public void setPseudoRoles(SortedSet<EPRole> pseudoRoles) {
445                 this.pseudoRoles = pseudoRoles;
446             }
447
448             public void setSelectedProfileId(Long selectedProfileId) {
449                 this.selectedProfileId = selectedProfileId;
450             }
451             
452                 public Long getTimeZoneId() {
453                         return timeZoneId;
454                 }
455
456                 public void setTimeZoneId(Long timeZoneId) {
457                         this.timeZoneId = timeZoneId;
458                 }
459
460                 public String getBusinessUnit() {
461                         return businessUnit;
462                 }
463
464                 public void setBusinessUnit(String businessUnit) {
465                         this.businessUnit = businessUnit;
466                 }
467
468                 public String getSiloStatus() {
469                         return siloStatus;
470                 }
471
472                 public void setSiloStatus(String siloStatus) {
473                         this.siloStatus = siloStatus;
474                 }
475
476                 public String getCostCenter() {
477                         return costCenter;
478                 }
479
480                 public void setCostCenter(String costCenter) {
481                         this.costCenter = costCenter;
482                 }
483
484                 public String getFinancialLocCode() {
485                         return financialLocCode;
486                 }
487
488                 public void setFinancialLocCode(String financialLocCode) {
489                         this.financialLocCode = financialLocCode;
490                 }
491                 
492                 public String getBusinessUnitName() {
493                         return businessUnitName;
494                 }
495
496                 public void setBusinessUnitName(String businessUnitName) {
497                         this.businessUnitName = businessUnitName;
498                 }
499
500                 public String getDepartmentName() {
501                         return departmentName;
502                 }
503
504                 public void setDepartmentName(String departmentName) {
505                         this.departmentName = departmentName;
506                 }
507
508                 public int compareTo(Object obj){
509               EPUser user = (EPUser)obj;
510
511               String c1 = getLastName() + getFirstName() + getMiddleInitial();
512               String c2 = user.getLastName() + user.getFirstName() + user.getMiddleInitial();
513
514               return c1.compareTo(c2);
515             }
516
517                 public boolean isOnline() {
518                         return online;
519                 }
520
521                 public void setOnline(boolean online) {
522                         this.online = online;
523                 }
524
525                 public String getChatId() {
526                         return chatId;
527                 }
528
529                 public void setChatId(String chatId) {
530                         this.chatId = chatId;
531                 }
532                 
533                 
534                 public Integer getLanguageId() {
535                         return languageId;
536                 }
537
538                 public void setLanguageId(Integer languageId) {
539                         this.languageId = languageId;
540                 }
541
542         public void setPseudoEPRoles(SortedSet<EPRole> pseudoRoles) {
543                 this.pseudoRoles = pseudoRoles;
544         }
545         
546         public SortedSet<EPUserApp> getEPUserApps() {
547                 return userApps;
548         }
549
550         public void setEPUserApps(SortedSet<EPUserApp> userApps) {
551                 this.userApps = userApps;
552         }
553
554         public void addUserApp(EPUserApp userApp) {
555                 userApps.add(userApp);
556         }
557         
558         public void addAppRoles(EPApp app, SortedSet<EPRole> roles) {
559                 if (roles != null) {
560                         // add all
561                         SortedSet<EPUserApp> userApps = new TreeSet<EPUserApp>();
562                         // this.userApps.removeAll(this.userApps);
563                         Iterator<EPRole> itr = roles.iterator();
564                         while (itr.hasNext()) {
565                                 EPRole role = (EPRole) itr.next();
566                                 EPUserApp userApp = new EPUserApp();
567                                 userApp.setUserId(this.id);
568                                 userApp.setApp(app);
569                                 userApp.setRole(role);
570                                 userApps.add(userApp);
571                         }
572                         setEPUserApps(userApps);
573                 } else {
574                         // remove all
575                         setEPUserApps(null);
576                 }
577
578         }
579
580         public SortedSet<EPRole> getAppEPRoles(EPApp app) {
581                 
582                 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - app = {}", app.getName());
583                 
584                 SortedSet<EPRole> roles = new TreeSet<EPRole>();
585                 SortedSet<EPUserApp> userAppRoles = getEPUserApps();
586                 
587                 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - userApps = {} ", userAppRoles.size());
588
589                 Iterator<EPUserApp> userAppRolesIterator = userAppRoles.iterator();
590
591                 EPUserApp userAppRole = null;
592                 // getting default app
593                 while (userAppRolesIterator.hasNext()) {
594                         EPUserApp tempUserApp = (EPUserApp) userAppRolesIterator.next();
595                         if (tempUserApp.getApp().getId().equals(app.getId())) {
596
597                                 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - for user {}, found application {}", this.getFullName(), app.getName());
598                                 
599                                 userAppRole = tempUserApp;
600                                 
601                                 EPRole role = userAppRole.getRole();
602                                 if(role.getActive()){
603                                         logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - Role {} is active - adding for user {} and app {}", role.getName(), this.getFullName(), app.getName());
604                                         roles.add((EPRole) role);
605                                 }
606                                 else{
607                                         logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - Role {} is NOT active - NOT adding for user {} and app {}", role.getName(), this.getFullName(), app.getName());
608                                 }                               
609                         }
610                 }
611                 logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - roles = {}" , roles.size());
612
613                 return roles;
614         }
615
616         
617         /**
618          * Attention! Not for use in ONAP
619          */
620         public SortedSet<EPRole> getAppRoles(EPApp app) {
621                 SortedSet<EPRole> roles = new TreeSet<EPRole>();
622                 SortedSet<EPUserApp> apps = getEPUserApps();
623                 Iterator<EPUserApp> appsItr = apps.iterator();
624                 EPUserApp userApp = null;
625                 // getting default app
626                 while (appsItr.hasNext()) {
627                         EPUserApp tempUserApp = (EPUserApp) appsItr.next();
628                         if (tempUserApp.getApp().getId().equals(app.getId())) {
629                                 userApp = tempUserApp;
630                                 roles.add((EPRole) userApp.getRole());
631                         }
632                 }
633                 return roles;
634         }
635
636         
637
638         /**
639          * Attention! Not for use in ONAP
640          */
641         public SortedSet<EPRole> getEPRoles() {
642                 EPApp app = new EPApp();
643                 app.setId(new Long(PortalConstants.PORTAL_APP_ID));
644                 app.setName(ECOMP_PORTAL_NAME);
645                 return getAppEPRoles(app);
646         }
647
648         /**
649          * Attention! Not for use in ONAP
650          */
651         public void setEPRoles(SortedSet<EPRole> roles) {
652                 EPApp app = new EPApp();
653                 app.setId(new Long(PortalConstants.PORTAL_APP_ID));
654                 app.setName(ECOMP_PORTAL_NAME);
655                 addAppRoles(app, roles);
656         }
657
658         /**
659          * Attention! Not for use in ONAP
660          */
661         public void removeEPRole(Long roleId) {
662                 SortedSet<EPUserApp> apps = getEPUserApps();
663                 Iterator<EPUserApp> appsItr = apps.iterator();
664                 // getting default app
665                 while (appsItr.hasNext()) {
666                         EPUserApp tempUserApp = (EPUserApp) appsItr.next();
667                         if (tempUserApp.equals(new Long(PortalConstants.PORTAL_APP_ID)) && tempUserApp.getRole().getId().equals(roleId)) {
668                                 appsItr.remove();
669                         }
670                 }
671         }
672
673         /**
674          * Attention! Not for use in ONAP
675          */
676         public void addEPRole(EPRole role) {
677                 if (role != null) {
678                         SortedSet<EPRole> roles = getEPRoles();
679                         if (roles == null) {
680                                 roles = new TreeSet<EPRole>();
681                         }
682                         roles.add(role);
683                         setEPRoles(roles);
684                 }
685         }
686         
687         public boolean isGuest() {
688                 return isGuest;
689         }
690
691         public void setGuest(boolean isGuest) {
692                 this.isGuest = isGuest;
693         }
694
695         @Override
696         public String toString() {
697                 return "EPUser [orgId=" + orgId + ", managerId=" + managerId + ", firstName=" + firstName + ", middleInitial="
698                                 + middleInitial + ", lastName=" + lastName + ", phone=" + phone + ", fax=" + fax + ", cellular="
699                                 + cellular + ", email=" + email + ", addressId=" + addressId + ", alertMethodCd=" + alertMethodCd
700                                 + ", hrid=" + hrid + ", orgUserId=" + orgUserId + ", orgCode=" + orgCode + ", address1=" + address1
701                                 + ", address2=" + address2 + ", city=" + city + ", state=" + state + ", zipCode=" + zipCode
702                                 + ", country=" + country + ", orgManagerUserId=" + orgManagerUserId + ", locationClli=" + locationClli
703                                 + ", businessCountryCode=" + businessCountryCode + ", businessCountryName=" + businessCountryName
704                                 + ", businessUnit=" + businessUnit + ", businessUnitName=" + businessUnitName + ", department="
705                                 + department + ", departmentName=" + departmentName + ", companyCode=" + companyCode + ", company="
706                                 + company + ", zipCodeSuffix=" + zipCodeSuffix + ", jobTitle=" + jobTitle + ", commandChain="
707                                 + commandChain + ", siloStatus=" + siloStatus + ", costCenter=" + costCenter + ", financialLocCode="
708                                 + financialLocCode + ", loginId=" + loginId + ", loginPwd=" + loginPwd + ", lastLoginDate="
709                                 + lastLoginDate + ", active=" + active + ", internal=" + internal + ", selectedProfileId="
710                                 + selectedProfileId + ", timeZoneId=" + timeZoneId + ", online=" + online + ", chatId=" + chatId
711                                 + ", isGuest=" + isGuest + ", userApps=" + userApps + ", pseudoRoles=" + pseudoRoles + "]";
712         }
713         
714         
715 }