use of com.salesmanager.core.model.catalog.product.review.ProductReview 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;
}
}
use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.
the class ProductReviewApi method update.
@RequestMapping(value = { "/private/products/{id}/reviews/{reviewid}", "/auth/products/{id}/reviews/{reviewid}" }, method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public PersistableProductReview update(@PathVariable final Long id, @PathVariable final Long reviewId, @Valid @RequestBody PersistableProductReview review, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
try {
ProductReview prodReview = productReviewService.getById(reviewId);
if (prodReview == null) {
response.sendError(404, "Product review with id " + reviewId + " does not exist");
return null;
}
if (prodReview.getCustomer().getId().longValue() != review.getCustomerId().longValue()) {
response.sendError(404, "Product review with id " + reviewId + " does not exist");
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;
}
}
use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.
the class ProductServiceImpl method delete.
@Override
public void delete(Product product) throws ServiceException {
LOGGER.debug("Deleting product");
Validate.notNull(product, "Product cannot be null");
Validate.notNull(product.getMerchantStore(), "MerchantStore cannot be null in product");
// Prevents detached entity
product = this.getById(product.getId());
// error
product.setCategories(null);
Set<ProductImage> images = product.getImages();
for (ProductImage image : images) {
productImageService.removeProductImage(image);
}
product.setImages(null);
// delete reviews
List<ProductReview> reviews = productReviewService.getByProductNoCustomers(product);
for (ProductReview review : reviews) {
productReviewService.delete(review);
}
// related - featured
List<ProductRelationship> relationships = productRelationshipService.listByProduct(product);
for (ProductRelationship relationship : relationships) {
productRelationshipService.deleteRelationship(relationship);
}
super.delete(product);
searchService.deleteIndex(product.getMerchantStore(), product);
}
use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.
the class ProductTest method testReview.
// REVIEW
private void testReview(Product product) throws Exception {
ProductReview review = new ProductReview();
review.setProduct(product);
review.setReviewRating(4d);
Language en = languageService.getByCode("en");
ProductReviewDescription reviewDescription = new ProductReviewDescription();
reviewDescription.setLanguage(en);
reviewDescription.setDescription("This is a product review");
reviewDescription.setName("A review for you");
reviewDescription.setProductReview(review);
review.getDescriptions().add(reviewDescription);
productReviewService.create(review);
}
use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.
the class ShopProductRESTController method createProductReview.
@RequestMapping(value = "/private/{store}/product/review", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public PersistableProductReview createProductReview(@PathVariable final String store, @Valid @RequestBody PersistableProductReview review, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
if (merchantStore != null) {
if (!merchantStore.getCode().equals(store)) {
merchantStore = null;
}
}
if (merchantStore == null) {
merchantStore = merchantStoreService.getByCode(store);
}
if (merchantStore == null) {
LOGGER.error("Merchant store is null for code " + store);
response.sendError(500, "Merchant store is null for code " + store);
return null;
}
// 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;
}
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, merchantStore, merchantStore.getDefaultLanguage());
productReviewService.create(rev);
review.setId(rev.getId());
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