InternalProvisionsRate.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tradecloud.domain.rate;

import com.tradecloud.domain.container.ContainerType;
import com.tradecloud.domain.item.ItemCategory;
import com.tradecloud.domain.model.organisationalunit.Brand;
import com.tradecloud.domain.model.organisationalunit.OrganisationalUnit;
import com.tradecloud.domain.model.payment.PaymentMethod;
import com.tradecloud.domain.model.payment.PaymentTerm;
import com.tradecloud.domain.party.Employee;
import com.tradecloud.domain.place.FinalDestination;
import com.tradecloud.domain.place.PlaceOfDischarge;
import com.tradecloud.domain.supplier.Supplier;

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

@Entity
@Table(name = "internalprovisionsrate")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "InternalProvisionsRate")
public class InternalProvisionsRate extends Rate {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    @ManyToOne
    private Employee buyer;

    @ManyToOne
    private Supplier supplier;

    @ManyToOne
    private PaymentMethod paymentMethod;

    @ManyToOne
    private PaymentTerm paymentTerm;

    @ManyToOne
    private ContainerType containerType;

    @ManyToOne
    private PlaceOfDischarge placeOfDischarge;

    @ManyToOne
    private FinalDestination finalDestination;

    @ManyToOne
    private ItemCategory itemCategory;

    @ManyToOne
    private OrganisationalUnit company;

    @ManyToOne
    protected Brand brand;

    public Employee getBuyer() {
        return buyer;
    }

    public void setBuyer(Employee buyer) {
        this.buyer = buyer;
    }

    public Supplier getSupplier() {
        return supplier;
    }

    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
    }

    public PaymentMethod getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(PaymentMethod paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    public PaymentTerm getPaymentTerm() {
        return paymentTerm;
    }

    public void setPaymentTerm(PaymentTerm paymentTerm) {
        this.paymentTerm = paymentTerm;
    }

    public ContainerType getContainerType() {
        return containerType;
    }

    public void setContainerType(ContainerType containerType) {
        this.containerType = containerType;
    }

    public PlaceOfDischarge getPlaceOfDischarge() {
        return placeOfDischarge;
    }

    public void setPlaceOfDischarge(PlaceOfDischarge placeOfDischarge) {
        this.placeOfDischarge = placeOfDischarge;
    }

    public FinalDestination getFinalDestination() {
        return finalDestination;
    }

    public void setFinalDestination(FinalDestination finalDestination) {
        this.finalDestination = finalDestination;
    }

    public ItemCategory getItemCategory() {
        return itemCategory;
    }

    public void setItemCategory(ItemCategory itemCategory) {
        this.itemCategory = itemCategory;
    }

    public OrganisationalUnit getCompany() {
        return company;
    }

    public void setCompany(OrganisationalUnit company) {
        this.company = company;
    }

    public Brand getBrand() {
        return brand;
    }

    public void setBrand(Brand brand) {
        this.brand = brand;
    }

    @Override
    public String toString() {
        return super.toString() +
                "Organisational Unit: '" + Optional.ofNullable(getOrganisationalUnit()).map(OrganisationalUnit::getName).orElse("") + "', " +
                "Buyer: '" + Optional.ofNullable(buyer).map(Employee::getFullName).orElse("") + "', " +
                "Supplier: '" + Optional.ofNullable(supplier).map(Supplier::getName).orElse("") + "', " +
                "Payment Method: '" + Optional.ofNullable(paymentMethod).map(PaymentMethod::getName).orElse("") + "', " +
                "Payment Term: '" + Optional.ofNullable(paymentTerm).map(PaymentTerm::getName).orElse("") + "', " +
                "Container Type: '" + Optional.ofNullable(containerType).map(ContainerType::getName).orElse("") + "', " +
                "Place of Discharge: '" + Optional.ofNullable(placeOfDischarge).map(PlaceOfDischarge::getName).orElse("") + "', " +
                "Final Destination: '" + Optional.ofNullable(finalDestination).map(FinalDestination::getName).orElse("") + "', " +
                "Category: '" + Optional.ofNullable(itemCategory).map(ItemCategory::getName).orElse("") + "', " +
                "Company: '" + Optional.ofNullable(company).map(OrganisationalUnit::getName).orElse("") + "'" +
                "Brand: '" + Optional.ofNullable(brand).map(Brand::getName).orElse("") + "'";
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) return false;
        if (!(obj instanceof InternalProvisionsRate)) {
            return false;
        }

        if (!super.equals(obj)) return false;

        InternalProvisionsRate other = (InternalProvisionsRate) obj;

        if (objectsEqual(containerType, other.getContainerType()) && objectsEqual(placeOfDischarge, other.getPlaceOfDischarge()) && objectsEqual
                (getOrganisationalUnit(), other.getOrganisationalUnit()) && objectsEqual(buyer, other.getBuyer()) && objectsEqual(supplier,
                other.getSupplier()) && objectsEqual(paymentMethod, other.getPaymentMethod()) && objectsEqual(paymentTerm,
                other.getPaymentTerm()) && objectsEqual(finalDestination, other.getFinalDestination()) &&
                objectsEqual(itemCategory, other.getItemCategory()) && objectsEqual(company, other.getCompany()) &&
                objectsEqual(brand, other.getBrand()))
            return true;

        return false;
    }
}