re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / UserData.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.resources.data;
22
23 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
24 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
25 import org.openecomp.sdc.be.dao.utils.DaoUtils;
26 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
27
28 import java.util.Date;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 public class UserData extends GraphNode {
33
34         private String firstName;
35
36         private String lastName;
37
38         private String userId;
39
40         private String email;
41
42         private String role;
43
44         private String status;
45
46         private Long lastLoginTime;
47
48         public UserData(String firstName, String lastName, String userId, String email, String role, String status,
49                         Long lastLoginTime) {
50                 super(NodeTypeEnum.User);
51                 this.firstName = firstName;
52                 this.lastName = lastName;
53                 this.userId = userId;
54                 this.email = email;
55                 this.role = role;
56                 this.status = status;
57                 this.lastLoginTime = lastLoginTime;
58         }
59
60         public UserData() {
61                 super(NodeTypeEnum.User);
62         }
63
64         public UserData(Map<String, Object> properties) {
65                 super(NodeTypeEnum.User);
66
67                 setFirstName((String) properties.get("firstName"));
68                 setLastName((String) properties.get("lastName"));
69                 setUserId((String) properties.get("userId"));
70                 setEmail((String) properties.get("email"));
71                 setRole((String) properties.get("role"));
72                 setStatus((String) properties.get("status"));
73                 setLastLoginTime((Long) properties.get("lastLoginTime"));
74         }
75
76         public String getFirstName() {
77                 return firstName;
78         }
79
80         public void setFirstName(String firstName) {
81                 this.firstName = firstName;
82         }
83
84         public String getLastName() {
85                 return lastName;
86         }
87
88         public void setLastName(String lastName) {
89                 this.lastName = lastName;
90         }
91
92         public String getUserId() {
93                 return userId;
94         }
95
96         public void setUserId(String userId) {
97                 this.userId = userId;
98         }
99
100         public String getEmail() {
101                 return email;
102         }
103
104         public void setEmail(String email) {
105                 this.email = email;
106         }
107
108         public String getRole() {
109                 return role;
110         }
111
112         public void setRole(String role) {
113                 this.role = role;
114         }
115
116         // right name?
117         public void setLastLoginTime() {
118                 Date d = new Date();
119                 this.lastLoginTime = new Long(d.getTime()); // this is in milli-seconds
120                                                                                                         // divide by 1000 to get
121                                                                                                         // secs?
122         }
123
124         public void setLastLoginTime(Long time) {
125                 this.lastLoginTime = time;
126         }
127
128         public Long getLastLoginTime() {
129                 return this.lastLoginTime;
130         }
131
132         @Override
133         public String toString() {
134                 return "UserData [firstName=" + firstName + ", lastName=" + lastName + ", userId=" + userId + ", email=" + email
135                                 + ", role=" + role + ", last Login time=" + lastLoginTime + ", parent: " + super.toString() + "]";
136         }
137
138         @Override
139         public int hashCode() {
140                 final int prime = 31;
141                 int result = 1;
142                 result = prime * result + ((userId == null) ? 0 : userId.hashCode());
143                 result = prime * result + ((email == null) ? 0 : email.hashCode());
144                 result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
145                 result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
146                 result = prime * result + ((role == null) ? 0 : role.hashCode());
147                 result = prime * result + ((lastLoginTime == null) ? 0 : lastLoginTime.hashCode());
148                 return result;
149         }
150
151         @Override
152         public boolean equals(Object obj) {
153                 if (this == obj)
154                         return true;
155                 if (obj == null)
156                         return false;
157                 if (getClass() != obj.getClass())
158                         return false;
159                 UserData other = (UserData) obj;
160                 if (userId == null) {
161                         if (other.userId != null)
162                                 return false;
163                 } else if (!userId.equals(other.userId))
164                         return false;
165                 if (email == null) {
166                         if (other.email != null)
167                                 return false;
168                 } else if (!email.equals(other.email))
169                         return false;
170                 if (firstName == null) {
171                         if (other.firstName != null)
172                                 return false;
173                 } else if (!firstName.equals(other.firstName))
174                         return false;
175                 if (lastName == null) {
176                         if (other.lastName != null)
177                                 return false;
178                 } else if (!lastName.equals(other.lastName))
179                         return false;
180                 if (role == null) {
181                         if (other.role != null)
182                                 return false;
183                 } else if (!role.equals(other.role))
184                         return false;
185                 if (lastLoginTime == null) {
186                         if (other.lastLoginTime != null)
187                                 return false;
188                 } else if (!lastLoginTime.equals(other.lastLoginTime))
189                         return false;
190                 return true;
191         }
192
193         public String toJson() {
194                 return DaoUtils.convertToJson(toGraphMap());
195         }
196
197         @Override
198         public Map<String, Object> toGraphMap() {
199                 Map<String, Object> map = new HashMap<>();
200                 addIfExists(map, GraphPropertiesDictionary.USERID, userId);
201                 addIfExists(map, GraphPropertiesDictionary.EMAIL, email);
202                 addIfExists(map, GraphPropertiesDictionary.FIRST_NAME, firstName);
203                 addIfExists(map, GraphPropertiesDictionary.LAST_NAME, lastName);
204                 addIfExists(map, GraphPropertiesDictionary.ROLE, role);
205                 addIfExists(map, GraphPropertiesDictionary.USER_STATUS, status);
206                 addIfExists(map, GraphPropertiesDictionary.LAST_LOGIN_TIME, lastLoginTime);
207                 return map;
208         }
209
210         @Override
211         public String getUniqueIdKey() {
212                 return GraphPropertiesDictionary.USERID.getProperty();
213         }
214
215         @Override
216         public String getUniqueId() {
217                 return userId;
218         }
219
220         public String getStatus() {
221                 return status;
222         }
223
224         public void setStatus(String status) {
225                 this.status = status;
226         }
227
228 }