Contact.java

package com.tradecloud.domain.party.base;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

@Entity
@Table(name = "contact", uniqueConstraints = {@UniqueConstraint(columnNames = {"firstname", "lastname"})})
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ContactType", propOrder = {"primaryContact", "externalReference", "function", "description", "correspondenceLanguage"})
public class Contact extends Person {

    private static final long serialVersionUID = 1L;

    /**
     * Reference from an external or third party system (external to Tradecloud).
     */
    @XmlAttribute
    protected String externalReference;

    @XmlAttribute
    protected boolean primaryContact;

    @XmlAttribute
    protected String function;

    @XmlAttribute
    protected String description;

    @XmlAttribute
    protected String correspondenceLanguage;

    @XmlAttribute
    private boolean registered;


    public Contact(boolean primaryContact, String firstName, String lastName) {
        super(firstName, lastName);
        this.primaryContact = primaryContact;
    }

    public Contact(String firstName, String lastName, boolean primaryContact, String externalReference, String function, String description,
                   String correspondenceLanguage) {
        super(firstName, lastName);
        this.primaryContact = primaryContact;
        this.externalReference = externalReference;
        this.function = function;
        this.description = description;
        this.correspondenceLanguage = correspondenceLanguage;
    }

    public Contact(Contact contact) {
        super(contact.getTitle(), contact.getFirstName(), contact.getLastName(), contact.getIdentificationNumber(),
                contact.getPhone(), contact.getEmail(), contact.getFax());
        this.primaryContact = contact.isPrimaryContact();
        this.externalReference = contact.getExternalReference();
        this.function = contact.getFunction();
        this.description = contact.getDescription();
        this.correspondenceLanguage = contact.getCorrespondenceLanguage();
    }

    public Contact() {
        super();
    }

    public boolean isPrimaryContact() {
        return primaryContact;
    }

    public void setPrimaryContact(boolean primaryContact) {
        this.primaryContact = primaryContact;
    }

    public String getFunction() {
        return function;
    }

    public void setFunction(String function) {
        this.function = function;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getCorrespondenceLanguage() {
        return correspondenceLanguage;
    }

    public void setCorrespondenceLanguage(String correspondenceLanguage) {
        this.correspondenceLanguage = correspondenceLanguage;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder()
                .appendSuper(super.hashCode())
                .append(description)
                .append(function)
                .append(correspondenceLanguage)
                .append(primaryContact)
                .toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Contact)) {
            return false;
        }
        Contact other = (Contact) obj;
        return new EqualsBuilder()
                .appendSuper(super.equals(other))
                .append(description, other.description)
                .append(function, other.function)
                .append(correspondenceLanguage, other.correspondenceLanguage)
                .append(primaryContact, other.primaryContact)
                .isEquals();
    }

    public int compareTo(Contact primaryContact2) {
        return getExternalReference().compareTo(primaryContact2.getExternalReference());
    }

    public String getExternalReference() {
        return externalReference;
    }

    public void setExternalReference(String externalReference) {
        this.externalReference = externalReference;
    }

    public boolean isRegistered() {
        return registered;
    }

    public void setRegistered(boolean registered) {
        this.registered = registered;
    }
}