Search in sources :

Example 21 with ProductSeries

use of eu.ggnet.dwoss.spec.ee.entity.ProductSeries in project dwoss by gg-net.

the class ReceiptProductLogicProductSpecIT method testUpdateProductSpecModelChange.

@Test
public void testUpdateProductSpecModelChange() {
    ProductModel productModel = productProcessor.create(ACER, NOTEBOOK, null, null, "TestModel");
    Cpu cpu = productProcessor.create(new Cpu(Cpu.Series.AMD_V, "TestCPU", Cpu.Type.MOBILE, 2.0, 5));
    Gpu gpu = productProcessor.create(new Gpu(Gpu.Type.MOBILE, Gpu.Series.GEFORCE_100, "TestGPU"));
    Notebook notebook = new Notebook();
    notebook.setDisplay(new Display(Display.Size._10_1, Display.Resolution.VGA, Display.Type.MATT, Display.Ration.FOUR_TO_THREE));
    notebook.setGpu(gpu);
    notebook.setCpu(cpu);
    notebook.setMemory(2048);
    notebook.setOs(Desktop.Os.LINUX);
    notebook.add(Desktop.Hdd.SSD_0016);
    notebook.add(Desktop.Hdd.ROTATING_2000);
    notebook.add(Desktop.Odd.DVD_ROM);
    notebook.setExtras(ProductSpec.Extra.E_SATA, ProductSpec.Extra.HIGHT_CHANGEABLE);
    notebook.setPartNo("LX.ASDFG.GHP");
    notebook.setModel(productModel);
    ProductSpec spec = productProcessor.create(notebook, productModel, 0);
    ProductFamily family = spec.getModel().getFamily();
    ProductModel productModel2 = productProcessor.create(ACER, NOTEBOOK, family.getSeries(), family, "TestModel2");
    spec = productProcessor.refresh(spec, productModel2);
    long model2Id = spec.getModel().getId();
    String comment = "MuhBlub";
    ((Notebook) spec).setComment(comment);
    productProcessor.update(spec, 0);
    List<ProductSeries> series = specAgent.findAllEager(ProductSeries.class);
    assertNotNull(series);
    assertEquals(1, series.size());
    assertNotNull(series.get(0));
    assertNotNull(series.get(0).getFamilys());
    assertEquals(1, series.get(0).getFamilys().size());
    assertNotNull(series.get(0).getFamilys().toArray()[0]);
    List<ProductSpec> specs = specAgent.findAllEager(ProductSpec.class);
    assertNotNull(specs);
    assertEquals(1, specs.size());
    assertEquals(model2Id, specs.get(0).getModel().getId());
    assertEquals(comment, ((Notebook) specs.get(0)).getComment());
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) Notebook(eu.ggnet.dwoss.spec.ee.entity.Notebook) Cpu(eu.ggnet.dwoss.spec.ee.entity.piece.Cpu) ProductSpec(eu.ggnet.dwoss.spec.ee.entity.ProductSpec) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries) Gpu(eu.ggnet.dwoss.spec.ee.entity.piece.Gpu) ProductModel(eu.ggnet.dwoss.spec.ee.entity.ProductModel) Display(eu.ggnet.dwoss.spec.ee.entity.piece.Display) Test(org.junit.Test)

Example 22 with ProductSeries

use of eu.ggnet.dwoss.spec.ee.entity.ProductSeries in project dwoss by gg-net.

the class SpecStore method makeSeries.

public ProductSeries makeSeries(TradeName brand, ProductGroup group, String name) {
    ProductSeries series = new ProductSeries(brand, group, name);
    em.persist(series);
    return series;
}
Also used : ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries)

Example 23 with ProductSeries

use of eu.ggnet.dwoss.spec.ee.entity.ProductSeries in project dwoss by gg-net.

the class SpecStore method makeFamily.

public ProductFamily makeFamily(String name, ProductSeries series) {
    series = em.find(ProductSeries.class, series.getId());
    ProductFamily family = new ProductFamily("Family 2");
    family.setSeries(series);
    em.persist(family);
    return family;
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries)

Example 24 with ProductSeries

use of eu.ggnet.dwoss.spec.ee.entity.ProductSeries in project dwoss by gg-net.

the class ProductProcessorOperation method create.

/**
 * Creates a new ProductModel and Persists it.
 * Multistep Process:
 * <ol>
 * <li>Validate and throw exception if a model with the same name exists</li>
 * <li>Selection of Family and Series
 * <ul>
 * <li>If Family is null and Series is null &rarr; find or create default Series and default Family</li>
 * <li>If only Family is null &rarr; find or create default default Family for Series</li>
 * <li>Else use supplied Family</li>
 * </ul>
 * </li>
 * <li>Persist new Model with Family</li>
 * </ol>
 *
 * @param brand     must not be null
 * @param group     must not be null
 * @param series    if null, default is used
 * @param family    if null, default is used
 * @param modelName the name of the model
 *
 * @return the persisted and detached Model
 */
