Person.java
package com.tradecloud.domain.party.base;
import com.tradecloud.domain.common.IntegratedPersistenceBase;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.xml.bind.annotation.XmlAttribute;
/**
* Mapped super class containing all the properties that a Person can have in
* Tradecloud.
* <p>
* A person cannot be instantiated. It must be sub classed
*/
@MappedSuperclass
public abstract class Person extends IntegratedPersistenceBase implements Comparable<Person> {
@XmlAttribute
private String title;
@XmlAttribute(required = true)
@NotNull(message = "First name is required")
@Column(nullable = false)
private String firstName;
@XmlAttribute(required = true)
@NotNull(message = "Last name is required")
@Column(nullable = false)
private String lastName;
@XmlAttribute
private String identificationNumber;
@XmlAttribute
private String phone;
@XmlAttribute
private String mobilePhone;
// @Pattern(regexp = "^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[a-zA-Z]{2,4}$", message = "Email format is not valid")
@Pattern(regexp = "^[\\w-_\\.+]*([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[a-zA-Z]{2,4}$", message = "Email format is not valid")
@XmlAttribute
private String email;
@XmlAttribute
private String fax;
@XmlAttribute
private Boolean active = Boolean.TRUE;
/**
* Constructor with just the required fields.
*
* @param firstName
* @param lastName
*/
public Person(String firstName, String lastName) {
super();
this.firstName = firstName;
this.lastName = lastName;
}
/**
* Constructor with all fields.
*
* @param title
* @param firstName
* @param lastName
* @param identificationNumber
* @param phone
* @param email
* @param fax
*/
public Person(String title, String firstName, String lastName, String identificationNumber, String phone, String email, String fax) {
super();
this.title = title;
this.firstName = firstName;
this.lastName = lastName;
this.identificationNumber = identificationNumber;
this.phone = phone;
this.email = email;
this.fax = fax;
}
public Person() {
}
public String getFullName() {
return (title != null ? title + " " : "") + (firstName != null ? firstName + " " : "") + (lastName != null ? lastName : "");
}
private static final long serialVersionUID = 1L;
public String getTitle() {
return title;
}
public void setTitle(String titleParam) {
this.title = titleParam;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstNameParam) {
this.firstName = firstNameParam;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastNameParam) {
this.lastName = lastNameParam;
}
public String getIdentificationNumber() {
return identificationNumber;
}
public void setIdentificationNumber(String identificationNumberParam) {
this.identificationNumber = identificationNumberParam;
}
public String getPhone() {
return phone;
}
public void setPhone(String phoneParam) {
this.phone = phoneParam;
}
public String getEmail() {
return email;
}
public void setEmail(String emailParam) {
this.email = emailParam;
}
public String getFax() {
return fax;
}
public void setFax(String faxParam) {
this.fax = faxParam;
}
public String getMobilePhone() {
return mobilePhone;
}
public void setMobilePhone(String mobilePhone) {
this.mobilePhone = mobilePhone;
}
@Override
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
@Override
public int hashCode() {
return new HashCodeBuilder()
.append(title)
.append(firstName)
.append(lastName)
.append(email)
.append(fax)
.append(identificationNumber)
.append(phone)
.append(mobilePhone)
.toHashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Person)) {
return false;
}
Person other = (Person) obj;
return new EqualsBuilder()
.append(title, other.title)
.append(firstName, other.firstName)
.append(lastName, other.lastName)
.append(email, other.email)
.append(fax, other.fax)
.append(identificationNumber, other.identificationNumber)
.append(phone, other.phone)
.append(mobilePhone, other.mobilePhone)
.isEquals();
}
@Override
public String toString() {
return "Person [title=" + title + ", firstName=" + firstName + ", lastName=" + lastName + ", identificationNumber=" + identificationNumber
+ ", phone=" + phone + ", mobilePhone=" + mobilePhone + ", email=" + email + ", fax=" + fax + ", active=" + active + "]";
}
@Override
public int compareTo(Person employee) {
return getFullName().compareTo(employee.getFullName());
}
}