AddedCommentIncCost.java

package com.tradecloud.domain.comment;

import com.tradecloud.authentication.MultiTenantUtil;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

@Embeddable
@Access(AccessType.FIELD)
/**
 * This will also capture costing comments for costline.
 */
public class AddedCommentIncCost implements Serializable, AddedCommentI {

    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    protected Date addedDate;

    @NotNull
    @Column(nullable = false)
    @Size(max = 255, message = "reason cannot exceed 255 characters")
    protected String reason;

    @NotNull
    @Column(nullable = false)
    protected String commentuser;

    @OneToOne(cascade = CascadeType.ALL)
//    @Column(name = "generalsequencenumber_id")
    //A hack to have unique id in embeddable object as they cannot have own id.
    @NotNull
    protected GeneralSequenceNumber generalSequenceNumber;
    //can be any date
    protected Date commentDate;
    //if comments for costline
    private String costline;

    public AddedCommentIncCost() {
        if (generalSequenceNumber == null) {
            generalSequenceNumber = new GeneralSequenceNumber();
        }
    }

    public AddedCommentIncCost(Date addedDate, String reason) {
        this.addedDate = addedDate;
        this.reason = reason;
        this.commentuser = MultiTenantUtil.getActiveUser().getUsername();
        generalSequenceNumber = new GeneralSequenceNumber();
    }

    public AddedCommentIncCost(Date addedDate, String reason, Date commentDate) {
        this.addedDate = addedDate;
        this.reason = reason;
        this.commentuser = MultiTenantUtil.getActiveUser().getUsername();
        generalSequenceNumber = new GeneralSequenceNumber();
        this.commentDate = commentDate;
    }

    public String getCostline() {
        return costline;
    }

    public void setCostline(String costline) {
        this.costline = costline;
    }

    @Override
    public Date getAddedDate() {
        return addedDate;
    }

    @Override
    public void setAddedDate(Date addedDate) {
        this.addedDate = addedDate;
    }

    @Override
    public String getReason() {
        return reason;
    }

    @Override
    public void setReason(String reason) {
        this.reason = reason;
    }

    @Override
    public Date getCommentDate() {
        return commentDate;
    }

    @Override
    public void setCommentDate(Date commentDate) {
        this.commentDate = commentDate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AddedCommentIncCost that = (AddedCommentIncCost) o;
        return Objects.equals(generalSequenceNumber, that.generalSequenceNumber);
    }

    @Override
    public int hashCode() {
        return Objects.hash(generalSequenceNumber);
    }

    @Override
    public GeneralSequenceNumber getGeneralSequenceNumber() {
        return generalSequenceNumber;
    }

    @Override
    public void setGeneralSequenceNumber(GeneralSequenceNumber generalSequenceNumber) {
        this.generalSequenceNumber = generalSequenceNumber;
    }

    public String getCommentuser() {
        return commentuser;
    }

    public void setCommentuser(String commentuser) {
        this.commentuser = commentuser;
    }
}