Search in sources :

Example 1 with ProductEao

use of eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao in project dwoss by gg-net.

the class ProductEaoIT method testFindPartNo.

@Test
public void testFindPartNo() throws Exception {
    utx.begin();
    em.joinTransaction();
    p = new Product(ProductGroup.MISC, TradeName.ACER, "AA.BBBBB.CCC", "Evil Acer Handy of Doom");
    em.persist(p);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    ProductEao productEao = new ProductEao(em);
    assertNotNull(productEao.findByPartNo(p.getPartNo()));
    assertNull(productEao.findByPartNo("bb.ccccc.aa"));
    assertEquals(p, productEao.findByPartNo("AA.BBBBB.CCC"));
    utx.commit();
}
Also used : Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) Test(org.junit.Test)

Example 2 with ProductEao

use of eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao in project dwoss by gg-net.

the class UniqurUnitItHelper method createSampleUnit.

public int createSampleUnit() {
    Product p = new ProductEao(em).findByPartNo("AA.AAAAA.AAA");
    if (p == null) {
        p = new Product(ProductGroup.DESKTOP, TradeName.FUJITSU, "AA.AAAAA.AAA", "Verition Stein");
        p.setDescription("Ein Tolles Gerät");
        p.setPrice(PriceType.MANUFACTURER_COST, 200.0, "JUnit - Testcase");
        p.setAdditionalPartNo(contractors.all().iterator().next(), "833.323");
        p.setPrice(PriceType.CONTRACTOR_REFERENCE, 240.0, "JUnit - Testcase");
        p.addFlag(Product.Flag.PRICE_FIXED);
        em.persist(p);
    }
    UniqueUnit unit = new UniqueUnit(p, new Date(), "");
    unit.setIdentifier(Identifier.SERIAL, "AAAAAAAAAAA123AAADFSADFSA");
    unit.setIdentifier(Identifier.REFURBISHED_ID, "30001");
    unit.setContractor(TradeName.ONESELF);
    unit.setComment("Ein Commentar");
    unit.setCondition(UniqueUnit.Condition.AS_NEW);
    em.persist(unit);
    return unit.getId();
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)

Example 3 with ProductEao

use of eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao in project dwoss by gg-net.

the class ImageIdHandlerOperation method importMissing.

@Override
public Reply<Void> importMissing(FileJacket inFile) {
    final SubMonitor m = monitorFactory.newSubMonitor("Image Ids importieren", 100);
    m.message("Reading File");
    m.start();
    LucidCalcReader reader = new JExcelLucidCalcReader();
    reader.addColumn(0, String.class);
    reader.addColumn(1, String.class);
    reader.addColumn(2, String.class);
    reader.addColumn(3, String.class);
    reader.addColumn(4, Integer.class);
    reader.setHeadline(true);
    reader.setTrim(true);
    File f = inFile.toTemporaryFile();
    List<ImageIdLine> lines = reader.read(f, ImageIdLine.class);
    List<String> errors = reader.getErrors();
    ProductEao productEao = new ProductEao(uuEm);
    m.message("Importing Data");
    m.setWorkRemaining(lines.size());
    for (ImageIdLine line : lines) {
        m.worked(1, "importing " + line.getPartNo());
        if (line.getImageId() == null) {
            errors.add("No ImageId for " + line.getPartNo());
            continue;
        }
        Product p = productEao.findByPartNo(line.getPartNo());
        if (p != null) {
            p.setImageId(line.getImageId());
        } else {
            errors.add("No Product for '" + line.getPartNo() + "'");
        }
    }
    m.finish();
    if (!errors.isEmpty())
        return Reply.failure(errors.toString());
    return Reply.success(null);
}
Also used : JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) LucidCalcReader(eu.ggnet.lucidcalc.LucidCalcReader) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) File(java.io.File)

Example 4 with ProductEao

use of eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao 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 5 with ProductEao

use of eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao in project dwoss by gg-net.

the class ProductProcessorOperation method update.

/**
 * Updates an existing ProductSpec and the relating Product and SopoProduct.
 * <p>
 * The process has multiple steps:
 * <ol>
 * <li>Validate and throw IllegalArgumentException:
 * <ul>
 * <li>if the ProductSpec.productId == null</li>
 * <li>if there does not exist a Product with ProductSpec.productId</li>
 * <li>if there does not exist a SopoProduct with Product.partNo (unchanged)</li>
 * </ul>
 * </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 the supplied ProductModel is different from ProductSpec.getModel it is merged and set</li>
 * <li>Overwrite all changes in Product</li>
 * <li>Overwrite all changes in SopoProduct</li>
 * <li> If PartNo change propagate to all matching SopoUnits</li>
 * </ol>
 *
 * @param spec the spec to be updated, must not be null and not new
 * @param gtin the value of gtin
 * @throws IllegalArgumentException if spec.productId == null
 * @return the eu.ggnet.dwoss.spec.entity.ProductSpec
 */
@Override
public ProductSpec update(ProductSpec spec, long gtin) throws IllegalArgumentException {
    // 1. Validation
    if (spec.getProductId() == null)
        throw new IllegalArgumentException("ProductSpec has no productId, violation ! " + spec);
    ProductEao productEao = new ProductEao(uuEm);
    Product product = productEao.findById(spec.getProductId());
    if (product == null)
        throw new IllegalArgumentException("ProductSpec.productId=" + spec.getProductId() + " does not have a Product");
    // 2. + 3. Update Spec
    if (spec instanceof DisplayAble && ((DisplayAble) spec).getDisplay().getId() == 0) {
        DisplayAble monitor = (DisplayAble) spec;
        DisplayEao displayEao = new DisplayEao(specEm);
        Display display = monitor.getDisplay();
        display = displayEao.find(display.getSize(), display.getResolution(), display.getType(), display.getRation());
        if (display != null)
            monitor.setDisplay(display);
    }
    L.info("updateing {}", SpecFormater.toDetailedName(spec));
    spec = specEm.merge(spec);
    // 4. overwrite 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("updateing {}", product);
    return spec;
}
Also used : DisplayAble(eu.ggnet.dwoss.spec.ee.entity.DisplayAble) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) DisplayEao(eu.ggnet.dwoss.spec.ee.eao.DisplayEao) Display(eu.ggnet.dwoss.spec.ee.entity.piece.Display)

Aggregations

ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)12 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)11 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)5 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)4 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)3 LucidCalcReader (eu.ggnet.lucidcalc.LucidCalcReader)3 JExcelLucidCalcReader (eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader)3 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)2 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)2 DisplayAble (eu.ggnet.dwoss.spec.ee.entity.DisplayAble)2 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)1 WarrantyService (eu.ggnet.dwoss.mandator.api.service.WarrantyService)1 Ledger (eu.ggnet.dwoss.mandator.api.value.Ledger)1 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)1 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)1 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)1 PartNoSupport (eu.ggnet.dwoss.rules.partno.PartNoSupport)1 CpuEao (eu.ggnet.dwoss.spec.ee.eao.CpuEao)1 DisplayEao (eu.ggnet.dwoss.spec.ee.eao.DisplayEao)1 GpuEao (eu.ggnet.dwoss.spec.ee.eao.GpuEao)1