/** * */ package org.minnal.examples.oms.domain; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import org.activejpa.entity.Model; import org.minnal.instrument.entity.Searchable; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; /** * @author ganeshs * */ @Entity public class OrderItem extends Model { /** * @author ganeshs * */ public enum Status { created, cancelled } @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="orderId") @JsonBackReference("items") private Order order; @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="productId", insertable=false, updatable=false) @JsonIgnore private Product product; private Long productId; @Searchable private int quantity; @Searchable @Enumerated(EnumType.STRING) private Status status = Status.created; private String cancellationReason; /** * @return the id */ public Long getId() { return id; } /** * @param id the id to set */ public void setId(Long id) { this.id = id; } /** * @return the order */ public Order getOrder() { return order; } /** * @param order the order to set */ public void setOrder(Order order) { this.order = order; } /** * @return the product */ public Product getProduct() { return product; } /** * @param product the product to set */ public void setProduct(Product product) { this.product = product; this.productId = product.getId(); } /** * @return the quantity */ public int getQuantity() { return quantity; } /** * @param quantity the quantity to set */ public void setQuantity(int quantity) { this.quantity = quantity; } /** * @return the productId */ public Long getProductId() { return productId; } /** * @param productId the productId to set */ public void setProductId(Long productId) { this.productId = productId; } /** * @return the status */ public Status getStatus() { return status; } /** * @param status the status to set */ public void setStatus(Status status) { this.status = status; } /** * @return the cancellationReason */ public String getCancellationReason() { return cancellationReason; } /** * @param cancellationReason the cancellationReason to set */ public void setCancellationReason(String cancellationReason) { this.cancellationReason = cancellationReason; } public void cancel(String reason) { setStatus(Status.cancelled); setCancellationReason(reason); } }