Project

General

Profile

1
package eu.dnetlib.domain.functionality;
2

    
3
import java.util.ArrayList;
4
import java.util.Date;
5
import java.util.HashSet;
6
import java.util.List;
7
import java.util.Set;
8

    
9
import eu.dnetlib.domain.SecureDriverResource;
10

    
11
/**
12
 * User's Profile class
13
 * 
14
 * @author <a href="mailto:kiatrop@di.uoa.gr">Katerina Iatropoulou</a>
15
 * 
16
 */
17

    
18
public class UserProfile extends SecureDriverResource{
19
	private static final long serialVersionUID = -1565597762736460041L;
20

    
21
	// general info
22
	private String email = null;
23
	private String username = null;
24
	private String firstname = null;
25
	private String lastname = null;
26

    
27
	private String institution = null;
28

    
29
	private boolean active = false;
30
	private String activationId = null;
31

    
32
	// recommendations
33
	private Set<String> recommendations = new HashSet<String>();
34
	private Boolean recommendationSendEmail = null;
35
	private Integer recommendationPeriod = null;
36
	private Date lastNotificationDate = null;
37

    
38
	// communities
39
	private static Set<CommunityRegistration> communities = new HashSet<CommunityRegistration>();
40

    
41
	// queries
42
	private static List<SavedQuery> savedQueries = new ArrayList<SavedQuery>();
43
	
44
	// filter
45
	private static SavedQuery filter = null;
46
	
47
	// list of documents
48
	private List<String> documentIds = new ArrayList<String>();
49
	
50
	// a place to store images and other user data
51
	private static UserStore store = null;
52
	
53
	private String userPhotoID = null;
54
	
55

    
56
	/**
57
	 * The default constructor sets the resourceKind to
58
	 * <b>UserDSResourceType</b>, resourceType to <b>UserDSResources</b> and
59
	 * dateOfCreation to the current system date.
60
	 */
61
	public UserProfile() {
62
		this.setResourceKind("UserDSResources");
63
		this.setResourceType("UserDSResourceType");
64
		recommendationSendEmail = Boolean.valueOf(false);
65
	}
66

    
67
	@Deprecated
68
	public String getUserId() {
69
		return this.getResourceId();
70
	}
71

    
72
	@Deprecated
73
	public void setUserId(String userId) {
74
		this.setResourceId(userId);
75
	}
76

    
77
	public String getActivationId() {
78
		return activationId;
79
	}
80

    
81
	public void setActivationId(String activationId) {
82
		this.activationId = activationId;
83
	}
84

    
85
	public String getEmail() {
86
		return email;
87
	}
88

    
89
	public void setEmail(String email) {
90
		this.email = email;
91
	}
92

    
93
	public String getUsername() {
94
		return username;
95
	}
96

    
97
	public void setUsername(String username) {
98
		this.username = username;
99
	}
100

    
101
	public String getPassword() {
102
		return this.getSecurityProfile().getPassword();
103
	}
104

    
105
	public void setPassword(String password) {
106
		this.getSecurityProfile().setPassword(password);
107
	}
108

    
109
	public String getFirstname() {
110
		return firstname;
111
	}
112

    
113
	public void setFirstname(String firstname) {
114
		this.firstname = firstname;
115
	}
116

    
117
	public String getLastname() {
118
		return lastname;
119
	}
120

    
121
	public void setLastname(String lastname) {
122
		this.lastname = lastname;
123
	}
124

    
125
	public String getInstitution() {
126
		return institution;
127
	}
128

    
129
	public void setInstitution(String institution) {
130
		this.institution = institution;
131
	}
132

    
133
	public Set<String> getRecommendations() {
134
		return recommendations;
135
	}
136

    
137
	public void setRecommendations(Set<String> recommendations) {
138
		this.recommendations = recommendations;
139
	}
140

    
141
	public Date getLastNotificationDate() {
142
		return this.lastNotificationDate;
143
	}
144

    
145
	public void setLastNotificationDate(Date lastNotificationDate) {
146
		this.lastNotificationDate = lastNotificationDate;
147
	}
148

    
149
	public Set<CommunityRegistration> getCommunities() {
150
		return communities;
151
	}
152

    
153
	public void setCommunities(Set<CommunityRegistration> communities) {
154
		this.communities = communities;
155
	}
156

    
157
	public Date getRegistrationDate() {
158
		return this.getDateOfCreation();
159
	}
160

    
161
	public void setRegistrationDate(Date registrationDate) {
162
		this.setDateOfCreation(registrationDate);
163
	}
164

    
165
	public Integer getRecommendationPeriod() {
166
		return recommendationPeriod;
167
	}
168

    
169
	public List<String> getRoles() {
170
		return this.getSecurityProfile().getIdentities();
171
	}
172

    
173
	public void setRoles(List<String> roles) {
174
		this.getSecurityProfile().setIdentities(new ArrayList<String>());
175

    
176
		for (String role : roles) {
177
			if (!this.getSecurityProfile().getIdentities().contains(role))
178
				this.getSecurityProfile().getIdentities().add(role);
179
		}
180
	}
181

    
182
	public List<SavedQuery> getSavedQueries() {
183
		return savedQueries;
184
	}
185

    
186
	public void setSavedQueries(List<SavedQuery> savedQueries) {
187
		this.savedQueries = savedQueries;
188
	}
189

    
190
	public boolean getActive() {
191
		return active;
192
	}
193

    
194
	public void setActive(boolean active) {
195
		this.active = active;
196
	}
197

    
198
	public Boolean getRecommendationSendEmail() {
199
		if (recommendationSendEmail == null) {
200
			recommendationSendEmail = Boolean.valueOf(true);
201
		}
202
		return recommendationSendEmail;
203
	}
204

    
205
	public void setRecommendationSendEmail(Boolean recommendationSendEmail) {
206
		this.recommendationSendEmail = recommendationSendEmail;
207
	}
208

    
209
	public void setRecommendationPeriod(Integer recommendationPeriod) {
210
		this.recommendationPeriod = recommendationPeriod;
211
	}
212

    
213
	public boolean hasSecurityProfile() {
214
		return true;
215
	}
216

    
217
	public String toString() {
218
		return this.getEmail();
219
	}
220

    
221
	public boolean getIsCollectionManager() {
222
		return (this.getRoles().contains("collectionManager") || this
223
				.getIsSuperUser());
224
	}
225

    
226
	public void setIsCollectionManager(boolean tonPoulo) {
227
		// nothing
228
	}
229

    
230
	public boolean getIsCommunityManager() {
231
		return (this.getRoles().contains("communityManager") || this
232
				.getIsSuperUser());
233
	}
234

    
235
	public void setIsCommunityManager(boolean tonPoulo) {
236
		// nothing
237
	}
238

    
239
	public boolean getIsUserManager() {
240
		return (this.getRoles().contains("userManager") || this
241
				.getIsSuperUser());
242
	}
243

    
244
	public void setIsUserManager(boolean value) {
245
		// nothing
246
	}
247

    
248
	public boolean getIsSuperUser() {
249
		return this.getRoles().contains("superUser");
250
	}
251

    
252
	public void setIsSuperUser(boolean tonPoulo) {
253
		// nothing
254
	}
255

    
256
	public SavedQuery getFilter() {
257
		return filter;
258
	}
259

    
260
	public void setFilter(SavedQuery filter) {
261
		this.filter = filter;
262
	}
263

    
264
	public List<String> getDocumentIds() {
265
		return documentIds;
266
	}
267

    
268
	public void setDocumentIds(List<String> documentIds) {
269
		this.documentIds = documentIds;
270
	}
271

    
272
	public UserStore getStore() {
273
		return store;
274
	}
275

    
276
	public void setStore(UserStore store) {
277
		this.store = store;
278
	}
279

    
280
	public String getUserPhotoID() {
281
		return userPhotoID;
282
	}
283

    
284
	public void setUserPhotoID(String userPhotoID) {
285
		this.userPhotoID = userPhotoID;
286
	}
287

    
288
	@Override
289
	public int hashCode() {
290
		final int prime = 31;
291
		int result = 1;
292
		result = prime * result
293
				+ ((activationId == null) ? 0 : activationId.hashCode());
294
		result = prime * result + (active ? 1231 : 1237);
295
		result = prime * result
296
				+ ((communities == null) ? 0 : communities.hashCode());
297
		result = prime * result
298
				+ ((documentIds == null) ? 0 : documentIds.hashCode());
299
		result = prime * result + ((email == null) ? 0 : email.hashCode());
300
		result = prime * result + ((filter == null) ? 0 : filter.hashCode());
301
		result = prime * result
302
				+ ((firstname == null) ? 0 : firstname.hashCode());
303
		result = prime * result
304
				+ ((institution == null) ? 0 : institution.hashCode());
305
		result = prime
306
				* result
307
				+ ((lastNotificationDate == null) ? 0 : lastNotificationDate
308
						.hashCode());
309
		result = prime * result
310
				+ ((lastname == null) ? 0 : lastname.hashCode());
311
		result = prime
312
				* result
313
				+ ((recommendationPeriod == null) ? 0 : recommendationPeriod
314
						.hashCode());
315
		result = prime
316
				* result
317
				+ ((recommendationSendEmail == null) ? 0
318
						: recommendationSendEmail.hashCode());
319
		result = prime * result
320
				+ ((recommendations == null) ? 0 : recommendations.hashCode());
321
		result = prime * result
322
				+ ((savedQueries == null) ? 0 : savedQueries.hashCode());
323
		result = prime * result + ((store == null) ? 0 : store.hashCode());
324
		result = prime * result
325
				+ ((userPhotoID == null) ? 0 : userPhotoID.hashCode());
326
		return result;
327
	}
328

    
329
	@Override
330
	public boolean equals(Object obj) {
331
		if (this == obj)
332
			return true;
333
		if (obj == null)
334
			return false;
335
		if (getClass() != obj.getClass())
336
			return false;
337
		UserProfile other = (UserProfile) obj;
338
		if (activationId == null) {
339
			if (other.activationId != null)
340
				return false;
341
		} else if (!activationId.equals(other.activationId))
342
			return false;
343
		if (active != other.active)
344
			return false;
345
		if (communities == null) {
346
			if (other.communities != null)
347
				return false;
348
		} else if (!communities.equals(other.communities))
349
			return false;
350
		if (documentIds == null) {
351
			if (other.documentIds != null)
352
				return false;
353
		} else if (!documentIds.equals(other.documentIds))
354
			return false;
355
		if (email == null) {
356
			if (other.email != null)
357
				return false;
358
		} else if (!email.equals(other.email))
359
			return false;
360
		if (username == null) {
361
			if (other.username != null)
362
				return false;
363
		} else if (!username.equals(other.username))
364
			return false;
365
		if (filter == null) {
366
			if (other.filter != null)
367
				return false;
368
		} else if (!filter.equals(other.filter))
369
			return false;
370
		if (firstname == null) {
371
			if (other.firstname != null)
372
				return false;
373
		} else if (!firstname.equals(other.firstname))
374
			return false;
375
		if (institution == null) {
376
			if (other.institution != null)
377
				return false;
378
		} else if (!institution.equals(other.institution))
379
			return false;
380
		if (lastNotificationDate == null) {
381
			if (other.lastNotificationDate != null)
382
				return false;
383
		} else if (!lastNotificationDate.equals(other.lastNotificationDate))
384
			return false;
385
		if (lastname == null) {
386
			if (other.lastname != null)
387
				return false;
388
		} else if (!lastname.equals(other.lastname))
389
			return false;
390
		if (recommendationPeriod == null) {
391
			if (other.recommendationPeriod != null)
392
				return false;
393
		} else if (!recommendationPeriod.equals(other.recommendationPeriod))
394
			return false;
395
		if (recommendationSendEmail == null) {
396
			if (other.recommendationSendEmail != null)
397
				return false;
398
		} else if (!recommendationSendEmail
399
				.equals(other.recommendationSendEmail))
400
			return false;
401
		if (recommendations == null) {
402
			if (other.recommendations != null)
403
				return false;
404
		} else if (!recommendations.equals(other.recommendations))
405
			return false;
406
		if (savedQueries == null) {
407
			if (other.savedQueries != null)
408
				return false;
409
		} else if (!savedQueries.equals(other.savedQueries))
410
			return false;
411
		if (store == null) {
412
			if (other.store != null)
413
				return false;
414
		} else if (!store.equals(other.store))
415
			return false;
416
		if (userPhotoID == null) {
417
			if (other.userPhotoID != null)
418
				return false;
419
		} else if (!userPhotoID.equals(other.userPhotoID))
420
			return false;
421
		return true;
422
	}
423
}
(52-52/59)