AirShipment.java

package com.tradecloud.domain.shipment;

import com.tradecloud.common.base.HibernateUtils;
import com.tradecloud.domain.item.WeightUnitOfMeasure;
import com.tradecloud.domain.model.shipment.ShippingMode;
import com.tradecloud.domain.party.ServiceProvider;
import com.tradecloud.domain.place.City;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.ForeignKey;
import org.springframework.stereotype.Component;

import javax.persistence.*;
import javax.validation.constraints.Size;
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.math.BigDecimal;
import java.util.Date;
import java.util.Set;

@Entity
@DiscriminatorValue("AIR_SHIPMENT")
@Table(name = "airshipment")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "AirShipment")
@Component
@Getter
@Setter
public class AirShipment extends Shipment implements Comparable<AirShipment>, AirShipmentInterface {

    private static final long serialVersionUID = 1L;

    @XmlAttribute
    @Size(max = 255)
    private String airlineName;

    @XmlAttribute
    @Size(max = 255)
    private String flightNumber;

    @XmlAttribute
    @Size(max = 255)
    private String houseAirwayBillNumber;

    @XmlAttribute
    @Size(max = 255)
    private String masterAirwayBillNumber;

    @XmlAttribute
    private Date houseAirwayBillIssueDate;

    @XmlAttribute
    private Date masterAirwayBillIssueDate;

    @ManyToOne
    protected City billPlaceOfIssue;

    @XmlAttribute
    private Date airwayBillSpot;

    @XmlAttribute
    private BigDecimal billOfLadingSpotRate;

    @XmlAttribute
    @Enumerated(EnumType.STRING)
    private ShippingMode shippingMode = ShippingMode.AIR;

    @ManyToOne(fetch = FetchType.LAZY)
    @ForeignKey(name = "fk_carrier")
    private ServiceProvider carrier;

    @ManyToOne(fetch = FetchType.LAZY)
    private ServiceProvider cargoCarrier;

    private BigDecimal chargeableWeight;

    @ManyToOne(fetch = FetchType.EAGER)
    private WeightUnitOfMeasure chargeableWeightUOM;

    public AirShipment() {
        super();
    }

    public AirShipment(String number, String reference) {
        super(number, reference);
    }

    public AirShipment(String number, String reference, String airlineName, String flightNumber, String houseAirwayBillNumber,
                       String masterAirwayBillNumber, Date houseAirwayBillIssueDate, Date masterAirwayBillIssueDate) {

        super(number, reference);
        this.airlineName = airlineName;
        this.flightNumber = flightNumber;
        this.houseAirwayBillNumber = houseAirwayBillNumber;
        this.masterAirwayBillNumber = masterAirwayBillNumber;
        this.houseAirwayBillIssueDate = houseAirwayBillIssueDate;
        this.masterAirwayBillIssueDate = masterAirwayBillIssueDate;
    }

    public AirShipment(String number, String reference, String airlineName, String flightNumber, String houseAirwayBillNumber,
                       String masterAirwayBillNumber, Date houseAirwayBillIssueDate, Date masterAirwayBillIssueDate,
                       Set<Transhipment> transhipments) {

        super(number, reference, transhipments);
        this.airlineName = airlineName;
        this.flightNumber = flightNumber;
        this.houseAirwayBillNumber = houseAirwayBillNumber;
        this.masterAirwayBillNumber = masterAirwayBillNumber;
        this.houseAirwayBillIssueDate = houseAirwayBillIssueDate;
        this.masterAirwayBillIssueDate = masterAirwayBillIssueDate;
    }

    @Override
    public String getAirlineName() {
        return this.airlineName;
    }

    public void setAirlineName(String airlineName) {
        this.airlineName = airlineName;
    }

    @Override
    public String getFlightNumber() {
        return this.flightNumber;
    }

    public void setFlightNumber(String flightNumber) {
        this.flightNumber = flightNumber;
    }

    @Override
    public String getHouseAirwayBillNumber() {
        return this.houseAirwayBillNumber;
    }

    public void setHouseAirwayBillNumber(String houseAirwayBillNumber) {
        this.houseAirwayBillNumber = houseAirwayBillNumber;
    }

