User.java 21.8 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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
package org.legrog.entities;

import javax.persistence.*;
import java.util.*;
// TODO Evaluer l'interet de ces imports
//import org.roliste.data.DbMaskableEntity;
//import org.roliste.data.DbValidationEntity;

// TODO Vérifier les extends
// TODO NameMask et DbMaskableEntity à traiter ensemble
@Entity
//@Table(name="utilisateur")
public class User /* extends org.roliste.data.DbTraceableEntity */ implements DisplayNameConfigurable /*, DbValidationEntity */ {

//    @Column(name="ID_UTILISATEUR")
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int userId;

    // TODO traiter Traceable
    /**
     * Retrieve this object's Traceable.
     * @hibernate.many-to-one
     * 		column="ID_JOURNALISABLE"
     * 		class="org.roliste.data.db.Traceable"
     *  	access="property"
     *  	lazy="false"
     *      cascade="all"
     *      foreign-key="FK_THEME_JOURNALISABLE"
     * @return the {@link org.roliste.data.db.Traceable} record corresponding to this object. May be <code>null</code>.
     * @see #setTraceable(org.roliste.data.db.Traceable)
     */
    /*
    public Traceable getTraceable()
    {
        return _traceRoot;
    }
*/
    // TODO NameMask et DbMaskableEntity à traiter ensemble
    /**
     * The mask used for user name.
     */
    private DisplayNameMask displayNameMask;
/*
    @Override
    public String getUrlKey()
    {
        return "/utilisateurs/" + getScreenName();
    }
*/
    /**
     * @return the user's name as desired. By default, return the complete name.
     * see org.roliste.data.db.NameMask#mask(org.roliste.data.DbMaskableEntity)
     */
    public String getDisplayName()
    {
        if (displayNameMask != null)
            return displayNameMask.getDisplayName(this);
        else
            return DisplayNameMask.COMPLET.getDisplayName(this);
    }

    /**
     * Returns the user's name mask.
     * @return the mask.
     * see #setNameMask(NameMask)
     * hibernate.property
     *  	column="MASQUE_NOM_UTILISATEUR"
     *  	access="property"
     *  	length="50"
     * @hibernate.type
     *      name="org.roliste.data.util.NameMaskUserType"
     */
    public DisplayNameMask getDisplayNameMask() {
        return displayNameMask;
    }

    /**
     * Initializes the user's name mask.
     * @param mask the new {link org.roliste.data.db.NameMask}.
     * see #getNameMask()
     */
    public void setDisplayNameMask(DisplayNameMask mask) {
        mask = mask;
    }


            // TODO Faire ailleurs les contrôles de chaîne vide sur : username, password, firstname, lastname, nickname, email, text
    /**
     * The user identifier.
     */
    private String username;

    /**
     * The user password.
     */
    private String password;

    /**
     * The user first name.
     */
    private String firstName;

    /**
     * The user last name.
     */
    private String lastName;

    /**
     * The user nick name.
     */
    private String nickname;

    /**
     * The user email address.
     */
    private String email;

    /**
     * The {@link org.roliste.data.db.UserRole}s for this user.
     */
    @ManyToMany
    private List<UserRole> roles;

    /**
     * Retrieves the list of {@link UserRole}s for this user.
     * SHALL be used as a read-only attribute. In particular, avoid
     * using {@link List#add(Object)} or {@link List#remove(Object)} on
     * the returned value without caution.
     * @return a {@link List} of {@link UserRole}. Shall not be <code>null</code>.
     * @see #setRoles(List)
     * @see #addToRole(UserRole)
     * @see #removeFromRole(UserRole)
     * hibernate.many-to-many
     *  	column="ROLE_FK"
     *  	class="org.roliste.data.db.UserRole"
     *      foreign-key="FK_UTILISATEURROLE_ROLEUTILISATEUR"
     * @hibernate.key
     * 		column="UTILISATEUR_FK"
     * 		not-null="true"
     *      foreign-key="FK_UTILISATEURROLE_UTILISATEUR"
     * @hibernate.bag
     * 		cascade="save-update"
     * 		access="property"
     * 		table="role_utilisateur"
     * 		lazy="true"
     */

    public List<UserRole> getRoles() {
        return roles;
    }

