1 /***
2 Copyright (C) 2005 The Java Community
3
4 This program is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free Software
6 Foundation; either version 2 of the License, or (at your option) any later
7 version.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 Place, Suite 330, Boston, MA 02111-1307 USA.
16 */
17 package org.bejug.javacareers.jobs.model;
18
19 import java.util.HashSet;
20 import java.util.LinkedHashSet;
21 import java.util.Locale;
22 import java.util.Set;
23
24 import org.apache.commons.lang.builder.CompareToBuilder;
25 import org.apache.commons.lang.builder.EqualsBuilder;
26 import org.apache.commons.lang.builder.HashCodeBuilder;
27 import org.apache.commons.lang.builder.ToStringBuilder;
28
29
30 /***
31 *
32 * @author Bart Meyers (last modified by $Author: shally $
33 * @version $Revision: 1.6 $ - $Date: 2005/12/20 15:36:45 $
34 */
35 public class User extends Person {
36
37 /***
38 * if true then user subscribes to regular job digest.
39 */
40 private boolean subscribeToJobDigest = false;
41
42 /***
43 * if true user auto subscribes to its own posts.
44 */
45 private boolean autoSubscribeToPosts = false;
46
47 /***
48 * the max lines per page the users whants to see.
49 */
50 private Integer linesPerPage;
51
52 /***
53 * the locale of this user.
54 */
55 private String locale = null;
56
57 /***
58 * the username.
59 */
60 private String userName;
61
62 /***
63 * the password of the user.
64 */
65 private String password;
66
67 /***
68 * the role of the user.
69 */
70 private String role;
71
72 /***
73 * The comments.
74 */
75 private Set comments;
76
77 /***
78 * type of user.
79 */
80 private String type;
81
82 /***
83 * signals a role change for bussiness rule
84 */
85 private boolean roleChanged;
86
87 /***
88 * Tenporary field for role before change
89 */
90 private String previousRole;
91
92 /***
93 * The resume Resume.
94 */
95 private Resume resume;
96
97 /***
98 * @return Returns the type.
99 */
100 public String getType() {
101 return type;
102 }
103 /***
104 * @param type The type to set.
105 */
106 public void setType(String type) {
107 this.type = type;
108 }
109 /***
110 * check if user has a cv Available.
111 */
112 private boolean cvAvailable = false;
113
114 /***
115 * organisation of the user.
116 */
117 private Organisation organisation;
118
119 /***
120 * transient field for storing the url to the uploaded pdf.
121 */
122 private String pdfUrl;
123
124 /***
125 * the offers of this user .
126 */
127 private Set offers;
128
129
130 /***
131 * Constructor.
132 */
133 public User() {
134 super();
135 }
136 /***
137 *
138 * @param userName String.
139 * @param email String.
140 * @param password String.
141 * @param role String.
142 */
143 public User(String userName, String email, String password, String role) {
144 super();
145
146 this.userName = userName;
147 this.getContact().setEmail(email);
148 this.password = password;
149 this.role = role;
150
151 }
152
153
154
155 /***
156 * @param userName String
157 * @param email String
158 * @param password String
159 * @param role String
160 * @param mobile String
161 * @param salutation Salutation
162 * @param firstName String
163 * @param lastName String
164 * @param phone String
165 * @param organisation Organisation
166 */
167 public User(String userName, String email, String password, String role,String mobile, String salutation, String firstName,
168 String lastName, String phone, Organisation organisation) {
169 this(userName, email, password, role, mobile, salutation, firstName,
170 lastName, phone);
171 this.organisation = organisation;
172 }
173 /***
174 * @param userName String
175 * @param email String
176 * @param password String
177 * @param role String
178 * @param mobile String
179 * @param salutation Salutation
180 * @param firstName String
181 * @param lastName String
182 * @param phone String
183 */
184 public User(String userName, String email, String password, String role, String mobile, String salutation, String firstName,
185 String lastName, String phone) {
186 this.userName = userName;
187 this.getContact().setEmail(email);
188 this.password = password;
189 this.role = role;
190
191 this.getContact().setMobile(mobile);
192 this.salutation = salutation;
193 this.firstName = firstName;
194 this.lastName = lastName;
195 this.getContact().setPhone(phone);
196 }
197
198 /***
199 *
200 * @return userName String.
201 */
202 public String getUserName() {
203 return userName;
204 }
205
206 /***
207 *
208 * @param userName String.
209 */
210 public void setUserName(String userName) {
211 this.userName = userName;
212 }
213
214
215
216
217 /***
218 * @return Returns the password.
219 */
220 public String getPassword() {
221 return password;
222 }
223 /***
224 * @param password The password to set.
225 */
226 public void setPassword(String password) {
227 this.password = password;
228 }
229
230 /***
231 * @return Returns the role.
232 */
233 public String getRole() {
234 return role;
235 }
236
237 /***
238 * @param role The role to set.
239 */
240 public void setRole(String role) {
241 this.role = role;
242 }
243
244 /***
245 * @return Returns the comments Set.
246 */
247 public Set getComments() {
248 if (comments == null) {
249 return new HashSet();
250 }
251 return comments;
252 }
253
254 /***
255 * @param comments
256 * The comments to set.
257 */
258 public void setComments(Set comments) {
259 this.comments = comments;
260 }
261
262 /***
263 * @param offer
264 * The offer to subscibe to.
265 */
266 public void subscribe(Offer offer) {
267 offer.getSubscribers().add(this);
268 this.comments.add(offer);
269 }
270
271 /***
272 * adds a comment
273 * @param comment the comment to add
274 */
275 public void addComment(Comment comment) {
276 if (comments == null) {
277 comments = new LinkedHashSet();
278 }
279 this.comments.add(comment);
280
281 }
282
283
284 /***
285 *
286 * @return offers Set
287 */
288 public Set getOffers() {
289 return offers;
290 }
291
292 /***
293 *
294 * @param offers Set
295 */
296 public void setOffers(Set offers) {
297 this.offers = offers;
298 }
299
300
301 /***
302 * @return Returns the organisations.
303 */
304 public Organisation getOrganisation() {
305 return organisation;
306 }
307 /***
308 * @param organisation The organisations to set.
309 */
310 public void setOrganisation(Organisation organisation) {
311 this.organisation = organisation;
312 }
313
314 /***
315 * adds an offer
316 * @param offer the offer to add
317 */
318 public void addOffer(Offer offer) {
319 if (offers == null) {
320 offers = new LinkedHashSet();
321 }
322 this.offers.add(offer);
323 offer.setUser(this);
324 }
325
326 /***
327 * @return Returns the cvAvailable.
328 */
329 public boolean isCvAvailable() {
330 return cvAvailable;
331 }
332
333 /***
334 * This method is needed by JSF (which is a bug, should be isCvAvailable)
335 * @return cvAvailible.
336 */
337 public boolean getCvAvailable() {
338 return cvAvailable;
339 }
340
341 /***
342 * @param cvAvailable The cvAvailable to set.
343 */
344 public void setCvAvailable(boolean cvAvailable) {
345 this.cvAvailable = cvAvailable;
346 }
347
348 /***
349 * @return the locale of this user as a locale object.
350 */
351 public Locale getLocaleObject() {
352
353 if (locale == null || locale.equals("")) {
354 return Locale.getDefault();
355 }
356 return new Locale(locale.substring(0, 2), locale.substring(3, 5));
357 }
358 /***
359 * @return Returns the locale.
360 */
361 public String getLocale() {
362 return locale;
363 }
364 /***
365 * @param locale The locale to set.
366 */
367 public void setLocale(String locale) {
368 this.locale = locale;
369 }
370 /***
371 * @return Returns the autoSubscribeToPosts.
372 */
373 public boolean isAutoSubscribeToPosts() {
374 return autoSubscribeToPosts;
375 }
376 /***
377 * @param autoSubscribeToPosts The autoSubscribeToPosts to set.
378 */
379 public void setAutoSubscribeToPosts(boolean autoSubscribeToPosts) {
380 this.autoSubscribeToPosts = autoSubscribeToPosts;
381 }
382 /***
383 * @return Returns the linesPerPage.
384 */
385 public Integer getLinesPerPage() {
386 return linesPerPage;
387 }
388 /***
389 * @param linesPerPage The linesPerPage to set.
390 */
391 public void setLinesPerPage(Integer linesPerPage) {
392 this.linesPerPage = linesPerPage;
393 }
394 /***
395 * @return Returns the subscribeToJobDigest.
396 */
397 public boolean isSubscribeToJobDigest() {
398 return subscribeToJobDigest;
399 }
400 /***
401 * @param subscribeToJobDigest The subscribeToJobDigest to set.
402 */
403 public void setSubscribeToJobDigest(boolean subscribeToJobDigest) {
404 this.subscribeToJobDigest = subscribeToJobDigest;
405 }
406
407 /***
408 * Convenience method for getting the url to the uploaded pdf
409 * @return pdfUrl the url to the uploaded pdf
410 */
411 public String getPdfUrl() {
412 return pdfUrl;
413 }
414
415 /***
416 * Convenience method for setting the url to the uploaded pdf
417 * @param pdfUrl the url to the uploaded pdf
418 */
419 public void setPdfUrl(String pdfUrl) {
420 this.pdfUrl = pdfUrl;
421 }
422
423 /***
424 * Indicates a role change
425 * @return True if role has been changed externally
426 */
427 public boolean isRoleChanged() {
428 return roleChanged;
429 }
430
431 /***
432 * Sets a role change
433 * @param roleChanged True if role has been changed
434 */
435 public void setRoleChanged(boolean roleChanged) {
436 this.roleChanged = roleChanged;
437 }
438
439 /***
440 * Gets role before change
441 * @return Role before change
442 */
443
444 public String getPreviousRole() {
445 return previousRole;
446 }
447
448 /***
449 * Sets role before role change
450 * @param previousRole Role before change
451 */
452
453 public void setPreviousRole(String previousRole) {
454 this.previousRole = previousRole;
455 }
456
457 /***
458 * @return Returns the resume.
459 */
460 public Resume getResume() {
461 return resume;
462 }
463 /***
464 * @param resume The resume to set.
465 */
466 public void setResume(Resume resume) {
467 this.resume = resume;
468 }
469
470
471
472
473 /***
474 * {@inheritDoc}
475 */
476 public int compareTo(Object o) {
477 User user = (User) o;
478 return new CompareToBuilder()
479 .appendSuper(super.compareTo(o))
480 .append(this.subscribeToJobDigest, user.isSubscribeToJobDigest())
481 .append(this.autoSubscribeToPosts, user.isAutoSubscribeToPosts())
482 .append(this.linesPerPage, user.getLinesPerPage())
483 .append(this.locale, user.getLocale())
484 .append(this.userName, user.getUserName())
485 .append(this.password, user.getPassword())
486 .append(this.role, user.getRole())
487 .append(this.comments, user.getComments())
488 .append(this.type, user.getType())
489 .append(this.roleChanged, user.isRoleChanged())
490 .append(this.previousRole, user.getPreviousRole())
491 .append(this.cvAvailable, user.isCvAvailable())
492 .append(this.organisation, user.getOrganisation())
493 .append(this.pdfUrl, user.getPdfUrl())
494 .append(this.offers, user.getOffers())
495 .toComparison();
496 }
497
498
499 /***
500 * {@inheritDoc}
501 */
502 public boolean equals(Object o) {
503 if (!(o instanceof User)) {
504 return false;
505 }
506 if (this == o) {
507 return true;
508 }
509 User user = (User) o;
510 return new EqualsBuilder()
511 .appendSuper(super.equals(o))
512 .append(this.subscribeToJobDigest, user.isSubscribeToJobDigest())
513 .append(this.autoSubscribeToPosts, user.isAutoSubscribeToPosts())
514 .append(this.linesPerPage, user.getLinesPerPage())
515 .append(this.locale, user.getLocale())
516 .append(this.userName, user.getUserName())
517 .append(this.password, user.getPassword())
518 .append(this.role, user.getRole())
519 .append(this.comments, user.getComments())
520 .append(this.type, user.getType())
521 .append(this.roleChanged, user.isRoleChanged())
522 .append(this.previousRole, user.getPreviousRole())
523 .append(this.cvAvailable, user.isCvAvailable())
524 .append(this.organisation, user.getOrganisation())
525 .append(this.pdfUrl, user.getPdfUrl())
526 .append(this.offers, user.getOffers())
527 .isEquals();
528 }
529
530
531 /***
532 * {@inheritDoc}
533 */
534 public int hashCode() {
535 return new HashCodeBuilder(999, 17)
536 .append(this.subscribeToJobDigest)
537 .append(this.autoSubscribeToPosts)
538 .append(this.linesPerPage)
539 .append(this.locale)
540 .append(this.userName)
541 .append(this.password)
542 .append(this.role)
543 .append(this.comments)
544 .append(this.type)
545 .append(this.roleChanged)
546 .append(this.previousRole)
547 .append(this.cvAvailable)
548 .append(this.organisation)
549 .append(this.pdfUrl)
550 .append(this.offers)
551 .toHashCode();
552 }
553
554
555 /***
556 * {@inheritDoc}
557 */
558 public String toString() {
559 return new ToStringBuilder(this)
560 .appendSuper(super.toString())
561 .append("userName", this.userName)
562 .append("role", this.role)
563 .append("type", this.type)
564 .append("organisation", this.organisation)
565 .toString();
566 }
567
568 /***
569 *
570 * @param roleuser is the role of the user
571 */
572 public void initialize(String roleuser){
573 this.setRole(roleuser);
574
575
576 Address address = new Address();
577 address.setName("home");
578
579
580 Organisation neworganisation = new Organisation();
581 neworganisation.setAddress(address);
582
583 this.setOrganisation(neworganisation);
584 }
585 }
586 /***
587 * $Log: User.java,v $
588 * Revision 1.6 2005/12/20 15:36:45 shally
589 * CheckStyle and PMD changes.
590 *
591 * Revision 1.5 2005/12/09 10:46:55 shally
592 * Opkuis voor checkstyle en PMD
593 *
594 * Revision 1.4 2005/11/29 12:30:07 shally
595 * Added edit capabilities to admin
596 *
597 * Revision 1.3 2005/09/06 14:53:03 schauwvliege
598 * added add item
599 *
600 * Revision 1.2 2005/08/31 12:15:09 bme_jcs
601 * refactoring and introduction of apache builders
602 *
603 * Revision 1.1 2005/08/26 07:58:26 ge0ffrey
604 * split up the sources in service, serviceimpl and webclient
605 *
606 * Revision 1.11 2005/08/23 11:57:52 schauwvliege
607 * Intruduction of Resume
608 *
609 * Revision 1.10 2005/08/19 13:29:53 bme_jcs
610 * checkstyle errors resolved
611 *
612 * Revision 1.9 2005/08/16 13:53:03 bavo_jcs
613 * Fixed issues with IssueTracker
614 *
615 * Revision 1.8 2005/08/11 10:26:32 bavo_jcs
616 * Role change rule
617 *
618 * Revision 1.7 2005/07/06 12:10:01 schauwvliege
619 * added person/contact and location to model
620 *
621 * Revision 1.6 2005/07/05 14:52:07 schauwvliege
622 * added person/contact and location to model
623 *
624 * Revision 1.5 2005/06/30 10:21:55 bme_jcs
625 * bugfix to be able to insert more than 1 comment on a job
626 *
627 * Revision 1.4 2005/06/17 12:19:59 schauwvliege
628 * CheckStyle/ PMD
629 *
630 * Revision 1.3 2005/06/14 12:05:53 schauwvliege
631 * CheckStyle and fixing tests
632 *
633 * Revision 1.2 2005/06/09 08:18:52 bejug_cc
634 * Fix initial import
635 *
636 * Revision 1.16 2005/06/06 14:55:11 PSONG09
637 * added transient field pdfUrl
638 *
639 * Revision 1.15 2005/06/03 13:31:11 ssc
640 * added UserTYpe
641 *
642 * Revision 1.14 2005/05/28 21:05:22 sja
643 * Added getCvAvailable method (JSF hack)
644 *
645 * Revision 1.13 2005/05/25 10:22:38 kva
646 * added setting to subscribe to job digest mail
647 *
648 * Revision 1.12 2005/05/17 14:22:17 ssc
649 * checkstyle
650 *
651 * Revision 1.11 2005/05/17 13:01:06 ssc
652 * added - linesperpage, locale, autoSubscribeToPosts
653 *
654 * Revision 1.10 2005/05/17 12:11:32 ssc
655 * renamed cvAdded to cvAvailable
656 *
657 * Revision 1.9 2005/05/17 11:59:56 ssc
658 * Refactored User and Publisher class to User Class added cvAvailable Boolean, added Address to user, Fixed test to work with this setup
659 *
660 * Revision 1.14 2005/05/13 14:55:49 ssc
661 * fixed error relationship when adding offer to user/comment
662 *
663 * Revision 1.13 2005/05/10 14:38:06 ssc
664 * Deleted Salutation
665 *
666 * Revision 1.12 2005/05/09 14:54:45 ssc
667 * checkstyle
668 *
669 * Revision 1.11 2005/05/09 13:42:10 ssc
670 * checkstyle
671 *
672 * Revision 1.10 2005/05/04 15:14:17 ssc
673 * removed Subsciber
674 *
675 * Revision 1.9 2005/05/04 14:30:00 ssc
676 * added constructor
677 *
678 * Revision 1.8 2005/05/04 08:56:48 ssc
679 * Changed List to Set
680 *
681 * Revision 1.7 2005/05/03 11:13:01 ssc
682 * added constructor
683 *
684 * Revision 1.6 2005/05/02 13:35:09 ssc
685 * changed constructors
686 *
687 * Revision 1.5 2005/04/29 14:14:15 ssc
688 * added constructor
689 *
690 * Revision 1.3 2005/04/27 21:42:16 ssc
691 * added user/subscriber
692 *
693 * Revision 1.2 2005/04/23 14:28:48 sja
694 * Added header and javadoc
695 *
696 * Revision 1.1 2005/04/19 11:51:22 PSONG09
697 * First release
698 *
699 * Revision 1.2 2005/04/18 18:56:53 sja
700 * Added CVS class header tags.
701 *
702 */