KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > johnmammen > betterpetshop > service > spring > PetshopManagerImpl


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.spring;
17
18 import java.sql.SQLException JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import johnmammen.betterpetshop.service.PetshopManager;
22 import johnmammen.betterpetshop.service.dao.IBannerdataDAO;
23 import johnmammen.betterpetshop.service.dao.ICustomerDAO;
24 import johnmammen.betterpetshop.service.dao.IOrderDAO;
25 import johnmammen.betterpetshop.service.dao.IProductDAO;
26
27 import org.apache.tapestry.pets.domain.model.ICustomer;
28 import org.apache.tapestry.pets.domain.model.IInventory;
29 import org.apache.tapestry.pets.domain.model.IItem;
30 import org.apache.tapestry.pets.domain.model.IProduct;
31 import org.apache.tapestry.pets.domain.model.IShoppingCart;
32 import org.apache.tapestry.pets.domain.model.IUserLogin;
33 import org.apache.tapestry.pets.domain.model.pojo.Inventory;
34
35 import org.springframework.dao.DataAccessException;
36
37 public class PetshopManagerImpl implements PetshopManager {
38
39     private IBannerdataDAO bannerdata;
40
41     private ICustomerDAO customer;
42
43     private IOrderDAO order;
44
45     private IProductDAO product;
46
47     private static int count = 0;
48
49     // BannerData///////////////////
50
public String JavaDoc getBannerPath(String JavaDoc favCategory) {
51         // this.getHibernateTemplate().find(
52
// "FROM bannerdata WHERE (favcategory = ?)", favCategory,
53
// Hibernate.CHARACTER);
54
// return null;
55
return getBannerdata().getBannerPath(favCategory);
56
57     }
58
59     // Customer////////////////////////////////
60

61     public ICustomer authenticate(IUserLogin signOn) {
62
63         // ICustomer cust = (ICustomer) this.getHibernateTemplate()
64
// .load(UseraccountBean.class, signOn.getUserID());
65
// if (cust != null) this.logger.debug("Got customer " +
66
// cust.getEmail());
67
// else logger.debug("Customer is null ");
68
//
69
// return cust;
70

71         return getCustomer().login(signOn.getUserID(), signOn.getPassword());
72
73     }
74
75     public ICustomer accountInfo(String JavaDoc userID) {
76         ICustomer c = null;
77         // c = (ICustomer)
78
// this.getHibernateTemplate().load(UseraccountBean.class, userID);
79

80         c = getCustomer().accountInfo(userID);
81
82         return c;
83     }
84
85     public boolean add(ICustomer newcustomer, IUserLogin userLogin) {
86         //this.getHibernateTemplate().saveOrUpdateCopy(userLogin);
87
return getCustomer().add(newcustomer, userLogin);
88         
89     }
90
91     /**
92      * Updates a customer account in the database.
93      */

94     public void updateAccount(ICustomer customer) {
95         getCustomer().updateAccount(customer);
96     }
97
98     //GenProducts////////////////////////
99
public IProduct[] getProducts() throws SQLException JavaDoc {
100         return getProduct().getProducts();
101
102     }
103
104     //Item//////////////////////////////////////////
105
public IItem[] getItemsByProduct(String JavaDoc prodid) {
106
107         // IItem[] items = new Item[1];
108
// ProductBean product = (ProductBean) getHibernateTemplate().load(
109
// ProductBean.class, prodid);
110
// IItem item = new Item();
111
// item.setDesc(product.getDescn());
112
// item.setImage(product.getImage());
113
// item.setItemAttr1(product.getName());
114
// item.setItemID(product.getProductid());
115
// item.setItemName(product.getProductName());
116
// double randomPrice = 1.99;
117
// item.setPrice(new BigDecimal(randomPrice));
118
// item.setQty(1);
119
// items[0] = item;
120
//
121
// return items;
122

123         return getProduct().getItemsByProduct(prodid);
124     }
125
126     public IItem getItem(String JavaDoc itemID) {
127         // ProductBean product = (ProductBean) getHibernateTemplate().load(
128
// ProductBean.class, itemID);
129
// IItem item = new Item();
130
// item.setDesc(product.getDescn());
131
// item.setImage(product.getImage());
132
// item.setItemAttr1(product.getName());
133
// item.setItemID(product.getProductid());
134
// item.setItemName(product.getProductName());
135
// item.setPrice(new BigDecimal("33.0"));
136
// item.setQty(1);
137
//
138
// return item;
139
return getProduct().getItem(itemID);
140     }
141
142     //Order///////////////////////////////////////////
143
public String JavaDoc addOrder(Map JavaDoc orderInfo, IShoppingCart cart) {
144         return getOrder().addOrder(orderInfo, cart);
145     }
146
147     //Product////////////////////////////////////////////////////
148
public IProduct[] findByCategory(String JavaDoc catid) throws DataAccessException {
149         // IProduct[] products = null;
150
// List prodlist = this.getHibernateTemplate().find(
151
// "from ProductBean product where product.catid=?", catid);
152
//
153
// if (prodlist != null && !prodlist.isEmpty()) {
154
// products = new IProduct[prodlist.size()];
155
// for (int i = 0; i < prodlist.size(); i++) {
156
// products[i] = (IProduct) prodlist.get(i);
157
//
158
// }
159
//
160
// }
161
// return products;
162
return getProduct().findByCategory(catid);
163     }
164
165     public IProduct[] findBySearchCriteria(String JavaDoc searchText) {
166
167         // searchText = "%" + searchText + "%";
168
// IProduct[] products = null;
169
// List prodlist = getHibernateTemplate()
170
// .find(
171
// "from ProductBean product where product.productDetails.productName
172
// like ?",
173
// searchText);
174
//
175
// if (prodlist != null && !prodlist.isEmpty()) {
176
// products = new IProduct[prodlist.size()];
177
// for (int i = 0; i < prodlist.size(); i++) {
178
// products[i] = (IProduct) prodlist.get(i);
179
//
180
// }
181
//
182
// }
183
//
184
// return products;
185
return getProduct().findBySearchCriteria(searchText);
186     }
187
188     //ShoppingCart///////////////////////////////////////
189

190     public IInventory[] getInventory(String JavaDoc csvItemList) {
191         //TO-DO
192
// There is a bug here I cant figure it out
193
// when I call the productDAO it give me null;
194

195         IInventory[] inventory = new Inventory[1];
196         IInventory inv = new Inventory();
197         inv.setItemID("TEST");
198         inv.setQty(100);
199         inventory[0] = inv;
200
201         return inventory;
202         //return getProduct().getInventory(csvItemList);
203
}
204
205     /**
206      * @return Returns the bannerdata.
207      */

208     public IBannerdataDAO getBannerdata() {
209         return bannerdata;
210     }
211
212     /**
213      * @param bannerdata
214      * The bannerdata to set.
215      */

216     public void setBannerdata(IBannerdataDAO bannerdata) {
217         this.bannerdata = bannerdata;
218     }
219
220     /**
221      * @return Returns the customer.
222      */

223     public ICustomerDAO getCustomer() {
224         return customer;
225     }
226
227     /**
228      * @param customer
229      * The customer to set.
230      */

231     public void setCustomer(ICustomerDAO customer) {
232         this.customer = customer;
233     }
234
235     /**
236      * @return Returns the order.
237      */

238     public IOrderDAO getOrder() {
239         return order;
240     }
241
242     /**
243      * @param order
244      * The order to set.
245      */

246     public void setOrder(IOrderDAO order) {
247         this.order = order;
248     }
249
250     /**
251      * @return Returns the product.
252      */

253     public IProductDAO getProduct() {
254         return product;
255     }
256
257     /**
258      * @param product
259      * The product to set.
260      */

261     public void setProduct(IProductDAO product) {
262         this.product = product;
263     }
264
265     /**
266      *
267      */

268     public PetshopManagerImpl() {
269         count++;
270         System.out
271                 .println("<<<<<<<<<<<<<<<>>>>>>>>>>>Incrementing PETSHOPMANGER "
272                         + count);
273     }
274 }
Popular Tags