Class Order

All Implemented Interfaces:
Serializable, Comparable<Order>

public final class Order extends CustomerEntity implements Serializable, Comparable<Order>
The Order Entity for the Customer application.

This class represents the following DB Table:
 CREATE TABLE ORDERS (
      ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
      ORDER_DATE DATE NOT NULL,
      CUSTOMER_ID  INTEGER,
      TOTAL_AMOUNT DECIMAL(12,2),
      ORDER_NUMBER VARCHAR(10),
      CONSTRAINT PK_ORDER PRIMARY KEY (ID)
   );
 
Version:
1.0
Author:
Jonathan Earl
See Also:
  • Constructor Details

    • Order

      public Order()
      The default constructor for the Order class.

      The initial values are:
      • id: 1
      • orderDate: Current Date
      • customerId: 1
      • totalAmount: 0.00
      • orderNumber: null
      • orderItems: empty
    • Order

      public Order(org.example.websecurity.XssSanitizer sanitizer)
      The overloaded constructor for the order class that takes an XssSanitizer as input.

      The initial values are:

      • id: 1
      • orderDate: Current Date
      • customerId: 1
      • totalAmount: 0.00
      • orderNumber: null
      • orderItems: empty
      Parameters:
      sanitizer - the XssSanitizer used by this instance
  • Method Details

    • compareTo

      public int compareTo(Order other)
      This will enable sorting of Order by Order number concatenated with Order Date.

      Specified by:
      compareTo in interface Comparable<Order>
      Parameters:
      other - the Order object to compare with
      Returns:
      the sort value of negative/zero/positive
    • getOrderDate

      public LocalDate getOrderDate()
      Returns the orderDate value for the Order.
      Returns:
      the orderDate value for the order
    • setOrderDate

      public void setOrderDate(LocalDate orderDate)
      Sets the order date value for the Customer.

      The business rules are:

      • the order date must not be null
      • the order date must today or earlier
      Parameters:
      orderDate - the value to set into the orderDate field
      Throws:
      IllegalArgumentException - if the first name is invalid
    • getCustomerId

      public int getCustomerId()
      Returns the id value for the Customer Id.
      Returns:
      the id value for the customer id
    • setCustomerId

      public void setCustomerId(int customerId)
      Sets the id value for the Customer ID.

      The business rules are:

      • the id must be 1 or greater
      Parameters:
      customerId - the value to set into the customer id field
      Throws:
      IllegalArgumentException - if the customerId is invalid
    • getTotalAmount

      public double getTotalAmount()
      Returns the total amount for the order.
      Returns:
      the totalAmount value for the order
    • setTotalAmount

      public void setTotalAmount(double totalAmount)
      Sets the total amount value for the Orde.

      The business rules are:

      • the TotalAmount must be 0.01 or greater
      Parameters:
      totalAmount - the value to set into the totalAmount field
      Throws:
      IllegalArgumentException - if the totalAmount is invalid
    • getOrderNumber

      public String getOrderNumber()
      Returns the orderNumber value for the Order.
      Returns:
      the orderNumber value for the order
    • setOrderNumber

      public void setOrderNumber(String orderNumber)
      Sets the orderNumber value for the Order.

      The business rules are:

      • the orderNumber may be null
      • the orderNumber must not be empty
      • the orderNumber must min length of 2 chars
      • the orderNumber must max length of 10 chars
      • XSS strings within the orderNumber will be removed
      Parameters:
      orderNumber - the value to set into the Order Number field
      Throws:
      IllegalArgumentException - if the orderNumber is invalid
    • getOrderItems

      public List<OrderItem> getOrderItems()
      Returns the orderItem list value for the Order.
      Returns:
      the myOrderItems for the order
    • setOrderItems

      public void setOrderItems(List<OrderItem> orderItems)
      Sets the orderItem list value for the Order.

      The business rules are:

      • the orderItems must not be null
      • the orderItems may be empty
      Parameters:
      orderItems - the list to set into the orderItems
      Throws:
      IllegalArgumentException - if the orderItems is invalid
    • hashCode

      public int hashCode()
      The hashCode() method of the Order class.

      This method uses:

      • id
      • order date
      • customer id
      • order number
      Overrides:
      hashCode in class CustomerEntity
      Returns:
      the hashCode value for this Order object
      See Also:
    • equals

      public boolean equals(Object obj)
      The equals() method of the order class.

      This method uses:

      • id
      • order date
      • customer id
      • order number
      Overrides:
      equals in class CustomerEntity
      Parameters:
      obj - the incoming object to compare against
      Returns:
      true if the fields being compared are equal
      See Also:
    • toString

      public String toString()
      The toString method for the Order class. this method will return:
      Order [Id=xxx, OrderDate=xx/xx/xx, CustomerId=xxx, TotalAmount=xxx, OrderNumber=xxx]
      Overrides:
      toString in class CustomerEntity