/*
 * Created on May 4, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package gov.nih.nci.camod.domain;

import gov.nih.nci.camod.service.impl.UserManagerSingleton;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * @author rajputs
 */
public class Person extends Party {

    private static final long serialVersionUID = 3258795453799404851L;
    
    private final Log log = LogFactory.getLog(Person.class);

    private String firstName;
    private String middleName;
    private String lastName;
    private String username;
    private Boolean isPrincipalInvestigtor;

    /**
     * NOTE: the following two methods do NOT user the getXXX naming because it
     * causes problems with the common persistence package
     */
    /**
     * @return Returns the display name
     */
    public String displayName() {
        return lastName + ", " + firstName;
    }

    /**
     * @return Returns the e-mail address
     */
    public String emailAddress() {

        String theEmailAddress = "";

        try {
            theEmailAddress = UserManagerSingleton.instance().getEmailForUser(username);
        } catch (Exception e) {
            log.error("Unable to get email address for user: " + username);
        }

        return theEmailAddress;
    }

    /**
     * @return Returns the username.
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username
     *            The username to set.
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return Returns the middleName.
     */
    public String getMiddleName() {
        return middleName;
    }

    /**
     * @param middleName
     *            The middleName to set.
     */
    public void setMiddleName(String middleName) {
        this.middleName = middleName;
    }

    /**
     * @return Returns the firstName.
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * @param firstName
     *            The firstName to set.
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * @return Returns the lastName.
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * @param lastName
     *            The lastName to set.
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * @return Returns the isPrincipleInvestigator flag.
     */
    public Boolean getIsPrincipalInvestigator() {
        return isPrincipalInvestigtor;
    }

    /**
     * @param inIsPrincipleInvestigtor
     *            Set's whether or not this user is a PI
     */
    public void setIsPrincipalInvestigator(Boolean inIsPrincipalInvestigtor) {
        this.isPrincipalInvestigtor = inIsPrincipalInvestigtor;
    }

    /**
     * @see java.lang.Object#toString()
     */
    public String toString() {
        String result = super.toString() + " - ";
        result += this.getUsername();
        return result;
    }

    public boolean equals(Object o) {
        if (!super.equals(o))
            return false;
        if (!(this.getClass().isInstance(o)))
            return false;
        return true;
    }
}

@@ -333,17 +333,16 @@
 ctory;%0A%0A
-%0A
 /**%0A * @
@@ -468,20 +468,16 @@
 04851L;%0A
-    
 %0A    pri
@@ -936,32 +936,33 @@
 layName() %7B%0A
+%0A
         
 return lastN
@@ -941,38 +941,141 @@
 me() %7B%0A%0A        
-return
+String theDisplayName = %22%22;%0A        if (lastName != null && firstName != null) %7B%0A            theDisplayName =
  lastName + %22, %22
@@ -1067,16 +1067,23 @@
 lastName
+.trim()
  + %22, %22 
@@ -1085,32 +1085,80 @@
 %22, %22 + firstName
+.trim();%0A        %7D%0A        return theDisplayName
 ;%0A    %7D%0A%0A    /**

Handle empty first/last names