AgentValueOverrides.java

package com.tradecloud.domain.agent;

import com.tradecloud.common.base.PersistenceBase;
import com.tradecloud.domain.common.Currency;
import com.tradecloud.domain.document.invoice.UnitPricePerItem;
import com.tradecloud.domain.model.payment.ActualPaymentBasis;
import com.tradecloud.domain.model.payment.EstimatedPaymentBasis;
import com.tradecloud.domain.model.payment.PaymentMethod;
import com.tradecloud.domain.model.payment.PaymentTerm;
import com.tradecloud.domain.party.Bank;
import com.tradecloud.domain.party.ServiceProvider;
import com.tradecloud.domain.party.base.Address;
import com.tradecloud.domain.party.base.Contact;
import com.tradecloud.domain.party.base.ValueOverrides;
import com.tradecloud.domain.place.PlaceOfExpiry;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.ForeignKey;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.*;
import java.math.BigDecimal;
import java.util.List;

/**
 * Used for holding any value overrides of the default agent values.
 * We don't want to extend Abstract agent here as Hibernate will then include it in the various
 * search results.
 */
@Entity
@Table(name = "agentvalueoverrides")
// , uniqueConstraints = { @UniqueConstraint(columnNames = { "organisationalunitagent_id" }) })
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "AgentValueOverrides")
public class AgentValueOverrides extends PersistenceBase implements ValueOverrides {

    @OneToOne
    @NotNull
    @XmlTransient
    private OrganisationalUnitAgent organisationalUnitAgent;

    @XmlAttribute
    private Boolean active;

    /**
     * UID.
     */
    private static final long serialVersionUID = 1L;

    @OneToOne(cascade = CascadeType.ALL)
    @XmlElement(name = "PhysicalAddress")
    private Address physicalAddress;

    @OneToOne(cascade = CascadeType.ALL)
    @XmlElement(name = "PostalAddress")
    private Address postalAddress;

    @OneToMany(cascade = CascadeType.ALL)
    @Fetch(value = FetchMode.SUBSELECT)
    @XmlElementWrapper(name = "Contacts")
    @XmlElement(name = "Contact")
    private List<Contact> contacts;

    @ManyToOne
    @XmlElement(name = "PaymentTerm", required = true)
    private PaymentTerm paymentTerm;

    @ManyToOne
    @XmlElement(name = "PaymentMethod", required = true)
    private PaymentMethod paymentMethod;

    @ManyToOne
    @XmlElement(name = "EstimatedPaymentBasis", required = true)
    private EstimatedPaymentBasis estimatedPaymentBasis;

    @ManyToOne
    @XmlElement(name = "ActualPaymentBasis", required = true)
    private ActualPaymentBasis actualPaymentBasis;

    @ManyToOne
    @XmlElement(name = "Currency", required = true)
    @ForeignKey(name = "fk_currency")
    private Currency currency;

    @Enumerated(value = EnumType.STRING)
    @XmlAttribute
    private UnitPricePerItem unitPricePerItem;

    /**
     * The freight forwarder used by this agent.
     */
    @XmlElement(name = "FreightForwarder")
    @ManyToOne
    @ForeignKey(name = "fk_freightforwarder")
    private ServiceProvider freightForwarder;

    /**
     * The agent who will be responsible for clearing this agent's goods.
     */
    @XmlElement(name = "ClearingAgent")
    @ManyToOne
    @ForeignKey(name = "fk_clearingagent")
    private ServiceProvider clearingAgent;

    /**
     * The transporter who will transport this agent's goods to the final destination.
     */
    @XmlElement(name = "Transporter")
    @ManyToOne
    @ForeignKey(name = "fk_transporter")
    private ServiceProvider transporter;

    /**
     * Indicates if the agent supports part shipments.
     */
    @XmlAttribute(required = true)
    // @NotNull
    private Boolean allowPartShipment;

    /**
     * Indicates if the agent supports trans shipments.
     */
    @XmlAttribute(required = true)
    // @NotNull
    private Boolean allowTransShipment;

    /**
     * Indicates that a LC can be drawn for X% more than the face value of the LC. Should not be less than 0 and more than 10.
     */
    @XmlAttribute
    private BigDecimal lcToleranceAbove;

