Search in sources :

Example 1 with ProductModelEmo

use of eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo in project dwoss by gg-net.

the class ProductModelEmoIT method testRequestBrandGroupNameByHand.

@Test
public void testRequestBrandGroupNameByHand() throws Exception {
    TradeName sb = TradeName.HP;
    ProductGroup sg = ProductGroup.PROJECTOR;
    String sn = "SERIES";
    String fn = "FAMILY";
    String mn = "MODEL";
    utx.begin();
    em.joinTransaction();
    new ProductSeriesEmo(em).request(sb, sg, sn);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    new ProductFamilyEmo(em).request(sb, sg, sn, fn);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    ProductModel model = new ProductModelEmo(em).request(sb, sg, sn, fn, mn);
    assertNotNull(model);
    utx.commit();
}
Also used : TradeName(eu.ggnet.dwoss.rules.TradeName) ProductGroup(eu.ggnet.dwoss.rules.ProductGroup) ProductModelEmo(eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo) ProductFamilyEmo(eu.ggnet.dwoss.spec.ee.emo.ProductFamilyEmo) ProductSeriesEmo(eu.ggnet.dwoss.spec.ee.emo.ProductSeriesEmo) ProductModel(eu.ggnet.dwoss.spec.ee.entity.ProductModel) Test(org.junit.Test)

Example 2 with ProductModelEmo

use of eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo in project dwoss by gg-net.

the class ContainerITGeneratorHelper method makeOne.

public ProductSpec makeOne() {
    SpecGenerator g = new SpecGenerator();
    ProductSpec spec = g.makeSpec();
    ProductModel model = spec.getModel();
    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);
    }
    specEm.persist(spec);
    return spec;
}
Also used : ProductModelEmo(eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo) DisplayAble(eu.ggnet.dwoss.spec.ee.entity.DisplayAble) Desktop(eu.ggnet.dwoss.spec.ee.entity.Desktop) SpecGenerator(eu.ggnet.dwoss.spec.ee.assist.gen.SpecGenerator) Cpu(eu.ggnet.dwoss.spec.ee.entity.piece.Cpu) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) DisplayEmo(eu.ggnet.dwoss.spec.ee.emo.DisplayEmo) Gpu(eu.ggnet.dwoss.spec.ee.entity.piece.Gpu) ProductModel(eu.ggnet.dwoss.spec.ee.entity.ProductModel) CpuEao(eu.ggnet.dwoss.spec.ee.eao.CpuEao) GpuEao(eu.ggnet.dwoss.spec.ee.eao.GpuEao)

Example 3 with ProductModelEmo

use of eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo 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 4 with ProductModelEmo

use of eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo in project dwoss by gg-net.

the class ProductModelEmoIT method testFullRequestBrandGroupName.

@Test
public void testFullRequestBrandGroupName() throws Exception {
    TradeName sb = TradeName.HP;
    ProductGroup sg = ProductGroup.PROJECTOR;
    String sn = "SERIES";
    String fn = "FAMILY";
    String mn = "MODEL";
    utx.begin();
    em.joinTransaction();
    ProductModelEmo modelEmo = new ProductModelEmo(em);
    ProductModel model = modelEmo.request(sb, sg, sn, fn, mn);
    assertNotNull(model);
    assertEquals(mn, model.getName());
    assertEquals(fn, model.getFamily().getName());
    assertEquals(sb, model.getFamily().getSeries().getBrand());
    assertEquals(sg, model.getFamily().getSeries().getGroup());
    assertEquals(sn, model.getFamily().getSeries().getName());
    long fid = model.getFamily().getId();
    long mid = model.getId();
    long sid = model.getFamily().getSeries().getId();
    utx.commit();
    utx.begin();
    em.joinTransaction();
    model = modelEmo.request(sb, sg, sn, fn, mn);
    assertNotNull(model);
    assertEquals(mid, model.getId());
    assertEquals(fid, model.getFamily().getId());
    assertEquals(sid, model.getFamily().getSeries().getId());
    utx.commit();
}
Also used : TradeName(eu.ggnet.dwoss.rules.TradeName) ProductGroup(eu.ggnet.dwoss.rules.ProductGroup) ProductModelEmo(eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo) ProductModel(eu.ggnet.dwoss.spec.ee.entity.ProductModel) Test(org.junit.Test)

