1 16 package johnmammen.betterpetshop.service.dao.hibernate; 17 18 import java.math.BigDecimal ; 19 import java.util.HashSet ; 20 import java.util.Iterator ; 21 import java.util.Map ; 22 import java.util.Set ; 23 24 import johnmammen.betterpetshop.bo.Item; 25 import johnmammen.betterpetshop.bo.Lineitem; 26 import johnmammen.betterpetshop.bo.LineitemPK; 27 import johnmammen.betterpetshop.bo.Order; 28 import johnmammen.betterpetshop.bo.Useraccount; 29 import johnmammen.betterpetshop.service.dao.IOrderDAO; 30 31 import org.apache.tapestry.pets.domain.model.IBasketItem; 32 import org.apache.tapestry.pets.domain.model.ICustomer; 33 import org.apache.tapestry.pets.domain.model.IItem; 34 import org.apache.tapestry.pets.domain.model.IShoppingCart; 35 import org.doomdark.uuid.UUIDGenerator; 36 import org.springframework.orm.hibernate.support.HibernateDaoSupport; 37 38 43 public class OrderDAO extends HibernateDaoSupport implements IOrderDAO { 44 45 48 public OrderDAO() { 49 super(); 50 } 51 52 58 public String addOrder(Map orderInfo, IShoppingCart cart) { 59 String orderID = getOrderID(); 60 Order o = new Order(); 61 ICustomer user = new Useraccount(); 62 user.setUserid((String ) orderInfo.get("UserID")); 63 64 o.setOrderid(orderID); 65 o.setUseraccount(user); 66 o.setShiptofirstname((String ) orderInfo.get("Ship_FirstName")); 67 o.setShiptolastname((String ) orderInfo.get("Ship_LastName")); 68 o.setShiptoaddress1((String ) orderInfo.get("Ship_Address1")); 69 o.setShiptoaddress2((String ) orderInfo.get("Ship_Address2")); 70 o.setShiptocity((String ) orderInfo.get("Ship_City")); 71 o.setShiptostate((String ) orderInfo.get("Ship_State")); 72 o.setShiptozip((String ) orderInfo.get("Ship_PostalCode")); 73 o.setShiptocountry((String ) orderInfo.get("Ship_Country")); 74 o.setShiptophonenumber((String ) orderInfo.get("Ship_PhoneNumber")); 75 o.setBilltofirstname((String ) orderInfo.get("Bill_FirstName")); 76 o.setBilltolastname((String ) orderInfo.get("Bill_LastName")); 77 o.setBilltoaddress1((String ) orderInfo.get("Bill_Address1")); 78 o.setBilltoaddress2((String ) orderInfo.get("Bill_Address2")); 79 o.setBilltocity((String ) orderInfo.get("Bill_City")); 80 o.setBilltostate((String ) orderInfo.get("Bill_State")); 81 o.setBilltopostalcode((String ) orderInfo.get("Bill_PostalCode")); 82 o.setBilltocountry((String ) orderInfo.get("Bill_Country")); 83 o.setBilltophonenumber((String ) orderInfo.get("Bill_PhoneNumber")); 84 String price = (String ) orderInfo.get("Total_Price"); 85 BigDecimal bdPrice = new BigDecimal (price); 86 o.setTotalprice(bdPrice); 87 o.setCardtype((String ) orderInfo.get("CardType")); 88 o.setCardnumber((String ) orderInfo.get("CardNumber")); 89 o.setCardexpiremonth((String ) orderInfo.get("CardExpireMonth")); 90 o.setCardexpireyear((String ) orderInfo.get("CardExpireYear")); 91 o.setLocale((String ) orderInfo.get("Locale")); 92 93 Set lineitems = new HashSet (); 94 int itemcount = 0; 95 for (Iterator iter = cart.getItems().iterator(); iter.hasNext();) { 96 IBasketItem bitem = (IBasketItem) iter.next(); 97 Lineitem li =new Lineitem(); 98 LineitemPK pk = new LineitemPK(); 99 pk.setOrderid(orderID); 100 101 pk.setLinenum(new Integer (itemcount)); 102 itemcount++; 103 IItem item = new Item(); 104 item.setItemid(bitem.getItemID()); 105 item.setListprice(new BigDecimal (bitem.getTotal())); 106 item.setUnitcost(bitem.getPrice()); 107 item.setQty(bitem.getQty()); 108 109 110 111 114 li.setComp_id(pk); 115 li.setItem(item); 116 li.setQuantity(bitem.getQty()); 117 li.setUnitprice(bitem.getPrice()); 118 lineitems.add(li); 119 120 121 } 127 o.setLineitems(lineitems); 128 getHibernateTemplate().save(o); 129 130 131 return orderID; 132 } 133 134 private String getOrderID() { 135 return UUIDGenerator.getInstance().generateTimeBasedUUID().toString(); 137 } 138 } | Popular Tags |