Incoterm.java

package com.tradecloud.domain.common;

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


/**
 * <p>
 * Java class for Incoterm.
 *
 * <p>
 * The following schema fragment specifies the expected content contained within
 * this class.
 * <p>
 *
 * <pre>
 * &lt;simpleType name="Incoterm">
 *   &lt;restriction base="{http://www.w3.org/2001/XMLSchema}token">
 *     &lt;enumeration value="EXW"/>
 *     &lt;enumeration value="FCA"/>
 *     &lt;enumeration value="FCA2"/>
 *     &lt;enumeration value="FAS"/>
 *     &lt;enumeration value="FOB"/>
 *     &lt;enumeration value="CFR"/>
 *     &lt;enumeration value="CIF"/>
 *     &lt;enumeration value="CPT"/>
 *     &lt;enumeration value="CIP"/>
 *     &lt;enumeration value="DAF"/>
 *     &lt;enumeration value="DES"/>
 *     &lt;enumeration value="DEQ"/>
 *     &lt;enumeration value="DDU"/>
 *     &lt;enumeration value="DDP"/>
 *   &lt;/restriction>
 * &lt;/simpleType>
 * </pre>
 * <p>
 * Example: <incoterm code="EXW" name="Ex Works" /> <incoterm code="FCA"
 * name="Free Carrier" /> <incoterm code="FCA2" name="Free Carrier" />
 */
@Entity
@Table(name = "incoterm", uniqueConstraints = {@UniqueConstraint(columnNames = {"code"})})
@NamedQueries({
    @NamedQuery(name = "incoterm.byCostingContextAndOrgUnitAssociatedToCostSetup",
        query = "from Incoterm i where i in (select distinct incoterm from CostDefinition where costingContextType = :costingContextType "
                        + "and organisationalUnit = :organisationalUnit and costableCostDefinition='f' and active='t')"),
    @NamedQuery(name = "incoterm.byCostingContextAssociatedToCostSetup",
        query = "from Incoterm i where i in (select distinct incoterm from CostDefinition where costingContextType = :costingContextType " +
                "and costableCostDefinition='f' and active='t') order by i.code desc"),
    @NamedQuery(name = "incoterm.byActiveIncoTerm",
        query = "from Incoterm i where i.active=true")})
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Incoterm")
//@Cacheable(value = "incoterm")
public class Incoterm extends IntegratedStaticDataEntityBase {

    /**
     * UID.
     */
    private static final long serialVersionUID = -2886804756569893010L;
    private static final short INCOTERM_CODE_SIZE = 3;
    private static final short INCOTERM_CODE_SIZE_ALT = 4;

    public Incoterm(String code, String name) {
        if (code.length() == INCOTERM_CODE_SIZE || code.length() == INCOTERM_CODE_SIZE_ALT) {
            setCode(code);
            setName(name);
        } else {
            throw new IllegalArgumentException("Incoterm code must be of length: " + INCOTERM_CODE_SIZE + " or " + INCOTERM_CODE_SIZE_ALT);
        }
    }

    public Incoterm(String code) {
        super(code, null);
    }

    public Incoterm() {
    }

    public static Incoterm findClosestIncoterm(Incoterm targetIncoterm, List<Incoterm> incoterms, boolean b, boolean c) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String toString() {
        return getCode() + " (" + getName() + ")";
    }
}