Search in sources :

Example 1 with ProductSeriesEao

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

the class ProductProcessorOperation method create.

/**
 * Creates and Persists a ProducFamily.
 * <ol>
 * <li>Validate and throw exception if a family with the same name exists</li>
 * <li>Selection of Series
 * <ul>
 * <li>If Series is null &rarr; find or create default Series</li>
 * <li>Else use supplied Series</li>
 * </ul>
 * </li>
 * <li>Persist new Family with Series</li>
 * </ol>
 *
 * @param brand      the brand
 * @param group      the group
 * @param series     the series
 * @param familyName the familyName
 *
 * @return the persisted and detached ProductFamily
 */
@Override
public ProductFamily create(final TradeName brand, final ProductGroup group, ProductSeries series, final String familyName) {
    EntityManager em = specEm;
    // 1. check if there exits a model anytwhere with the same name. -> throw Exception
    ProductFamilyEao familyEao = new ProductFamilyEao(em);
    ProductFamily family = familyEao.find(familyName);
    if (family != null)
        throw new RuntimeException("There exits a family " + family + " but we want to create it");
    // 2. Create Family
    family = new ProductFamily(familyName);
    if (series != null && series.getId() != 0) {
        // 3. if series not null, get from db
        ProductSeriesEao seriesEao = new ProductSeriesEao(em);
        series = seriesEao.findById(series.getId());
    } else {
        // 4. get or create default series
        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);
        }
    }
    family.setSeries(series);
    em.persist(family);
    return family;
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) EntityManager(javax.persistence.EntityManager) ProductFamilyEao(eu.ggnet.dwoss.spec.ee.eao.ProductFamilyEao) ProductSeriesEao(eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries)

Example 2 with ProductSeriesEao

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

the class ProductFamilyEmo method request.

/**
 * Requests a Family, never returning null.
 * <p>
 * @param seriesBrand the brand of the series
 * @param seriesGroup the group of the series
 * @param seriesName  the name of the series
 * @param familyName  the name of the family
 * @return the family, either newly persisted or old existing.
 */
public ProductFamily request(final TradeName seriesBrand, final ProductGroup seriesGroup, final String seriesName, final String familyName) {
    ProductFamily family = new ProductFamilyEao(em).find(seriesBrand, seriesGroup, seriesName, familyName);
    if (family == null) {
        ProductSeries series = new ProductSeriesEao(em).find(seriesBrand, seriesGroup, seriesName);
        if (series == null) {
            series = new ProductSeries(seriesBrand, seriesGroup, seriesName);
        }
        family = new ProductFamily(familyName, series);
        em.persist(family);
    }
    return family;
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) ProductFamilyEao(eu.ggnet.dwoss.spec.ee.eao.ProductFamilyEao) ProductSeriesEao(eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries)

Example 3 with ProductSeriesEao

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

the class ProductSeriesEmo method request.

/**
 * Requests a Series.
 * <p>
 * @param brand the brand
 * @param group the group
 * @param name  the name
 * @return the series, either newly persisted or old existing.
 */
public ProductSeries request(final TradeName brand, final ProductGroup group, final String name) {
    ProductSeries series = new ProductSeriesEao(em).find(brand, group, name);
    if (series == null) {
        series = new ProductSeries(brand, group, name);
        em.persist(series);
    }
    return series;
}
Also used : ProductSeriesEao(eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries)

Example 4 with ProductSeriesEao

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

the class ProductSeriesEmoIT method testRequestBrandGroupName.

@Test
public void testRequestBrandGroupName() throws Exception {
    TradeName b1 = TradeName.APPLE;
    ProductGroup g1 = ProductGroup.PROJECTOR;
    String n1 = "SERIES";
    TradeName b2 = TradeName.LENOVO;
    ProductGroup g2 = ProductGroup.DESKTOP;
    String n2 = "SERIES";
    utx.begin();
    em.joinTransaction();
    em.persist(new ProductSeries(b1, g1, n1));
    utx.commit();
    utx.begin();
    em.joinTransaction();
    ProductSeriesEmo seriesEmo = new ProductSeriesEmo(em);
    ProductSeries productSeries = seriesEmo.request(b1, g1, n1);
    assertNotNull(productSeries);
    assertEquals(b1, productSeries.getBrand());
    assertEquals(g1, productSeries.getGroup());
    assertEquals(n1, productSeries.getName());
    utx.commit();
    utx.begin();
    em.joinTransaction();
    productSeries = seriesEmo.request(b2, g2, n2);
    assertNotNull(productSeries);
    assertEquals(b2, productSeries.getBrand());
    assertEquals(g2, productSeries.getGroup());
    assertEquals(n2, productSeries.getName());
    utx.commit();
    utx.begin();
    em.joinTransaction();
    seriesEmo.request(b2, g2, n2);
    seriesEmo.request(b2, g2, n2);
    seriesEmo.request(b2, g2, n2);
    List<ProductSeries> pss = new ProductSeriesEao(em).findAll();
    assertNotNull(pss);
    assertEquals("Only Two Elements should exist", 2, pss.size());
    utx.commit();
}
Also used : TradeName(eu.ggnet.dwoss.rules.TradeName) ProductGroup(eu.ggnet.dwoss.rules.ProductGroup) ProductSeriesEao(eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries) ProductSeriesEmo(eu.ggnet.dwoss.spec.ee.emo.ProductSeriesEmo) Test(org.junit.Test)

Example 5 with ProductSeriesEao

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

the class ProductSeriesEaoIT method testFindBrandGroupName.

@Test
public void testFindBrandGroupName() throws Exception {
    utx.begin();
    em.joinTransaction();
    ProductSeries series = new ProductSeries(TradeName.SAMSUNG, ProductGroup.MISC, "GG-Net uber Multicore");
    em.persist(series);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    ProductSeriesEao seriesEao = new ProductSeriesEao(em);
    ProductSeries productSeries = seriesEao.find(series.getBrand(), series.getGroup(), series.getName());
    assertNull(seriesEao.find(TradeName.SAMSUNG, ProductGroup.MISC, "Gibbet nich"));
    assertNotNull(productSeries);
    assertEquals(series, productSeries);
    utx.commit();
}
Also used : ProductSeriesEao(eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries) Test(org.junit.Test)

Aggregations

ProductSeriesEao (eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao)7 ProductSeries (eu.ggnet.dwoss.spec.ee.entity.ProductSeries)7 ProductFamilyEao (eu.ggnet.dwoss.spec.ee.eao.ProductFamilyEao)3 ProductFamily (eu.ggnet.dwoss.spec.ee.entity.ProductFamily)3 EntityManager (javax.persistence.EntityManager)3 Test (org.junit.Test)2 ProductGroup (eu.ggnet.dwoss.rules.ProductGroup)1 TradeName (eu.ggnet.dwoss.rules.TradeName)1 ProductModelEao (eu.ggnet.dwoss.spec.ee.eao.ProductModelEao)1 ProductSeriesEmo (eu.ggnet.dwoss.spec.ee.emo.ProductSeriesEmo)1 ProductModel (eu.ggnet.dwoss.spec.ee.entity.ProductModel)1