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