    /**
     * Lists the list of {@link UserRole}s for this user.
     * @param roles the new {@link List} of {@link UserRole}s. Shall not be <code>null</code>.
     * @throws NullPointerException if roles is <code>null</code>.
     * @see #getRoles()
     * see #addToRole(UserRole)
     * see #removeFromRole(UserRole)
     */

    public void setRoles(List<UserRole> roles) {
        if (roles == null)
        {
            throw new NullPointerException("Impossible d'affecter un ensemble nul aux r�les d'un utilisateur");
        }
        this.roles = roles;
    }

    /**
     * Add the user to a given {@link UserRole}s.
     * @param role the new {@link UserRole}. Ignored if <code>null</code>.
     * @see #getRoles()
     * @see #setRoles(List)
     * @see #removeFromRole(UserRole)
     */
    /*
    public void addToRole(UserRole role) {
        synchronized (this)
        {
            if ((role != null) && !(getRoles().contains(role)) )
            {
                role.getUsers().add(this);
                getRoles().add(role);
            }
        }
    }
*/
    /**
     * Remove the user from a given {@link UserRole}s.
     * @param role the {@link UserRole} this {@link User} will lose. Ignored if <code>null</code>.
     * @see #getRoles()
     * @see #setRoles(List)
     * @see #addToRole(UserRole)
     */
    /*
    public void removeFromRole(UserRole role) {
        synchronized (this)
        {
            if ((role != null) && (getRoles().contains(role)) )
            {
                role.getUsers().remove(this);
                getRoles().remove(role);
            }
        }
    }
*/
    /**
     * The user anonymous status.
     * If anonymous, user cannot be contacted through email.
     */
    private boolean anonymous;

    /**
     * The user validation status.
     */
    private boolean visible;

    /**
     * The user was activated at least once.
     */
    private boolean activated;

    /**
     * The user provides critics for archive.
     */
    private boolean criticProvider;

    /**
     * Presentation text.
     */
    private String presentation;

    /**
     * The {@link org.roliste.data.db.BookDetails}s in this user's collection.
     */
//    private List<BookDetails> _collection;

    /**
     * Retrieves the list of {@link org.roliste.data.db.BookDetails}s in this user's collection.
     * SHALL be used as a read-only attribute. In particular, avoid using {@link List#add(Object)}
     * or {@link List#remove(Object)} on the returned value without caution.
     * @return a {@link List} of {@link org.roliste.data.db.BookDetails}. Shall not be <code>null</code>.
     * @see #setCollection(List)
     * @see #addToCollection(BookDetails)
     * @see #removeFromCollection(BookDetails)
     * @hibernate.many-to-many
     *  	column="DETAILS_FK"
     *  	class="org.roliste.data.db.BookDetails"
     *      foreign-key="FK_COLLECTION_DETAIL"
     * @hibernate.key
     * 		column="UTILISATEUR_FK"
     * 		not-null="true"
     *      foreign-key="FK_COLLECTION_UTILISATEUR"
     * @hibernate.bag
     * 		access="property"
     * 		table="collection"
     * 		lazy="true"
     */
    /*
    public List<BookDetails> getCollection() {
        return _collection;
    }
*/
    /**
     * Lists the list of {@link org.roliste.data.db.BookDetails}s in this user's collection.
     * @param collec the new {@link List} of {@link org.roliste.data.db.BookDetails}s. Shall not be <code>null</code>.
     * @throws NullPointerException if collec is <code>null</code>.
     * @see #getCollection()
     * @see #addToCollection(BookDetails)
     * @see #removeFromCollection(BookDetails)
     */
    /*
    public void setCollection(List<BookDetails> collec) {
        if (collec == null)
        {
            throw new NullPointerException("Impossible d'affecter un ensemble nul pour la collection d'un utilisateur");
        }
        _collection = collec;
    }
*/
    /**
     * Add a book to the user's collection.
     * @param book the new {@link org.roliste.data.db.BookDetails}. Ignored if <code>null</code>.
     * @see #getCollection()
     * @see #setCollection(List)
     * @see #removeFromCollection(BookDetails)
     */
    /*
    public void addToCollection(BookDetails book) {
        synchronized (this)
        {
            if ((book != null) && !(getCollection().contains(book)) )
            {
                book.getOwners().add(this);
                getCollection().add(book);
            }
        }
    }
*/
    /**
     * Remove a book from user's collection.
     * @param book the {@link org.roliste.data.db.BookDetails} this {@link User} will lose. Ignored if <code>null</code>.
     * @see #getCollection()
     * @see #setCollection(List)
     * @see #addToCollection(BookDetails)
     */
    /*
    public void removeFromCollection(BookDetails book) {
        synchronized (this)
        {
            if ((book != null) && (getCollection().contains(book)) )
            {
                book.getOwners().remove(this);
                getCollection().remove(book);
            }
        }
    }
*/
    /**
     * The {@link org.roliste.data.db.Traceable}s delegated to this user.
     */
//    private List<Traceable> _delegations;