Example 5 with ProductModelEmo

use of eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo in project dwoss by gg-net.

the class ProductModelEmoIT method testHalfRequestBrandGroupName.

@Test
public void testHalfRequestBrandGroupName() throws Exception {
    TradeName sb = TradeName.HP;
    ProductGroup sg = ProductGroup.PROJECTOR;
    String sn = "SERIES";
    String fn = "FAMILY";
    String mn = "MODEL";
    utx.begin();
    em.joinTransaction();
    new ProductFamilyEmo(em).request(sb, sg, sn, fn);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    ProductModelEmo modelEmo = new ProductModelEmo(em);
    ProductModel model = modelEmo.request(sb, sg, sn, fn, mn);
    assertNotNull(model);
    assertEquals(mn, model.getName());
    assertEquals(fn, model.getFamily().getName());
    assertEquals(sb, model.getFamily().getSeries().getBrand());
    assertEquals(sg, model.getFamily().getSeries().getGroup());
    assertEquals(sn, model.getFamily().getSeries().getName());
    long fid = model.getFamily().getId();
    long mid = model.getId();
    long sid = model.getFamily().getSeries().getId();
    utx.commit();
    utx.begin();
    em.joinTransaction();
    model = modelEmo.request(sb, sg, sn, fn, mn);
    assertNotNull(model);
    assertEquals(mid, model.getId());
    assertEquals(fid, model.getFamily().getId());
    assertEquals(sid, model.getFamily().getSeries().getId());
    utx.commit();
}
Also used : TradeName(eu.ggnet.dwoss.rules.TradeName) ProductGroup(eu.ggnet.dwoss.rules.ProductGroup) ProductModelEmo(eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo) ProductFamilyEmo(eu.ggnet.dwoss.spec.ee.emo.ProductFamilyEmo) ProductModel(eu.ggnet.dwoss.spec.ee.entity.ProductModel) Test(org.junit.Test)

Aggregations

ProductModelEmo (eu.ggnet.dwoss.spec.ee.emo.ProductModelEmo)5 ProductModel (eu.ggnet.dwoss.spec.ee.entity.ProductModel)4 ProductGroup (eu.ggnet.dwoss.rules.ProductGroup)3 TradeName (eu.ggnet.dwoss.rules.TradeName)3 Test (org.junit.Test)3 CpuEao (eu.ggnet.dwoss.spec.ee.eao.CpuEao)2 GpuEao (eu.ggnet.dwoss.spec.ee.eao.GpuEao)2 DisplayEmo (eu.ggnet.dwoss.spec.ee.emo.DisplayEmo)2 ProductFamilyEmo (eu.ggnet.dwoss.spec.ee.emo.ProductFamilyEmo)2 Desktop (eu.ggnet.dwoss.spec.ee.entity.Desktop)2 DisplayAble (eu.ggnet.dwoss.spec.ee.entity.DisplayAble)2 Cpu (eu.ggnet.dwoss.spec.ee.entity.piece.Cpu)2 Gpu (eu.ggnet.dwoss.spec.ee.entity.piece.Gpu)2 SpecGenerator (eu.ggnet.dwoss.spec.ee.assist.gen.SpecGenerator)1 ProductSpecEao (eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao)1 ProductSeriesEmo (eu.ggnet.dwoss.spec.ee.emo.ProductSeriesEmo)1 DesktopBundle (eu.ggnet.dwoss.spec.ee.entity.DesktopBundle)1 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)1 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)1 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)1