Search in sources :

Example 61 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class ShoppingCartApi method getByCustomer.

@Deprecated
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/auth/customer/{id}/cart", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get a shopping cart by customer id. Customer must be authenticated", notes = "", produces = "application/json", response = ReadableShoppingCart.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
// customer
@ResponseBody
public // customer
ReadableShoppingCart getByCustomer(// customer
@PathVariable Long id, // cart code
@RequestParam Optional<String> cart, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    Principal principal = request.getUserPrincipal();
    // lookup customer
    Customer customer = customerService.getById(id);
    if (customer == null) {
        throw new ResourceNotFoundException("No Customer found for id [" + id + "]");
    }
    customerFacadev1.authorize(customer, principal);
    ReadableShoppingCart readableCart = shoppingCartFacadev1.get(cart, id, merchantStore, language);
    if (readableCart == null) {
        throw new ResourceNotFoundException("No cart found for customerid [" + id + "]");
    }
    return readableCart;
}
Also used : Customer(com.salesmanager.core.model.customer.Customer) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Principal(java.security.Principal) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 62 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class ShoppingCartApi method getByCustomer.

@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/auth/customer/cart", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get a shopping cart by authenticated customer", notes = "", produces = "application/json", response = ReadableShoppingCart.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public ReadableShoppingCart getByCustomer(// cart code
@RequestParam Optional<String> cart, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    Principal principal = request.getUserPrincipal();
    Customer customer = null;
    try {
        customer = customerFacade.getCustomerByUserName(principal.getName(), merchantStore);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Exception while getting customer [ " + principal.getName() + "]");
    }
    if (customer == null) {
        throw new ResourceNotFoundException("No Customer found for principal[" + principal.getName() + "]");
    }
    customerFacadev1.authorize(customer, principal);
    ReadableShoppingCart readableCart = shoppingCartFacadev1.get(cart, customer.getId(), merchantStore, language);
    if (readableCart == null) {
        throw new ResourceNotFoundException("No cart found for customer [" + principal.getName() + "]");
    }
    return readableCart;
}
Also used : Customer(com.salesmanager.core.model.customer.Customer) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Principal(java.security.Principal) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 63 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class ShoppingCartFacadeImpl method modifyCart.

@Override
public ReadableShoppingCart modifyCart(String cartCode, PersistableShoppingCartItem item, MerchantStore store, Language language) throws Exception {
    Validate.notNull(cartCode, "String cart code cannot be null");
    Validate.notNull(item, "PersistableShoppingCartItem cannot be null");
    ShoppingCart cartModel = getCartModel(cartCode, store);
    if (cartModel == null) {
        throw new ResourceNotFoundException("Cart code [" + cartCode + "] not found");
    }
    return modifyCart(cartModel, item, store, language);
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 64 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method deleteCustomerReview.

@Override
public void deleteCustomerReview(Long customerId, Long reviewId, MerchantStore store, Language language) {
    CustomerReview customerReview = getCustomerReviewById(reviewId);
    if (!customerReview.getReviewedCustomer().getId().equals(customerId)) {
        throw new ResourceNotFoundException("Customer review with id " + reviewId + " does not exist for this customer");
    }
    deleteCustomerReview(customerReview);
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCustomerReview(com.salesmanager.shop.model.customer.ReadableCustomerReview) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview)

Example 65 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method updateCustomerReview.

@Override
public PersistableCustomerReview updateCustomerReview(Long id, Long reviewId, PersistableCustomerReview review, MerchantStore store, Language language) {
    CustomerReview customerReview = getCustomerReviewById(reviewId);
    if (!customerReview.getReviewedCustomer().getId().equals(id)) {
        throw new ResourceNotFoundException("Customer review with id " + reviewId + " does not exist for this customer");
    }
    // rating maximum 5
    if (review.getRating() > Constants.MAX_REVIEW_RATING_SCORE) {
        throw new ServiceRuntimeException("Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE);
    }
    review.setReviewedCustomer(id);
    return review;
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCustomerReview(com.salesmanager.shop.model.customer.ReadableCustomerReview) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)108 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)77 ServiceException (com.salesmanager.core.business.exception.ServiceException)62 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)22 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)22 Product (com.salesmanager.core.model.catalog.product.Product)21 Language (com.salesmanager.core.model.reference.language.Language)19 List (java.util.List)19 Collectors (java.util.stream.Collectors)19 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)17 ArrayList (java.util.ArrayList)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 ConversionException (com.salesmanager.core.business.exception.ConversionException)13 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)13 Inject (javax.inject.Inject)12 Optional (java.util.Optional)11 Service (org.springframework.stereotype.Service)11 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)11