SABSTariff.java

package com.tradecloud.domain.sabs;

import com.tradecloud.domain.common.Currency;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;

/**
 * SABS Tariff Library.
 */
@Entity
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlRootElement(name = "SabsTariff")
@Table(name = "sabstariff", uniqueConstraints = {@UniqueConstraint(columnNames = {"effectiveDate", "code"})})
@NamedQueries({@NamedQuery(name = "findSabsTariffById",
        query = "from SABSTariff sabstariff left join fetch sabstariff.events where sabstariff.id=:id")})
public class SABSTariff extends AbstractSABSTariff implements Comparable<SABSTariff> {

    public SABSTariff() {
    }

    public SABSTariff(String description) {
        super(description);
    }

    public SABSTariff(String description, Date effectiveDate) {
        super(description, effectiveDate);
    }

    public SABSTariff(String description, Date effectiveDate, Currency currency, String code, String category) {
        super(description, effectiveDate, currency, code, category);
    }

    private static final long serialVersionUID = 1L;

    /**
     * TODO - just using values from the parent for now.
     */
    @Override
    public int compareTo(SABSTariff sABSTariff) {
        if (getDescription() != null) {
            if (getDescription().compareTo(sABSTariff.getDescription()) != 0) {
                return getDescription().compareTo(sABSTariff.getDescription());
            }
        }

        if (getEffectiveDate() != null) {
            if (getEffectiveDate().compareTo(sABSTariff.getEffectiveDate()) != 0) {
                return getEffectiveDate().compareTo(sABSTariff.getEffectiveDate());
            }
        }

        if (getCurrency() != null) {
            if (getCurrency().compareTo(sABSTariff.getCurrency()) != 0) {
                return getCurrency().compareTo(sABSTariff.getCurrency());
            }
        }

        if (getCategory() != null) {
            if (getCategory().compareTo(sABSTariff.getCategory()) != 0) {
                return getCategory().compareTo(sABSTariff.getCategory());
            }
        }

        if (getCode() != null) {
            if (getCode().compareTo(sABSTariff.getCode()) != 0) {
                return getCode().compareTo(sABSTariff.getCode());
            }
        }

        return 0;
    }

    @XmlID
    public String getIdStr() {
        return String.valueOf(super.getId());
    }

    public String getDescriptionCode() {
        return getDescription() + " - " + getCode();
    }

}