Search in sources :

Example 1 with ProductFamilyEao

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

the class ProductFamilyEaoIT method testFind.

/**
 * Test of find method, of class ProductFamilyEao.
 */
@Test
public void testFind() throws Exception {
    utx.begin();
    em.joinTransaction();
    ProductFamily productFamily = new ProductFamily("PF1");
    ProductSeries testSeries1 = new ProductSeries(TradeName.HP, ProductGroup.MISC, "TestSeries1");
    em.persist(testSeries1);
    productFamily.setSeries(testSeries1);
    em.persist(productFamily);
    ProductFamily productFamily1 = new ProductFamily("PF2");
    ProductSeries testSeries2 = new ProductSeries(TradeName.HP, ProductGroup.COMMENTARY, "TestSeries2");
    em.persist(testSeries2);
    productFamily1.setSeries(testSeries2);
    em.persist(productFamily1);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    ProductFamilyEao familyEao = new ProductFamilyEao(em);
    ProductFamily testFamily = familyEao.find("PF1");
    assertNotNull(testFamily);
    assertNull(familyEao.find("NoFamily"));
    assertEquals(productFamily.getId(), testFamily.getId());
    utx.commit();
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) ProductFamilyEao(eu.ggnet.dwoss.spec.ee.eao.ProductFamilyEao) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries) Test(org.junit.Test)

Example 2 with ProductFamilyEao

use of eu.ggnet.dwoss.spec.ee.eao.ProductFamilyEao 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 ProductFamilyEao

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

use of eu.ggnet.dwoss.spec.ee.eao.ProductFamilyEao 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)

Aggregations

ProductFamilyEao (eu.ggnet.dwoss.spec.ee.eao.ProductFamilyEao)4 ProductFamily (eu.ggnet.dwoss.spec.ee.entity.ProductFamily)4 ProductSeries (eu.ggnet.dwoss.spec.ee.entity.ProductSeries)4 ProductSeriesEao (eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao)3 EntityManager (javax.persistence.EntityManager)2 ProductModelEao (eu.ggnet.dwoss.spec.ee.eao.ProductModelEao)1 ProductModel (eu.ggnet.dwoss.spec.ee.entity.ProductModel)1 Test (org.junit.Test)1