View Javadoc
1   /*
2    *    Copyright 2010-2026 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.jpetstore.domain;
17  
18  import java.io.Serializable;
19  import java.math.BigDecimal;
20  import java.util.ArrayList;
21  import java.util.Date;
22  import java.util.Iterator;
23  import java.util.List;
24  
25  /**
26   * The Class Order.
27   *
28   * @author Eduardo Macarron
29   */
30  public class Order implements Serializable {
31  
32    /** The serial version uid. */
33    private static final long serialVersionUID = 6321792448424424931L;
34  
35    /** The order id. */
36    private int orderId;
37    /** The username. */
38    private String username;
39    /** The order date. */
40    private Date orderDate;
41    /** The ship address1. */
42    private String shipAddress1;
43    /** The ship address2. */
44    private String shipAddress2;
45    /** The ship city. */
46    private String shipCity;
47    /** The ship state. */
48    private String shipState;
49    /** The ship zip. */
50    private String shipZip;
51    /** The ship country. */
52    private String shipCountry;
53    /** The bill address1. */
54    private String billAddress1;
55    /** The bill address2. */
56    private String billAddress2;
57    /** The bill city. */
58    private String billCity;
59    /** The bill state. */
60    private String billState;
61    /** The bill zip. */
62    private String billZip;
63    /** The bill country. */
64    private String billCountry;
65    /** The courier. */
66    private String courier;
67    /** The total price. */
68    private BigDecimal totalPrice;
69    /** The bill to first name. */
70    private String billToFirstName;
71    /** The bill to last name. */
72    private String billToLastName;
73    /** The ship to first name. */
74    private String shipToFirstName;
75    /** The ship to last name. */
76    private String shipToLastName;
77    /** The credit card. */
78    private String creditCard;
79    /** The expiry date. */
80    private String expiryDate;
81    /** The card type. */
82    private String cardType;
83    /** The locale. */
84    private String locale;
85    /** The status. */
86    private String status;
87    /** The line items. */
88    private List<LineItem> lineItems = new ArrayList<>();
89  
90    /**
91     * Gets the order id.
92     *
93     * @return the order id
94     */
95    public int getOrderId() {
96      return orderId;
97    }
98  
99    /**
100    * Sets the order id.
101    *
102    * @param orderId
103    *          the order id
104    */
105   public void setOrderId(int orderId) {
106     this.orderId = orderId;
107   }
108 
109   /**
110    * Gets the username.
111    *
112    * @return the username
113    */
114   public String getUsername() {
115     return username;
116   }
117 
118   /**
119    * Sets the username.
120    *
121    * @param username
122    *          the username
123    */
124   public void setUsername(String username) {
125     this.username = username;
126   }
127 
128   /**
129    * Gets the order date.
130    *
131    * @return the order date
132    */
133   public Date getOrderDate() {
134     return orderDate;
135   }
136 
137   /**
138    * Sets the order date.
139    *
140    * @param orderDate
141    *          the order date
142    */
143   public void setOrderDate(Date orderDate) {
144     this.orderDate = orderDate;
145   }
146 
147   /**
148    * Gets the ship address1.
149    *
150    * @return the ship address1
151    */
152   public String getShipAddress1() {
153     return shipAddress1;
154   }
155 
156   /**
157    * Sets the ship address1.
158    *
159    * @param shipAddress1
160    *          the ship address1
161    */
162   public void setShipAddress1(String shipAddress1) {
163     this.shipAddress1 = shipAddress1;
164   }
165 
166   /**
167    * Gets the ship address2.
168    *
169    * @return the ship address2
170    */
171   public String getShipAddress2() {
172     return shipAddress2;
173   }
174 
175   /**
176    * Sets the ship address2.
177    *
178    * @param shipAddress2
179    *          the ship address2
180    */
181   public void setShipAddress2(String shipAddress2) {
182     this.shipAddress2 = shipAddress2;
183   }
184 
185   /**
186    * Gets the ship city.
187    *
188    * @return the ship city
189    */
190   public String getShipCity() {
191     return shipCity;
192   }
193 
194   /**
195    * Sets the ship city.
196    *
197    * @param shipCity
198    *          the ship city
199    */
200   public void setShipCity(String shipCity) {
201     this.shipCity = shipCity;
202   }
203 
204   /**
205    * Gets the ship state.
206    *
207    * @return the ship state
208    */
209   public String getShipState() {
210     return shipState;
211   }
212 
213   /**
214    * Sets the ship state.
215    *
216    * @param shipState
217    *          the ship state
218    */
219   public void setShipState(String shipState) {
220     this.shipState = shipState;
221   }
222 
223   /**
224    * Gets the ship zip.
225    *
226    * @return the ship zip
227    */
228   public String getShipZip() {
229     return shipZip;
230   }
231 
232   /**
233    * Sets the ship zip.
234    *
235    * @param shipZip
236    *          the ship zip
237    */
238   public void setShipZip(String shipZip) {
239     this.shipZip = shipZip;
240   }
241 
242   /**
243    * Gets the ship country.
244    *
245    * @return the ship country
246    */
247   public String getShipCountry() {
248     return shipCountry;
249   }
250 
251   /**
252    * Sets the ship country.
253    *
254    * @param shipCountry
255    *          the ship country
256    */
257   public void setShipCountry(String shipCountry) {
258     this.shipCountry = shipCountry;
259   }
260 
261   /**
262    * Gets the bill address1.
263    *
264    * @return the bill address1
265    */
266   public String getBillAddress1() {
267     return billAddress1;
268   }
269 
270   /**
271    * Sets the bill address1.
272    *
273    * @param billAddress1
274    *          the bill address1
275    */
276   public void setBillAddress1(String billAddress1) {
277     this.billAddress1 = billAddress1;
278   }
279 
280   /**
281    * Gets the bill address2.
282    *
283    * @return the bill address2
284    */
285   public String getBillAddress2() {
286     return billAddress2;
287   }
288 
289   /**
290    * Sets the bill address2.
291    *
292    * @param billAddress2
293    *          the bill address2
294    */
295   public void setBillAddress2(String billAddress2) {
296     this.billAddress2 = billAddress2;
297   }
298 
299   /**
300    * Gets the bill city.
301    *
302    * @return the bill city
303    */
304   public String getBillCity() {
305     return billCity;
306   }
307 
308   /**
309    * Sets the bill city.
310    *
311    * @param billCity
312    *          the bill city
313    */
314   public void setBillCity(String billCity) {
315     this.billCity = billCity;
316   }
317 
318   /**
319    * Gets the bill state.
320    *
321    * @return the bill state
322    */
323   public String getBillState() {
324     return billState;
325   }
326 
327   /**
328    * Sets the bill state.
329    *
330    * @param billState
331    *          the bill state
332    */
333   public void setBillState(String billState) {
334     this.billState = billState;
335   }
336 
337   /**
338    * Gets the bill zip.
339    *
340    * @return the bill zip
341    */
342   public String getBillZip() {
343     return billZip;
344   }
345 
346   /**
347    * Sets the bill zip.
348    *
349    * @param billZip
350    *          the bill zip
351    */
352   public void setBillZip(String billZip) {
353     this.billZip = billZip;
354   }
355 
356   /**
357    * Gets the bill country.
358    *
359    * @return the bill country
360    */
361   public String getBillCountry() {
362     return billCountry;
363   }
364 
365   /**
366    * Sets the bill country.
367    *
368    * @param billCountry
369    *          the bill country
370    */
371   public void setBillCountry(String billCountry) {
372     this.billCountry = billCountry;
373   }
374 
375   /**
376    * Gets the courier.
377    *
378    * @return the courier
379    */
380   public String getCourier() {
381     return courier;
382   }
383 
384   /**
385    * Sets the courier.
386    *
387    * @param courier
388    *          the courier
389    */
390   public void setCourier(String courier) {
391     this.courier = courier;
392   }
393 
394   /**
395    * Gets the total price.
396    *
397    * @return the total price
398    */
399   public BigDecimal getTotalPrice() {
400     return totalPrice;
401   }
402 
403   /**
404    * Sets the total price.
405    *
406    * @param totalPrice
407    *          the total price
408    */
409   public void setTotalPrice(BigDecimal totalPrice) {
410     this.totalPrice = totalPrice;
411   }
412 
413   /**
414    * Gets the bill to first name.
415    *
416    * @return the bill to first name
417    */
418   public String getBillToFirstName() {
419     return billToFirstName;
420   }
421 
422   /**
423    * Sets the bill to first name.
424    *
425    * @param billToFirstName
426    *          the bill to first name
427    */
428   public void setBillToFirstName(String billToFirstName) {
429     this.billToFirstName = billToFirstName;
430   }
431 
432   /**
433    * Gets the bill to last name.
434    *
435    * @return the bill to last name
436    */
437   public String getBillToLastName() {
438     return billToLastName;
439   }
440 
441   /**
442    * Sets the bill to last name.
443    *
444    * @param billToLastName
445    *          the bill to last name
446    */
447   public void setBillToLastName(String billToLastName) {
448     this.billToLastName = billToLastName;
449   }
450 
451   /**
452    * Gets the ship to first name.
453    *
454    * @return the ship to first name
455    */
456   public String getShipToFirstName() {
457     return shipToFirstName;
458   }
459 
460   /**
461    * Sets the ship to first name.
462    *
463    * @param shipFoFirstName
464    *          the ship fo first name
465    */
466   public void setShipToFirstName(String shipFoFirstName) {
467     this.shipToFirstName = shipFoFirstName;
468   }
469 
470   /**
471    * Gets the ship to last name.
472    *
473    * @return the ship to last name
474    */
475   public String getShipToLastName() {
476     return shipToLastName;
477   }
478 
479   /**
480    * Sets the ship to last name.
481    *
482    * @param shipToLastName
483    *          the ship to last name
484    */
485   public void setShipToLastName(String shipToLastName) {
486     this.shipToLastName = shipToLastName;
487   }
488 
489   /**
490    * Gets the credit card.
491    *
492    * @return the credit card
493    */
494   public String getCreditCard() {
495     return creditCard;
496   }
497 
498   /**
499    * Sets the credit card.
500    *
501    * @param creditCard
502    *          the credit card
503    */
504   public void setCreditCard(String creditCard) {
505     this.creditCard = creditCard;
506   }
507 
508   /**
509    * Gets the expiry date.
510    *
511    * @return the expiry date
512    */
513   public String getExpiryDate() {
514     return expiryDate;
515   }
516 
517   /**
518    * Sets the expiry date.
519    *
520    * @param expiryDate
521    *          the expiry date
522    */
523   public void setExpiryDate(String expiryDate) {
524     this.expiryDate = expiryDate;
525   }
526 
527   /**
528    * Gets the card type.
529    *
530    * @return the card type
531    */
532   public String getCardType() {
533     return cardType;
534   }
535 
536   /**
537    * Sets the card type.
538    *
539    * @param cardType
540    *          the card type
541    */
542   public void setCardType(String cardType) {
543     this.cardType = cardType;
544   }
545 
546   /**
547    * Gets the locale.
548    *
549    * @return the locale
550    */
551   public String getLocale() {
552     return locale;
553   }
554 
555   /**
556    * Sets the locale.
557    *
558    * @param locale
559    *          the locale
560    */
561   public void setLocale(String locale) {
562     this.locale = locale;
563   }
564 
565   /**
566    * Gets the status.
567    *
568    * @return the status
569    */
570   public String getStatus() {
571     return status;
572   }
573 
574   /**
575    * Sets the status.
576    *
577    * @param status
578    *          the status
579    */
580   public void setStatus(String status) {
581     this.status = status;
582   }
583 
584   /**
585    * Sets the line items.
586    *
587    * @param lineItems
588    *          the line items
589    */
590   public void setLineItems(List<LineItem> lineItems) {
591     this.lineItems = lineItems;
592   }
593 
594   /**
595    * Gets the line items.
596    *
597    * @return the line items
598    */
599   public List<LineItem> getLineItems() {
600     return lineItems;
601   }
602 
603   /**
604    * Inits the order.
605    *
606    * @param account
607    *          the account
608    * @param cart
609    *          the cart
610    */
611   public void initOrder(Account account, Cart cart) {
612 
613     username = account.getUsername();
614     orderDate = new Date();
615 
616     shipToFirstName = account.getFirstName();
617     shipToLastName = account.getLastName();
618     shipAddress1 = account.getAddress1();
619     shipAddress2 = account.getAddress2();
620     shipCity = account.getCity();
621     shipState = account.getState();
622     shipZip = account.getZip();
623     shipCountry = account.getCountry();
624 
625     billToFirstName = account.getFirstName();
626     billToLastName = account.getLastName();
627     billAddress1 = account.getAddress1();
628     billAddress2 = account.getAddress2();
629     billCity = account.getCity();
630     billState = account.getState();
631     billZip = account.getZip();
632     billCountry = account.getCountry();
633 
634     totalPrice = cart.getSubTotal();
635 
636     creditCard = "999 9999 9999 9999";
637     expiryDate = "12/03";
638     cardType = "Visa";
639     courier = "UPS";
640     locale = "CA";
641     status = "P";
642 
643     Iterator<CartItem> i = cart.getAllCartItems();
644     while (i.hasNext()) {
645       CartItem cartItem = i.next();
646       addLineItem(cartItem);
647     }
648 
649   }
650 
651   /**
652    * Add line item.
653    *
654    * @param cartItem
655    *          the cart item
656    */
657   public void addLineItem(CartItem cartItem) {
658     LineItem lineItem = new LineItem(lineItems.size() + 1, cartItem);
659     addLineItem(lineItem);
660   }
661 
662   /**
663    * Add line item.
664    *
665    * @param lineItem
666    *          the line item
667    */
668   public void addLineItem(LineItem lineItem) {
669     lineItems.add(lineItem);
670   }
671 
672 }