DealsEvent.java

package com.tradecloud.domain.event;

import com.tradecloud.domain.common.Currency;
import com.tradecloud.domain.model.organisationalunit.OrganisationalUnit;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.math.BigDecimal;
import java.util.Date;

/**
 * Created by ds on 2017/05/22.
 */

@Entity
@Table(name = "DealsEvent")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "DealsEvent")
public class DealsEvent extends Event implements EnumTypedEvent<DealsEventType> {

    @Enumerated(EnumType.STRING)
    private DealsEventType eventType;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "organisationalunit_id")
    private OrganisationalUnit organisationalUnit;

    @ManyToOne
    private Currency currency;

    @Column(precision = 19, scale = 15)
    private BigDecimal value;

    private Date shipmentDate;
    //Just the id of the deal
    private Long dealUniqueRef;

    private String reference;

    public DealsEvent(String username, String reference, DealsEventType eventType, OrganisationalUnit organisationalUnit, Currency currency,
                      BigDecimal value, Date shipmentDate, Long dealUniqueRef) {
        super(username);
        this.reference = reference;
        this.eventType = eventType;
        this.organisationalUnit = organisationalUnit;
        this.currency = currency;
        this.value = value;
        this.shipmentDate = shipmentDate;
        this.dealUniqueRef = dealUniqueRef;
    }

    public DealsEvent() {
    }

    @Override
    public DealsEventType getEventType() {
        return eventType;
    }

    @Override
    public void setEventType(DealsEventType eventType) {
        this.eventType = eventType;
    }

    public OrganisationalUnit getOrganisationalUnit() {
        return organisationalUnit;
    }

    public void setOrganisationalUnit(OrganisationalUnit organisationalUnit) {
        this.organisationalUnit = organisationalUnit;
    }

    public Currency getCurrency() {
        return currency;
    }

    public void setCurrency(Currency currency) {
        this.currency = currency;
    }

    public BigDecimal getValue() {
        return value;
    }

    public void setValue(BigDecimal value) {
        this.value = value;
    }

    public Date getShipmentDate() {
        return shipmentDate;
    }

    public void setShipmentDate(Date shipmentDate) {
        this.shipmentDate = shipmentDate;
    }

    public Long getDealUniqueRef() {
        return dealUniqueRef;
    }

    public void setDealUniqueRef(Long dealUniqueRef) {
        this.dealUniqueRef = dealUniqueRef;
    }

    public String getReference() {
        return reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        DealsEvent that = (DealsEvent) o;

        return dealUniqueRef.equals(that.dealUniqueRef);
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + dealUniqueRef.hashCode();
        return result;
    }
}