Schedule3Part1.java

package com.tradecloud.domain.duties;

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

import javax.persistence.*;
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;
import java.math.BigDecimal;

/**
 * Entity representing Schedule 2 Part 1 - Anti-Dumping.
 */
@Entity
@Table(name = "schedule3Part1")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "schedule3Part1")
public class Schedule3Part1 extends TypedDutySchedule implements Serializable, Cloneable {

    private static final long serialVersionUID = 1L;

    @Transient
    public final int PART1_MAX_LENGTH = 3;

    /**
     * The method that will be used to calculate the "Other Duty" values.
     */
    @Enumerated(value = EnumType.STRING)
    @XmlAttribute
    private DutyCalculationMethod calculationMethod;

    @XmlAttribute
    @Enumerated(value = EnumType.STRING)
    private RebateOptions rebateOptions = RebateOptions.LESS;

    @XmlAttribute
    private String rebateCode;

    @XmlAttribute
    private boolean vatExemption;

    public Schedule3Part1() {
        super();
        if (getDutyRate() == null) {
            dutyRate = new TypedDutyRate();
            dutyRate.setValue(BigDecimal.ZERO);
            dutyRate.setPercentage(BigDecimal.valueOf(100));
            dutyRate.setOtherDuty1(new OtherDuty());
            dutyRate.setOtherDuty2(new OtherDuty());
            dutyRate.setOtherDuty3(new OtherDuty());
        }
        dutyRate.setType(DutyType.ORDINARY);
        dutyRate.setValue(BigDecimal.ZERO);
        dutyRate.setPercentage(BigDecimal.valueOf(100));
        ;
    }

    public Schedule3Part1(Schedule3Part1 schedule3Part1) {
        super(schedule3Part1);
        calculationMethod = schedule3Part1.calculationMethod;
        rebateOptions = schedule3Part1.rebateOptions;
    }

    public DutyCalculationMethod getCalculationMethod() {
        return calculationMethod;
    }

    public void setCalculationMethod(DutyCalculationMethod calculationMethod) {
        this.calculationMethod = calculationMethod;
    }

    @Override
    public Schedule3Part1 clone() {
        Schedule3Part1 clone = new Schedule3Part1();
        clone.setCalculationMethod(calculationMethod);
        clone.setTariffHeading(getTariffHeading() != null ? getTariffHeading().clone() : null);
        clone.setValid(isValid());
        clone.setDutyRate(dutyRate != null ? dutyRate.clone() : null);
        clone.setRebateOptions(rebateOptions);
        return clone;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).append("calculationMethod", calculationMethod).toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Schedule3Part1)) {
            return false;
        }
        Schedule3Part1 other = (Schedule3Part1) obj;
        return new EqualsBuilder().appendSuper(super.equals(obj)).append(calculationMethod, other.calculationMethod).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().appendSuper(super.hashCode()).append(calculationMethod).toHashCode();
    }

    @Override
    public String getCostlineCode() {
        return null;
    }

    @Override
    protected boolean getDoCheckProof() {
        return false;
    }

    @Override
    protected int getPart1MaxLength() {
        return PART1_MAX_LENGTH;
    }

    @Override
    protected boolean getDoCheckPercentage() {
        return false;
    }

    @Override
    protected boolean getDoCheckValue() {
        return true;
    }

    public RebateOptions getRebateOptions() {
        return rebateOptions;
    }

    public void setRebateOptions(RebateOptions rebateOptions) {
        this.rebateOptions = rebateOptions;
    }

    public String getRebateCode() {
        return rebateCode;
    }

    public void setRebateCode(String rebateCode) {
        this.rebateCode = rebateCode;
    }

    public boolean isVatExemption() {
        return vatExemption;
    }

    public void setVatExemption(boolean vatExemption) {
        this.vatExemption = vatExemption;
    }

    @Override
    public String getType() {
        return "S3";
    }
}