001: package org.springunit.framework.samples.jpetstore.domain;
002:
003: import java.util.ArrayList;
004: import java.util.Date;
005: import java.util.Iterator;
006: import java.util.List;
007:
008: import org.apache.commons.lang.builder.CompareToBuilder;
009: import org.apache.commons.lang.builder.EqualsBuilder;
010: import org.apache.commons.lang.builder.HashCodeBuilder;
011: import org.apache.commons.lang.builder.ToStringBuilder;
012: import org.apache.commons.lang.builder.ToStringStyle;
013:
014: public class Order extends Persistable {
015:
016: public String getBillAddress1() {
017: return billAddress1;
018: }
019:
020: public String getBillAddress2() {
021: return billAddress2;
022: }
023:
024: public String getBillCity() {
025: return billCity;
026: }
027:
028: public String getBillCountry() {
029: return billCountry;
030: }
031:
032: public String getBillState() {
033: return billState;
034: }
035:
036: public String getBillToFirstName() {
037: return billToFirstName;
038: }
039:
040: public String getBillToLastName() {
041: return billToLastName;
042: }
043:
044: public String getBillZip() {
045: return billZip;
046: }
047:
048: public String getCardType() {
049: return cardType;
050: }
051:
052: public String getCourier() {
053: return courier;
054: }
055:
056: public String getCreditCard() {
057: return creditCard;
058: }
059:
060: public String getExpiryDate() {
061: return expiryDate;
062: }
063:
064: public List<LineItem> getLineItems() {
065: return lineItems;
066: }
067:
068: public String getLocale() {
069: return locale;
070: }
071:
072: public Date getOrderDate() {
073: return orderDate;
074: }
075:
076: public String getShipAddress1() {
077: return shipAddress1;
078: }
079:
080: public String getShipAddress2() {
081: return shipAddress2;
082: }
083:
084: public String getShipCity() {
085: return shipCity;
086: }
087:
088: public String getShipCountry() {
089: return shipCountry;
090: }
091:
092: public String getShipState() {
093: return shipState;
094: }
095:
096: public String getShipToFirstName() {
097: return shipToFirstName;
098: }
099:
100: public String getShipToLastName() {
101: return shipToLastName;
102: }
103:
104: public String getShipZip() {
105: return shipZip;
106: }
107:
108: public String getStatus() {
109: return status;
110: }
111:
112: public double getTotalPrice() {
113: return totalPrice;
114: }
115:
116: public String getUsername() {
117: return username;
118: }
119:
120: public void setBillAddress1(String billAddress1) {
121: this .billAddress1 = billAddress1;
122: }
123:
124: public void setBillAddress2(String billAddress2) {
125: this .billAddress2 = billAddress2;
126: }
127:
128: public void setBillCity(String billCity) {
129: this .billCity = billCity;
130: }
131:
132: public void setBillCountry(String billCountry) {
133: this .billCountry = billCountry;
134: }
135:
136: public void setBillState(String billState) {
137: this .billState = billState;
138: }
139:
140: public void setBillToFirstName(String billToFirstName) {
141: this .billToFirstName = billToFirstName;
142: }
143:
144: public void setBillToLastName(String billToLastName) {
145: this .billToLastName = billToLastName;
146: }
147:
148: public void setBillZip(String billZip) {
149: this .billZip = billZip;
150: }
151:
152: public void setCardType(String cardType) {
153: this .cardType = cardType;
154: }
155:
156: public void setCourier(String courier) {
157: this .courier = courier;
158: }
159:
160: public void setCreditCard(String creditCard) {
161: this .creditCard = creditCard;
162: }
163:
164: public void setExpiryDate(String expiryDate) {
165: this .expiryDate = expiryDate;
166: }
167:
168: public void setLineItems(List<LineItem> lineItems) {
169: this .lineItems = lineItems;
170: }
171:
172: public void setLocale(String locale) {
173: this .locale = locale;
174: }
175:
176: public void setOrderDate(Date orderDate) {
177: this .orderDate = orderDate;
178: }
179:
180: public void setShipAddress1(String shipAddress1) {
181: this .shipAddress1 = shipAddress1;
182: }
183:
184: public void setShipAddress2(String shipAddress2) {
185: this .shipAddress2 = shipAddress2;
186: }
187:
188: public void setShipCity(String shipCity) {
189: this .shipCity = shipCity;
190: }
191:
192: public void setShipCountry(String shipCountry) {
193: this .shipCountry = shipCountry;
194: }
195:
196: public void setShipState(String shipState) {
197: this .shipState = shipState;
198: }
199:
200: public void setShipToFirstName(String shipToFirstName) {
201: this .shipToFirstName = shipToFirstName;
202: }
203:
204: public void setShipToLastName(String shipToLastName) {
205: this .shipToLastName = shipToLastName;
206: }
207:
208: public void setShipZip(String shipZip) {
209: this .shipZip = shipZip;
210: }
211:
212: public void setStatus(String status) {
213: this .status = status;
214: }
215:
216: public void setTotalPrice(double totalPrice) {
217: this .totalPrice = totalPrice;
218: }
219:
220: public void setUsername(String username) {
221: this .username = username;
222: }
223:
224: public void initOrder(Account account, Cart cart) {
225: this .username = account.getUsername();
226: this .orderDate = new Date();
227:
228: this .shipToFirstName = account.getFirstName();
229: this .shipToLastName = account.getLastName();
230: this .shipAddress1 = account.getAddress1();
231: this .shipAddress2 = account.getAddress2();
232: this .shipCity = account.getCity();
233: this .shipState = account.getState();
234: this .shipZip = account.getZip();
235: this .shipCountry = account.getCountry();
236:
237: this .billToFirstName = account.getFirstName();
238: this .billToLastName = account.getLastName();
239: this .billAddress1 = account.getAddress1();
240: this .billAddress2 = account.getAddress2();
241: this .billCity = account.getCity();
242: this .billState = account.getState();
243: this .billZip = account.getZip();
244: this .billCountry = account.getCountry();
245:
246: this .totalPrice = cart.getSubTotal();
247:
248: this .creditCard = "999 9999 9999 9999";
249: this .expiryDate = "12/03";
250: this .cardType = "Visa";
251: this .courier = "UPS";
252: this .locale = "CA";
253: this .status = "P";
254:
255: Iterator i = cart.getAllCartItems();
256: while (i.hasNext()) {
257: CartItem cartItem = (CartItem) i.next();
258: addLineItem(cartItem);
259: }
260: }
261:
262: public void addLineItem(CartItem cartItem) {
263: LineItem lineItem = new LineItem(this .lineItems.size() + 1,
264: cartItem);
265: addLineItem(lineItem);
266: }
267:
268: public void addLineItem(LineItem lineItem) {
269: this .lineItems.add(lineItem);
270: }
271:
272: public int compareTo(Object that) {
273: Order other = (Order) that;
274: return new CompareToBuilder().append(getUsername(),
275: other.getUsername()).append(getOrderDate(),
276: other.getOrderDate()).append(getTotalPrice(),
277: other.getTotalPrice()).toComparison();
278: }
279:
280: public boolean equals(Object that) {
281: if (this == that) {
282: return true;
283: }
284: if (!(that instanceof Order)) {
285: return false;
286: }
287: Order other = (Order) that;
288: return new EqualsBuilder().append(getUsername(),
289: other.getUsername()).append(getOrderDate(),
290: other.getOrderDate()).append(getTotalPrice(),
291: other.getTotalPrice()).isEquals();
292: }
293:
294: public int hashCode() {
295: return new HashCodeBuilder(PRIME, MULTIPLIER).append(
296: getUsername()).append(getOrderDate()).append(
297: getTotalPrice()).toHashCode();
298: }
299:
300: public String toString() {
301: return new ToStringBuilder(this , ToStringStyle.MULTI_LINE_STYLE)
302: .appendSuper(super .toString()).append("username",
303: getUsername()).append("orderDate",
304: getOrderDate()).append("status", getStatus())
305: .append("shipToFirstName", getShipToFirstName())
306: .append("shipToLastName", getShipToLastName()).append(
307: "shipAddress1", getShipAddress1()).append(
308: "shipAddress2", getShipAddress2()).append(
309: "shipCity", getShipCity()).append("shipState",
310: getShipState()).append("shipZip", getShipZip())
311: .append("shipCountry", getShipCountry()).append(
312: "billToFirstName", getBillToFirstName())
313: .append("billToLastName", getBillToLastName()).append(
314: "billAddress1", getBillAddress1()).append(
315: "billAddress2", getBillAddress2()).append(
316: "billCity", getBillCity()).append("billState",
317: getBillState()).append("billZip", getBillZip())
318: .append("billCountry", getBillCountry()).append(
319: "courier", getCourier()).append("totalPrice",
320: getTotalPrice()).append("creditCard",
321: getCreditCard()).append("expiryDate",
322: getExpiryDate()).append("cardType",
323: getCardType()).append("locale", getLocale())
324: .toString();
325: }
326:
327: private static final long serialVersionUID = 6L;
328:
329: private String username;
330: private Date orderDate;
331: private String shipAddress1;
332: private String shipAddress2;
333: private String shipCity;
334: private String shipState;
335: private String shipZip;
336: private String shipCountry;
337: private String billAddress1;
338: private String billAddress2;
339: private String billCity;
340: private String billState;
341: private String billZip;
342: private String billCountry;
343: private String courier;
344: private double totalPrice;
345: private String billToFirstName;
346: private String billToLastName;
347: private String shipToFirstName;
348: private String shipToLastName;
349: private String creditCard;
350: private String expiryDate;
351: private String cardType;
352: private String locale;
353: private String status;
354: private List<LineItem> lineItems = new ArrayList<LineItem>();
355:
356: }
|