use of eu.ggnet.dwoss.spec.ee.entity.ProductFamily in project dwoss by gg-net.
the class SpecStore method makeFamily.
public ProductFamily makeFamily(String name, ProductSeries series) {
series = em.find(ProductSeries.class, series.getId());
ProductFamily family = new ProductFamily("Family 2");
family.setSeries(series);
em.persist(family);
return family;
}
use of eu.ggnet.dwoss.spec.ee.entity.ProductFamily 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 → find or create default Series and default Family</li>
* <li>If only Family is null → 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;
}
use of eu.ggnet.dwoss.spec.ee.entity.ProductFamily in project dwoss by gg-net.
the class ReceiptProductLogicPossibleDeadlockIT method testDeadlockProductSpec.
@Test
@Ignore
public void testDeadlockProductSpec() throws Exception {
//
//
// Test will run into a Deadlock if no Product Modell is setted!
// It will Display no Error but we hope for an Exception!
// To Recreated the Deadlock comment the Line Between the "Comment This" Comments
//
//
// Possible Reason that it will here appear a deadlock ist a bug in EJB that by a Validator Exception not return a exception
// but hang there. Maybe fixed in next version.
// TODO when used new Version of EJB then testet deadlock again!
//
Display display = new Display(Display.Size._10_1, Display.Resolution.VGA, Display.Type.MATT, Display.Ration.FOUR_TO_THREE);
ProductModel productModel = new ProductModel("TestModel");
productModel.setFamily(new ProductFamily("TestFamily"));
// Create a CPU and GPU and persist it.
utx.begin();
em.joinTransaction();
Cpu cpu = new Cpu(Cpu.Series.CORE, "TestCPU", Cpu.Type.MOBILE, 2.0, 5);
Gpu gpu = new Gpu(Gpu.Type.MOBILE, Gpu.Series.GEFORCE_100, "TestGPU");
ProductSeries productSeries = new ProductSeries(TradeName.ONESELF, ProductGroup.MISC, "TestSeries");
ProductFamily productFamily = new ProductFamily("TestFamily", productSeries);
// Comment This
// productModel.setFamily(productFamily);
// Comment This
em.persist(cpu);
em.persist(gpu);
em.persist(productSeries);
em.persist(productFamily);
em.persist(productModel);
utx.commit();
Notebook notebook = new Notebook(display, Desktop.Os.LINUX, cpu, null, gpu, null, 2048, null);
notebook.add(Desktop.Hdd.SSD_0016);
notebook.add(Desktop.Hdd.ROTATING_2000);
notebook.add(Desktop.Odd.DVD_ROM);
notebook.setExtras(ProductSpec.Extra.E_SATA, ProductSpec.Extra.HIGHT_CHANGEABLE);
notebook.setPartNo("LX.ASDFG.GHJ");
notebook.setModel(productModel);
ProductSpec testSpec = productLogic.create(notebook, productModel, 0);
assertThat(testSpec).isNotNull();
}
Aggregations