    /**
     * Retrieves the list of delegations for this user.
     * Each delegation is a link to a {@link org.roliste.data.db.Traceable} object.
     * A user having delegation may update field values for delegated object.
     * @return a {@link List} of {@link UserRole}. Shall not be <code>null</code>. SHALL be used as a
     * read-only attribute. In particular, avoid using {@link List#add(Object)} or {@link List#remove(Object)}
     * on the returned value without caution.
     * @see #setDelegations(List)
     * @see #giveDelegation(Traceable)
     * @see #removeDelegation(Traceable)
     * @hibernate.many-to-many
     *  	column="ID_JOURNALISABLE"
     *  	class="org.roliste.data.db.Traceable"
     *      foreign-key="FK_DELEGATION_JOURNALISABLE"
     * @hibernate.key
     * 		column="ID_UTILISATEUR"
     * 		not-null="true"
     *      foreign-key="FK_DELEGATION_UTILISATEUR"
     * @hibernate.bag
     * 		cascade="save-update"
     * 		access="property"
     * 		table="delegation_utilisateur"
     * 		lazy="true"
     */
    /*
    public List<Traceable> getDelegations() {
        return _delegations;
    }
*/
    /**
     * Sets the list of delegations for this user.
     * @param objects the new {@link List} of delegated {@link Traceable}. Shall not be <code>null</code>.
     * @throws NullPointerException if objects is <code>null</code>.
     * @see #getDelegations()
     * @see #giveDelegation(Traceable)
     * @see #removeDelegation(Traceable)
     */
    /*
    public void setDelegations(List<Traceable> objects) {
        if (_delegations == null)
        {
            throw new NullPointerException("Impossible d'affecter un ensemble nul aux d�l�gations d'un utilisateur");
        }
        _delegations = objects;
    }
*/
    /**
     * Give delegation on a given {@link Traceable} to this user.
     * @param object the new delegation. Ignored if <code>null</code>.
     * @see #getDelegations()
     * @see #setDelegations(List)
     * @see #removeDelegation(Traceable)
     */
    /*
    public void giveDelegation(Traceable object) {
        synchronized (this)
        {
            if ((object != null) && !(getDelegations().contains(object)) )
            {
                object.getDelegates().add(this);
                getDelegations().add(object);
            }
        }
    }
*/
    /**
     * Remove delegation on a given {@link Traceable} from this user.
     * @param object the delegation this {@link User} will lose. Ignored if <code>null</code>.
     * @see #getDelegations()
     * @see #setDelegations(List)
     * @see #giveDelegation(Traceable)
     */
    /*
    public void removeDelegation(Traceable object) {
        synchronized (this)
        {
            if ((object != null) && (getDelegations().contains(object)) )
            {
                object.getDelegates().remove(this);
                getDelegations().remove(object);
            }
        }
    }
*/
    /**
     * Clear all delegations for this user.
     */
    /*
    public void clearDelegations()
    {
        synchronized (this)
        {
            for (Traceable root : getDelegations())
            {
                root.getDelegates().remove(this);
            }
            getDelegations().clear();
        }
    }
*/
    /**
     * The list of attributes / properties for this user.
     */
    @OneToMany
    private List<UserAttribute> userAttributes;

    /**
     * Retrieve this user's attributes.
     * @hibernate.one-to-many
     * 		class="org.roliste.data.db.UserAttribute"
     * @hibernate.bag
     *      cascade="all"
     *      lazy="true"
     *      inverse="true"
     * @hibernate.key
     *      column="ID_UTILISATEUR"
     * @return a {@link java.util.List} of user attributes linked to this. Shall not be <code>null</code>.
     * @see #setAttributes(java.util.List)
     */

