Search in sources :

Example 41 with ResourceNotFoundException

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

the class CatalogFacadeImpl method deleteCatalog.

@Override
public void deleteCatalog(Long catalogId, MerchantStore store, Language language) {
    Validate.notNull(catalogId, "Catalog id cannot be null");
    Validate.isTrue(catalogId > 0, "Catalog id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Catalog c = catalogService.getById(catalogId);
    if (Objects.isNull(c)) {
        throw new ResourceNotFoundException("Catalog with id [" + catalogId + "] not found");
    }
    if (Objects.nonNull(c.getMerchantStore()) && !c.getMerchantStore().getCode().equals(store.getCode())) {
        throw new ResourceNotFoundException("Catalog with id [" + catalogId + "] not found for merchant [" + store.getCode() + "]");
    }
    try {
        catalogService.delete(c);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while deleting catalog id [" + catalogId + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 42 with ResourceNotFoundException

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

the class CatalogFacadeImpl method updateCatalog.

@Override
public void updateCatalog(Long catalogId, PersistableCatalog catalog, MerchantStore store, Language language) {
    Validate.notNull(catalogId, "Catalog id cannot be null");
    Validate.isTrue(catalogId > 0, "Catalog id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Catalog c = Optional.ofNullable(catalogService.getById(catalogId)).orElseThrow(() -> new ResourceNotFoundException("Catalog with id [" + catalogId + "] not found"));
    if (Objects.nonNull(c.getMerchantStore()) && !c.getMerchantStore().getCode().equals(store.getCode())) {
        throw new ResourceNotFoundException("Catalog with id [" + catalogId + "] not found for merchant [" + store.getCode() + "]");
    }
    c.setDefaultCatalog(catalog.isDefaultCatalog());
    c.setVisible(catalog.isVisible());
    catalogService.saveOrUpdate(c, store);
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 43 with ResourceNotFoundException

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

the class CatalogFacadeImpl method listCatalogEntry.

@Override
public ReadableEntityList<ReadableCatalogCategoryEntry> listCatalogEntry(Optional<String> product, Long id, MerchantStore store, Language language, int page, int count) {
    Validate.notNull(store, "MerchantStore cannot be null");
    String productCode = product.orElse(null);
    Catalog catalog = catalogService.getById(id, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with id [" + id + "] not found for store [" + store.getCode() + "]"));
    Page<CatalogCategoryEntry> entries = catalogEntryService.list(catalog, store, language, productCode, page, count);
    if (entries.isEmpty()) {
        return new ReadableEntityList<>();
    }
    List<ReadableCatalogCategoryEntry> readableList = entries.getContent().stream().map(cat -> readableCatalogEntryMapper.convert(cat, store, language)).collect(Collectors.toList());
    return createReadableList(entries, readableList);
}
Also used : PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) ReadableEntityUtil.createReadableList(com.salesmanager.shop.util.ReadableEntityUtil.createReadableList) ReadableCatalogCategoryEntryMapper(com.salesmanager.shop.mapper.catalog.ReadableCatalogCategoryEntryMapper) CatalogService(com.salesmanager.core.business.services.catalog.catalog.CatalogService) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Autowired(org.springframework.beans.factory.annotation.Autowired) ReadableCatalogMapper(com.salesmanager.shop.mapper.catalog.ReadableCatalogMapper) ServiceException(com.salesmanager.core.business.exception.ServiceException) CatalogFacade(com.salesmanager.shop.store.controller.catalog.facade.CatalogFacade) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) CatalogEntryService(com.salesmanager.core.business.services.catalog.catalog.CatalogEntryService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog) PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) Mapper(com.salesmanager.shop.mapper.Mapper) Validate(org.jsoup.helper.Validate) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) PersistableCatalogMapper(com.salesmanager.shop.mapper.catalog.PersistableCatalogMapper) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 44 with ResourceNotFoundException

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

the class OrderApi method checkout.

/**
 * Action for performing a checkout on a given shopping cart
 *
 * @param id
 * @param order
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = { "/auth/cart/{code}/checkout" }, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrderConfirmation checkout(// shopping cart
@PathVariable final String code, // order
@Valid @RequestBody PersistableOrder order, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    try {
        Principal principal = request.getUserPrincipal();
        String userName = principal.getName();
        Customer customer = customerService.getByNick(userName);
        if (customer == null) {
            response.sendError(401, "Error while performing checkout customer not authorized");
            return null;
        }
        ShoppingCart cart = shoppingCartService.getByCode(code, merchantStore);
        if (cart == null) {
            throw new ResourceNotFoundException("Cart code " + code + " does not exist");
        }
        order.setShoppingCartId(cart.getId());
        // That is an existing customer purchasing
        order.setCustomerId(customer.getId());
        Order modelOrder = orderFacade.processOrder(order, customer, merchantStore, language, locale);
        Long orderId = modelOrder.getId();
        modelOrder.setId(orderId);
        return orderFacadeV1.orderConfirmation(modelOrder, customer, merchantStore, language);
    } catch (Exception e) {
        LOGGER.error("Error while processing checkout", e);
        try {
            response.sendError(503, "Error while processing checkout " + e.getMessage());
        } catch (Exception ignore) {
        }
        return null;
    }
}
Also used : PersistableAnonymousOrder(com.salesmanager.shop.model.order.v1.PersistableAnonymousOrder) PersistableOrder(com.salesmanager.shop.model.order.v1.PersistableOrder) Order(com.salesmanager.core.model.order.Order) ReadableOrder(com.salesmanager.shop.model.order.v0.ReadableOrder) ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Principal(java.security.Principal) CredentialsException(com.salesmanager.shop.store.security.services.CredentialsException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) GenericRuntimeException(com.salesmanager.shop.store.api.exception.GenericRuntimeException) 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)

Example 45 with ResourceNotFoundException

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

the class OrderPaymentApi method init.

@RequestMapping(value = { "/cart/{code}/payment/init" }, method = RequestMethod.POST)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableTransaction init(@Valid @RequestBody PersistablePayment payment, @PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws Exception {
    ShoppingCart cart = shoppingCartService.getByCode(code, merchantStore);
    if (cart == null) {
        throw new ResourceNotFoundException("Cart code " + code + " does not exist");
    }
    PersistablePaymentPopulator populator = new PersistablePaymentPopulator();
    populator.setPricingService(pricingService);
    Payment paymentModel = new Payment();
    populator.populate(payment, paymentModel, merchantStore, language);
    Transaction transactionModel = paymentService.initTransaction(null, paymentModel, merchantStore);
    ReadableTransaction transaction = new ReadableTransaction();
    ReadableTransactionPopulator trxPopulator = new ReadableTransactionPopulator();
    trxPopulator.setOrderService(orderService);
    trxPopulator.setPricingService(pricingService);
    trxPopulator.populate(transactionModel, transaction, merchantStore, language);
    return transaction;
}
Also used : PersistablePayment(com.salesmanager.shop.model.order.transaction.PersistablePayment) Payment(com.salesmanager.core.model.payments.Payment) ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ReadableTransactionPopulator(com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) PersistablePaymentPopulator(com.salesmanager.shop.populator.order.transaction.PersistablePaymentPopulator) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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