@Override
public ProductModel create(final TradeName brand, final ProductGroup group, ProductSeries series, ProductFamily family, final String modelName) {
    EntityManager em = specEm;
    // 1. check if there exits a model anytwhere with the same name. -> throw Exception
    ProductModelEao modelEao = new ProductModelEao(em);
    ProductModel model = modelEao.find(modelName);
    if (model != null)
        throw new RuntimeException("There exits a model " + model + " but we want to create it");
    // 2. Select Family and Series
    if (family != null && family.getId() != 0) {
        ProductFamilyEao familyEao = new ProductFamilyEao(em);
        family = familyEao.findById(family.getId());
    } else {
        if (series != null && series.getId() != 0) {
            ProductSeriesEao seriesEao = new ProductSeriesEao(em);
            series = seriesEao.findById(series.getId());
        } else {
            ProductSeriesEao seriesEao = new ProductSeriesEao(em);
            series = seriesEao.find(brand, group, SpecPu.DEFAULT_NAME);
            if (series == null) {
                series = new ProductSeries(brand, group, SpecPu.DEFAULT_NAME);
                em.persist(series);
            }
        }
        for (ProductFamily f : series.getFamilys()) {
            if (f.getName().equals(SpecPu.DEFAULT_NAME)) {
                family = f;
            }
        }
        if (family == null) {
            family = new ProductFamily(SpecPu.DEFAULT_NAME);
            family.setSeries(series);
            em.persist(family);
        }
    }
    // 3. Create Model
    model = new ProductModel(modelName);
    model.setFamily(family);
    em.persist(model);
    return model;
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) EntityManager(javax.persistence.EntityManager) ProductFamilyEao(eu.ggnet.dwoss.spec.ee.eao.ProductFamilyEao) ProductModelEao(eu.ggnet.dwoss.spec.ee.eao.ProductModelEao) ProductSeriesEao(eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries) ProductModel(eu.ggnet.dwoss.spec.ee.entity.ProductModel)

Example 25 with ProductSeries

use of eu.ggnet.dwoss.spec.ee.entity.ProductSeries in project dwoss by gg-net.

the class ProductProcessorOperation method create.

@Override
public Reply<ProductSeries> create(TradeName brand, ProductGroup group, String seriesName) {
    EntityManager em = specEm;
    // 1. check if there exits a model anytwhere with the same name. -> throw Exception
    ProductSeriesEao seriesEoa = new ProductSeriesEao(em);
    ProductSeries series = seriesEoa.find(seriesName);
    if (series != null)
        Reply.failure("There exits a series " + series + " but we want to create it");
    // 2. Create Family
    series = new ProductSeries(brand, group, seriesName);
    em.persist(series);
    return Reply.success(series);
}
Also used : EntityManager(javax.persistence.EntityManager) ProductSeriesEao(eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries)

Aggregations

ProductSeries (eu.ggnet.dwoss.spec.ee.entity.ProductSeries)32 ProductFamily (eu.ggnet.dwoss.spec.ee.entity.ProductFamily)23 Test (org.junit.Test)17 ProductModel (eu.ggnet.dwoss.spec.ee.entity.ProductModel)15 Cpu (eu.ggnet.dwoss.spec.ee.entity.piece.Cpu)8 Gpu (eu.ggnet.dwoss.spec.ee.entity.piece.Gpu)8 ProductSeriesEao (eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao)7 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)7 Notebook (eu.ggnet.dwoss.spec.ee.entity.Notebook)6 Display (eu.ggnet.dwoss.spec.ee.entity.piece.Display)6 ProductFamilyEao (eu.ggnet.dwoss.spec.ee.eao.ProductFamilyEao)4 Desktop (eu.ggnet.dwoss.spec.ee.entity.Desktop)3 EntityManager (javax.persistence.EntityManager)3 TradeName (eu.ggnet.dwoss.rules.TradeName)2 ProductModelEao (eu.ggnet.dwoss.spec.ee.eao.ProductModelEao)2 ProductSpecEao (eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao)2 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)2 Mandators (eu.ggnet.dwoss.mandator.Mandators)1 eu.ggnet.dwoss.mandator.api.value (eu.ggnet.dwoss.mandator.api.value)1 ProductProcessor (eu.ggnet.dwoss.receipt.ee.ProductProcessor)1