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()); }
// TODO zmenit nazov metody lebo sa voal ked sa upstate npodaril public void changeUpdateStatus(Long productInEshopId, ProductInEshopUpdateStatus updateStatus) { ProductInEshopEntity productInEshopEntity = productInEshopDao.readMandatory(productInEshopId); productInEshopEntity.setLastModified(new Date()); // musi tyu byt lebo inak stale ten isty produkt vytahuje ze ho chce upatovat productInEshopEntity.setLastUpdatedPrice(new Date()); productInEshopEntity.setUpdateStatus(updateStatus); productInEshopEntity.setPriceForOneItemInPackage(new BigDecimal(-1)); productInEshopEntity.setPriceForPackage(new BigDecimal(-1)); productInEshopEntity.setPriceForUnit(new BigDecimal(-1)); productInEshopDao.update(productInEshopEntity); }
public void updateInfoOfProductInEshop(ProductInEshopInfoUpdateDto priceUpdateDto) { val.notNull(priceUpdateDto, "priceUpdateDto is null"); val.notNull(priceUpdateDto.getId(), "id is null"); // TODO validacie ProductInEshopEntity entity = productInEshopDao.readMandatory(priceUpdateDto.getId()); entity.setPriceForUnit(priceUpdateDto.getPriceForUnit()); entity.setPriceForPackage(priceUpdateDto.getPriceForPackage()); entity.setPriceForOneItemInPackage(priceUpdateDto.getPriceForOneItemInPackage()); entity.setLastUpdatedPrice(new Date()); entity.setUpdateStatus(ProductInEshopUpdateStatus.OK); // TODO ako jeden // nastavenie best price if (notExistBestPrice(entity)) { entity.setBestPrice(priceUpdateDto.getPriceForPackage()); } else { if (isBestPriceGreaterThanActualPriceForPackage(priceUpdateDto, entity)) { // nastav lepsiu cenu entity.setBestPrice(priceUpdateDto.getPriceForPackage()); } } entity.setProductAction(priceUpdateDto.getProductAction()); entity.setActionValidTo(priceUpdateDto.getActionValidTo()); entity.setProductNameInEhop(priceUpdateDto.getProductName()); entity.setProductPictureUrl(priceUpdateDto.getPictureUrl()); productInEshopDao.update(entity); }
private boolean notExistBestPrice(ProductInEshopEntity entity) { return entity.getBestPrice() == null; }
private boolean isBestPriceGreaterThanActualPriceForPackage( ProductInEshopInfoUpdateDto priceUpdateDto, ProductInEshopEntity entity) { return entity.getBestPrice().compareTo(priceUpdateDto.getPriceForPackage()) > 0; }