-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUser.java
More file actions
318 lines (248 loc) · 7.7 KB
/
User.java
File metadata and controls
318 lines (248 loc) · 7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package es.tid.wallet.model.users;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import es.tid.wallet.model.cards.Card;
import es.tid.wallet.model.coupons.Coupon;
import es.tid.wallet.model.payments.PaymentMethod;
import es.tid.wallet.model.payments.PaymentMethod.PaymentMethodType;
/**
* User Entity.
* Modified again.
* Line to keep.
*/
@Entity
@Table(name = "users")
public class User implements Serializable {
/**
* User Status.
*/
public static enum UserStatus {
UNREGISTERED, REGISTERED, VALIDATE_PENDING, BLOCKED, LOGIN, PIN_BLOCKED
};
/**
* Pin Status.
*/
public enum PinStatus {
OFF, ACTIVATED, DEACTIVATED
};
private static final long serialVersionUID = 2548439201124643740L;
public static final int MAX_ATTEMPTS = 3;
@Id
@Column(name = "msisdn", nullable = false)
private String msisdn;
@Enumerated(EnumType.STRING)
@Column(name = "status", nullable = false)
private UserStatus status;
@Column(name = "pin", nullable = true)
private String pin;
@Enumerated(EnumType.STRING)
@Column(name = "pinStatus", nullable = true)
private PinStatus pinStatus = PinStatus.OFF;
@Column(name = "userId", nullable = true)
private String userId;
@Column(name = "pinAttempts", nullable = false)
private int pinAttempts = 0;
@Column(name = "country", nullable = true)
private String country;
@Column(name = "authToken", nullable = true)
private String authToken;
@Column(name = "authPass", nullable = true)
private String authPass;
@Column(name = "creation_date", nullable = false)
private Date creationDate;
@Column(name = "last_access_date", nullable = false)
private Date lastAccessDate;
@OneToMany(targetEntity = Card.class, cascade = CascadeType.ALL, mappedBy = "user", fetch = FetchType.EAGER)
private List<Card> cards;
@Transient
private List<PaymentMethod> paymentMethods;
@Transient
private List<Coupon> coupons;
@Transient
private int availableCouponResults;
@Transient
private List<Message> messages;
@Transient
private boolean hasAccount;
@Transient
private boolean hasPayments;
@Transient
private boolean hasWallet;
@Transient
private boolean peopleIsAttending;
/**
* Constructor.
*/
public User() {
cards = new ArrayList<Card>();
messages = new ArrayList<Message>();
creationDate = new Date();
lastAccessDate = new Date();
}
public User(String msisdn, String userId, UserStatus status) {
this();
this.msisdn = msisdn;
this.userId = userId;
this.status = status;
}
public String getMsisdn() {
return msisdn;
}
public void setMsisdn(String msisdn) {
this.msisdn = msisdn;
}
public String getPin() {
return pin;
}
public void setPin(String pin) {
this.pin = pin;
}
public PinStatus getPinStatus() {
if (pinStatus == null) {
pinStatus = PinStatus.OFF;
}
return pinStatus;
}
public void setPinStatus(PinStatus pinStatus) {
this.pinStatus = pinStatus;
}
public List<Card> getCards() {
return cards;
}
public void setCards(List<Card> cards) {
this.cards = cards;
}
public UserStatus getStatus() {
return status;
}
public void setStatus(UserStatus status) {
this.status = status;
}
public int getPinAttempts() {
return pinAttempts;
}
public void setPinAttempts(int pinAttempts) {
this.pinAttempts = pinAttempts;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public List<PaymentMethod> getPaymentMethods() {
return paymentMethods;
}
public void setPaymentMethods(List<PaymentMethod> paymentMethods) {
this.paymentMethods = paymentMethods;
}
public List<Coupon> getCoupons() {
return coupons;
}
public void setCoupons(List<Coupon> coupons) {
this.coupons = coupons;
}
public int getAvailableCouponResults() {
return availableCouponResults;
}
public void setAvailableCouponResults(int availableCouponResults) {
this.availableCouponResults = availableCouponResults;
}
public List<Message> getMessages() {
return messages;
}
public void setMessages(List<Message> messages) {
this.messages = messages;
}
public String getAuthToken() {
return authToken;
}
public void setAuthToken(String authToken) {
this.authToken = authToken;
}
public String getAuthPass() {
return authPass;
}
public void setAuthPass(String authPass) {
this.authPass = authPass;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getLastAccessDate() {
return lastAccessDate;
}
public void setLastAccessDate(Date lastAccessDate) {
this.lastAccessDate = lastAccessDate;
}
public boolean isHasAccount() {
return hasAccount;
}
public void setHasAccount(boolean hasAccount) {
this.hasAccount = hasAccount;
}
public boolean isHasPayments() {
return hasPayments;
}
public void setHasPayments(boolean hasPayments) {
this.hasPayments = hasPayments;
}
/**
* Checks if user has SVA.
*
* @return
*/
public boolean hasSVA() {
boolean hasSVA = false;
if (paymentMethods != null) {
for (PaymentMethod paymentMethod : paymentMethods) {
if (paymentMethod.getType() == PaymentMethod.PaymentMethodType.EMONEY) {
// Let's write a useless comment
hasSVA = true;
break;
}
}
}
return hasSVA;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("User [msisdn=").append(msisdn).append(", status=").append(status).append(", pin=").append(pin)
.append(", pinStatus=").append(pinStatus).append(", userId=").append(userId).append(", pinAttempts=")
.append(pinAttempts).append(", country=").append(country).append(", authToken=").append(authToken)
.append(", authPass=").append(authPass).append(", creationDate=").append(creationDate)
.append(", lastAccessDate=").append(lastAccessDate).append(", cards=").append(cards)
.append(", paymentMethods=").append(paymentMethods).append(", couponInstanceNews=").append(coupons)
.append(", availableCouponResults=").append(availableCouponResults).append(", hasAccount=")
.append(hasAccount).append(", hasPayments=").append(hasPayments).append("]");
return builder.toString();
}
public boolean isHasWallet() {
return hasWallet;
}
public void setHasWallet(boolean hasWallet) {
this.hasWallet = hasWallet;
}
}