1 25 26 package com.j2biz.blogunity.pojo; 27 28 import java.io.Serializable ; 29 import java.util.Date ; 30 import java.util.Iterator ; 31 import java.util.Locale ; 32 import java.util.Set ; 33 import java.util.TreeSet ; 34 35 import net.sf.hibernate.Validatable; 36 import net.sf.hibernate.ValidationFailure; 37 38 import com.j2biz.blogunity.util.CommentComparator; 39 import com.j2biz.blogunity.util.BlogComparator; 40 import com.j2biz.blogunity.util.UserComparator; 41 import com.j2biz.blogunity.util.BlogUtils; 42 import com.j2biz.blogunity.util.UserpicComparator; 43 44 54 public class User implements Validatable, Serializable { 55 56 59 private static final long serialVersionUID = 3258697602278439221L; 60 61 public static final int MALE = 0; 62 63 public static final int FEMALE = 1; 64 65 private Long id; 66 67 private String nickname; 68 69 private String firstname; 70 71 private String lastname; 72 73 private String bioRaw; 74 75 private String bio; 76 77 private String password; 78 79 private String email; 80 81 private String homepage; 82 83 private Date birthday; 84 85 private String icq; 86 87 private String msn; 88 89 private String yahoo; 90 91 private String jabber; 92 93 private int sex = MALE; 94 95 private Set userpics = new TreeSet (new UserpicComparator()); 96 97 private Set friends = new TreeSet (new UserComparator()); 98 99 private Set foundedBlogs = new TreeSet (new BlogComparator()); 100 101 private Set contributedBlogs = new TreeSet (new BlogComparator()); 102 103 private Set favoriteBlogs = new TreeSet (new BlogComparator()); 104 105 private Set waitingForAcceptanceBlogs = new TreeSet (new BlogComparator()); 106 107 private Set comments = new TreeSet (new CommentComparator()); 108 109 private boolean isActive = true; 110 111 private boolean showEmail = true; 112 113 private Date registerTime = new Date (); 114 115 private Date lastUpdateTime = new Date (); 116 117 private boolean isAdministrator = false; 118 119 private Locale language = Locale.ENGLISH; 120 121 124 public User() { 125 126 } 127 128 public User(String name, String password, String email, String firstname, String lastname) { 129 130 this.nickname = name; 131 this.password = password; 132 this.email = email; 133 this.firstname = firstname; 134 this.lastname = lastname; 135 136 } 137 138 144 public Long getId() { 145 return id; 146 } 147 148 152 public void setId(Long id) { 153 this.id = id; 154 } 155 156 163 public Locale getLanguage() { 164 return language; 165 } 166 167 170 public void setLanguage(Locale language) { 171 this.language = language; 172 } 173 174 185 public Set getComments() { 186 return comments; 187 } 188 189 193 public void setComments(Set comments) { 194 this.comments = comments; 195 } 196 197 204 public String getEmail() { 205 return email; 206 } 207 208 212 public void setEmail(String email) { 213 this.email = email; 214 } 215 216 223 public String getNickname() { 224 return nickname; 225 } 226 227 231 public void setNickname(String name) { 232 this.nickname = name; 233 } 234 235 241 public String getPassword() { 242 return password; 243 } 244 245 249 public void setPassword(String password) { 250 this.password = password; 251 } 252 253 262 public Set getUserpics() { 263 return userpics; 264 } 265 266 270 public void setUserpics(Set userpics) { 271 this.userpics = userpics; 272 } 273 274 public void addUserpic(Userpic pic) { 275 userpics.add(pic); 276 } 277 278 284 public boolean containsUserpicWithUrl(String url) { 285 for (Iterator it = getUserpics().iterator(); it.hasNext();) { 286 Userpic e = (Userpic) it.next(); 287 if (e.getUrl().equals(url)) return true; 288 } 289 290 return false; 291 } 292 293 public boolean containsUserpicWithName(String name) { 294 for (Iterator it = getUserpics().iterator(); it.hasNext();) { 295 Userpic e = (Userpic) it.next(); 296 if (e.getName().equals(name)) return true; 297 } 298 return false; 299 } 300 301 public boolean containsUserpic(Userpic pic) { 302 for (Iterator it = getUserpics().iterator(); it.hasNext();) { 303 Userpic e = (Userpic) it.next(); 304 if (e.getName().equals(pic.getName()) && e.getUrl().equals(pic.getUrl())) return true; 305 } 306 return false; 307 } 308 309 319 public Set getFriends() { 320 return friends; 321 } 322 323 public void addFriend(User friend) { 324 friends.add(friend); 325 } 326 327 331 public void setFriends(Set friends) { 332 this.friends = friends; 333 } 334 335 347 public Set getContributedBlogs() { 348 return contributedBlogs; 349 } 350 351 public void addContributedBlog(Blog blog) { 352 contributedBlogs.add(blog); 353 } 354 355 359 public void setContributedBlogs(Set contributedBlogs) { 360 this.contributedBlogs = contributedBlogs; 361 } 362 363 375 public Set getWaitingForAcceptanceBlogs() { 376 return waitingForAcceptanceBlogs; 377 } 378 379 383 public void setWaitingForAcceptanceBlogs(Set waitingForAcceptanceBlogs) { 384 this.waitingForAcceptanceBlogs = waitingForAcceptanceBlogs; 385 } 386 387 public void addWaitingForAcceptanceBlog(Blog blog) { 388 waitingForAcceptanceBlogs.add(blog); 389 } 390 391 400 public Set getFoundedBlogs() { 401 return foundedBlogs; 402 } 403 404 public int getNumberOfIndividualBlogsFounded() { 405 int counter = 0; 406 for (Iterator i = getFoundedBlogs().iterator(); i.hasNext();) { 407 Blog b = (Blog) i.next(); 408 if (b.getType() == Blog.INDIVIDUAL_BLOG) counter++; 409 410 } 411 return counter; 412 } 413 414 public int getNumberOfCommunityBlogsFounded() { 415 int counter = 0; 416 for (Iterator i = getFoundedBlogs().iterator(); i.hasNext();) { 417 Blog b = (Blog) i.next(); 418 if (b.getType() == Blog.COMMUNITY_BLOG) counter++; 419 420 } 421 return counter; 422 } 423 424 428 public void setFoundedBlogs(Set foundedBlogs) { 429 this.foundedBlogs = foundedBlogs; 430 } 431 432 public void addFoundedBlog(Blog blog) { 433 foundedBlogs.add(blog); 434 } 435 436 447 public Set getFavoriteBlogs() { 448 return favoriteBlogs; 449 } 450 451 455 public void setFavoriteBlogs(Set favoriteBlogs) { 456 this.favoriteBlogs = favoriteBlogs; 457 } 458 459 public void addFavoriteBlog(Blog blog) { 460 favoriteBlogs.add(blog); 461 } 462 463 469 public boolean getActive() { 470 return isActive; 471 } 472 473 476 public boolean isActive() { 477 return isActive; 478 } 479 480 484 public void setActive(boolean isActive) { 485 this.isActive = isActive; 486 } 487 488 494 public boolean getAdministrator() { 495 return isAdministrator; 496 } 497 498 501 public boolean isAdministrator() { 502 return isAdministrator; 503 } 504 505 509 public void setAdministrator(boolean isAdministrator) { 510 this.isAdministrator = isAdministrator; 511 } 512 513 520 public String getBio() { 521 return bio; 522 } 523 524 528 public void setBio(String bio) { 529 this.bio = bio; 530 } 531 532 538 public String getBioRaw() { 539 return bioRaw; 540 } 541 542 546 public void setBioRaw(String bioRaw) { 547 this.bioRaw = bioRaw; 548 } 549 550 556 public String getFirstname() { 557 return firstname; 558 } 559 560 564 public void setFirstname(String firstName) { 565 this.firstname = firstName; 566 } 567 568 574 public String getLastname() { 575 return lastname; 576 } 577 578 582 public void setLastname(String lastName) { 583 this.lastname = lastName; 584 } 585 586 592 public boolean getShowEmail() { 593 return showEmail; 594 } 595 596 599 public boolean isShowEmail() { 600 return showEmail; 601 } 602 603 607 public void setShowEmail(boolean showEmail) { 608 this.showEmail = showEmail; 609 } 610 611 617 public Date getRegisterTime() { 618 return registerTime; 619 } 620 621 625 public void setRegisterTime(Date regiterTime) { 626 this.registerTime = regiterTime; 627 } 628 629 635 public String getHomepage() { 636 return homepage; 637 } 638 639 643 public void setHomepage(String homepage) { 644 this.homepage = homepage; 645 } 646 647 652 public String getIcq() { 653 return icq; 654 } 655 656 660 public void setIcq(String icq) { 661 this.icq = icq; 662 } 663 664 669 public String getJabber() { 670 return jabber; 671 } 672 673 677 public void setJabber(String jabber) { 678 this.jabber = jabber; 679 } 680 681 686 public String getMsn() { 687 return msn; 688 } 689 690 694 public void setMsn(String msn) { 695 this.msn = msn; 696 } 697 698 704 public String getYahoo() { 705 return yahoo; 706 } 707 708 712 public void setYahoo(String yahoo) { 713 this.yahoo = yahoo; 714 } 715 716 722 public Date getBirthday() { 723 return birthday; 724 } 725 726 730 public void setBirthday(Date birthday) { 731 this.birthday = birthday; 732 } 733 734 740 public Date getLastUpdateTime() { 741 return lastUpdateTime; 742 } 743 744 750 public int getSex() { 751 return sex; 752 } 753 754 758 public void setSex(int sex) { 759 this.sex = sex; 760 } 761 762 766 public void setLastUpdateTime(Date lastUpdateTime) { 767 this.lastUpdateTime = lastUpdateTime; 768 } 769 770 782 public boolean canPostToBlog(Blog blog) { 783 if (isFounder(blog) || isContributor(blog) || isAdministrator()) return true; 784 return false; 785 } 786 787 791 public boolean isContributor(Blog blog) { 792 793 if (blog.getType() == Blog.INDIVIDUAL_BLOG) { 794 return false; 795 } else { 796 Iterator it = blog.getContributors().iterator(); 797 while (it.hasNext()) { 798 User u = (User) it.next(); 799 if (u.getId().longValue() == this.id.longValue()) return true; 800 801 } 802 } 803 return false; 804 } 805 806 810 public boolean isFounder(Blog blog) { 811 return (blog.getFounder().getId().longValue() == this.id.longValue()); 812 } 813 814 823 public boolean containsAsFriend(User u) { 824 Set fr = getFriends(); 825 Iterator it = fr.iterator(); 826 while (it.hasNext()) { 827 User f = (User) it.next(); 828 if (f.getId().longValue() == u.getId().longValue()) return true; 829 } 830 831 return false; 832 } 833 834 839 public void validate() throws ValidationFailure { 840 841 if (!BlogUtils.getInstance().isValidNickname(nickname)) 842 throw new ValidationFailure("Nickname is not valid!"); 843 844 if (!BlogUtils.getInstance().isValidEmailAddress(email)) 845 throw new ValidationFailure("Email is not valid!"); 846 847 } 848 849 } | Popular Tags |