* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface Orderable extends Serializable {
+public interface Orderable extends Comparable<Orderable>, Serializable {
/**
* Getter for access key
* <p>
* @return Created timestamp
*/
- Date getOrderCreated ();
+ Date getOrderEntryCreated ();
/**
* Setter for created timestamp
* <p>
- * @param created Created timestamp
+ * @param orderEntryCreated Created timestamp
*/
- void setOrderCreated (final Date created);
+ void setOrderEntryCreated (final Date orderEntryCreated);
+
+ /**
+ * Getter for updated timestamp
+ * <p>
+ * @return Updated timestamp
+ */
+ Date getOrderEntryUpdated ();
+
+ /**
+ * Setter for updated timestamp
+ * <p>
+ * @param orderEntryUpdated Updated timestamp
+ */
+ void setOrderEntryUpdated (final Date orderEntryUpdated);
/**
* Getter for customer instance
*/
package org.mxchange.jshopcore.model.order;
+import java.text.MessageFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.mxchange.jcoreutils.comparable.ComparableUtils;
+import org.mxchange.jcoreutils.number.SafeNumberUtils;
import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.jcustomercore.model.utils.CustomerUtils;
import org.mxchange.jshopcore.model.basket.AddableBasketItem;
/**
*/
@Basic (optional = false)
@Temporal (TemporalType.TIMESTAMP)
- @Column (name = "order_created", nullable = false)
- private Date orderCreated;
+ @Column (name = "order_entry_created", nullable = false, updatable = false)
+ private Date orderEntryCreated;
+
+ /**
+ * Updated timestamp
+ */
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "order_entry_created", insertable = false)
+ private Date orderEntryUpdated;
/**
* Order orderId
@Transient
private List<AddableBasketItem> orderedItems;
+ /**
+ * The default constructor is for the JPA to invoke
+ */
+ public ShopOrder () {
+ }
+
+ /**
+ * Constructor with all required fields
+ * <p>
+ * @param accessKey Access key
+ * @param customer An instance of a Customer class
+ */
+ public ShopOrder (final String accessKey, final Customer customer) {
+ // Invoke simplier constructor first
+ this();
+
+ // Check all parameter
+ if (null == accessKey) {
+ // Throw NPE
+ throw new NullPointerException("Parameter 'accessKey' is null"); //NOI18N
+ } else if (accessKey.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("Parameter 'accessKey' is empty"); //NOI18N
+ } else if (null == customer) {
+ // Throw NPE again
+ throw new NullPointerException("Parameter 'customer' is null"); //NOI18N
+ } else if (customer.getCustomerId() == null) {
+ // Throw it again
+ throw new NullPointerException("customer.customerId is null"); //NOI18N
+ } else if (customer.getCustomerId() < 1) {
+ // Throw IAE again
+ throw new IllegalArgumentException(MessageFormat.format("customer.customerId={0} is invalid", customer.getCustomerId())); //NOI18N
+ }
+
+ // Set all here
+ this.accessKey = accessKey;
+ this.customer = customer;
+ }
+
+ @Override
+ public int compareTo (final Orderable orderable) {
+ // Check parameter on null-reference and equality to this
+ if (null == orderable) {
+ // Should not happen
+ throw new NullPointerException("orderable is null"); //NOI18N
+ } else if (Objects.equals(this, orderable)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparators
+ final int comparators[] = {
+ // First compare access key
+ this.getAccessKey().compareTo(orderable.getAccessKey()),
+ // ... next customer
+ CustomerUtils.compare(this.getCustomer(), orderable.getCustomer()),
+ // ... next primary key
+ SafeNumberUtils.compare(this.getOrderId(), orderable.getOrderId())
+ };
+
+ // Check all values
+ final int comparison = ComparableUtils.checkAll(comparators);
+
+ // Return value
+ return comparison;
+ }
+
@Override
public boolean equals (final Object object) {
if (this == object) {
@Override
@SuppressWarnings ("ReturnOfDateField")
- public Date getOrderCreated () {
- return this.orderCreated;
+ public Date getOrderEntryCreated () {
+ return this.orderEntryCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setOrderEntryCreated (final Date orderEntryCreated) {
+ this.orderEntryCreated = orderEntryCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getOrderEntryUpdated () {
+ return this.orderEntryUpdated;
}
@Override
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setOrderCreated (final Date orderCreated) {
- this.orderCreated = orderCreated;
+ public void setOrderEntryUpdated (final Date orderEntryUpdated) {
+ this.orderEntryUpdated = orderEntryUpdated;
}
@Override
*/
package org.mxchange.jshopcore.model.order.items;
+import java.text.MessageFormat;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
/**
* Product instance
*/
+ @Basic (optional = false)
@JoinColumn (name = "order_product_id", updatable = false)
@OneToOne (targetEntity = GenericProduct.class, cascade = CascadeType.REFRESH)
private Product product;
public OrderItem () {
}
+ /**
+ * Constructor with all required fields
+ * <p>
+ * @param itemType Item type
+ * @param orderedAmount Ordered amount
+ * @param product Ordered product
+ */
+ public OrderItem (final String itemType, final Long orderedAmount, final Product product) {
+ // Invoke simplier constrcutor
+ this();
+
+ // Check all parameter
+ if (null == itemType) {
+ // Throw NPE
+ throw new NullPointerException("Parameter 'itemType' is null"); //NOI18N
+ } else if (null == orderedAmount) {
+ // Throw it again
+ throw new NullPointerException("Parameter 'orderedAmount' is null"); //NOI18N
+ } else if (orderedAmount < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("orderedAmount={0} is invalid", orderedAmount)); //NOI18N
+ } else if (null == product) {
+ // Throw NPE
+ throw new NullPointerException("Parameter 'product' is null"); //NOI18N
+ } else if (product.getProductId() == null) {
+ // Throw NPE
+ throw new NullPointerException("product.productId is null"); //NOI18N
+ } else if (product.getProductId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("product.productId={0} is invalid", product.getProductId())); //NOI18N
+ }
+
+ // Set all here
+ this.itemType = itemType;
+ this.orderedAmount = orderedAmount;
+ this.product = product;
+ }
+
@Override
public boolean equals (final Object object) {
if (this == object) {
final AddableBasketItem item = (AddableBasketItem) object;
- if (!Objects.equals(this.itemType, item.getItemType())) {
+ if (!Objects.equals(this.getItemType(), item.getItemType())) {
return false;
- } else if (!Objects.equals(this.orderedAmount, item.getOrderedAmount())) {
+ } else if (!Objects.equals(this.getOrderedAmount(), item.getOrderedAmount())) {
+ return false;
+ } else if (!Objects.equals(this.getItemProduct(), item.getItemProduct())) {
return false;
}
@Override
public int hashCode () {
int hash = 3;
+
hash = 53 * hash + Objects.hashCode(this.getItemType());
hash = 53 * hash + Objects.hashCode(this.getOrderedAmount());
hash = 53 * hash + Objects.hashCode(this.getItemProduct());
+
return hash;
}