PlaceOfLoading.java

package com.tradecloud.domain.place;

import com.tradecloud.domain.common.IntegratedStaticDataEntityBase;
import com.tradecloud.domain.model.shipment.ShippingMode;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 */
@Entity
@Table(name = "placeofloading")
@XmlRootElement(name = "PlaceOfLoading")
public class PlaceOfLoading extends IntegratedStaticDataEntityBase {

    private static final long serialVersionUID = 1L;

    @NotNull
    private boolean exportPlace;

    @NotNull
    private boolean importPlace;

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

    @ManyToOne(fetch = FetchType.LAZY)
    @NotNull
    private Country country;

    @ManyToOne(fetch = FetchType.LAZY)
    private Region region;

    @ManyToOne(fetch = FetchType.LAZY)
    private City city;

    @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
    private ControllingOffice controllingOffice;

    @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
    private ContainerFreightStation containerFreightStation;

    public PlaceOfLoading() {
    }

    public PlaceOfLoading(String code, String name) {
        setCode(code);
        setName(name);
        setActive(true);
    }

    public PlaceOfLoading(String code, String name, ShippingMode shippingMode, Country country) {
        super();
        setCode(code);
        setName(name);
        setActive(true);
        setShippingMode(shippingMode);
        setCountry(country);
    }

    public PlaceOfLoading(String code, String name, ShippingMode shippingMode, Country country, ControllingOffice controllingOffice) {
        super();
        setCode(code);
        setName(name);
        setActive(true);
        setShippingMode(shippingMode);
        setCountry(country);
        setControllingOffice(controllingOffice);
    }

    public boolean isExportPlace() {
        return exportPlace;
    }

    public void setExportPlace(boolean exportPlace) {
        this.exportPlace = exportPlace;
    }

    public boolean isImportPlace() {
        return importPlace;
    }

    public void setImportPlace(boolean importPlace) {
        this.importPlace = importPlace;
    }

    public ShippingMode getShippingMode() {
        return shippingMode;
    }

    public void setShippingMode(ShippingMode shippingMode) {
        this.shippingMode = shippingMode;
    }

    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    public Region getRegion() {
        return region;
    }

    public void setRegion(Region region) {
        this.region = region;
    }

    @Override
    public int hashCode() {
        // Removing country, so it can be lazy loaded
        return new HashCodeBuilder()
                .append(getName())
                .append(getActive()).append(getCode())
                //.append(getCountry().getCode())
                .append(getShippingMode())
                .toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof PlaceOfLoading)) {
            return false;
        }
        PlaceOfLoading other = (PlaceOfLoading) obj;
        // Removing country, so it can be lazy loaded
        return new EqualsBuilder()
                .append(getCode(), other.getCode())
                .append(getName(), other.getName())
                .append(getActive(), other.getActive())
                .append(getShippingMode(), other.getShippingMode())
                .append(getControllingOffice(), other.getControllingOffice())
                .isEquals();
    }

    @Override
    public String toString() {
        // Removing country, so it can be lazy loaded
        return "PlaceOfLoading [shippingMode=" + shippingMode + ", country=" /*+ country.getCode() + ", getCode()=" + getCode()*/ + ", getName()="
                + getName() + ", getActive()=" + getActive() + ", getClass()=" + getClass() + "]";
    }

    public void setControllingOffice(ControllingOffice controllingOffice) {
        this.controllingOffice = controllingOffice;
    }

    public ControllingOffice getControllingOffice() {
        return controllingOffice;
    }

    public ContainerFreightStation getContainerFreightStation() {
        return containerFreightStation;
    }

    public void setContainerFreightStation(ContainerFreightStation containerFreightStation) {
        this.containerFreightStation = containerFreightStation;
    }

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }
}