SettlementDateCalculation.java

package com.tradecloud.domain.settlement;

import com.tradecloud.common.base.PersistenceBase;
import com.tradecloud.domain.costing.CostGroup;
import com.tradecloud.domain.costing.CostingType;
import com.tradecloud.domain.model.payment.PaymentBasis;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.NaturalId;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;

/**
 * Entity that captures the settlement date calculation info for a specific cost group.
 */
@Entity
@Table(name = "settlementdatecalculation")
@NamedQueries({@NamedQuery(name = "findAllOrderByTypeDescAndCostGroupAsc",
        query = "from SettlementDateCalculation order by costingType desc, costGroup")})
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "SettlementDateCalculation")
public class SettlementDateCalculation extends PersistenceBase implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * The costing type i.e. CLC or ALC.
     */
    @XmlAttribute(required = true)
    @Enumerated(value = EnumType.STRING)
    @NotNull(message = "Costing type is required")
    @Column(nullable = false)
    @NaturalId
    private CostingType costingType;

    /**
     * The indirect cost group.
     */
    @XmlAttribute(required = true)
    @Enumerated(value = EnumType.STRING)
    @NotNull(message = "Cost group is required")
    @Column(nullable = false)
    @NaturalId
    private CostGroup costGroup;

    /**
     * Number of days to be added to the consignment date to calculate the settlement date.
     */
    @XmlAttribute(required = true)
    @NotNull(message = "Number of days is required")
    @Column(nullable = false)
    private int numberOfDays;

    /**
     * A set of basis dates to be used in the settlement date calculation.
     */
    @XmlAttribute(required = true)
    @OneToOne
    @ForeignKey(name = "fk_paymentbasis")
    @JoinColumn(name = "paymentbasis_code")
    @NotNull(message = "Payment basis is required")
    private PaymentBasis paymentBasis;

    public SettlementDateCalculation() {
    }

    public SettlementDateCalculation(CostingType costingType, CostGroup costGroup, int numberOfDays, PaymentBasis paymentBasis) {
        this.costingType = costingType;
        this.costGroup = costGroup;
        this.numberOfDays = numberOfDays;
        this.paymentBasis = paymentBasis;
    }

    public SettlementDateCalculation(SettlementDateCalculation settlementDateCalculation) {
        this.costingType = settlementDateCalculation.costingType;
        this.costGroup = settlementDateCalculation.costGroup;
        this.numberOfDays = settlementDateCalculation.numberOfDays;
        this.paymentBasis = settlementDateCalculation.paymentBasis;
    }

    public CostingType getCostingType() {
        return costingType;
    }

    public void setCostingType(CostingType costingType) {
        this.costingType = costingType;
    }

    public CostGroup getCostGroup() {
        return costGroup;
    }

    public void setCostGroup(CostGroup costGroup) {
        this.costGroup = costGroup;
    }

    public int getNumberOfDays() {
        return numberOfDays;
    }

    public void setNumberOfDays(int numberOfDays) {
        this.numberOfDays = numberOfDays;
    }

    public PaymentBasis getPaymentBasis() {
        return paymentBasis;
    }

    public void setPaymentBasis(PaymentBasis paymentBasis) {
        this.paymentBasis = paymentBasis;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(costingType).append(costGroup).toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof SettlementDateCalculation)) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        SettlementDateCalculation other = (SettlementDateCalculation) obj;
        return new EqualsBuilder().append(costingType, other.costingType).append(costGroup, other.costGroup).isEquals();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).append(costingType).append(costGroup).append(numberOfDays).append(paymentBasis).toString();
    }
}