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