Search in sources :

Example 1 with ProductSpecEao

use of eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao in project dwoss by gg-net.

the class ProductProcessorOperation method create.

/**
 * Creates a new ProductSpec and the relating Product and SopoProduct.
 * <p>
 * The process has multiple steps:
 * <ol>
 * <li>Merge the ProductModel and set it in the Spec</li>
 * <li>If Spec is a DisplayAble its assumed the Display is either existent or new.<br />
 * In case it exists, the existent value will be set in the Spec</li>
 * <li>If Spec is a Desktop its assumed that the Cpu and Gpu are existent, and they are merged and set.</li>
 * <li>The Spec is persisted</li>
 * <li>A Product is created and persisted</li>
 * <li>The Spec.productId is set to Product.id (WeakReference)</li>
 * <li>A SopoProduct is searched. If found, it is updated, else a new one is created</li>
 * </ol>
 *
 * @param spec  the spec to persist, must not be null
 * @param model the model for the spec, must not be null or new
 * @param gtin  the value of gtin
 * @throws IllegalArgumentException if Cpu or Gpu in a Desktop are new.
 *
 * @return the eu.ggnet.dwoss.spec.entity.ProductSpec
 */
// TODO: Check if the model as parameter is still needed.
@Override
public ProductSpec create(ProductSpec spec, ProductModel model, long gtin) throws IllegalArgumentException {
    if (model == null)
        throw new NullPointerException("Model is null");
    if (spec == null)
        throw new NullPointerException("ProductSpec is null");
    // Hint: Normally the column unique option should do that, but HSQLDB somehow lost it.
    if (new ProductEao(uuEm).findByPartNo(spec.getPartNo()) != null)
        throw new IllegalArgumentException("PartNo=" + spec.getPartNo() + " exists allready, but create is calles");
    ProductModelEmo productModelEmo = new ProductModelEmo(specEm);
    model = productModelEmo.request(model.getFamily().getSeries().getBrand(), model.getFamily().getSeries().getGroup(), model.getFamily().getSeries().getName(), model.getFamily().getName(), model.getName());
    spec.setModel(model);
    if (spec instanceof DisplayAble) {
        DisplayAble da = (DisplayAble) spec;
        da.setDisplay(new DisplayEmo(specEm).weakRequest(da.getDisplay().getSize(), da.getDisplay().getResolution(), da.getDisplay().getType(), da.getDisplay().getRation()));
    }
    if (spec instanceof Desktop) {
        Desktop desktop = (Desktop) spec;
        if (desktop.getCpu() == null || desktop.getGpu() == null)
            throw new IllegalArgumentException("Cpu or Gpu of a Desktop are null. " + desktop);
        Cpu cpu = new CpuEao(specEm).findById(desktop.getCpu().getId());
        Gpu gpu = new GpuEao(specEm).findById(desktop.getGpu().getId());
        if (cpu != null)
            desktop.setCpu(cpu);
        if (gpu != null)
            desktop.setGpu(gpu);
    }
    if (spec instanceof DesktopBundle) {
        DesktopBundle bundle = (DesktopBundle) spec;
        if (bundle.getDesktop().getId() == 0 || bundle.getMonitor().getId() == 0)
            throw new IllegalArgumentException("Monitor or Desktop are new. Impossible");
        ProductSpecEao specEao = new ProductSpecEao(specEm);
        bundle.setDesktop(specEao.findById(bundle.getDesktop().getId()));
        bundle.setMonitor(specEao.findById(bundle.getMonitor().getId()));
    }
    L.info("Persisting {} including model change={}", SpecFormater.toDetailedName(spec), (model == spec.getModel()));
    specEm.persist(spec);
    // Ensuring Id generation.
    specEm.flush();
    ProductEao productEao = new ProductEao(uuEm);
    Product product = productEao.findByPartNo(spec.getPartNo());
    if (product == null)
        product = new Product();
    product.setGroup(spec.getModel().getFamily().getSeries().getGroup());
    product.setTradeName(spec.getModel().getFamily().getSeries().getBrand());
    product.setPartNo(spec.getPartNo());
    product.setName(spec.getModel().getName());
    product.setDescription(SpecFormater.toSingleLine(spec));
    product.setGtin(gtin);
    L.debug("persisting {}", product);
    if (!uuEm.contains(product)) {
        uuEm.persist(product);
        // Ensuring Id generation
        uuEm.flush();
    }
    L.debug("creating weak reference ProductSpec.productId=Product.id value ({})", product.getId());
    spec.setProductId(product.getId());
    return spec;
}
Also used : ProductModelEmo(eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo) Cpu(eu.ggnet.dwoss.spec.ee.entity.piece.Cpu) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) DisplayEmo(eu.ggnet.dwoss.spec.ee.emo.DisplayEmo) DesktopBundle(eu.ggnet.dwoss.spec.ee.entity.DesktopBundle) Gpu(eu.ggnet.dwoss.spec.ee.entity.piece.Gpu) GpuEao(eu.ggnet.dwoss.spec.ee.eao.GpuEao) DisplayAble(eu.ggnet.dwoss.spec.ee.entity.DisplayAble) Desktop(eu.ggnet.dwoss.spec.ee.entity.Desktop) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) CpuEao(eu.ggnet.dwoss.spec.ee.eao.CpuEao)

