re base code
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / User.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.model;
22
23 import org.joda.time.DateTime;
24 import org.joda.time.DateTimeZone;
25 import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
26 import org.openecomp.sdc.be.resources.data.UserData;
27
28 public class User {
29     public static final String FORCE_DELETE_HEADER_FLAG = "FORCE_DELETE";
30
31     private String firstName;
32
33     private String lastName;
34
35     private String userId;
36
37     private String email;
38
39     private String role;
40
41     private Long lastLoginTime;
42
43     private UserStatusEnum status = UserStatusEnum.ACTIVE;
44
45     public User() {
46     }
47
48     public User(UserData userDate) {
49         this(userDate.getFirstName(), userDate.getLastName(), userDate.getUserId(), userDate.getEmail(),
50                 userDate.getRole(), userDate.getLastLoginTime());
51     }
52
53     public User(String firstName, String lastName, String userId, String emailAddress, String role,
54             Long lastLoginTime) {
55         this.firstName = firstName;
56         this.lastName = lastName;
57         this.userId = userId;
58         this.email = emailAddress;
59         this.role = role;
60         this.lastLoginTime = lastLoginTime;
61
62     }
63
64     public void copyData(User other) {
65                 if(other == null) {
66                         return;
67                 }
68         this.firstName = other.getFirstName();
69         this.lastName = other.getLastName();
70         this.userId = other.getUserId();
71         this.email = other.getEmail();
72         this.role = other.getRole();
73         this.lastLoginTime = other.getLastLoginTime();
74
75     }
76
77     public User(User aUser) {
78         this(aUser.getFirstName(), aUser.getLastName(), aUser.getUserId(), aUser.getEmail(), aUser.getRole(),
79                 aUser.getLastLoginTime());
80     }
81
82     public String getFirstName() {
83         return firstName;
84     }
85
86     public void setFirstName(String firstName) {
87         this.firstName = firstName;
88     }
89
90     public String getLastName() {
91         return lastName;
92     }
93
94     public void setLastName(String lastName) {
95         this.lastName = lastName;
96     }
97
98     public String getUserId() {
99         return userId;
100     }
101
102     public void setUserId(String userId) {
103         this.userId = userId;
104     }
105
106     public String getEmail() {
107         return email;
108     }
109
110     public void setEmail(String email) {
111         this.email = email;
112     }
113
114     public String getRole() {
115         return role;
116     }
117
118     public void setRole(String role) {
119         this.role = role;
120     }
121
122     public String getFullName() {
123         return this.getFirstName() + " " + this.getLastName();
124     }
125
126     public void setLastLoginTime() {
127         DateTime now = new DateTime(DateTimeZone.UTC);
128         this.lastLoginTime = now.getMillis();
129     }
130
131     public void setLastLoginTime(Long time) {
132         this.lastLoginTime = time;
133     }
134
135     public Long getLastLoginTime() {
136         return this.lastLoginTime;
137     }
138
139     @Override
140     public int hashCode() {
141         final int prime = 31;
142         int result = 1;
143         result = prime * result + ((userId == null) ? 0 : userId.hashCode());
144         result = prime * result + ((email == null) ? 0 : email.hashCode());
145         result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
146         result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
147         result = prime * result + ((role == null) ? 0 : role.hashCode());
148         result = prime * result + ((lastLoginTime == null) ? 0 : lastLoginTime.hashCode());
149         return result;
150     }
151
152     @Override
153     public boolean equals(Object obj) {
154         if (this == obj)
155             return true;
156         if (obj == null)
157             return false;
158         if (getClass() != obj.getClass())
159             return false;
160         User other = (User) obj;
161         if (userId == null) {
162             if (other.userId != null)
163                 return false;
164         } else if (!userId.equals(other.userId))
165             return false;
166         if (email == null) {
167             if (other.email != null)
168                 return false;
169         } else if (!email.equals(other.email))
170             return false;
171         if (firstName == null) {
172             if (other.firstName != null)
173                 return false;
174         } else if (!firstName.equals(other.firstName))
175             return false;
176         if (lastName == null) {
177             if (other.lastName != null)
178                 return false;
179         } else if (!lastName.equals(other.lastName))
180             return false;
181         if (role == null) {
182             if (other.role != null)
183                 return false;
184         } else if (!role.equals(other.role))
185             return false;
186         if (lastLoginTime == null) {
187             if (other.lastLoginTime != null)
188                 return false;
189         } else if (!lastLoginTime.equals(other.lastLoginTime))
190             return false;
191         return true;
192     }
193
194     public UserStatusEnum getStatus() {
195         return status;
196     }
197
198     public void setStatus(UserStatusEnum status) {
199         this.status = status;
200     }
201
202     @Override
203     public String toString() {
204         return "User [firstName=" + firstName + ", lastName=" + lastName + ", userId=" + userId + ", email=" + email
205                 + ", role=" + role + ", last login time=" + lastLoginTime + "]";
206     }
207
208 }