Search in sources :

Example 6 with ProductSeries

use of eu.ggnet.dwoss.spec.ee.entity.ProductSeries 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 7 with ProductSeries

use of eu.ggnet.dwoss.spec.ee.entity.ProductSeries 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 8 with ProductSeries

use of eu.ggnet.dwoss.spec.ee.entity.ProductSeries 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 9 with ProductSeries

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

the class ReceiptProductLogicProductFamilyIT method testCreateProductFamily.

@Test
public void testCreateProductFamily() {
    ProductFamily productFamily = productProcessor.create(TradeName.DELL, ProductGroup.NOTEBOOK, null, "TestPC");
    // Test if the created ProductFamily is not Null
    assertThat(productFamily).isNotNull();
    // Test if the ProductFamily has a ID
    assertTrue(productFamily.getId() > 0);
    // Test if the Name of the created Series the Default Name is
    assertEquals(SpecPu.DEFAULT_NAME, productFamily.getSeries().getName());
    ProductFamily productFamily2 = productProcessor.create(TradeName.DELL, ProductGroup.NOTEBOOK, null, "TestPC2");
    // Test if the created ProductFamily is not Null
    assertNotNull(productFamily2);
    // Test if the ProductFamily has a ID
    assertTrue(productFamily2.getId() > 0);
    // Test if the first created ProductFamily != the secound is!
    assertFalse(productFamily.equals(productFamily2));
    // Test if the Name of the created Series the Default Name is
    assertTrue(productFamily2.getSeries().getName().equals(SpecPu.DEFAULT_NAME));
    // Test if the ID of the Series is the same
    assertEquals(productFamily.getSeries(), productFamily2.getSeries());
    // Create a ProductSeries and persist it.
    ProductSeries series = bean.makeSeries(TradeName.DELL, ProductGroup.MISC, "Der Name");
    ProductFamily productFamily3 = productProcessor.create(TradeName.DELL, ProductGroup.NOTEBOOK, series, "TestPC3");
    // Test if the created ProductFamily is not Null
    assertNotNull(productFamily3);
    // Test if the ProductFamily has a ID
    assertTrue(productFamily3.getId() > 0);
    // Test if the Name of the Series now the same name is as on the creation
    assertEquals("Der Name", productFamily3.getSeries().getName());
    assertNotSame(productFamily3.getSeries(), productFamily.getSeries());
    // Test if the Series not the Same is as the DefaultSeries
    ProductFamily productFamily4 = productProcessor.create(TradeName.DELL, ProductGroup.NOTEBOOK, series, "TestPC4");
    // Test if the created ProductFamily is not Null
    assertNotNull(productFamily4);
    // Test if the ProductFamily has a ID
    assertTrue(productFamily4.getId() > 0);
    // Test if the Both ProdcutFamily have the same series
    assertTrue(productFamily3.getSeries().equals(productFamily4.getSeries()));
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries) Test(org.junit.Test)

Example 10 with ProductSeries

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

the class SimpleView method addSeriesButtonActionPerformed.

// GEN-LAST:event_editButtonActionPerformed
private void addSeriesButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_addSeriesButtonActionPerformed
    final String seriesName = (String) seriesBox.getSelectedItem();
    if (StringUtils.isBlank(seriesName)) {
        error("Keinen Serienname hinterlegt!");
        return;
    }
    if (allSeries.stream().map(ProductSeries::getName).anyMatch(n -> seriesName.trim().equals(n))) {
        error("Serie " + seriesName + " existiert schon");
        // Found an equal, so nothing to do
        return;
    }
    Reply<ProductSeries> reply = productProcessor.create(getBrand(), getGroup(), seriesName);
    if (!Ui.failure().handle(reply))
        return;
    ProductSeries series = reply.getPayload();
    JOptionPane.showMessageDialog(this, "Serie " + series.getName() + " wurde hinzugefĆ¼gt.\nAktualisiere Lokale Liste.");
    parent.setEnabled(false);
    allSeries = specAgent.findAll(ProductSeries.class);
    parent.setEnabled(true);
    updateSeries();
    updateFamily();
    updateModel();
    seriesBox.setSelectedItem(series.getName());
    enableAddButtons();
}
Also used : 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