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