StockLevel.java

package com.tradecloud.domain.model.requestforquote;

import com.tradecloud.common.base.PersistenceBase;
import com.tradecloud.domain.model.organisationalunit.OrganisationalUnit;
import com.tradecloud.domain.place.Region;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.*;

@Entity
@Table(name = "StockLevel")
@Access(AccessType.FIELD)
public class StockLevel extends PersistenceBase {

    @OneToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "StockLevel_organisationalUnits")
    private List<OrganisationalUnit> organisationalUnits;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "StockLevel_regions")
    private Set<Region> regions;

//    @ManyToOne
//    private FinalDestination finalDestination;

    @OneToMany(mappedBy = "stockLevel", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
    private List<StockLevelStyle> stockLevelStyles=new ArrayList<>();

    private boolean hideEmptyStock=false;

    private BigDecimal bufferFactor=BigDecimal.valueOf(2.5);

    private Date generatedDate;

    private Date stockLevelUpdated;
    @Enumerated(value = EnumType.STRING)
    private GeneratedColumns defaultAverage=GeneratedColumns.TWO_MONTH_AVG_SALES;

    private transient Set<String> productsMissingStyles=new HashSet<>();

    public List<StockLevelStyle> getStockLevelStyles() {
        return stockLevelStyles;
    }

    public void setStockLevelStyles(List<StockLevelStyle> stockLevelStyles) {
        this.stockLevelStyles = stockLevelStyles;
    }

    public void addStockLevelStyle(StockLevelStyle stockLevelStyle){
        stockLevelStyle.setStockLevel(this);
        if(stockLevelStyles==null){
            stockLevelStyles=new ArrayList<>();
        }
        stockLevelStyles.add(stockLevelStyle);
    }

    public boolean isHideEmptyStock() {
        return hideEmptyStock;
    }

    public void setHideEmptyStock(boolean hideEmptyStock) {
        this.hideEmptyStock = hideEmptyStock;
    }

    public BigDecimal getBufferFactor() {
        return bufferFactor;
    }

    public void setBufferFactor(BigDecimal bufferFactor) {
        this.bufferFactor = bufferFactor;
    }

    public Date getGeneratedDate() {
        return generatedDate;
    }

    public void setGeneratedDate(Date generatedDate) {
        this.generatedDate = generatedDate;
    }

    public List<OrganisationalUnit> getOrganisationalUnits() {
        return organisationalUnits;
    }

    public void setOrganisationalUnits(List<OrganisationalUnit> organisationalUnits) {
        this.organisationalUnits = organisationalUnits;
    }

    public List<OrganisationalUnit> getOrganisationalUnits2() {
        return organisationalUnits != null ? new ArrayList<>(organisationalUnits) : null;
    }

    public void setOrganisationalUnits2(List<OrganisationalUnit> organisationalUnits) {
        this.organisationalUnits = organisationalUnits;
    }

    public Date getStockLevelUpdated() {
        return stockLevelUpdated;
    }

    public void setStockLevelUpdated(Date stockLevelUpdated) {
        this.stockLevelUpdated = stockLevelUpdated;
    }

    public GeneratedColumns getDefaultAverage() {
        return defaultAverage;
    }

    public void setDefaultAverage(GeneratedColumns defaultAverage) {
        this.defaultAverage = defaultAverage;
    }

    public Set<Region> getRegions() {
        return regions;
    }

    public void setRegions(Set<Region> regions) {
        this.regions = regions;
    }

    public Set<Region> getRegions2() {
        return regions != null ? new HashSet<>(regions) : null;
    }

    public void setRegions2(Set<Region> regions) {
        this.regions = regions;
    }

    public Set<String> getProductsMissingStyles() {
        return productsMissingStyles;
    }
}