Merge "Portal El-Alto Release Note"
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / dto / ecomp / EPUser.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ===================================================================
9  *
10  * Unless otherwise specified, all software contained herein is licensed
11  * under the Apache License, Version 2.0 (the "License");
12  * you may not use this software except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *             http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  * Unless otherwise specified, all documentation contained herein is licensed
24  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25  * you may not use this documentation except in compliance with the License.
26  * You may obtain a copy of the License at
27  *
28  *             https://creativecommons.org/licenses/by/4.0/
29  *
30  * Unless required by applicable law or agreed to in writing, documentation
31  * distributed under the License is distributed on an "AS IS" BASIS,
32  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33  * See the License for the specific language governing permissions and
34  * limitations under the License.
35  *
36  * ============LICENSE_END============================================
37  *
38  *
39  */
40
41 package org.onap.portal.domain.dto.ecomp;
42
43 import com.fasterxml.jackson.annotation.JsonIgnore;
44 import java.util.Date;
45 import java.util.Iterator;
46 import java.util.SortedSet;
47 import java.util.TreeSet;
48 import javax.validation.Valid;
49 import lombok.AllArgsConstructor;
50 import lombok.Builder;
51 import lombok.Getter;
52 import lombok.NoArgsConstructor;
53 import lombok.Setter;
54 import lombok.ToString;
55 import org.hibernate.validator.constraints.SafeHtml;
56 import org.onap.portalsdk.core.domain.User;
57 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
58
59 @Getter
60 @Setter
61 @Builder
62 @ToString
63 @NoArgsConstructor
64 @AllArgsConstructor
65 public class EPUser extends User {
66
67        private Long orgId;
68        private Long managerId;
69        @SafeHtml
70        private String firstName;
71        @SafeHtml
72        private String middleInitial;
73        @SafeHtml
74        private String lastName;
75        @SafeHtml
76        private String phone;
77        @SafeHtml
78        private String fax;
79        @SafeHtml
80        private String cellular;
81        @SafeHtml
82        private String email;
83        private Long addressId;
84        @SafeHtml
85        private String alertMethodCd;
86        @SafeHtml
87        private String hrid;
88        @SafeHtml
89        private String orgUserId;
90        @SafeHtml
91        private String orgCode;
92        @SafeHtml
93        private String address1;
94        @SafeHtml
95        private String address2;
96        @SafeHtml
97        private String city;
98        @SafeHtml
99        private String state;
100        @SafeHtml
101        private String zipCode;
102        @SafeHtml
103        private String country;
104        @SafeHtml
105        private String orgManagerUserId;
106        @SafeHtml
107        private String locationClli;
108        @SafeHtml
109        private String businessCountryCode;
110        @SafeHtml
111        private String businessCountryName;
112        @SafeHtml
113        private String businessUnit;
114        @SafeHtml
115        private String businessUnitName;
116        @SafeHtml
117        private String department;
118        @SafeHtml
119        private String departmentName;
120        @SafeHtml
121        private String companyCode;
122        @SafeHtml
123        private String company;
124        @SafeHtml
125        private String zipCodeSuffix;
126        @SafeHtml
127        private String jobTitle;
128        @SafeHtml
129        private String commandChain;
130        @SafeHtml
131        private String siloStatus;
132        @SafeHtml
133        private String costCenter;
134        @SafeHtml
135        private String financialLocCode;
136        @SafeHtml
137        private String loginId;
138        @SafeHtml
139        private String loginPwd;
140        private Date lastLoginDate;
141        private boolean active;
142        private boolean internal;
143        private Long selectedProfileId;
144        private Long timeZoneId;
145        private boolean online;
146        @SafeHtml
147        private String chatId;
148        private boolean systemUser;
149        private Integer languageId;
150        private static final long serialVersionUID = 1L;
151        private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPUser.class);
152        private static final String ECOMP_PORTAL_NAME = "ECOMP";
153        private boolean isGuest = false;
154        @Valid
155        private SortedSet<EPUserApp> userApps = new TreeSet<>();
156        @Valid
157        private SortedSet<EPRole> pseudoRoles = new TreeSet<>();
158
159        @JsonIgnore
160        public String getFullName() {
161               return getFirstName() + " " + getLastName();
162        }
163
164        public int compareTo(Object obj) {
165               EPUser user = (EPUser) obj;
166
167               String c1 = getLastName() + getFirstName() + getMiddleInitial();
168               String c2 = user.getLastName() + user.getFirstName() + user.getMiddleInitial();
169
170               return c1.compareTo(c2);
171        }
172
173
174        public void addAppRoles(EPApp app, SortedSet<EPRole> roles) {
175               if (roles != null) {
176                      // add all
177                      SortedSet<EPUserApp> userApps = new TreeSet<>();
178                      // this.userApps.removeAll(this.userApps);
179                      for (EPRole role : roles) {
180                             EPUserApp userApp = new EPUserApp();
181                             userApp.setUserId(this.id);
182                             userApp.setApp(app);
183                             userApp.setRole(role);
184                             userApps.add(userApp);
185                      }
186                      setUserApps(userApps);
187               } else {
188                      setUserApps(null);
189               }
190
191        }
192
193        public SortedSet<EPRole> getAppEPRoles(EPApp app) {
194
195               logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - app = {}", app.getName());
196
197               SortedSet<EPRole> roles = new TreeSet<>();
198               SortedSet<EPUserApp> userAppRoles = getUserApps();
199
200               logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - userApps = {} ",
201                       userAppRoles.size());
202
203               Iterator<EPUserApp> userAppRolesIterator = userAppRoles.iterator();
204
205               EPUserApp userAppRole;
206               // getting default app
207               while (userAppRolesIterator.hasNext()) {
208                      EPUserApp tempUserApp = userAppRolesIterator.next();
209                      if (tempUserApp.getApp().getId().equals(app.getId())) {
210
211                             logger.debug(EELFLoggerDelegate.debugLogger,
212                                     "In EPUser.getAppEPRoles() - for user {}, found application {}", this.getFullName(),
213                                     app.getName());
214
215                             userAppRole = tempUserApp;
216
217                             EPRole role = userAppRole.getRole();
218                             if (role.isActive()) {
219                                    logger.debug(EELFLoggerDelegate.debugLogger,
220                                            "In EPUser.getAppEPRoles() - Role {} is active - adding for user {} and app {}",
221                                            role.getName(), this.getFullName(), app.getName());
222                                    roles.add(role);
223                             } else {
224                                    logger.debug(EELFLoggerDelegate.debugLogger,
225                                            "In EPUser.getAppEPRoles() - Role {} is NOT active - NOT adding for user {} and app {}",
226                                            role.getName(), this.getFullName(), app.getName());
227                             }
228                      }
229               }
230               logger.debug(EELFLoggerDelegate.debugLogger, "In EPUser.getAppEPRoles() - roles = {}", roles.size());
231
232               return roles;
233        }
234
235 }