Commit 842e5f50 by Tuomas Riihimäki

Add Vip product and vip product delivery entities

1 parent 84d6c52c
......@@ -254,10 +254,10 @@ public class BootstrapBean implements BootstrapBeanLocal {
"DELETE FROM product_limitations_roles where productlimitation_id in (SELECT id FROM product_limitations WHERE TYPE = 'PLACE')",
"DELETE FROM products_product_limitations where productlimits_id in (SELECT id FROM product_limitations WHERE TYPE = 'PLACE')",
"DELETE FROM product_limitations WHERE TYPE = 'PLACE'",
});
dbUpdates.add(new String[]{
dbUpdates.add(new String[] {
new DDLBuilder().createTable("vips")
.serialPK("id")
.text("description", false)
......@@ -270,6 +270,15 @@ public class BootstrapBean implements BootstrapBeanLocal {
.toString()
});
dbUpdates.add(new String[] {
"CREATE TABLE vip_product_deliveries (id SERIAL NOT NULL, DELIVERYTIME TIMESTAMPTZ NOT NULL, meta json, NOTES TEXT, quantity DECIMAL(24,4) NOT NULL, DELIVERER_id INTEGER NOT NULL, VIPPRODUCT_id INTEGER NOT NULL, PRIMARY KEY (id))",
"CREATE TABLE vip_products (id SERIAL NOT NULL, meta json, NAME TEXT, NOTES TEXT, quantity DECIMAL(24,4) NOT NULL, PRODUCT_id INTEGER, VIP_id INTEGER NOT NULL, PRIMARY KEY (id))",
"ALTER TABLE vip_product_deliveries ADD CONSTRAINT FK_vip_product_deliveries_DELIVERER_id FOREIGN KEY (DELIVERER_id) REFERENCES event_users (id)",
"ALTER TABLE vip_product_deliveries ADD CONSTRAINT FK_vip_product_deliveries_VIPPRODUCT_id FOREIGN KEY (VIPPRODUCT_id) REFERENCES vip_products (id)",
"ALTER TABLE vip_products ADD CONSTRAINT FK_vip_products_PRODUCT_id FOREIGN KEY (PRODUCT_id) REFERENCES products (id)",
"ALTER TABLE vip_products ADD CONSTRAINT FK_vip_products_VIP_id FOREIGN KEY (VIP_id) REFERENCES vips (id)"
});
}
public BootstrapBean() {
......
......@@ -129,8 +129,8 @@ public class LanEvent extends GenericEntity {
@OneToMany(mappedBy = "event", cascade = CascadeType.ALL)
private List<LanEventProperty> properties = new ArrayList<LanEventProperty>();
@OneToMany(mappedBy = "event")
private List<Vip> vips;
// @OneToMany(mappedBy = "event")
// private List<Vip> vips;
public LanEvent() {
......@@ -337,11 +337,11 @@ public class LanEvent extends GenericEntity {
this.theme = theme;
}
public List<Vip> getVips() {
return vips;
}
public void setVips(List<Vip> vips) {
this.vips = vips;
}
// public List<Vip> getVips() {
// return vips;
// }
//
// public void setVips(List<Vip> vips) {
// this.vips = vips;
// }
}
package fi.codecrew.moya.model;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* VIP list. Info staff will use the VIP list information to allow certain
......@@ -10,96 +22,128 @@ import java.util.Calendar;
* The VIP list entry can be just a free form description containing the names
* of VIPs and what makes them VIP, or the entry may refer to an EventUser.
*
* Every VIP entry must have a responsible person in the organization.
* Creator must also be recorder.
* Every VIP entry must have a responsible person in the organization. Creator
* must also be recorder.
*
*/
@Entity
@Table(name="vips")
@Table(name = "vips")
public class Vip extends GenericEntity {
private static final long serialVersionUID = 1L;
private static final String EVENT_ID_COLUMN = "event_id";
private static final String VIP_EVENT_USER_ID_COLUMN = "vip_event_user_id";
private static final String CREATOR_EVENT_USER_ID_COLUMN = "creator_event_user_id";
private static final String HOST_EVENT_USER_ID_COLUMN = "host_event_user_id";
@Column(name = "description", nullable = false)
@Lob
private String description;
@Column(name = "created", nullable = false, updatable = false)
@Temporal(TemporalType.TIMESTAMP)
private Calendar created = Calendar.getInstance();
@ManyToOne
@JoinColumn(name = EVENT_ID_COLUMN, referencedColumnName = LanEvent.ID_COLUMN, nullable = false)
private LanEvent event;
@ManyToOne
@JoinColumn(name = VIP_EVENT_USER_ID_COLUMN, referencedColumnName = EventUser.ID_COLUMN, nullable = true)
private EventUser eventUser;
/**
* Mandatory creator of this VIP list entry.
*/
@ManyToOne
@JoinColumn(name = CREATOR_EVENT_USER_ID_COLUMN, referencedColumnName = EventUser.ID_COLUMN, nullable = false)
private EventUser creator;
/**
* Mandatory responsible person of this VIP list entry.
*/
@ManyToOne
@JoinColumn(name = HOST_EVENT_USER_ID_COLUMN, referencedColumnName = EventUser.ID_COLUMN, nullable = false)
private EventUser host;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Calendar getCreated() {
return created;
}
public void setCreated(Calendar created) {
this.created = created;
}
public LanEvent getEvent() {
return event;
}
public void setEvent(LanEvent event) {
this.event = event;
}
public EventUser getEventUser() {
return eventUser;
}
public void setEventUser(EventUser eventUser) {
this.eventUser = eventUser;
}
public EventUser getCreator() {
return creator;
}
public void setCreator(EventUser creator) {
this.creator = creator;
}
public EventUser getHost() {
return host;
}
public void setHost(EventUser host) {
this.host = host;
}
private static final long serialVersionUID = 1L;
private static final String EVENT_ID_COLUMN = "event_id";
private static final String VIP_EVENT_USER_ID_COLUMN = "vip_event_user_id";
private static final String CREATOR_EVENT_USER_ID_COLUMN = "creator_event_user_id";
private static final String HOST_EVENT_USER_ID_COLUMN = "host_event_user_id";
@Column(name = "description", nullable = false)
@Lob
private String description;
@Column(name = "shortdescr", nullable = false)
@Lob
private String shortdescr;
@Column(name = "created", nullable = false, updatable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date created = new Date();
@ManyToOne
@JoinColumn(name = EVENT_ID_COLUMN, referencedColumnName = LanEvent.ID_COLUMN, nullable = false)
private LanEvent event;
@ManyToOne
@JoinColumn(name = VIP_EVENT_USER_ID_COLUMN, referencedColumnName = EventUser.ID_COLUMN, nullable = true)
private EventUser eventUser;
/**
* Mandatory creator of this VIP list entry.
*/
@ManyToOne
@JoinColumn(name = CREATOR_EVENT_USER_ID_COLUMN, referencedColumnName = EventUser.ID_COLUMN, nullable = false)
private EventUser creator;
/**
* Mandatory responsible person of this VIP list entry.
*/
@ManyToOne
@JoinColumn(name = HOST_EVENT_USER_ID_COLUMN, referencedColumnName = EventUser.ID_COLUMN, nullable = false)
private EventUser host;
@OneToMany(mappedBy = "vip")
private List<VipProduct> products = new ArrayList<>();
public String getShortDisplayDescr() {
String ret = shortdescr;
if ((ret == null || ret.trim().isEmpty()) && description != null) {
ret = description;
if (description.length() > 85)
ret = description.substring(0, 80);
}
return ret;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public LanEvent getEvent() {
return event;
}
public void setEvent(LanEvent event) {
this.event = event;
}
public EventUser getEventUser() {
return eventUser;
}
public void setEventUser(EventUser eventUser) {
this.eventUser = eventUser;
}
public EventUser getCreator() {
return creator;
}
public void setCreator(EventUser creator) {
this.creator = creator;
}
public EventUser getHost() {
return host;
}
public void setHost(EventUser host) {
this.host = host;
}
public String getShortdescr() {
return shortdescr;
}
public void setShortdescr(String shortdescr) {
this.shortdescr = shortdescr;
}
public List<VipProduct> getProducts() {
return products;
}
public void setProducts(List<VipProduct> products) {
this.products = products;
}
}
package fi.codecrew.moya.model;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name = "vip_products")
public class VipProduct extends GenericEntity {
/**
*
*/
private static final long serialVersionUID = 1L;
@ManyToOne()
@JoinColumn(nullable = false)
private Vip vip;
/**
* If product is null this is used as the name of the product
*/
private String name;
@ManyToOne()
@JoinColumn(nullable = true)
private Product product;
@Lob
private String notes;
/** How many products should be given to the vip */
@Column(name = "quantity", nullable = false, precision = 24, scale = 4)
private BigDecimal quantity = BigDecimal.ONE;
@OneToMany(mappedBy = "vipProduct")
private List<VipProductDelivery> deliveries = new ArrayList<>();
/**
* Returns name of the product. If @Field product is empty, use @Field name
*
* @return
*/
@Transient
public String getProductName() {
String ret = name;
if (product == null) {
ret = product.getName();
}
return ret;
}
/**
* Have all products been delivered?
*
* @return
*/
public boolean isAllDelivered()
{
return quantity.compareTo(getDelivered()) <= 0;
}
public BigDecimal getDelivered()
{
BigDecimal delivered = BigDecimal.ZERO;
if (deliveries != null) {
for (VipProductDelivery d : deliveries) {
delivered = delivered.add(d.getQuantity());
}
}
return delivered;
}
public Vip getVip() {
return vip;
}
public void setVip(Vip vip) {
this.vip = vip;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public BigDecimal getQuantity() {
return quantity;
}
public void setQuantity(BigDecimal quantity) {
this.quantity = quantity;
}
public List<VipProductDelivery> getDeliveries() {
return deliveries;
}
public void setDeliveries(List<VipProductDelivery> deliveries) {
this.deliveries = deliveries;
}
}
package fi.codecrew.moya.model;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "vip_product_deliveries")
public class VipProductDelivery extends GenericEntity {
private static final long serialVersionUID = 1L;
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false)
private Date deliveryTime;
@JoinColumn(nullable = false)
@ManyToOne
private VipProduct vipProduct;
@JoinColumn(nullable = false)
@ManyToOne
private EventUser deliverer;
/** How many products has been given to the vip */
@Column(name = "quantity", nullable = false, precision = 24, scale = 4)
private BigDecimal quantity = BigDecimal.ONE;
@Lob
private String notes;
public Date getDeliveryTime() {
return deliveryTime;
}
public void setDeliveryTime(Date deliveryTime) {
this.deliveryTime = deliveryTime;
}
public VipProduct getVipProduct() {
return vipProduct;
}
public void setVipProduct(VipProduct vipProduct) {
this.vipProduct = vipProduct;
}
public EventUser getDeliverer() {
return deliverer;
}
public void setDeliverer(EventUser deliverer) {
this.deliverer = deliverer;
}
public BigDecimal getQuantity() {
return quantity;
}
public void setQuantity(BigDecimal quantity) {
this.quantity = quantity;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!