KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > johnmammen > betterpetshop > service > dao > hibernate > OrderDAO


1 /*
2  * Copyright 2004 John S. Mammen
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package johnmammen.betterpetshop.service.dao.hibernate;
17
18 import java.math.BigDecimal JavaDoc;
19 import java.util.HashSet JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Set JavaDoc;
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 /**
39  * @author admin
40  *
41  *
42  */

43 public class OrderDAO extends HibernateDaoSupport implements IOrderDAO {
44
45     /**
46      *
47      */

48     public OrderDAO() {
49         super();
50     }
51
52     /*
53      * (non-Javadoc)
54      *
55      * @see johnmammen.betterpetshop.service.dao.IOrderDAO#addOrder(java.util.Map,
56      * org.apache.tapestry.pets.domain.model.IShoppingCart)
57      */

58     public String JavaDoc addOrder(Map JavaDoc orderInfo, IShoppingCart cart) {
59         String JavaDoc orderID = getOrderID();
60         Order o = new Order();
61         ICustomer user = new Useraccount();
62         user.setUserid((String JavaDoc) orderInfo.get("UserID"));
63
64         o.setOrderid(orderID);
65         o.setUseraccount(user);
66         o.setShiptofirstname((String JavaDoc) orderInfo.get("Ship_FirstName"));
67         o.setShiptolastname((String JavaDoc) orderInfo.get("Ship_LastName"));
68         o.setShiptoaddress1((String JavaDoc) orderInfo.get("Ship_Address1"));
69         o.setShiptoaddress2((String JavaDoc) orderInfo.get("Ship_Address2"));
70         o.setShiptocity((String JavaDoc) orderInfo.get("Ship_City"));
71         o.setShiptostate((String JavaDoc) orderInfo.get("Ship_State"));
72         o.setShiptozip((String JavaDoc) orderInfo.get("Ship_PostalCode"));
73         o.setShiptocountry((String JavaDoc) orderInfo.get("Ship_Country"));
74         o.setShiptophonenumber((String JavaDoc) orderInfo.get("Ship_PhoneNumber"));
75         o.setBilltofirstname((String JavaDoc) orderInfo.get("Bill_FirstName"));
76         o.setBilltolastname((String JavaDoc) orderInfo.get("Bill_LastName"));
77         o.setBilltoaddress1((String JavaDoc) orderInfo.get("Bill_Address1"));
78         o.setBilltoaddress2((String JavaDoc) orderInfo.get("Bill_Address2"));
79         o.setBilltocity((String JavaDoc) orderInfo.get("Bill_City"));
80         o.setBilltostate((String JavaDoc) orderInfo.get("Bill_State"));
81         o.setBilltopostalcode((String JavaDoc) orderInfo.get("Bill_PostalCode"));
82         o.setBilltocountry((String JavaDoc) orderInfo.get("Bill_Country"));
83         o.setBilltophonenumber((String JavaDoc) orderInfo.get("Bill_PhoneNumber"));
84         String JavaDoc price = (String JavaDoc) orderInfo.get("Total_Price");
85         BigDecimal JavaDoc bdPrice = new BigDecimal JavaDoc(price);
86         o.setTotalprice(bdPrice);
87         o.setCardtype((String JavaDoc) orderInfo.get("CardType"));
88         o.setCardnumber((String JavaDoc) orderInfo.get("CardNumber"));
89         o.setCardexpiremonth((String JavaDoc) orderInfo.get("CardExpireMonth"));
90         o.setCardexpireyear((String JavaDoc) orderInfo.get("CardExpireYear"));
91         o.setLocale((String JavaDoc) orderInfo.get("Locale"));
92         
93        Set JavaDoc lineitems = new HashSet JavaDoc();
94        int itemcount = 0;
95         for (Iterator JavaDoc 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 JavaDoc(itemcount));
102             itemcount++;
103             IItem item = new Item();
104             item.setItemid(bitem.getItemID());
105             item.setListprice(new BigDecimal JavaDoc(bitem.getTotal()));
106             item.setUnitcost(bitem.getPrice());
107             item.setQty(bitem.getQty());
108            
109           
110         
111             //System.out.println("INSIDE LINEITEM <><>M>M><><<<<<<<><>>bitem.getItemID() "+bitem.getItemID());
112
//System.out.println("INSIDE LINEITEM <><>M>M><><<<<<<<><>>bitem.getPrice() "+bitem.getPrice());
113

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 //
122
// trans.modify(sql_step2, new Object[] { orderID,
123
// new Integer(itemNum++), bitem.getItemID(),
124
// new Integer(bitem.getQty()), bitem.getPrice()},
125
// updateProcessor);
126
}
127         o.setLineitems(lineitems);
128         getHibernateTemplate().save(o);
129
130
131         return orderID;
132     }
133
134     private String JavaDoc getOrderID() {
135         //return null;
136
return UUIDGenerator.getInstance().generateTimeBasedUUID().toString();
137     }
138 }
Popular Tags