use of eu.ggnet.dwoss.spec.ee.entity.piece.Gpu in project dwoss by gg-net.
the class PieceTest method testGpu.
/**
* Test of getExtras method, of class BasicSpec.
*/
@Test
public void testGpu() {
Gpu gpu = new Gpu();
Set<ConstraintViolation<Gpu>> violations = validator.validate(gpu);
assertEquals(2, violations.size());
Set<String> properties = new HashSet<>();
for (ConstraintViolation<Gpu> constraintViolation : violations) {
properties.add(constraintViolation.getPropertyPath().toString());
}
assertTrue(properties.contains("series"));
assertTrue(properties.contains("model"));
gpu.setSeries(Gpu.Series.GEFORCE_8000);
violations = validator.validate(gpu);
assertEquals(1, violations.size());
assertTrue(violations.iterator().next().getPropertyPath().toString().equals("model"));
gpu.setModel("");
violations = validator.validate(gpu);
assertEquals(1, violations.size());
assertTrue(violations.iterator().next().getPropertyPath().toString().equals("model"));
gpu.setModel(" ");
violations = validator.validate(gpu);
assertEquals(1, violations.size());
assertTrue(violations.iterator().next().getPropertyPath().toString().equals("model"));
gpu.setModel("Hd334");
violations = validator.validate(gpu);
assertTrue(violations.isEmpty());
}
use of eu.ggnet.dwoss.spec.ee.entity.piece.Gpu in project dwoss by gg-net.
the class ProductProcessorOperation method create.
/**
* Creates a new ProductSpec and the relating Product and SopoProduct.
* <p>
* The process has multiple steps:
* <ol>
* <li>Merge the ProductModel and set it in the Spec</li>
* <li>If Spec is a DisplayAble its assumed the Display is either existent or new.<br />
* In case it exists, the existent value will be set in the Spec</li>
* <li>If Spec is a Desktop its assumed that the Cpu and Gpu are existent, and they are merged and set.</li>
* <li>The Spec is persisted</li>
* <li>A Product is created and persisted</li>
* <li>The Spec.productId is set to Product.id (WeakReference)</li>
* <li>A SopoProduct is searched. If found, it is updated, else a new one is created</li>
* </ol>
*
* @param spec the spec to persist, must not be null
* @param model the model for the spec, must not be null or new
* @param gtin the value of gtin
* @throws IllegalArgumentException if Cpu or Gpu in a Desktop are new.
*
* @return the eu.ggnet.dwoss.spec.entity.ProductSpec
*/
// TODO: Check if the model as parameter is still needed.
@Override
public ProductSpec create(ProductSpec spec, ProductModel model, long gtin) throws IllegalArgumentException {
if (model == null)
throw new NullPointerException("Model is null");
if (spec == null)
throw new NullPointerException("ProductSpec is null");
// Hint: Normally the column unique option should do that, but HSQLDB somehow lost it.
if (new ProductEao(uuEm).findByPartNo(spec.getPartNo()) != null)
throw new IllegalArgumentException("PartNo=" + spec.getPartNo() + " exists allready, but create is calles");
ProductModelEmo productModelEmo = new ProductModelEmo(specEm);
model = productModelEmo.request(model.getFamily().getSeries().getBrand(), model.getFamily().getSeries().getGroup(), model.getFamily().getSeries().getName(), model.getFamily().getName(), model.getName());
spec.setModel(model);
if (spec instanceof DisplayAble) {
DisplayAble da = (DisplayAble) spec;
da.setDisplay(new DisplayEmo(specEm).weakRequest(da.getDisplay().getSize(), da.getDisplay().getResolution(), da.getDisplay().getType(), da.getDisplay().getRation()));
}
if (spec instanceof Desktop) {
Desktop desktop = (Desktop) spec;
if (desktop.getCpu() == null || desktop.getGpu() == null)
throw new IllegalArgumentException("Cpu or Gpu of a Desktop are null. " + desktop);
Cpu cpu = new CpuEao(specEm).findById(desktop.getCpu().getId());
Gpu gpu = new GpuEao(specEm).findById(desktop.getGpu().getId());
if (cpu != null)
desktop.setCpu(cpu);
if (gpu != null)
desktop.setGpu(gpu);
}
if (spec instanceof DesktopBundle) {
DesktopBundle bundle = (DesktopBundle) spec;
if (bundle.getDesktop().getId() == 0 || bundle.getMonitor().getId() == 0)
throw new IllegalArgumentException("Monitor or Desktop are new. Impossible");
ProductSpecEao specEao = new ProductSpecEao(specEm);
bundle.setDesktop(specEao.findById(bundle.getDesktop().getId()));
bundle.setMonitor(specEao.findById(bundle.getMonitor().getId()));
}
L.info("Persisting {} including model change={}", SpecFormater.toDetailedName(spec), (model == spec.getModel()));
specEm.persist(spec);
// Ensuring Id generation.
specEm.flush();
ProductEao productEao = new ProductEao(uuEm);
Product product = productEao.findByPartNo(spec.getPartNo());
if (product == null)
product = new Product();
product.setGroup(spec.getModel().getFamily().getSeries().getGroup());
product.setTradeName(spec.getModel().getFamily().getSeries().getBrand());
product.setPartNo(spec.getPartNo());
product.setName(spec.getModel().getName());
product.setDescription(SpecFormater.toSingleLine(spec));
product.setGtin(gtin);
L.debug("persisting {}", product);
if (!uuEm.contains(product)) {
uuEm.persist(product);
// Ensuring Id generation
uuEm.flush();
}
L.debug("creating weak reference ProductSpec.productId=Product.id value ({})", product.getId());
spec.setProductId(product.getId());
return spec;
}
use of eu.ggnet.dwoss.spec.ee.entity.piece.Gpu in project dwoss by gg-net.
the class DesktopView method filterGpuNames.
private void filterGpuNames() {
List filteredGpus = new ArrayList<>();
for (Gpu gpu : allGpus) {
if (gpu.getTypes().contains(gpuTypes.getSelected()) && gpuSeries.getSelected() == gpu.getSeries())
filteredGpus.add(gpu);
}
Collections.sort(filteredGpus, gpuComparator);
gpuBox.setModel(new DefaultComboBoxModel(filteredGpus.toArray()));
}
use of eu.ggnet.dwoss.spec.ee.entity.piece.Gpu in project dwoss by gg-net.
the class ReceiptProductLogicProductSpecIT method testCreateProductSpec.
@Test
public void testCreateProductSpec() throws Exception {
final long GTIN = 123456782;
// Create a CPU and GPU and persist it.
Cpu cpu = productProcessor.create(new Cpu(Cpu.Series.AMD_V, "TestCPU", Cpu.Type.MOBILE, 2.0, 5));
Gpu gpu = productProcessor.create(new Gpu(Gpu.Type.MOBILE, Gpu.Series.GEFORCE_100, "TestGPU"));
// Persist Display
Display display = new Display(Display.Size._10_1, Display.Resolution.VGA, Display.Type.MATT, Display.Ration.FOUR_TO_THREE);
ProductModel productModel = new ProductModel("M", new ProductFamily("F", new ProductSeries(ACER, NOTEBOOK, "S")));
Notebook notebook = new Notebook();
notebook.setDisplay(display);
notebook.setGpu(gpu);
notebook.setCpu(cpu);
notebook.setMemory(2048);
notebook.setOs(Desktop.Os.LINUX);
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 = productProcessor.create(notebook, productModel, 0);
assertNotNull(testSpec);
Notebook notebook2 = new Notebook();
notebook2.setDisplay(display);
notebook2.setGpu(gpu);
notebook2.setCpu(cpu);
notebook2.setMemory(2048);
notebook2.setOs(Desktop.Os.LINUX);
notebook2.add(Desktop.Hdd.SSD_0016);
notebook2.add(Desktop.Hdd.ROTATING_2000);
notebook2.add(Desktop.Odd.DVD_ROM);
notebook2.setExtras(ProductSpec.Extra.E_SATA, ProductSpec.Extra.HIGHT_CHANGEABLE);
notebook2.setPartNo("LX.ASDFG.GH2");
notebook2.setModel(productModel);
ProductSpec testSpec2 = productProcessor.create(notebook2, productModel, GTIN);
assertNotNull(testSpec2);
assertNotSame(testSpec2, testSpec);
Product product = uuAgent.findById(Product.class, testSpec2.getProductId());
assertThat(product).isNotNull().returns(GTIN, Product::getGtin);
}
use of eu.ggnet.dwoss.spec.ee.entity.piece.Gpu in project dwoss by gg-net.
the class ReceiptProductLogicProductSpecIT method testCreateProductSpecException.
@Test(expected = RuntimeException.class)
public void testCreateProductSpecException() {
// Create a CPU and GPU and persist it.
Cpu cpu = productProcessor.create(new Cpu(Cpu.Series.AMD_V, "TestCPU", Cpu.Type.MOBILE, 2.0, 5));
Gpu gpu = productProcessor.create(new Gpu(Gpu.Type.MOBILE, Gpu.Series.GEFORCE_100, "TestGPU"));
// Persist Display
Display display = new Display(Display.Size._10_1, Display.Resolution.VGA, Display.Type.MATT, Display.Ration.FOUR_TO_THREE);
ProductModel productModel = new ProductModel("M", new ProductFamily("F", new ProductSeries(PACKARD_BELL, NOTEBOOK, "S")));
Notebook notebook = new Notebook();
notebook.setDisplay(display);
notebook.setGpu(gpu);
notebook.setCpu(cpu);
notebook.setMemory(2048);
notebook.setOs(Desktop.Os.LINUX);
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);
productProcessor.create(notebook, productModel, 0);
productProcessor.create(notebook, productModel, 0);
fail("Error 040: No Exception Found at: CreateProductSpec");
}
Aggregations