StockLevelStyle.java
package com.tradecloud.domain.model.requestforquote;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Entity
@Table(name = "StockLevelStyle")
@Access(AccessType.FIELD)
public class StockLevelStyle extends StockLevelRow {
@Column(name = "style", nullable = false)
private String style;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "stock_level_id", nullable = true)
private StockLevel stockLevel;
@OneToMany(mappedBy = "stockLevelStyle", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
private List<StockLevelRegion> stockLevelRegions=new ArrayList<>();
private Integer quantity;
public StockLevelStyle() {
}
public StockLevelStyle(String style, StockLevel stockLevel) {
this.style = style;
this.stockLevel = stockLevel;
}
@Override
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public List<StockLevelStyleProduct> getStockLevelStyleProducts() {
return stockLevelRegions.stream().flatMap(stockLevelRegion -> stockLevelRegion.getStockLevelStyleProducts().stream()).collect(Collectors.toList());
}
public void setStockLevelStyleProducts(List<StockLevelStyleProduct> stockLevelStyleProducts) {
//this.stockLevelStyleProducts = stockLevelStyleProducts;
}
// public void addStockLevelStyleProduct(StockLevelStyleProduct product){
//// product.setStockLevelStyle(this);
//// this.stockLevelStyleProducts.add(product);
// }
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public StockLevel getStockLevel() {
return stockLevel;
}
public void setStockLevel(StockLevel stockLevel) {
this.stockLevel = stockLevel;
}
public List<StockLevelRegion> getStockLevelRegions() {
return stockLevelRegions;
}
public void setStockLevelRegions(List<StockLevelRegion> stockLevelRegions) {
this.stockLevelRegions = stockLevelRegions;
}
@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;
StockLevelStyle that = (StockLevelStyle) o;
return Objects.equals(style, that.style) && Objects.equals(stockLevel, that.stockLevel);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), style, stockLevel);
}
}