use of eu.ggnet.dwoss.spec.ee.entity.DesktopBundle in project dwoss by gg-net.
the class PersistenceIT method testPersistence.
@Test
public void testPersistence() throws Exception {
utx.begin();
em.joinTransaction();
// A Notebook
ProductSeries ps = new ProductSeries(TradeName.ACER, ProductGroup.NOTEBOOK, "TravelMate");
em.persist(ps);
ProductFamily pf = new ProductFamily("TravelMate 8700");
pf.setSeries(ps);
em.persist(pf);
ProductModel pm = new ProductModel("TravelMate 8741-81222132");
pm.setFamily(pf);
em.persist(pm);
Notebook notebook = new Notebook();
notebook.setPartNo("LX.AAAAA.BBB");
notebook.setModel(pm);
notebook.setVideoPorts(EnumSet.allOf(BasicSpec.VideoPort.class));
notebook.setComment("Ein Kommentar");
notebook.setCpu(new Cpu(Cpu.Series.CORE, "Eine CPU", Cpu.Type.MOBILE, 123.1, 2));
notebook.setGpu(new Gpu(Gpu.Type.MOBILE, Gpu.Series.RADEON_HD_4000, "Eine Graphiccarte"));
notebook.setOs(Desktop.Os.LINUX);
notebook.setMemory(12345);
notebook.add(Desktop.Hdd.ROTATING_0500);
notebook.add(Desktop.Odd.BLURAY_COMBO);
notebook.setExtras(Desktop.Extra.KAMERA);
notebook.setDisplay(new Display(Display.Size._10_1, Display.Resolution.VGA, Display.Type.MATT, Display.Ration.FOUR_TO_THREE));
em.persist(notebook);
// An AllInOne
ps = new ProductSeries(TradeName.ACER, ProductGroup.ALL_IN_ONE, "AllInOne");
em.persist(ps);
pf = new ProductFamily("Z5600");
pf.setSeries(ps);
em.persist(pf);
pm = new ProductModel("Z6523");
pm.setFamily(pf);
em.persist(pm);
Notebook allInOne = new Notebook();
allInOne.setPartNo("PX.AASAA.BBB");
allInOne.setModel(pm);
allInOne.setVideoPorts(EnumSet.allOf(BasicSpec.VideoPort.class));
allInOne.setComment("Ein Kommentar");
allInOne.setCpu(new Cpu(Cpu.Series.CELERON, "Eine CPU", Cpu.Type.MOBILE, 123.1, 2));
allInOne.setGpu(new Gpu(Gpu.Type.MOBILE, Gpu.Series.RADEON_HD_4000, "Eine Graphiccarte"));
allInOne.setOs(Desktop.Os.LINUX);
allInOne.setMemory(12345);
allInOne.add(Desktop.Hdd.ROTATING_0500);
allInOne.add(Desktop.Odd.BLURAY_COMBO);
allInOne.setExtras(Desktop.Extra.KAMERA);
allInOne.setDisplay(new Display(Display.Size._10_1, Display.Resolution.VGA, Display.Type.MATT, Display.Ration.FOUR_TO_THREE));
em.persist(allInOne);
// A Desktop
ProductSeries veriton = new ProductSeries(TradeName.ACER, ProductGroup.DESKTOP, "Veriton");
em.persist(veriton);
ProductFamily m400 = new ProductFamily("M400");
m400.setSeries(veriton);
em.persist(m400);
ProductModel M480G = new ProductModel("M480G");
M480G.setFamily(m400);
em.persist(M480G);
Gpu gpu = new Gpu(Gpu.Type.MOBILE, Gpu.Series.RADEON_HD_4000, "Eine Graphiccarte");
em.persist(gpu);
Cpu cpu = new Cpu(Cpu.Series.CORE, "Eine CPU", Cpu.Type.MOBILE, 123.1, 2);
cpu.setEmbeddedGpu(gpu);
em.persist(cpu);
Desktop M480G_1 = new Desktop("PX.99999.321", 2L);
M480G_1.setModel(M480G);
M480G_1.setVideoPorts(EnumSet.allOf(BasicSpec.VideoPort.class));
M480G_1.setComment("Ein Kommentar");
M480G_1.setCpu(cpu);
M480G_1.setGpu(gpu);
M480G_1.setOs(Desktop.Os.LINUX);
M480G_1.setMemory(12345);
M480G_1.add(Desktop.Hdd.ROTATING_0500);
M480G_1.add(Desktop.Odd.BLURAY_COMBO);
M480G_1.setExtras(Desktop.Extra.KAMERA);
em.persist(M480G_1);
// A Monitor
ProductSeries a = new ProductSeries(TradeName.ACER, ProductGroup.MONITOR, "A");
em.persist(a);
ProductFamily a230 = new ProductFamily("A230");
a230.setSeries(a);
em.persist(a230);
ProductModel a231Hbmd = new ProductModel("A231Hbmd");
a231Hbmd.setFamily(a230);
em.persist(a231Hbmd);
Monitor A231spec = new Monitor(new Display(Display.Size._11_6, Display.Resolution.VGA, Display.Type.CRYSTAL_BRIGHT, Display.Ration.SIXTEEN_TO_NINE));
A231spec.setModel(a231Hbmd);
A231spec.setPartNo("ET.VA1HE.008");
A231spec.setProductId(3L);
A231spec.setVideoPorts(EnumSet.allOf(BasicSpec.VideoPort.class));
A231spec.setComment("Ein Kommentar");
em.persist(A231spec);
// A Bundle
ProductSeries box = new ProductSeries(TradeName.ACER, ProductGroup.DESKTOP_BUNDLE, "Veriton");
em.persist(box);
ProductFamily boxf = new ProductFamily("M480");
boxf.setSeries(box);
em.persist(boxf);
ProductModel boxm = new ProductModel("M480G + A231MuhMäh");
boxm.setFamily(boxf);
em.persist(boxm);
DesktopBundle bundle = new DesktopBundle();
bundle.setPartNo("BL.32199.321");
bundle.setProductId(1L);
bundle.setDesktop(M480G_1);
bundle.setMonitor(A231spec);
bundle.setModel(boxm);
em.persist(bundle);
utx.commit();
utx.begin();
em.joinTransaction();
CriteriaQuery<ProductSeries> cq = em.getCriteriaBuilder().createQuery(ProductSeries.class);
cq.select(cq.from(ProductSeries.class));
List<ProductSeries> serieses = em.createQuery(cq).getResultList();
assertFalse(serieses.isEmpty());
for (ProductSeries series : serieses) {
assertNotNull(series.getFamilys());
assertFalse(series.getFamilys().isEmpty());
for (ProductFamily family : series.getFamilys()) {
assertNotNull(family.getModels());
assertFalse(family.getModels().isEmpty());
for (ProductModel model : family.getModels()) {
assertNotNull(model.getSpecs());
assertFalse(model.getSpecs().isEmpty());
for (ProductSpec spec : model.getSpecs()) {
assertNotNull(spec.getPartNo());
assertNotNull(spec.getModel());
assertNotNull(spec.getModel().getFamily());
assertNotNull(spec.getModel().getFamily().getSeries());
assertNotNull(spec.getModel().getFamily().getSeries().getBrand());
assertNotNull(spec.getModel().getFamily().getSeries().getGroup());
}
}
}
}
utx.commit();
}
use of eu.ggnet.dwoss.spec.ee.entity.DesktopBundle 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.DesktopBundle in project dwoss by gg-net.
the class DesktopBundleViewTryout method tryoutView.
@Test
public void tryoutView() throws InterruptedException {
final ProductSpec spec = new SpecGenerator().makeSpec();
DesktopBundleView view = new DesktopBundleView(new Mandators() {
@Override
public Mandator loadMandator() {
return Mandator.builder().defaultMailSignature(null).smtpConfiguration(null).mailTemplateLocation(null).company(CompanyGen.makeCompany()).dossierPrefix("DW").documentIntermix(null).documentIdentifierGeneratorConfigurations(new EnumMap<>(DocumentType.class)).build();
}
@Override
public DefaultCustomerSalesdata loadSalesdata() {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("loadSalesdata - Not supported yet.");
}
@Override
public ReceiptCustomers loadReceiptCustomers() {
return ReceiptCustomers.builder().build();
}
@Override
public SpecialSystemCustomers loadSystemCustomers() {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("loadSystemCustomers - Not supported yet.");
}
@Override
public Contractors loadContractors() {
return new Contractors(EnumSet.of(TradeName.ALSO, TradeName.ACER), EnumSet.of(TradeName.ACER));
}
@Override
public PostLedger loadPostLedger() {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("loadPostLedger - Not supported yet.");
}
@Override
public ShippingTerms loadShippingTerms() {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("loadShippingTerms - Not supported yet.");
}
}, new SpecAgent() {
@Override
public ProductSpec findProductSpecByPartNoEager(String partNo) {
if (partNo == null)
return null;
if (partNo.startsWith("X"))
return null;
spec.setPartNo(partNo);
return spec;
}
// <editor-fold defaultstate="collapsed" desc="Unneeded Methods">
@Override
public <T> long count(Class<T> entityClass) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> List<T> findAll(Class<T> entityClass) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> List<T> findAll(Class<T> entityClass, int start, int amount) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> List<T> findAllEager(Class<T> entityClass) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> List<T> findAllEager(Class<T> entityClass, int start, int amount) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T findById(Class<T> entityClass, Object id) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T findById(Class<T> entityClass, Object id, LockModeType lockModeType) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T findByIdEager(Class<T> entityClass, Object id) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T findByIdEager(Class<T> entityClass, Object id, LockModeType lockModeType) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
}, new ProductProcessorStub(), TradeName.ACER, TradeName.ACER, ProductGroup.DESKTOP, ProductGroup.MONITOR);
view.setSpec(new DesktopBundle());
OkCancelDialog<DesktopBundleView> dialog = new OkCancelDialog<>("BundleView", view);
dialog.setVisible(true);
dialog.dispose();
}
use of eu.ggnet.dwoss.spec.ee.entity.DesktopBundle 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