public Long createProductInEshop(ProductInEshopCreateDto createDto) throws PriceComparatorBusinesException { val.notNull(createDto, "createDto is null"); val.notNull(createDto.getEshopId(), ProductInEshopCreateDto.AT_ESHOP_ID + " is null"); val.notNull(createDto.getProductId(), ProductInEshopCreateDto.AT_PRODUCT_ID + " is null"); val.notNullAndNotEmpty( createDto.getEshopProductPage(), ProductInEshopCreateDto.AT_ESHOP_PRODUCT_PAGE + " is null or empty"); // kontrola, ci produkt v eshope s takou url uz neexistuje if (productInEshopDao.existProductWithGivenUrl(createDto.getEshopProductPage())) { throw new PriceComparatorBusinesException( ERR_PRODUCT_WITH_URL_ALLREADY_EXIST, createDto.getEshopProductPage()); } // kontola, ci kombinacia produkt <-> eshop uz neexistuje if (productInEshopDao.existProductInEshop(createDto.getEshopId(), createDto.getProductId())) { // FIXME err kluc throw new PriceComparatorBusinesException("Produkt v danom eshope uz je pridany."); } // kontrola, ci URL je pre dany eshop EshopEntity eshop = eshopDao.readMandatory(createDto.getEshopId()); if (!createDto.getEshopProductPage().startsWith(eshop.getHomePage())) { // FIXME err kluc // throw new PriceComparatorBusinesException("Dana URL produktu nie je pre dany // eshop."); } // vytvorenie ProductInEshopEntity entity = new ProductInEshopEntity(); entity.setEshop(eshop); entity.setProduct(productDao.readMandatory(createDto.getProductId())); entity.setProductPageInEshop(createDto.getEshopProductPage()); // ulozenie do DB return productInEshopDao.create(entity); }
public void updateProductInEshop(ProductInEshopUpdateDto updateDto) { val.notNull(updateDto, "updateDto is null"); val.notNull(updateDto.getEshopId(), ProductInEshopUpdateDto.AT_ESHOP_ID + " is null"); val.notNull(updateDto.getProductId(), ProductInEshopUpdateDto.AT_PRODUCT_ID + " is null"); val.notNullAndNotEmpty( updateDto.getEshopProductPage(), ProductInEshopUpdateDto.AT_ESHOP_PRODUCT_PAGE + " is null or empty"); // TODO validacie take co su v create plus este dalsie... ProductInEshopEntity entity = productInEshopDao.readMandatory(updateDto.getId()); entity.setEshop(eshopDao.readMandatory(updateDto.getEshopId())); entity.setProduct(productDao.readMandatory(updateDto.getProductId())); entity.setProductPageInEshop(updateDto.getEshopProductPage()); }