Search in sources :

Example 1 with ProductFamily

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

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

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

the class SimpleView method addModelButtonActionPerformed.

// GEN-LAST:event_familyBoxActionPerformed
private void addModelButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_addModelButtonActionPerformed
    String modelName = (String) modelBox.getSelectedItem();
    if (StringUtils.isBlank(modelName)) {
        error("Keine Modellname hinterlegt!");
        return;
    }
    for (ProductSeries series : allSeries) {
        for (ProductFamily family : series.getFamilys()) {
            for (ProductModel model : family.getModels()) {
                if (model.getName().equals(modelName)) {
                    error("Modell " + modelName + " existiert schon in " + series.getName() + "/" + family.getName());
                    // Found an equal, so nothing to do
                    return;
                }
            }
        }
    }
    if (!getSelectedSeries().isPresent()) {
        if (!warn("Keine Serie und Familie ausgewählt, es werde Standartwerte verwendet."))
            return;
    } else if (!getSelectedFamily().isPresent()) {
        if (!warn("Keine Familie ausgewählt, es wird ein Standartwert verwendet."))
            return;
    }
    ProductModel model = productProcessor.create(getBrand(), getGroup(), getSelectedSeries().orElse(null), getSelectedFamily().orElse(null), modelName);
    // TODO: Add Model to local list in a better way
    // TODO: And show the active backgroundprogress.
    JOptionPane.showMessageDialog(this, "Modell " + model.getName() + " wurde hinzugefügt.\nAktualisiere Lokale Liste.");
    parent.setEnabled(false);
    allSeries = specAgent.findAll(ProductSeries.class);
    parent.setEnabled(true);
    updateSeries();
    updateFamily();
    updateModel();
    seriesBox.setSelectedItem(model.getFamily().getSeries().getName());
    familyBox.setSelectedItem(model.getFamily().getName());
    modelBox.setSelectedItem(model.getName());
    enableAddButtons();
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries) ProductModel(eu.ggnet.dwoss.spec.ee.entity.ProductModel)

Example 4 with ProductFamily

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

the class SimpleView method addFamilyButtonActionPerformed.

// GEN-LAST:event_addModelButtonActionPerformed
private void addFamilyButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_addFamilyButtonActionPerformed
    String familyName = (String) familyBox.getSelectedItem();
    if (StringUtils.isBlank(familyName)) {
        error("Keine Familienname hinterlegt!");
        return;
    }
    for (ProductSeries series : allSeries) {
        for (ProductFamily family : series.getFamilys()) {
            if (family.getName().equals(familyName)) {
                error("Familie " + familyName + " existiert schon in " + series.getName());
                // Found an equal, so nothing to do
                return;
            }
        }
    }
    if (!getSelectedSeries().isPresent()) {
        if (!warn("Keine Serie ausgewählt, es wird ein Standartwert verwendet."))
            return;
    }
    ProductFamily family = productProcessor.create(getBrand(), getGroup(), getSelectedSeries().orElse(null), familyName);
    // TODO: Add Family to local list in a better way
    // TODO: And show the active backgroundprogress.
    JOptionPane.showMessageDialog(this, "Familie " + family.getName() + " wurde hinzugefügt.\nAktualisiere Lokale Liste.");
    parent.setEnabled(false);
    allSeries = specAgent.findAll(ProductSeries.class);
    parent.setEnabled(true);
    updateSeries();
    updateFamily();
    updateModel();
    seriesBox.setSelectedItem(family.getSeries().getName());
    familyBox.setSelectedItem(family.getName());
    enableAddButtons();
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries)

Example 5 with ProductFamily

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

the class ProductProcessorStub method create.

/**
 * Creates a new ProductModel and Persists it.
 *
 * How this works: If series is null, family is also as null asumed. - so a default series and a default family is selected. If family is null, a default
 * one is selecte at the series. In both cases, if no default exists, create on. Now create a ProductModel with the family.
 *
 * @param brand     may not be null
 * @param group     may 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
 */
@Override
public ProductModel create(final TradeName brand, final ProductGroup group, ProductSeries series, ProductFamily family, final String modelName) {
    if (series == null) {
        // implies, that family is also null
        for (ProductSeries s : serieses) {
            if (s.getBrand().equals(brand) && s.getGroup().equals(group) && s.getName().equals(SpecPu.DEFAULT_NAME)) {
                series = s;
            }
        }
        if (series == null) {
            series = soc.newProductSeries(brand, group, SpecPu.DEFAULT_NAME);
            serieses.add(series);
        }
    }
    if (family == null) {
        for (ProductFamily f : series.getFamilys()) {
            if (f.getName().equals(SpecPu.DEFAULT_NAME)) {
                family = f;
            }
        }
        if (family == null) {
            family = soc.newProductFamily();
            family.setName(SpecPu.DEFAULT_NAME);
            series.addFamily(family);
        }
    }
    // TODO: Check if name exists, just to be sure
    ProductModel model = soc.newProductModel();
    model.setName(modelName);
    model.setFamily(family);
    return model;
}
Also used : ProductFamily(eu.ggnet.dwoss.spec.ee.entity.ProductFamily) ProductSeries(eu.ggnet.dwoss.spec.ee.entity.ProductSeries) ProductModel(eu.ggnet.dwoss.spec.ee.entity.ProductModel)

Aggregations

ProductFamily (eu.ggnet.dwoss.spec.ee.entity.ProductFamily)23 ProductSeries (eu.ggnet.dwoss.spec.ee.entity.ProductSeries)23 ProductModel (eu.ggnet.dwoss.spec.ee.entity.ProductModel)15 Test (org.junit.Test)14 Cpu (eu.ggnet.dwoss.spec.ee.entity.piece.Cpu)8 Gpu (eu.ggnet.dwoss.spec.ee.entity.piece.Gpu)8 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 ProductSeriesEao (eu.ggnet.dwoss.spec.ee.eao.ProductSeriesEao)3 Desktop (eu.ggnet.dwoss.spec.ee.entity.Desktop)3 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 EntityManager (javax.persistence.EntityManager)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 UnitSupporter (eu.ggnet.dwoss.receipt.ee.UnitSupporter)1