use of eu.ggnet.dwoss.spec.ee.eao.DisplayEao in project dwoss by gg-net.
the class ProductProcessorOperation method update.
/**
* Updates an existing ProductSpec and the relating Product and SopoProduct.
* <p>
* The process has multiple steps:
* <ol>
* <li>Validate and throw IllegalArgumentException:
* <ul>
* <li>if the ProductSpec.productId == null</li>
* <li>if there does not exist a Product with ProductSpec.productId</li>
* <li>if there does not exist a SopoProduct with Product.partNo (unchanged)</li>
* </ul>
* </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 the supplied ProductModel is different from ProductSpec.getModel it is merged and set</li>
* <li>Overwrite all changes in Product</li>
* <li>Overwrite all changes in SopoProduct</li>
* <li> If PartNo change propagate to all matching SopoUnits</li>
* </ol>
*
* @param spec the spec to be updated, must not be null and not new
* @param gtin the value of gtin
* @throws IllegalArgumentException if spec.productId == null
* @return the eu.ggnet.dwoss.spec.entity.ProductSpec
*/
@Override
public ProductSpec update(ProductSpec spec, long gtin) throws IllegalArgumentException {
// 1. Validation
if (spec.getProductId() == null)
throw new IllegalArgumentException("ProductSpec has no productId, violation ! " + spec);
ProductEao productEao = new ProductEao(uuEm);
Product product = productEao.findById(spec.getProductId());
if (product == null)
throw new IllegalArgumentException("ProductSpec.productId=" + spec.getProductId() + " does not have a Product");
// 2. + 3. Update Spec
if (spec instanceof DisplayAble && ((DisplayAble) spec).getDisplay().getId() == 0) {
DisplayAble monitor = (DisplayAble) spec;
DisplayEao displayEao = new DisplayEao(specEm);
Display display = monitor.getDisplay();
display = displayEao.find(display.getSize(), display.getResolution(), display.getType(), display.getRation());
if (display != null)
monitor.setDisplay(display);
}
L.info("updateing {}", SpecFormater.toDetailedName(spec));
spec = specEm.merge(spec);
// 4. overwrite 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("updateing {}", product);
return spec;
}
use of eu.ggnet.dwoss.spec.ee.eao.DisplayEao in project dwoss by gg-net.
the class DisplayEaoIT method testFind.
@Test
public void testFind() throws Exception {
utx.begin();
em.joinTransaction();
Display d = new Display(Display.Size._10_1, Display.Resolution.VGA, Display.Type.MATT, Display.Ration.SIXTEEN_TO_NINE);
em.persist(d);
em.persist(new Display(Display.Size._15, Display.Resolution.VGA, Display.Type.CRYSTAL_BRIGHT, Display.Ration.SIXTEEN_TO_NINE));
utx.commit();
utx.begin();
em.joinTransaction();
DisplayEao displayEao = new DisplayEao(em);
Display display = displayEao.find(d.getSize(), d.getResolution(), d.getType(), d.getRation());
assertNotNull(display);
assertEquals(d.getId(), display.getId());
display = displayEao.find(Display.Size._11_6, Display.Resolution.HD, Display.Type.MATT, Display.Ration.SIXTEEN_TO_TEN);
assertNull(display);
utx.commit();
}
Aggregations