Example 2 with ProductSpecEao

use of eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao in project dwoss by gg-net.

the class ExporterOperation method toXls.

/**
 * Creates a price compare sheet, expects a list of partNos and returns a xls File with last sales and estimated generated price
 *
 * @param partNos the partNos to inspect
 * @return the xls file with informations
 */
private FileJacket toXls(String... partNos) {
    // Create a Produkt with the part no;
    SubMonitor m = monitorFactory.newSubMonitor("Auswertung über PartNos", partNos.length + 10);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
    StockUnitEao suEao = new StockUnitEao(stockEm);
    DocumentEao documentEao = new DocumentEao(redTapeEm);
    List<List<Object>> model = new ArrayList<>();
    for (String partNo : partNos) {
        m.worked(1, "loading: " + partNo);
        List<Object> line = new ArrayList<>();
        model.add(line);
        partNo = partNo.trim();
        line.add(partNo);
        List<UniqueUnit> uus = uniqueUnitEao.findByProductPartNo(partNo);
        if (uus.isEmpty()) {
            line.add("Keine Geräte oder Produkte im System.");
            for (int i = 0; i < 14; i++) line.add(null);
            continue;
        }
        Product product = uus.get(0).getProduct();
        line.add(ProductFormater.toName(product));
        line.add(uus.size());
        line.add(maxPrice(uus, PriceType.CUSTOMER));
        line.add(minPrice(uus, PriceType.RETAILER));
        List<Document> documents = documentEao.findInvoiceWithProdcutId(product.getId());
        for (int i = 0; i < 3; i++) {
            if (documents.size() > i) {
                // TODO: Was balancingId
                line.add(documents.get(i).getActual());
                line.add(priceByProductId(documents.get(i), product.getId()));
            } else {
                line.add(null);
                line.add(null);
            }
        }
        PriceEngineResult per = priceEngine.estimate(uus.get(0), productSpecEao.findByProductId(product.getId()), suEao.findByUniqueUnitId(uus.get(0).getId()).getStock().getName());
        line.add(per.getCostPrice());
        line.add(per.getRetailerPrice());
        line.add(per.getCustomerPrice());
        line.add(per.getRulesLog());
    }
    m.message("creating File");
    STable table = new STable();
    CFormat euro = new CFormat(RIGHT, CURRENCY_EURO);
    CFormat date = new CFormat(CENTER, SHORT_DATE);
    table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC, WHITE, BLUE, CENTER, new CBorder(BLACK)));
    table.add(new STableColumn("PartNo", 15)).add(new STableColumn("Name", 30));
    table.add(new STableColumn("Menge im System", 12));
    table.add(new STableColumn("VP(Min)", 12, euro)).add(new STableColumn("VP(Max)", 12, euro));
    table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
    table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
    table.add(new STableColumn("Datum", 12, date)).add(new STableColumn("Vk", 12, euro));
    table.add(new STableColumn("Cp", 12, euro)).add(new STableColumn("Hp", 12, euro)).add(new STableColumn("Ep", 12, euro));
    table.add(new STableColumn("Rules", 40));
    table.setModel(new STableModelList(model));
    CCalcDocument cdoc = new TempCalcDocument("PartNoPrice_");
    cdoc.add(new CSheet("PartNoPrice", table));
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
    FileJacket result = new FileJacket("PartNoPrice", ".xls", file);
    m.finish();
    return result;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) FileJacket(eu.ggnet.dwoss.util.FileJacket) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) File(java.io.File)

Example 3 with ProductSpecEao

use of eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao in project dwoss by gg-net.

the class ExporterOperation method onePrice.

/**
 * Calculates a Price for on Unit.
 *
 * @param refurbishId the refurbishId
 * @return The PriceEngineResult or Null if Id not found
 */
@Override
public PriceEngineResult onePrice(String refurbishId) {
    final UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    final ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
    final StockUnitEao suEao = new StockUnitEao(stockEm);
    L.info("Loading s.getUnit({})", refurbishId);
    UniqueUnit uu = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbishId);
    if (uu == null)
        return null;
    ProductSpec spec = productSpecEao.findByProductId(uu.getProduct().getId());
    String stock = suEao.findByUniqueUnitId(uu.getId()).getStock().getName();
    return priceEngine.estimate(uu, spec, stock);
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 4 with ProductSpecEao

use of eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao in project dwoss by gg-net.

the class PriceCoreOperation method loadAndCalculate.

/**
 * Loads all AVAILABLE SopoUnits from the Sopodb an puts them trough the PriceEngine
 *
 * @param monitor
 * @return
 */