    public List<UserAttribute> getAttributes()
    {
        return userAttributes;
    }

    /**
     * @param attribs the List of attributes for this user.
     * @see #getAttributes()
     */

    public void setAttributes(List<UserAttribute> attribs)
    {
        this.userAttributes = attribs;
    }

    /**
     * The {@link org.roliste.data.db.GamingEvent}s this user's visited.
     */
//    private Set<GamingEvent> _visitedEvents = new HashSet<GamingEvent>();

    /**
     * Retrieves the list of {@link GamingEvent}s visited by this user.
     * SHALL be used as a read-only attribute. In particular, avoid
     * using {@link Set#add(Object)} or {@link Set#remove(Object)} on
     * the returned value without caution.
     * @return a {@link Set} of {@link GamingEvent}s. May be <code>null</code>.
     * @see #setVisitedEvents(Set)
     * @hibernate.many-to-many
     *  	column="MANIF_FK"
     *  	class="org.roliste.data.db.GamingEvent"
     * @hibernate.key
     * 		column="UTILISATEUR_FK"
     * 		not-null="true"
     * @hibernate.set
     * 		access="property"
     * 		table="manif_utilisateur"
     *		inverse="true"
     *		lazy="true"
     */
    /*
    public Set<GamingEvent> getVisitedEvents() {
        return _visitedEvents;
    }
*/
    /**
     * Sets the list of {link GamingEvent}s for this user.
     * param events the new {@link Set} of {link GamingEvent}s. May be
     * <code>null</code> (we don't handle the relation from this side).
     * see #getVisitedEvents()
     */
    /*
    protected void setVisitedEvents(Set<GamingEvent> events) {
        _visitedEvents = events;
    }
*/

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    /**
     * Returns the user identifier.
     * @return the {@link String} identifier.
     * @see #setUsername(String)
     * hibernate.property
     *  	column="LOGIN_UTILISATEUR"
     *  	not-null="true"
     *  	unique="true"
     *  	access="property"
     *  	length="50"
     */
    public String getUsername() {
        return username;
    }

    /**
     * Initializes the user identifier.
     * @param name the new {@link String} identifier.
     * @see #getUsername()
     */
    public void setUsername(String name) {
        this.username = name;
    }
    /**
     * Returns the user password.
     * @return the {@link String} password.
     * @see #setPassword(String)
     * hibernate.property
     *  	column="PASS_UTILISATEUR"
     *  	not-null="true"
     *  	access="property"
     *  	length="50"
     */
    public String getPassword() {
        return password;
    }

    /**
     * Initializes the user password.
     * @param pwd the new {@link String} password.
     * @see #getPassword()
     */
    public void setPassword(String pwd) {
        this.password = pwd;
    }

    /**
     * Returns the user full first name.
     * @return the {@link String} first name.
     * @see #setFirstName(String)
     * hibernate.property
     *  	column="PRENOM_UTILISATEUR"
     *  	not-null="true"
     *  	access="property"
     *  	length="50"
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Initializes the user first name.
     * @param name the new {@link String} first name.
     * @see #getFirstName()
     */
    public void setFirstName(String name) {
        this.firstName = name;
    }

    /**
     * Returns the user full last name.
     * @return the {@link String} last name.
     * @see #setLastName(String)
     * hibernate.property
     *  	column="NOM_UTILISATEUR"
     *  	not-null="true"
     *  	access="property"
     *  	length="50"
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Initializes the user last name.
     * @param name the new {@link String} last name.
     * @see #getLastName()
     */
    public void setLastName(String name) {
        this.lastName = name;
    }

    /**
     * Returns the user full screen name.
     * @return the {@link String} screen name.
     * @see #setNickName(String)
     * hibernate.property
     *  	column="PSEUDO_UTILISATEUR"
     *  	access="property"
     *  	length="50"
     */
    public String getNickName() {
        return nickname;
    }

    /**
     * Initializes the user screen name.
     * @param name the new {@link String} screen name.
     * @see #getNickName()
     */
    public void setNickName(String name) {
        this.nickname = name;
    }

