Search in sources :

Example 1 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 2 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 3 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)

Example 4 with ProductSeries

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

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

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