Search in sources :

Example 1 with ProductReview

use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.

the class ProductFacadeImpl method getProductReviews.

@Override
public List<ReadableProductReview> getProductReviews(Product product, MerchantStore store, Language language) throws Exception {
    List<ProductReview> reviews = productReviewService.getByProduct(product);
    ReadableProductReviewPopulator populator = new ReadableProductReviewPopulator();
    List<ReadableProductReview> productReviews = new ArrayList<ReadableProductReview>();
    for (ProductReview review : reviews) {
        ReadableProductReview readableReview = new ReadableProductReview();
        populator.populate(review, readableReview, store, language);
        productReviews.add(readableReview);
    }
    return productReviews;
}
Also used : ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ArrayList(java.util.ArrayList) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ReadableProductReviewPopulator(com.salesmanager.shop.populator.catalog.ReadableProductReviewPopulator)

Example 2 with ProductReview

use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.

the class CustomerProductReviewController method displayProductReview.

@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/review.html", method = RequestMethod.GET)
public String displayProductReview(@RequestParam Long productId, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
    Language language = super.getLanguage(request);
    // get product
    Product product = productService.getById(productId);
    if (product == null) {
        return "redirect:" + Constants.SHOP_URI;
    }
    if (product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
        return "redirect:" + Constants.SHOP_URI;
    }
    // create readable product
    ReadableProduct readableProduct = new ReadableProduct();
    ReadableProductPopulator readableProductPopulator = new ReadableProductPopulator();
    readableProductPopulator.setPricingService(pricingService);
    readableProductPopulator.setimageUtils(imageUtils);
    readableProductPopulator.populate(product, readableProduct, store, language);
    model.addAttribute("product", readableProduct);
    Customer customer = customerFacade.getCustomerByUserName(request.getRemoteUser(), store);
    List<ProductReview> reviews = productReviewService.getByProduct(product, language);
    for (ProductReview r : reviews) {
        if (r.getCustomer().getId().longValue() == customer.getId().longValue()) {
            ReadableProductReviewPopulator reviewPopulator = new ReadableProductReviewPopulator();
            ReadableProductReview rev = new ReadableProductReview();
            reviewPopulator.populate(r, rev, store, language);
            model.addAttribute("customerReview", rev);
            break;
        }
    }
    ProductReview review = new ProductReview();
    review.setCustomer(customer);
    review.setProduct(product);
    ReadableProductReview productReview = new ReadableProductReview();
    ReadableProductReviewPopulator reviewPopulator = new ReadableProductReviewPopulator();
    reviewPopulator.populate(review, productReview, store, language);
    model.addAttribute("review", productReview);
    model.addAttribute("reviews", reviews);
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.review).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) Customer(com.salesmanager.core.model.customer.Customer) ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) ReadableProductReviewPopulator(com.salesmanager.shop.populator.catalog.ReadableProductReviewPopulator) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ProductReview

use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.

the class ProductCommonFacadeImpl method getProductReviews.

@Override
public List<ReadableProductReview> getProductReviews(Product product, MerchantStore store, Language language) throws Exception {
    List<ProductReview> reviews = productReviewService.getByProduct(product);
    ReadableProductReviewPopulator populator = new ReadableProductReviewPopulator();
    List<ReadableProductReview> productReviews = new ArrayList<ReadableProductReview>();
    for (ProductReview review : reviews) {
        ReadableProductReview readableReview = new ReadableProductReview();
        populator.populate(review, readableReview, store, language);
        productReviews.add(readableReview);
    }
    return productReviews;
}
Also used : ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ArrayList(java.util.ArrayList) ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) ReadableProductReviewPopulator(com.salesmanager.shop.populator.catalog.ReadableProductReviewPopulator)

Example 4 with ProductReview

use of com.salesmanager.core.model.catalog.product.review.ProductReview 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);
    }
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Language(com.salesmanager.core.model.reference.language.Language) Customer(com.salesmanager.core.model.customer.Customer) Product(com.salesmanager.core.model.catalog.product.Product) ProductReviewDescription(com.salesmanager.core.model.catalog.product.review.ProductReviewDescription) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) Date(java.util.Date) ConversionException(com.salesmanager.core.business.exception.ConversionException) HashSet(java.util.HashSet)

Example 5 with ProductReview

use of com.salesmanager.core.model.catalog.product.review.ProductReview in project shopizer by shopizer-ecommerce.

the class ProductReviewApi method delete.

@RequestMapping(value = { "/private/products/{id}/reviews/{reviewid}", "/auth/products/{id}/reviews/{reviewid}" }, method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public void delete(@PathVariable final Long id, @PathVariable final Long reviewId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) {
    try {
        ProductReview prodReview = productReviewService.getById(reviewId);
        if (prodReview == null) {
            response.sendError(404, "Product review with id " + reviewId + " does not exist");
            return;
        }
        if (prodReview.getProduct().getId().longValue() != id.longValue()) {
            response.sendError(404, "Product review with id " + reviewId + " does not exist");
            return;
        }
        productCommonFacade.deleteReview(prodReview, merchantStore, language);
    } catch (Exception e) {
        LOGGER.error("Error while deleting product review", e);
        try {
            response.sendError(503, "Error while deleting product review" + e.getMessage());
        } catch (Exception ignore) {
        }
        return;
    }
}
Also used : ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ProductReview (com.salesmanager.core.model.catalog.product.review.ProductReview)12 PersistableProductReview (com.salesmanager.shop.model.catalog.product.PersistableProductReview)9 ReadableProductReview (com.salesmanager.shop.model.catalog.product.ReadableProductReview)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Language (com.salesmanager.core.model.reference.language.Language)5 ReadableProductReviewPopulator (com.salesmanager.shop.populator.catalog.ReadableProductReviewPopulator)5 Product (com.salesmanager.core.model.catalog.product.Product)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 Customer (com.salesmanager.core.model.customer.Customer)3 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)3 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)3 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)3 ArrayList (java.util.ArrayList)3 ProductReviewDescription (com.salesmanager.core.model.catalog.product.review.ProductReviewDescription)2 PersistableProductReviewPopulator (com.salesmanager.shop.populator.catalog.PersistableProductReviewPopulator)2 Date (java.util.Date)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1