    /**
     * Indicates that a LC can be drawn for X% less than the face value of the LC. Should not be less than 0 or more than 10.
     */
    @XmlAttribute
    private BigDecimal lcToleranceBelow;

    @XmlAttribute
    private BigDecimal presentationDays;

    @ManyToOne
    @ForeignKey(name = "fk_placeOfExpiry")
    @XmlElement(name = "PlaceOfExpiry")
    private PlaceOfExpiry placeOfExpiry;

    @ManyToOne
    @XmlElement(name = "Bank")
    private Bank advisingBank;

    @XmlAttribute
    private String salesTaxRegistrationNumber;

    @XmlAttribute
    private String vatRegistrationNumber;

    @XmlAttribute
    private String companyRegistrationNumber;

    @XmlAttribute
    private String warehouseCode;

    /**
     * Constructor.
     */
    public AgentValueOverrides() {
        super();
    }

    public AgentValueOverrides(OrganisationalUnitAgent organisationalUnitAgent) {
        super();
        this.organisationalUnitAgent = organisationalUnitAgent;
    }

    public PaymentTerm getPaymentTerm() {
        return paymentTerm;
    }

    public void setPaymentTerm(PaymentTerm paymentTerm) {
        this.paymentTerm = paymentTerm;
    }

    public PaymentMethod getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(PaymentMethod paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    public EstimatedPaymentBasis getEstimatedPaymentBasis() {
        return estimatedPaymentBasis;
    }

    public void setEstimatedPaymentBasis(EstimatedPaymentBasis estimatedPaymentBasis) {
        this.estimatedPaymentBasis = estimatedPaymentBasis;
    }

    public ActualPaymentBasis getActualPaymentBasis() {
        return actualPaymentBasis;
    }

    public void setActualPaymentBasis(ActualPaymentBasis actualPaymentBasis) {
        this.actualPaymentBasis = actualPaymentBasis;
    }

    public Currency getCurrency() {
        return currency;
    }

    public void setCurrency(Currency currency) {
        this.currency = currency;
    }

    public UnitPricePerItem getUnitPricePerItem() {
        return unitPricePerItem;
    }

    public void setUnitPricePerItem(UnitPricePerItem unitPricePerItem) {
        this.unitPricePerItem = unitPricePerItem;
    }

    public ServiceProvider getFreightForwarder() {
        return freightForwarder;
    }

    public void setFreightForwarder(ServiceProvider freightForwarder) {
        this.freightForwarder = freightForwarder;
    }

    public ServiceProvider getClearingAgent() {
        return clearingAgent;
    }

    public void setClearingAgent(ServiceProvider clearingAgent) {
        this.clearingAgent = clearingAgent;
    }

    public ServiceProvider getTransporter() {
        return transporter;
    }

    public void setTransporter(ServiceProvider transporter) {
        this.transporter = transporter;
    }

    public Boolean getAllowPartShipment() {
        return allowPartShipment;
    }

    public void setAllowPartShipment(Boolean allowPartShipment) {
        this.allowPartShipment = allowPartShipment;
    }

    public Boolean getAllowTransShipment() {
        return allowTransShipment;
    }

    public void setAllowTransShipment(Boolean allowTransShipment) {
        this.allowTransShipment = allowTransShipment;
    }

    public BigDecimal getLcToleranceAbove() {
        return lcToleranceAbove;
    }

    public void setLcToleranceAbove(BigDecimal lcToleranceAbove) {
        this.lcToleranceAbove = lcToleranceAbove;
    }

    public BigDecimal getLcToleranceBelow() {
        return lcToleranceBelow;
    }

    public void setLcToleranceBelow(BigDecimal lcToleranceBelow) {
        this.lcToleranceBelow = lcToleranceBelow;
    }

    public BigDecimal getPresentationDays() {
        return presentationDays;
    }

    public void setPresentationDays(BigDecimal presentationDays) {
        this.presentationDays = presentationDays;
    }

    public PlaceOfExpiry getPlaceOfExpiry() {
        return placeOfExpiry;
    }

    public void setPlaceOfExpiry(PlaceOfExpiry placeOfExpiry) {
        this.placeOfExpiry = placeOfExpiry;
    }

    public Bank getAdvisingBank() {
        return advisingBank;
    }

    public void setAdvisingBank(Bank advisingBank) {
        this.advisingBank = advisingBank;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    public Address getPhysicalAddress() {
        return physicalAddress;
    }

    public void setPhysicalAddress(Address physicalAddress) {
        this.physicalAddress = physicalAddress;
    }

    public Address getPostalAddress() {
        return postalAddress;
    }

    public void setPostalAddress(Address postalAddress) {
        this.postalAddress = postalAddress;
    }

    public List<Contact> getContacts() {
        return contacts;
    }

    public void setContacts(List<Contact> contacts) {
        this.contacts = contacts;
    }

    public String getSalesTaxRegistrationNumber() {
        return salesTaxRegistrationNumber;
    }

    public void setSalesTaxRegistrationNumber(String salesTaxRegistrationNumber) {
        this.salesTaxRegistrationNumber = salesTaxRegistrationNumber;
    }

    public String getVatRegistrationNumber() {
        return vatRegistrationNumber;
    }

    public void setVatRegistrationNumber(String vatRegistrationNumber) {
        this.vatRegistrationNumber = vatRegistrationNumber;
    }

    public String getCompanyRegistrationNumber() {
        return companyRegistrationNumber;
    }

    public void setCompanyRegistrationNumber(String companyRegistrationNumber) {
        this.companyRegistrationNumber = companyRegistrationNumber;
    }

    public String getWarehouseCode() {
        return warehouseCode;
    }

    public void setWarehouseCode(String warehouseCode) {
        this.warehouseCode = warehouseCode;
    }

    public OrganisationalUnitAgent getOrganisationalUnitAgent() {
        return organisationalUnitAgent;
    }

    public void setOrganisationalUnitAgent(OrganisationalUnitAgent organisationalUnitAgent) {
        this.organisationalUnitAgent = organisationalUnitAgent;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((actualPaymentBasis == null) ? 0 : actualPaymentBasis.hashCode());
        result = prime * result + ((advisingBank == null) ? 0 : advisingBank.hashCode());
        result = prime * result + ((allowPartShipment == null) ? 0 : allowPartShipment.hashCode());
        result = prime * result + ((allowTransShipment == null) ? 0 : allowTransShipment.hashCode());
        result = prime * result + ((clearingAgent == null) ? 0 : clearingAgent.hashCode());
        result = prime * result + ((contacts == null) ? 0 : contacts.hashCode());
        result = prime * result + ((currency == null) ? 0 : currency.hashCode());
        result = prime * result + ((companyRegistrationNumber == null) ? 0 : companyRegistrationNumber.hashCode());
        result = prime * result + ((estimatedPaymentBasis == null) ? 0 : estimatedPaymentBasis.hashCode());
        result = prime * result + ((freightForwarder == null) ? 0 : freightForwarder.hashCode());
        result = prime * result + ((lcToleranceAbove == null) ? 0 : lcToleranceAbove.hashCode());
        result = prime * result + ((lcToleranceBelow == null) ? 0 : lcToleranceBelow.hashCode());
        result = prime * result + ((organisationalUnitAgent == null) ? 0 : organisationalUnitAgent.hashCode());
        result = prime * result + ((paymentMethod == null) ? 0 : paymentMethod.hashCode());
        result = prime * result + ((paymentTerm == null) ? 0 : paymentTerm.hashCode());
        result = prime * result + ((physicalAddress == null) ? 0 : physicalAddress.hashCode());
        result = prime * result + ((placeOfExpiry == null) ? 0 : placeOfExpiry.hashCode());
        result = prime * result + ((postalAddress == null) ? 0 : postalAddress.hashCode());
        result = prime * result + ((presentationDays == null) ? 0 : presentationDays.hashCode());
        result = prime * result + ((salesTaxRegistrationNumber == null) ? 0 : salesTaxRegistrationNumber.hashCode());
        result = prime * result + ((transporter == null) ? 0 : transporter.hashCode());
        result = prime * result + ((unitPricePerItem == null) ? 0 : unitPricePerItem.hashCode());
        result = prime * result + ((vatRegistrationNumber == null) ? 0 : vatRegistrationNumber.hashCode());
        result = prime * result + ((warehouseCode == null) ? 0 : warehouseCode.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (getClass() != obj.getClass())
            return false;
        AgentValueOverrides other = (AgentValueOverrides) obj;
        if (actualPaymentBasis == null) {
            if (other.actualPaymentBasis != null)
                return false;
        } else if (!actualPaymentBasis.equals(other.actualPaymentBasis))
            return false;
        if (advisingBank == null) {
            if (other.advisingBank != null)
                return false;
        } else if (!advisingBank.equals(other.advisingBank))
            return false;
        if (allowPartShipment == null) {
            if (other.allowPartShipment != null)
                return false;
        } else if (!allowPartShipment.equals(other.allowPartShipment))
            return false;
        if (allowTransShipment == null) {
            if (other.allowTransShipment != null)
                return false;
        } else if (!allowTransShipment.equals(other.allowTransShipment))
            return false;
        if (clearingAgent == null) {
            if (other.clearingAgent != null)
                return false;
        } else if (!clearingAgent.equals(other.clearingAgent))
            return false;
        if (contacts == null) {
            if (other.contacts != null)
                return false;
        } else if (!contacts.equals(other.contacts))
            return false;
        if (currency == null) {
            if (other.currency != null)
                return false;
        } else if (!currency.equals(other.currency))
            return false;
        if (companyRegistrationNumber == null) {
            if (other.companyRegistrationNumber != null)
                return false;
        } else if (!companyRegistrationNumber.equals(other.companyRegistrationNumber))
            return false;
        if (estimatedPaymentBasis == null) {
            if (other.estimatedPaymentBasis != null)
                return false;
        } else if (!estimatedPaymentBasis.equals(other.estimatedPaymentBasis))
            return false;
        if (freightForwarder == null) {
            if (other.freightForwarder != null)
                return false;
        } else if (!freightForwarder.equals(other.freightForwarder))
            return false;
        if (lcToleranceAbove == null) {
            if (other.lcToleranceAbove != null)
                return false;
        } else if (!lcToleranceAbove.equals(other.lcToleranceAbove))
            return false;
        if (lcToleranceBelow == null) {
            if (other.lcToleranceBelow != null)
                return false;
        } else if (!lcToleranceBelow.equals(other.lcToleranceBelow))
            return false;
        if (organisationalUnitAgent == null) {
            if (other.organisationalUnitAgent != null)
                return false;
        } else if (!organisationalUnitAgent.equals(other.organisationalUnitAgent))
            return false;
        if (paymentMethod == null) {
            if (other.paymentMethod != null)
                return false;
        } else if (!paymentMethod.equals(other.paymentMethod))
            return false;
        if (paymentTerm == null) {
            if (other.paymentTerm != null)
                return false;
        } else if (!paymentTerm.equals(other.paymentTerm))
            return false;
        if (physicalAddress == null) {
            if (other.physicalAddress != null)
                return false;
        } else if (!physicalAddress.equals(other.physicalAddress))
            return false;
        if (placeOfExpiry == null) {
            if (other.placeOfExpiry != null)
                return false;
        } else if (!placeOfExpiry.equals(other.placeOfExpiry))
            return false;
        if (postalAddress == null) {
            if (other.postalAddress != null)
                return false;
        } else if (!postalAddress.equals(other.postalAddress))
            return false;
        if (presentationDays == null) {
            if (other.presentationDays != null)
                return false;
        } else if (!presentationDays.equals(other.presentationDays))
            return false;
        if (salesTaxRegistrationNumber == null) {
            if (other.salesTaxRegistrationNumber != null)
                return false;
        } else if (!salesTaxRegistrationNumber.equals(other.salesTaxRegistrationNumber))
            return false;
        if (transporter == null) {
            if (other.transporter != null)
                return false;
        } else if (!transporter.equals(other.transporter))
            return false;
        if (unitPricePerItem != other.unitPricePerItem)
            return false;
        if (vatRegistrationNumber == null) {
            if (other.vatRegistrationNumber != null)
                return false;
        } else if (!vatRegistrationNumber.equals(other.vatRegistrationNumber))
            return false;
        if (warehouseCode == null) {
            if (other.warehouseCode != null)
                return false;
        } else if (!warehouseCode.equals(other.warehouseCode))
            return false;
        return true;
    }

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }

}