001    package org.cocome.tradingsystem.testdriver;
002    
003    import org.cocome.tradingsystem.inventory.data.enterprise.Product;
004    import org.cocome.tradingsystem.inventory.data.enterprise.ProductSupplier;
005    import org.cocome.tradingsystem.inventory.data.enterprise.TradingEnterprise;
006    import org.cocome.tradingsystem.systests.interfaces.IEnterprise;
007    import org.cocome.tradingsystem.systests.interfaces.IProduct;
008    import org.cocome.tradingsystem.systests.interfaces.IStorePC;
009    
010    /**
011     * Glue code for the entire enterprice (i.e. the database).
012     * 
013     * @author Benjamin Hummel
014     * @author $Author: hummel $
015     * @version $Rev: 63 $
016     * @levd.rating GREEN Rev: 63
017     */
018    public class Enterprise implements IEnterprise {
019    
020            /** The DB representation of the enterprise. */
021            private final TradingEnterprise dbEnterprise;
022    
023            /** The supplier used for all products. */
024            private final ProductSupplier defaultSupplier;
025    
026            /** Create the enterprise. */
027            public Enterprise() {
028                    dbEnterprise = new TradingEnterprise();
029                    dbEnterprise.setName("My Enterprise");
030                    DBManager.getInstance().persistDBObject(dbEnterprise);
031    
032                    defaultSupplier = new ProductSupplier();
033                    defaultSupplier.setName("default supplier");
034                    DBManager.getInstance().persistDBObject(defaultSupplier);
035            }
036    
037            /** {@inheritDoc} */
038            public IProduct createProduct(int barcode, int purchasePrice, String name) {
039                    Product product = new Product();
040                    product.setBarcode(barcode);
041                    product.setName(name);
042                    product.setPurchasePrice(purchasePrice / 100.);
043                    product.setSupplier(defaultSupplier);
044                    DBManager.getInstance().persistDBObject(product);
045                    return new ProductWrapper(product);
046            }
047    
048            /** Returns the enterprise DB object. */
049            public TradingEnterprise getDBEnterprise() {
050                    return dbEnterprise;
051            }
052    
053            /** {@inheritDoc} */
054            public boolean existsProductTransfer(IProduct product, IStorePC storeFrom,
055                            IStorePC storeTo) {
056    
057                    /*
058                     * Currently we only check, if there are incoming goods and not, if they
059                     * are really from the expected store.
060                     */
061    
062                    StorePC to = (StorePC) storeTo;
063                    return (to.getIncomingAmount(product) > 0);
064            }
065    
066    }