use of com.salesmanager.shop.model.catalog.product.PersistableProductReview in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method saveOrUpdateReview.
@Override
public void saveOrUpdateReview(PersistableProductReview review, MerchantStore store, Language language) throws Exception {
PersistableProductReviewPopulator populator = new PersistableProductReviewPopulator();
populator.setLanguageService(languageService);
populator.setCustomerService(customerService);
populator.setProductService(productService);
com.salesmanager.core.model.catalog.product.review.ProductReview rev = new com.salesmanager.core.model.catalog.product.review.ProductReview();
populator.populate(review, rev, store, language);
if (review.getId() == null) {
productReviewService.create(rev);
} else {
productReviewService.update(rev);
}
review.setId(rev.getId());
}
use of com.salesmanager.shop.model.catalog.product.PersistableProductReview in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method saveOrUpdateReview.
@Override
public void saveOrUpdateReview(PersistableProductReview review, MerchantStore store, Language language) throws Exception {
PersistableProductReviewPopulator populator = new PersistableProductReviewPopulator();
populator.setLanguageService(languageService);
populator.setCustomerService(customerService);
populator.setProductService(productService);
com.salesmanager.core.model.catalog.product.review.ProductReview rev = new com.salesmanager.core.model.catalog.product.review.ProductReview();
populator.populate(review, rev, store, language);
if (review.getId() == null) {
productReviewService.create(rev);
} else {
productReviewService.update(rev);
}
review.setId(rev.getId());
}
use of com.salesmanager.shop.model.catalog.product.PersistableProductReview in project shopizer by shopizer-ecommerce.
the class ProductManagementAPIIntegrationTest method createProductReview.
/**
* Creates a ProductReview requires an existing Customer and an existing
* Product
*
* @throws Exception
*/
@Ignore
@Test
public void createProductReview() throws Exception {
final PersistableProductReview review = new PersistableProductReview();
review.setCustomerId(1L);
review.setProductId(1L);
review.setLanguage("en");
// rating is on 5
review.setRating(2D);
review.setDescription("Not as good as expected. From what i understood that was supposed to be premium quality but unfortunately i had to return the item after one week... Verry disapointed !");
review.setDate("2021-06-06");
final HttpEntity<PersistableProductReview> entity = new HttpEntity<>(review, getHeader());
final ResponseEntity<PersistableProductReview> response = testRestTemplate.postForEntity("/api/v1/private/products/1/reviews?store=" + Constants.DEFAULT_STORE, entity, PersistableProductReview.class);
final PersistableProductReview rev = response.getBody();
assertThat(response.getStatusCode(), is(CREATED));
assertNotNull(rev.getId());
}
use of com.salesmanager.shop.model.catalog.product.PersistableProductReview in project shopizer by shopizer-ecommerce.
the class PersistableProductReviewPopulator method populate.
@Override
public ProductReview populate(PersistableProductReview source, ProductReview target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(customerService, "customerService cannot be null");
Validate.notNull(productService, "productService cannot be null");
Validate.notNull(languageService, "languageService cannot be null");
Validate.notNull(source.getRating(), "Rating cannot bot be null");
try {
if (target == null) {
target = new ProductReview();
}
Customer customer = customerService.getById(source.getCustomerId());
// check if customer belongs to store
if (customer == null || customer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid customer id for the given store");
}
if (source.getDate() == null) {
String date = DateUtil.formatDate(new Date());
source.setDate(date);
}
target.setReviewDate(DateUtil.getDate(source.getDate()));
target.setCustomer(customer);
target.setReviewRating(source.getRating());
Product product = productService.getById(source.getProductId());
// check if product belongs to store
if (product == null || product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid product id for the given store");
}
target.setProduct(product);
Language lang = languageService.getByCode(language.getCode());
if (lang == null) {
throw new ConversionException("Invalid language code, use iso codes (en, fr ...)");
}
ProductReviewDescription description = new ProductReviewDescription();
description.setDescription(source.getDescription());
description.setLanguage(lang);
description.setName("-");
description.setProductReview(target);
Set<ProductReviewDescription> descriptions = new HashSet<ProductReviewDescription>();
descriptions.add(description);
target.setDescriptions(descriptions);
return target;
} catch (Exception e) {
throw new ConversionException("Cannot populate ProductReview", e);
}
}
use of com.salesmanager.shop.model.catalog.product.PersistableProductReview in project shopizer by shopizer-ecommerce.
the class ProductReviewApi method create.
@RequestMapping(value = { "/private/products/{id}/reviews", "/auth/products/{id}/reviews", "/auth/products/{id}/reviews", "/auth/products/{id}/reviews" }, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public PersistableProductReview create(@PathVariable final Long id, @Valid @RequestBody PersistableProductReview review, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
try {
// rating already exist
ProductReview prodReview = productReviewService.getByProductAndCustomer(review.getProductId(), review.getCustomerId());
if (prodReview != null) {
response.sendError(500, "A review already exist for this customer and product");
return null;
}
// rating maximum 5
if (review.getRating() > Constants.MAX_REVIEW_RATING_SCORE) {
response.sendError(503, "Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE);
return null;
}
review.setProductId(id);
productCommonFacade.saveOrUpdateReview(review, merchantStore, language);
return review;
} catch (Exception e) {
LOGGER.error("Error while saving product review", e);
try {
response.sendError(503, "Error while saving product review" + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations