Search in sources :

Example 1 with DisplayEao

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;
}
Also used : DisplayAble(eu.ggnet.dwoss.spec.ee.entity.DisplayAble) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) DisplayEao(eu.ggnet.dwoss.spec.ee.eao.DisplayEao) Display(eu.ggnet.dwoss.spec.ee.entity.piece.Display)

Example 2 with DisplayEao

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();
}
Also used : DisplayEao(eu.ggnet.dwoss.spec.ee.eao.DisplayEao) Display(eu.ggnet.dwoss.spec.ee.entity.piece.Display) Test(org.junit.Test)

Aggregations

DisplayEao (eu.ggnet.dwoss.spec.ee.eao.DisplayEao)2 Display (eu.ggnet.dwoss.spec.ee.entity.piece.Display)2 DisplayAble (eu.ggnet.dwoss.spec.ee.entity.DisplayAble)1 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)1 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)1 Test (org.junit.Test)1