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