use of eu.ggnet.dwoss.spec.ee.entity.ProductSpec in project dwoss by gg-net.
the class ReceiptGeneratorOperation method makeProductSpec.
/**
* Generates one ProductSpec and receipts it.
*
* @param generateCostPrice if true generates a random costprice between 1 and 1000
* @return the generated ProductSpec.
*/
private ProductSpec makeProductSpec(boolean generateCostPrice) {
ProductSpec spec = specGenerator.makeSpec();
L.debug("Persisting {}", spec);
spec = productProcessor.create(spec, spec.getModel(), 0);
if (generateCostPrice)
productOperation.updatePrice(spec.getProductId(), PriceType.MANUFACTURER_COST, R.nextInt(1000) + 1, "Generated by ReceiptGeneratorOperation.makeProductSpec()");
return spec;
}
use of eu.ggnet.dwoss.spec.ee.entity.ProductSpec in project dwoss by gg-net.
the class ReceiptGeneratorOperation method makeUniqueUnits.
/**
* Generates an amount of UniquUnits and receipts them.
*
* @param amount the amount to generate.
* @param generateSalesChannel
* @param generatePrice if true a random customer and retailer price is set
* @return the generated and receipted UniquUnits.
*/
// TODO: Create more Shipments on multiple contractors.
public List<UniqueUnit> makeUniqueUnits(int amount, boolean generateSalesChannel, boolean generatePrice) {
final int minProducts = 5;
final int maxProducts = 450;
int amountProducts = (amount / 25);
if (amountProducts <= minProducts)
amountProducts = minProducts;
if (amountProducts >= maxProducts)
amountProducts = maxProducts;
L.info("Generating {} Units", amount);
SubMonitor m = monitorFactory.newSubMonitor("Generating " + amount + " Units", amount);
m.start();
List<ProductSpec> productSpecs = makeProductSpecs(amountProducts, generatePrice);
List<UniqueUnit> units = new ArrayList<>();
Stock stock = findOrMakeStock();
TradeName contractor = new ArrayList<>(contractors.all()).get(R.nextInt(contractors.all().size()));
Shipment shipment = new Shipment("TEST-SHIPMENT-" + R.nextInt(10), contractor, TradeName.ACER, Shipment.Status.OPENED);
stockEm.persist(shipment);
StockTransaction transaction = stockTransactionEmo.requestRollInPrepared(stock.getId(), "SampleGenerator", "Rollin via make UniqueUnits");
L.debug("Transaction prepared {}", transaction);
for (int i = 0; i < amount; i++) {
ProductSpec productSpec = productSpecs.get(R.nextInt(productSpecs.size()));
Product product = uniqueUnitAgent.findById(Product.class, productSpec.getProductId());
UniqueUnit unit = unitGenerator.makeUniqueUnit(contractor, product);
m.worked(1, "created SopoNr " + unit.getRefurbishId());
if (generatePrice) {
int price = R.nextInt(1000) + 1;
unit.setPrice(PriceType.CUSTOMER, price, "Generated by ReceiptGeneratorOperation.makeUniqueUnits()");
unit.setPrice(PriceType.RETAILER, price * 1.08, "Generated by ReceiptGeneratorOperation.makeUniqueUnits()");
}
if (generateSalesChannel)
unit.setSalesChannel(R.nextBoolean() ? SalesChannel.CUSTOMER : SalesChannel.RETAILER);
unitProcessor.receipt(unit, product, shipment, transaction, ReceiptOperation.SALEABLE, "SampleGenerator", "Generator");
// Ad the now persisted instance.
units.add(uniqueUnitAgent.findUnitByIdentifierEager(REFURBISHED_ID, unit.getRefurbishId()));
}
stockTransactionProcessor.rollIn(Arrays.asList(transaction), "JUnit");
m.finish();
return units;
}
use of eu.ggnet.dwoss.spec.ee.entity.ProductSpec 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();
}
use of eu.ggnet.dwoss.spec.ee.entity.ProductSpec in project dwoss by gg-net.
the class ProductSpecTest method testValidateProductSpec.
@Test
public void testValidateProductSpec() {
ProductSeries veriton = new ProductSeries(TradeName.ACER, ProductGroup.DESKTOP, "Veriton");
ProductFamily lfamiliy = new ProductFamily("Veriton L");
lfamiliy.setSeries(veriton);
ProductModel l640 = new ProductModel("Veriton L640");
l640.setFamily(lfamiliy);
ProductSpec s = new BasicSpec("LX.AAAAA.BBB", 1L);
s.setModel(l640);
assertThat(validator.validate(s)).isEmpty();
s.setPartNo("LX.AAAAA.OOB");
assertTrue("The letter O should be allowed", validator.validate(s).isEmpty());
s.setPartNo(" LLL");
assertFalse(s.getPartNo() + " should be invalid", validator.validate(s).isEmpty());
s.setPartNo("RA LL");
assertFalse(s.getPartNo() + " should be invalid", validator.validate(s).isEmpty());
}
use of eu.ggnet.dwoss.spec.ee.entity.ProductSpec in project dwoss by gg-net.
the class SpecExporterOperation method toXml.
/**
* Exports specs to an XML till the supplied amount.
* <p>
* @param amount the amount to export
* @return a FileJacket containing all the found specs.
*/
@Override
public FileJacket toXml(int amount) {
SubMonitor m = monitorFactory.newSubMonitor("Export ProductSpecs", amount + 10);
m.start();
m.message("init");
ProductSpecEao specEao = new ProductSpecEao(em);
int count = specEao.count();
m.worked(2);
if (count < amount) {
m.setWorkRemaining(count + 8);
amount = count;
}
// load in the batches of 10
int step = 10;
List<ProductSpec> exportSpecs = new ArrayList<>();
for (int i = 0; i <= amount; i = i + step) {
m.worked(step, "loading " + step + " Spec beginning by " + i);
for (ProductSpec spec : specEao.findAll(i, step)) {
if (spec instanceof DesktopBundle)
continue;
exportSpecs.add(spec);
}
}
try {
File f = File.createTempFile("specs", ".xml");
try (OutputStream fw = new BufferedOutputStream(new FileOutputStream(f))) {
m.message("marschaling");
JAXB.marshal(new SpecsRoot(exportSpecs), fw);
}
return new FileJacket("specs", ".xml", f);
} catch (IOException ex) {
throw new RuntimeException("", ex);
} finally {
m.finish();
}
}
Aggregations