@Override public void setPackageProductType(ProductType packageProductType) { this.packageProductType = packageProductType; this.packageProductTypeItem = null; productTypeItemList.clear(); productTypeGUIList.removeAll(); if (packageProductType != null) { String languageID = NLLocale.getDefault().getLanguage(); if (packageProductType.getInnerPriceConfig() != null) { productTypeItemList.add(new Item(false, true, packageProductType)); productTypeGUIList.add( packageProductType.getName().getText(languageID) + Messages.getString( "org.nightlabs.jfire.trade.admin.ui.gridpriceconfig.ProductTypeSelectorListImpl.packageProductType_base")); //$NON-NLS-1$ } // EventInnerProductInfo assemblyInnerProductInfo = // assemblyPackageProductInfo.getEventInnerProductInfo(); // if (!(assemblyInnerProductInfo.getPriceConfig() instanceof FormulaPriceConfig)) // throw new IllegalArgumentException("The PriceConfig of assemblyInnerProductInfo is not // an instance of FormulaPriceConfig!"); // // productTypeItemList.add(assemblyInnerProductInfo); // productTypeGUIList.add(assemblyInnerProductInfo.getPrimaryKey()); // TO DO i18n for (NestedProductTypeLocal nestedProductTypeLocal : packageProductType.getProductTypeLocal().getNestedProductTypeLocals()) { ProductType productType = nestedProductTypeLocal.getInnerProductTypeLocal().getProductType(); // if (assemblyInnerProductInfo == productInfo) // continue; productTypeItemList.add(new Item(false, false, productType)); productTypeGUIList.add( productType.getName().getText(languageID) + " [" + nestedProductTypeLocal.getQuantity() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } if (packageProductType.getPackagePriceConfig() != null) { packageProductTypeItem = new Item(true, false, packageProductType); productTypeItemList.add(packageProductTypeItem); productTypeGUIList.add( packageProductType.getName().getText(languageID) + Messages.getString( "org.nightlabs.jfire.trade.admin.ui.gridpriceconfig.ProductTypeSelectorListImpl.packageProductType_total")); //$NON-NLS-1$ } productTypeGUIList.select(0); } // if (assemblyPackageProductInfo != null) { fireSelectionChangedEvent(); }
@Override @SuppressWarnings("unchecked") public Collection<? extends Product> findProducts( User user, ProductType productType, NestedProductTypeLocal nestedProductTypeLocal, ProductLocator productLocator) { if (logger.isDebugEnabled()) logger.debug( "findProducts entered. organisationID = " + getOrganisationID() + " productType=" + productType.getPrimaryKey()); VoucherType vt = (VoucherType) productType; VoucherTypeLocal vtl = (VoucherTypeLocal) productType.getProductTypeLocal(); int qty = nestedProductTypeLocal == null ? 1 : nestedProductTypeLocal.getQuantity(); PersistenceManager pm = getPersistenceManager(); Store store = Store.getStore(pm); // search for an available product Query q = pm.newQuery(Voucher.class); q.setFilter("productType == pProductType && productLocal.available"); q.declareParameters("VoucherType pProductType"); q.declareImports("import " + VoucherType.class.getName()); Collection availableProducts = (Collection) q.execute( productType); // Product.getProducts(pm, this, ProductStatus.STATUS_AVAILABLE); ArrayList res = new ArrayList(); Iterator iteratorAvailableProducts = availableProducts.iterator(); for (int i = 0; i < qty; ++i) { Voucher product = null; if (iteratorAvailableProducts.hasNext()) { product = (Voucher) iteratorAvailableProducts.next(); res.add(product); } else { // create products only if this product type is ours if (productType.getOrganisationID().equals(store.getOrganisationID())) { long createdProductCount = vtl.getCreatedVoucherCount(); if (vtl.getMaxVoucherCount() < 0 || createdProductCount + 1 <= vtl.getMaxVoucherCount()) { product = new Voucher(vt, Product.createProductID()); vtl.setCreatedVoucherCount(createdProductCount + 1); store.addProduct(user, product); // , (Repository)vt.getProductTypeLocal().getHome()); res.add(product); } } // This productType is factored by this organisation else throw new UnsupportedOperationException("NYI"); } } return res; }