    /**
     * Returns the user email.
     * @return the {@link String} email.
     * @see #setEmail(String)
     * hibernate.property
     *  	column="EMAIL_UTILISATEUR"
     *  	unique="true"
     *      not-null="true"
     *  	access="property"
     *  	length="100"
     */
    public String getEmail() {
        return email;
    }

    /**
     * Initializes the user email.
     * @param address the new {@link String} email.
     * @see #getEmail()
     */
    public void setEmail(String address) {
        this.email = address;
    }

    /**
     * Indicates if the user is anonymous.
     * Anonymous users' email and first/last name won't be shown.
     * @return the anonymous flag.
     * @see #setAnonymous(boolean)
     * hibernate.property
     *  	column="IND_ANONYME"
     *  	access="property"
     */
    public boolean isAnonymous() {
        return anonymous;
    }

    /**
     * Initializes the user anonymous flag.
     * @param anonymous the new flag value.
     * @see #isAnonymous
     */
    public void setAnonymous(boolean anonymous) {
        this.anonymous = anonymous;
    }

    /**
     * hibernate.property
     *  	column="IND_VISIBLE"
     *  	access="property"
     */
    public boolean isVisible() {
        // WARNING: Method documentation copied from DbValidationEntity
        return visible;
    }

    public void setVisible(boolean visible) {
        // WARNING: Method documentation copied from DbValidationEntity
        this.visible = visible;
    }

    /**
     * Indicates if the user was activated at least once.
     * @return the activation flag.
     * @see #setCriticProvider(boolean)
     * hibernate.property
     *  	column="IND_ACTIVE"
     *  	access="property"
     */
    public boolean isActivated() {
        return activated;
    }

    /**
     * Initializes the user activation flag.
     * @param active the new flag value.
     * @see #isActivated
     */
    public void setActivated(boolean active) {
        this.activated = active;
    }

    /**
     * Indicates if the user provides critics for archives.
     * @return the critics provider flag.
     * @see #setCriticProvider(boolean)
     * hibernate.property
     *  	column="IND_CRITIQUES"
     *  	access="property"
     */
    public boolean isCriticProvider() {
        return criticProvider;
    }

    /**
     * Initializes the critics provider flag.
     * @param flag the new flag value.
     * @see #isCriticProvider
     */
    public void setCriticProvider(boolean flag) {
        this.criticProvider = flag;
    }

    /**
     * Returns the HTML text presentation for this user.
     * @return the {@link String} HTML text.
     * @see #setPresentation(String)
     * hibernate.property
     *  	column="PRESENTATION"
     *  	access="property"
     *      type="text"
     *      length="2147483647"
     */
    public String getPresentation() {
        return presentation;
    }

    /**
     * Initializes the HTML text presentation.
     * @param presentation the new {@link String} HTML text.
     * @see #getPresentation()
     */
    public void setPresentation(String presentation) {
        this.presentation = presentation;
    }

    /**
     * The user submission date.
     */
    private Date creationDate;

    /**
     * Returns this object creation {@link Date}.
     * @return the object creation {@link Date}.
     * @see #setCreationDate(Date)
     * hibernate.property
     *  	column="DATE_ENREGISTREMENT"
     *  	access="property"
     */
    public Date getCreationDate() {
        return creationDate;
    }

    /**
     * Initializes the object creation {@link Date}.
     * @param date the new object creation {@link Date}.
     * @see #getCreationDate()
     */
    public void setCreationDate(Date date) {
        this.creationDate = date;
    }

    /**
     * Returns a string representation of this user definition.
     * @return a string representing this user definition.
     * hidden
     */
    public String toString()
    {
        StringBuilder sb = new StringBuilder();

        sb.append("ID_UTILISATEUR=");
        sb.append(userId);

        sb.append(" LOGIN_UTILISATEUR=");
        sb.append(username);

        sb.append(" EMAIL_UTILISATEUR=");
        sb.append(email);

        sb.append(" PRENOM_UTILISATEUR=");
        sb.append(firstName);

        sb.append(" NOM_UTILISATEUR=");
        sb.append(lastName);

        sb.append(" PSEUDO_UTILISATEUR=");
        sb.append(nickname);

        return sb.toString();
    }
}