View Javadoc
1   /*
2    *    Copyright 2010-2022 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    private static final long serialVersionUID = 6321792448424424931L;
33  
34    private int orderId;
35    private String username;
36    private Date orderDate;
37    private String shipAddress1;
38    private String shipAddress2;
39    private String shipCity;
40    private String shipState;
41    private String shipZip;
42    private String shipCountry;
43    private String billAddress1;
44    private String billAddress2;
45    private String billCity;
46    private String billState;
47    private String billZip;
48    private String billCountry;
49    private String courier;
50    private BigDecimal totalPrice;
51    private String billToFirstName;
52    private String billToLastName;
53    private String shipToFirstName;
54    private String shipToLastName;
55    private String creditCard;
56    private String expiryDate;
57    private String cardType;
58    private String locale;
59    private String status;
60    private List<LineItem> lineItems = new ArrayList<>();
61  
62    public int getOrderId() {
63      return orderId;
64    }
65  
66    public void setOrderId(int orderId) {
67      this.orderId = orderId;
68    }
69  
70    public String getUsername() {
71      return username;
72    }
73  
74    public void setUsername(String username) {
75      this.username = username;
76    }
77  
78    public Date getOrderDate() {
79      return orderDate;
80    }
81  
82    public void setOrderDate(Date orderDate) {
83      this.orderDate = orderDate;
84    }
85  
86    public String getShipAddress1() {
87      return shipAddress1;
88    }
89  
90    public void setShipAddress1(String shipAddress1) {
91      this.shipAddress1 = shipAddress1;
92    }
93  
94    public String getShipAddress2() {
95      return shipAddress2;
96    }
97  
98    public void setShipAddress2(String shipAddress2) {
99      this.shipAddress2 = shipAddress2;
100   }
101 
102   public String getShipCity() {
103     return shipCity;
104   }
105 
106   public void setShipCity(String shipCity) {
107     this.shipCity = shipCity;
108   }
109 
110   public String getShipState() {
111     return shipState;
112   }
113 
114   public void setShipState(String shipState) {
115     this.shipState = shipState;
116   }
117 
118   public String getShipZip() {
119     return shipZip;
120   }
121 
122   public void setShipZip(String shipZip) {
123     this.shipZip = shipZip;
124   }
125 
126   public String getShipCountry() {
127     return shipCountry;
128   }
129 
130   public void setShipCountry(String shipCountry) {
131     this.shipCountry = shipCountry;
132   }
133 
134   public String getBillAddress1() {
135     return billAddress1;
136   }
137 
138   public void setBillAddress1(String billAddress1) {
139     this.billAddress1 = billAddress1;
140   }
141 
142   public String getBillAddress2() {
143     return billAddress2;
144   }
145 
146   public void setBillAddress2(String billAddress2) {
147     this.billAddress2 = billAddress2;
148   }
149 
150   public String getBillCity() {
151     return billCity;
152   }
153 
154   public void setBillCity(String billCity) {
155     this.billCity = billCity;
156   }
157 
158   public String getBillState() {
159     return billState;
160   }
161 
162   public void setBillState(String billState) {
163     this.billState = billState;
164   }
165 
166   public String getBillZip() {
167     return billZip;
168   }
169 
170   public void setBillZip(String billZip) {
171     this.billZip = billZip;
172   }
173 
174   public String getBillCountry() {
175     return billCountry;
176   }
177 
178   public void setBillCountry(String billCountry) {
179     this.billCountry = billCountry;
180   }
181 
182   public String getCourier() {
183     return courier;
184   }
185 
186   public void setCourier(String courier) {
187     this.courier = courier;
188   }
189 
190   public BigDecimal getTotalPrice() {
191     return totalPrice;
192   }
193 
194   public void setTotalPrice(BigDecimal totalPrice) {
195     this.totalPrice = totalPrice;
196   }
197 
198   public String getBillToFirstName() {
199     return billToFirstName;
200   }
201 
202   public void setBillToFirstName(String billToFirstName) {
203     this.billToFirstName = billToFirstName;
204   }
205 
206   public String getBillToLastName() {
207     return billToLastName;
208   }
209 
210   public void setBillToLastName(String billToLastName) {
211     this.billToLastName = billToLastName;
212   }
213 
214   public String getShipToFirstName() {
215     return shipToFirstName;
216   }
217 
218   public void setShipToFirstName(String shipFoFirstName) {
219     this.shipToFirstName = shipFoFirstName;
220   }
221 
222   public String getShipToLastName() {
223     return shipToLastName;
224   }
225 
226   public void setShipToLastName(String shipToLastName) {
227     this.shipToLastName = shipToLastName;
228   }
229 
230   public String getCreditCard() {
231     return creditCard;
232   }
233 
234   public void setCreditCard(String creditCard) {
235     this.creditCard = creditCard;
236   }
237 
238   public String getExpiryDate() {
239     return expiryDate;
240   }
241 
242   public void setExpiryDate(String expiryDate) {
243     this.expiryDate = expiryDate;
244   }
245 
246   public String getCardType() {
247     return cardType;
248   }
249 
250   public void setCardType(String cardType) {
251     this.cardType = cardType;
252   }
253 
254   public String getLocale() {
255     return locale;
256   }
257 
258   public void setLocale(String locale) {
259     this.locale = locale;
260   }
261 
262   public String getStatus() {
263     return status;
264   }
265 
266   public void setStatus(String status) {
267     this.status = status;
268   }
269 
270   public void setLineItems(List<LineItem> lineItems) {
271     this.lineItems = lineItems;
272   }
273 
274   public List<LineItem> getLineItems() {
275     return lineItems;
276   }
277 
278   /**
279    * Inits the order.
280    *
281    * @param account
282    *          the account
283    * @param cart
284    *          the cart
285    */
286   public void initOrder(Account account, Cart cart) {
287 
288     username = account.getUsername();
289     orderDate = new Date();
290 
291     shipToFirstName = account.getFirstName();
292     shipToLastName = account.getLastName();
293     shipAddress1 = account.getAddress1();
294     shipAddress2 = account.getAddress2();
295     shipCity = account.getCity();
296     shipState = account.getState();
297     shipZip = account.getZip();
298     shipCountry = account.getCountry();
299 
300     billToFirstName = account.getFirstName();
301     billToLastName = account.getLastName();
302     billAddress1 = account.getAddress1();
303     billAddress2 = account.getAddress2();
304     billCity = account.getCity();
305     billState = account.getState();
306     billZip = account.getZip();
307     billCountry = account.getCountry();
308 
309     totalPrice = cart.getSubTotal();
310 
311     creditCard = "999 9999 9999 9999";
312     expiryDate = "12/03";
313     cardType = "Visa";
314     courier = "UPS";
315     locale = "CA";
316     status = "P";
317 
318     Iterator<CartItem> i = cart.getAllCartItems();
319     while (i.hasNext()) {
320       CartItem cartItem = i.next();
321       addLineItem(cartItem);
322     }
323 
324   }
325 
326   public void addLineItem(CartItem cartItem) {
327     LineItem lineItem = new LineItem(lineItems.size() + 1, cartItem);
328     addLineItem(lineItem);
329   }
330 
331   public void addLineItem(LineItem lineItem) {
332     lineItems.add(lineItem);
333   }
334 
335 }