public List<PriceEngineResult> loadAndCalculate(IMonitor monitor) {
    L.info("Starting loadAndCalculate()");
    final SubMonitor m = SubMonitor.convert(monitor, 100);
    m.start();
    final StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    final UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    final ProductSpecEao productSpecEao = new ProductSpecEao(specEm);
    m.message("loading Units");
    List<Integer> uuids = stockUnitEao.findByNoLogicTransactionAsUniqueUnitId();
    List<UniqueUnit> uus = uniqueUnitEao.findByIds(uuids);
    m.worked(10, "updating Eols");
    updateEols(uus);
    m.worked(5, "loading ProductSpecs");
    Set<Product> products = toProducts(uus);
    List<ProductSpec> productSpecs = productSpecEao.findByProductIds(toProductIds(products));
    Map<Product, ProductSpec> productToSpecs = toProductProductSpec(products, productSpecs);
    m.worked(10);
    final List<PriceEngineResult> pers = new ArrayList<>();
    m.setWorkRemaining(uus.size() + 5);
    for (UniqueUnit uu : uus) {
        m.worked(1, "Calculating RefurbishId(" + uu.getRefurbishId() + ")");
        StockUnit su = stockUnitEao.findByUniqueUnitId(uu.getId());
        pers.add(priceEngine.estimate(uu, productToSpecs.get(uu.getProduct()), su.getStock() != null ? su.getStock().getName() : "kein Lager"));
    }
    m.finish();
    L.info("Finished loadAndCalculate(), estimated {} Units", pers.size());
    return pers;
}
Also used : PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 5 with ProductSpecEao

use of eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao in project dwoss by gg-net.

the class ProductSpecEaoFindByPartNoIT method testFindByPartNo.

/**
 * Test of findByPartNo method, of class ProductSpecEao.
 */
@Test
public void testFindByPartNo() throws Exception {
    utx.begin();
    em.joinTransaction();
    ProductSeries veriton = new ProductSeries(TradeName.FUJITSU, ProductGroup.DESKTOP, "Veriton");
    em.persist(veriton);
    ProductFamily m400 = new ProductFamily("M400");
    m400.setSeries(veriton);
    em.persist(m400);
    ProductModel M480G = new ProductModel("M480G");
    M480G.setFamily(m400);
    em.persist(M480G);
    Desktop M480G_1 = new Desktop("PX.99999.321", 2L);
    M480G_1.setModel(M480G);
    M480G_1.setVideoPorts(EnumSet.allOf(BasicSpec.VideoPort.class));
    M480G_1.setComment("Ein Kommentar");
    M480G_1.setCpu(new Cpu(Cpu.Series.CORE, "Eine CPU", Cpu.Type.MOBILE, 123.0, 2));
    M480G_1.setGpu(new Gpu(Gpu.Type.MOBILE, Gpu.Series.RADEON_HD_4000, "Eine Graphiccarte"));
    M480G_1.setOs(Desktop.Os.LINUX);
    M480G_1.setMemory(12345);
    M480G_1.add(Desktop.Hdd.ROTATING_1000);
    M480G_1.add(Desktop.Odd.BLURAY_COMBO);
    M480G_1.setExtras(Desktop.Extra.KAMERA);
    em.persist(M480G_1);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    ProductSpecEao specEao = new ProductSpecEao(em);
    Desktop spec = (Desktop) specEao.findByPartNo(M480G_1.getPartNo());
    assertNotNull(spec);
    assertEquals(M480G_1.getExtras(), spec.getExtras());
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) Desktop(eu.ggnet.dwoss.spec.ee.entity.Desktop) Cpu(eu.ggnet.dwoss.spec.ee.entity.piece.Cpu) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries) ProductSpecEao(eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao) Gpu(eu.ggnet.dwoss.spec.ee.entity.piece.Gpu) ProductModel(eu.ggnet.dwoss.spec.ee.entity.ProductModel) Test(org.junit.Test)

Aggregations

ProductSpecEao (eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao)7 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)4 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)3 Desktop (eu.ggnet.dwoss.spec.ee.entity.Desktop)3 Cpu (eu.ggnet.dwoss.spec.ee.entity.piece.Cpu)3 Gpu (eu.ggnet.dwoss.spec.ee.entity.piece.Gpu)3 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)3 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)3 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)2 DesktopBundle (eu.ggnet.dwoss.spec.ee.entity.DesktopBundle)2 ProductFamily (eu.ggnet.dwoss.spec.ee.entity.ProductFamily)2 ProductModel (eu.ggnet.dwoss.spec.ee.entity.ProductModel)2 ProductSeries (eu.ggnet.dwoss.spec.ee.entity.ProductSeries)2 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)2 FileJacket (eu.ggnet.dwoss.util.FileJacket)2 Test (org.junit.Test)2 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)1 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)1 CpuEao (eu.ggnet.dwoss.spec.ee.eao.CpuEao)1 GpuEao (eu.ggnet.dwoss.spec.ee.eao.GpuEao)1