RFQRegion.java
package com.tradecloud.domain.model.requestforquote;
import com.tradecloud.domain.place.Region;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "RFQRegion")
@Access(AccessType.FIELD)
public class RFQRegion extends StockLevelRow{
@ManyToOne
@NotNull(message = "rfqStyle should not be null")
private RFQStyle rfqStyle;
@ManyToOne
@NotNull(message = "region should not be null")
private Region region;
@OneToMany(mappedBy = "rfqRegion", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<RFQProduct> rfqProducts=new ArrayList<>();
private boolean approved;
private boolean originalQuantitySelected;
private boolean branchQuantitySelected;
public RFQRegion(){
}
public RFQRegion(Region region, RFQStyle rfqStyle) {
this.region = region;
this.rfqStyle = rfqStyle;
}
public @NotNull(message = "rfqStyle should not be null") RFQStyle getRfqStyle() {
return rfqStyle;
}
public void setRfqStyle(@NotNull(message = "rfqStyle should not be null") RFQStyle rfqStyle) {
this.rfqStyle = rfqStyle;
}
public @NotNull(message = "region should not be null") Region getRegion() {
return region;
}
public void setRegion(@NotNull(message = "region should not be null") Region region) {
this.region = region;
}
public List<RFQProduct> getRfqProducts() {
return rfqProducts;
}
public void setRfqProducts(List<RFQProduct> rfqProducts) {
this.rfqProducts = rfqProducts;
}
@Override
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
if (!super.equals(object)) return false;
RFQRegion rfqRegion = (RFQRegion) object;
return Objects.equals(rfqStyle, rfqRegion.rfqStyle) && Objects.equals(region, rfqRegion.region);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), rfqStyle, region);
}
public void addRfqProduct(RFQProduct rfqProduct) {
rfqProduct.setRfqRegion(this);
rfqProducts.add(rfqProduct);
}
@Override
public String getStyle(){
return region.getName();
}
public boolean isApproved() {
return approved;
}
public void setApproved(boolean approved) {
this.approved = approved;
}
@Override
public boolean isOriginalQuantitySelected() {
return originalQuantitySelected;
}
@Override
public void setOriginalQuantitySelected(boolean originalQuantitySelected) {
this.originalQuantitySelected = originalQuantitySelected;
}
@Override
public boolean isBranchQuantitySelected() {
return branchQuantitySelected;
}
@Override
public void setBranchQuantitySelected(boolean branchQuantitySelected) {
this.branchQuantitySelected = branchQuantitySelected;
}
@Override
public boolean isRegion(){
return true;
}
public String getName(){
return this.region.getName();
}
}