package pl.hplxtool.model; import java.io.Serializable; import java.text.Normalizer; import java.util.List; import java.util.Set; import javax.jdo.annotations.Index; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import pl.hplxtool.dozer.Convertable; @Entity public class Product extends BaseEntity implements Serializable, Convertable, Comparable { private static final long serialVersionUID = -4719905761198080302L; @GeneratedValue(strategy = GenerationType.AUTO) @Id private long id; @Column(nullable = false) private String name = ""; @Index private String symbol = ""; @Index private String wwwUrl = ""; @Index @ManyToOne(fetch = FetchType.EAGER) private Supplier supplier; @Index @OneToMany(targetEntity = Picture.class, cascade = CascadeType.PERSIST, fetch = FetchType.EAGER) private List pictures; @Index @ManyToOne(fetch = FetchType.EAGER) private InspirationType type; private Float depth; private Float width; private Float height; private Float averagePrice; private String collection = ""; @OneToMany(targetEntity = Shop.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List stores; @ElementCollection(fetch = FetchType.EAGER) private List definedAttributes; @OneToMany(targetEntity = Offer.class, mappedBy = "product", fetch = FetchType.LAZY, cascade = CascadeType.ALL) private Set offers; private boolean done; private String addedBy; private String storeUrl; private long storeID; private List stationaryStores; @ManyToMany(targetEntity = Inspiration.class, fetch = FetchType.LAZY, mappedBy = "products") private List inspirations; @ManyToMany(targetEntity = Store.class, fetch = FetchType.LAZY, mappedBy = "products") private Set listOfStores; private Float defaultPrice; private Float pricePerUnitCount = 1f; private Float numberOfUnitsInPackage = null; private String unitOfMeasure = ""; private Float relativeQuantityPerUnitOfPerformance = null; private String unitOfPerformance = "m2"; public Product() { super(); } public Product(long id) { super(); this.id = id; } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getNormName() { if (name != null && !name.isEmpty()) return Normalizer.normalize(this.name, Normalizer.Form.NFD); else return name; } public String getSymbol() { return symbol; } public void setSymbol(String symbol) { this.symbol = symbol; } public String getWwwUrl() { return wwwUrl; } public void setWwwUrl(String wwwUrl) { this.wwwUrl = wwwUrl; } public Supplier getSupplier() { return supplier; } public void setSupplier(Supplier supplier) { this.supplier = supplier; } public List getPictures() { return pictures; } public void setPictures(List pictures) { this.pictures = pictures; } public InspirationType getType() { return type; } public void setType(InspirationType type) { this.type = type; } public Float getDepth() { return depth; } public void setDepth(Float depth) { this.depth = depth; } public Float getWidth() { return width; } public void setWidth(Float width) { this.width = width; } public Float getHeight() { return height; } public void setHeight(Float height) { this.height = height; } public Float getAveragePrice() { return averagePrice; } public void setAveragePrice(Float averagePrice) { this.averagePrice = averagePrice; } public String getUnitOfMeasure() { return unitOfMeasure; } public void setUnitOfMeasure(String unitOfMeasure) { this.unitOfMeasure = unitOfMeasure; } public Float getPricePerUnitCount() { return pricePerUnitCount; } public void setPricePerUnitCount(Float pricePerUnitCount) { this.pricePerUnitCount = pricePerUnitCount; } public List getStores() { return stores; } public void setStores(List stores) { this.stores = stores; } public List getDefinedAttributes() { return definedAttributes; } public void setDefinedAttributes(List definedAttributes) { this.definedAttributes = definedAttributes; } public String getCollection() { return collection; } public void setCollection(String collection) { this.collection = collection; } public boolean isDone() { return done; } public void setDone(boolean done) { this.done = done; } public String getAddedBy() { return addedBy; } public void setAddedBy(String addedBy) { this.addedBy = addedBy; } public Float getNumberOfUnitsInPackage() { return numberOfUnitsInPackage; } public void setNumberOfUnitsInPackage(Float numberOfUnitsInPackage) { this.numberOfUnitsInPackage = numberOfUnitsInPackage; } public Float getRelativeQuantityPerUnitOfPerformance() { return relativeQuantityPerUnitOfPerformance; } public void setRelativeQuantityPerUnitOfPerformance(Float relativeQuantityPerUnitOfPerformance) { this.relativeQuantityPerUnitOfPerformance = relativeQuantityPerUnitOfPerformance; } public String getUnitOfPerformance() { return unitOfPerformance; } public void setUnitOfPerformance(String unitOfPerformance) { this.unitOfPerformance = unitOfPerformance; } public Float getDefaultPrice() { return defaultPrice; } public void setDefaultPrice(Float defaultPrice) { this.defaultPrice = defaultPrice; } public String getStoreUrl() { return storeUrl; } public void setStoreUrl(String storeUrl) { this.storeUrl = storeUrl; } public Set getOffers() { return offers; } public void setOffers(Set offers) { this.offers = offers; } public long getStoreID() { return storeID; } public void setStoreID(long storeID) { this.storeID = storeID; } public List getStationaryStores() { return stationaryStores; } public void setStationaryStores(List stationaryStores) { this.stationaryStores = stationaryStores; } public List getInspirations() { return inspirations; } public void setInspirations(List inspirations) { this.inspirations = inspirations; } public Set getListOfStores() { return listOfStores; } public void setListOfStores(Set listOfStores) { this.listOfStores = listOfStores; } public String[] getCSV() { String[] forCSV = new String[19]; forCSV[0] = String.valueOf(this.getId()); forCSV[1] = String.valueOf(this.isInspDone()); forCSV[2] = String.valueOf(this.getCollection()); forCSV[3] = String.valueOf(this.getDefaultPrice()); forCSV[4] = String.valueOf(this.isDone()); forCSV[5] = String.valueOf(this.getName()); forCSV[6] = String.valueOf(this.getPricePerUnitCount()); forCSV[7] = String.valueOf(this.getSupplier().getId()); forCSV[8] = String.valueOf(this.getSymbol()); forCSV[9] = String.valueOf(this.getUnitOfMeasure()); forCSV[10] = String.valueOf(this.getUnitOfPerformance()); forCSV[11] = String.valueOf(this.getHeight()); forCSV[12] = String.valueOf(this.getWidth()); forCSV[13] = String.valueOf(this.getDepth()); forCSV[14] = String.valueOf(this.getWwwUrl()); forCSV[15] = String.valueOf(this.getAddedBy()); forCSV[16] = String.valueOf(this.getRelativeQuantityPerUnitOfPerformance()); forCSV[17] = String.valueOf(this.getNumberOfUnitsInPackage()); forCSV[18] = String.valueOf(this.getStoreUrl()); return forCSV; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append(id); builder.append(", "); if (name != null) { builder.append(name); builder.append(", "); } if (symbol != null) { builder.append(symbol); builder.append(", "); } if (wwwUrl != null) { builder.append(wwwUrl); builder.append(", "); } if (type != null) { builder.append(type); builder.append(", "); } if (depth != null) { builder.append(depth); builder.append(", "); } if (width != null) { builder.append(width); builder.append(", "); } if (height != null) { builder.append(height); builder.append(", "); } if (averagePrice != null) { builder.append(averagePrice); builder.append(", "); } if (unitOfMeasure != null) { builder.append(unitOfMeasure); builder.append(", "); } if (pricePerUnitCount != null) { builder.append(pricePerUnitCount); builder.append(", "); } if (collection != null) { builder.append(collection); builder.append(", "); } if (stores != null) { builder.append(stores); builder.append(", "); } if (definedAttributes != null) { builder.append(definedAttributes); builder.append(", "); } builder.append(done); builder.append(", "); if (addedBy != null) builder.append(addedBy); return builder.toString(); } @Override public int compareTo(Object arg0) { Product prod = (Product) arg0; if (this.id == prod.getId()) return 0; else if (this.id > prod.getId()) return 1; else return -1; } }