001 package org.cocome.tradingsystem.testdriver;
002
003 import java.util.Date;
004
005 import javax.naming.OperationNotSupportedException;
006
007 import org.cocome.tradingsystem.inventory.data.store.ProductOrder;
008 import org.cocome.tradingsystem.inventory.data.store.StockItem;
009 import org.cocome.tradingsystem.inventory.data.store.Store;
010 import org.cocome.tradingsystem.systests.interfaces.IOrder;
011 import org.cocome.tradingsystem.systests.interfaces.IProduct;
012 import org.cocome.tradingsystem.systests.interfaces.IStorePC;
013
014 /**
015 * Glue code for the store PC.
016 *
017 * @author Benjamin Hummel
018 * @author $Author: hummel $
019 * @version $Rev: 63 $
020 * @levd.rating YELLOW Rev: 56
021 */
022 public class StorePC implements IStorePC {
023
024 /** The index of this stock PC. */
025 private final int index;
026
027 /** DB representation of this store. */
028 private final Store dbStore;
029
030 /** Create a new stock PC. */
031 public StorePC(int index, Enterprise enterprise) {
032 this.index = index;
033 dbStore = new Store();
034 dbStore.setEnterprise(enterprise.getDBEnterprise());
035 dbStore.setLocation("Location " + index);
036 dbStore.setName("Store" + index);
037 DBManager.getInstance().persistDBObject(dbStore);
038 }
039
040 /** {@inheritDoc} */
041 public int getAmount(IProduct product) {
042 ProductWrapper wrapper = (ProductWrapper) product;
043 StockItem item = DBManager.getInstance().getStoreQuery()
044 .queryStockItem(dbStore.getId(),
045 wrapper.getProduct().getBarcode(),
046 DBManager.getInstance().createPersistenceContext());
047 return (int) item.getAmount();
048 }
049
050 /** Returns the incoming amount for a product. */
051 /*package*/ int getIncomingAmount(IProduct product) {
052 ProductWrapper wrapper = (ProductWrapper) product;
053 StockItem item = DBManager.getInstance().getStoreQuery()
054 .queryStockItem(dbStore.getId(),
055 wrapper.getProduct().getBarcode(),
056 DBManager.getInstance().createPersistenceContext());
057 return (int) item.getIncomingAmount();
058 }
059
060 /** {@inheritDoc} */
061 public void insertStockItem(IProduct product, int salesPrice, int amount,
062 int minAmount) {
063 ProductWrapper wrapper = (ProductWrapper) product;
064
065 StockItem item = new StockItem();
066 item.setAmount(amount);
067 item.setMinStock(minAmount);
068 item.setMaxStock(100 * amount);
069 item.setProduct(wrapper.getProduct());
070 item.setStore(dbStore);
071 item.setSalesPrice(salesPrice / 100.);
072
073 DBManager.getInstance().persistDBObject(item);
074 }
075
076 /** Returns the index of this stock PC. */
077 public int getIndex() {
078 return index;
079 }
080
081 /** {@inheritDoc} */
082 public IOrder createOrder() {
083 ProductOrder po = new ProductOrder();
084 po.setOrderingDate(new Date());
085 po.setStore(dbStore);
086 DBManager.getInstance().persistDBObject(po);
087 return new OrderWrapper(po);
088 }
089
090 /** {@inheritDoc} */
091 public void executeOrder(IOrder order)
092 throws OperationNotSupportedException {
093 // FIXME: this is currently not supported as the relevant methods of the
094 // implementation are hard to access
095 throw new OperationNotSupportedException();
096 }
097
098 /** {@inheritDoc} */
099 public void rollInOrder(IOrder order) throws OperationNotSupportedException {
100 // FIXME: this is currently not supported as the relevant methods of the
101 // implementation are hard to access
102 throw new OperationNotSupportedException();
103 }
104 }