    @Override
    public String getMasterAirwayBillNumber() {
        return this.masterAirwayBillNumber;
    }

    public void setMasterAirwayBillNumber(String masterAirwayBillNumber) {
        this.masterAirwayBillNumber = masterAirwayBillNumber;
    }

    @Override
    public Date getHouseAirwayBillIssueDate() {
        return this.houseAirwayBillIssueDate;
    }

    public void setHouseAirwayBillIssueDate(Date houseAirwayBillIssueDate) {
        this.houseAirwayBillIssueDate = houseAirwayBillIssueDate;
    }

    public ServiceProvider getCarrier() {
        return carrier;
    }

    public void setCarrier(ServiceProvider carrier) {
        this.carrier = carrier;
    }

    public ServiceProvider getCargoCarrier() {
        return cargoCarrier;
    }

    public void setCargoCarrier(ServiceProvider cargoCarrier) {
        this.cargoCarrier = cargoCarrier;
    }

    @Override
    public Date getMasterAirwayBillIssueDate() {
        return this.masterAirwayBillIssueDate;
    }

    public void setMasterAirwayBillIssueDate(Date masterAirwayBillIssueDate) {
        this.masterAirwayBillIssueDate = masterAirwayBillIssueDate;
    }

    @Override
    public Date getAirwayBillSpot() {
        return airwayBillSpot;
    }

    public void setAirwayBillSpot(Date airwayBillSpot) {
        this.airwayBillSpot = airwayBillSpot;
    }

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

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        // Do not use class.equals. This can return false for proxy objects
        if (!HibernateUtils.proxyClassEquals(this, obj)) {
            return false;
        }
        AirShipment other = (AirShipment) HibernateUtils.initializeAndUnproxy(obj);
        return new EqualsBuilder()
                .appendSuper(super.equals(other))
                .append(airlineName, other.getAirlineName())
                .append(flightNumber, other.getFlightNumber())
                .append(shippingMode, other.getShippingMode())
                .isEquals();
    }

    @Override
    public String toString() {
        return "AirShipment [airlineName=" + airlineName + ", flightNumber=" + flightNumber + ", houseAirwayBillNumber=" + houseAirwayBillNumber
                + ", masterAirwayBillNumber=" + masterAirwayBillNumber + ", houseAirwayBillIssueDate=" + houseAirwayBillIssueDate
                + ", masterAirwayBillIssueDate=" + masterAirwayBillIssueDate + "]";
    }

    @Override
    public ShippingMode getShippingMode() {
        return shippingMode;
    }

    @Override
    public int compareTo(AirShipment other) {
        return getNumber().compareTo(other.getNumber());
    }

    @Override
    public Date getBillOfLadingDate() {
        return getHouseAirwayBillIssueDate();
    }

    @Override
    public AirShipment initialize() {
        HibernateUtils.initializeAndUnproxy(getCarrier());
        return (AirShipment) super.initialize();
    }

    public City getBillPlaceOfIssue() {
        return billPlaceOfIssue;
    }

    public void setBillPlaceOfIssue(City billPlaceOfIssue) {
        this.billPlaceOfIssue = billPlaceOfIssue;
    }

    @Override
    public BigDecimal getBillOfLadingSpotRate() {
        return billOfLadingSpotRate;
    }

    @Override
    public void setBillOfLadingSpotRate(BigDecimal billOfLadingSpotRate) {
        this.billOfLadingSpotRate = billOfLadingSpotRate;
    }

    @Override
    public ShippingMode getMultiModalShippingMode() {
        return getShippingInfo().getMultiModalShippingMode();
    }

    public WeightUnitOfMeasure getChargeableWeightUOM() {
        return chargeableWeightUOM;
    }

    public void setChargeableWeightUOM(WeightUnitOfMeasure chargeableWeightUOM) {
        this.chargeableWeightUOM = chargeableWeightUOM;
    }

    public BigDecimal getChargeableWeight() {
        return chargeableWeight;
    }

    public void setChargeableWeight(BigDecimal chargeableWeight) {
        this.chargeableWeight = chargeableWeight;
    }
}