Search in sources :

Example 61 with ServiceRuntimeException

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

the class ShoppingCartFacadeImpl method addToCart.

@Override
public ReadableShoppingCart addToCart(PersistableShoppingCartItem item, MerchantStore store, Language language) {
    Validate.notNull(item, "PersistableShoppingCartItem cannot be null");
    // if cart does not exist create a new one
    ShoppingCart cartModel = new ShoppingCart();
    cartModel.setMerchantStore(store);
    cartModel.setShoppingCartCode(uniqueShoppingCartCode());
    if (!StringUtils.isBlank(item.getPromoCode())) {
        cartModel.setPromoCode(item.getPromoCode());
        cartModel.setPromoAdded(new Date());
    }
    try {
        return readableShoppingCart(cartModel, item, store, language);
    } catch (Exception e) {
        if (e instanceof ResourceNotFoundException) {
            throw (ResourceNotFoundException) e;
        } else {
            throw new ServiceRuntimeException(e);
        }
    }
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Date(java.util.Date) LocalDate(java.time.LocalDate) NoResultException(javax.persistence.NoResultException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) CartModificationException(com.salesmanager.shop.model.shoppingcart.CartModificationException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 62 with ServiceRuntimeException

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

the class StoreFacadeImpl method create.

@Override
public void create(PersistableMerchantStore store) {
    Validate.notNull(store, "PersistableMerchantStore must not be null");
    Validate.notNull(store.getCode(), "PersistableMerchantStore.code must not be null");
    // check if store code exists
    MerchantStore storeForCheck = get(store.getCode());
    if (storeForCheck != null) {
        throw new ServiceRuntimeException("MerhantStore " + store.getCode() + " already exists");
    }
    MerchantStore mStore = convertPersistableMerchantStoreToMerchantStore(store, languageService.defaultLanguage());
    createMerchantStore(mStore);
}
Also used : MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 63 with ServiceRuntimeException

use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException 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 64 with ServiceRuntimeException

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

the class OrderFacadeImpl method getReadableOrderList.

@Override
public com.salesmanager.shop.model.order.v0.ReadableOrderList getReadableOrderList(OrderCriteria criteria, MerchantStore store) {
    try {
        criteria.setLegacyPagination(false);
        OrderList orderList = orderService.getOrders(criteria, store);
        List<Order> orders = orderList.getOrders();
        com.salesmanager.shop.model.order.v0.ReadableOrderList returnList = new com.salesmanager.shop.model.order.v0.ReadableOrderList();
        if (CollectionUtils.isEmpty(orders)) {
            returnList.setRecordsTotal(0);
            return returnList;
        }
        List<com.salesmanager.shop.model.order.v0.ReadableOrder> readableOrders = new ArrayList<com.salesmanager.shop.model.order.v0.ReadableOrder>();
        for (Order order : orders) {
            com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
            readableOrderPopulator.populate(order, readableOrder, null, null);
            readableOrders.add(readableOrder);
        }
        returnList.setOrders(readableOrders);
        returnList.setRecordsTotal(orderList.getTotalCount());
        returnList.setTotalPages(orderList.getTotalPages());
        returnList.setNumber(orderList.getOrders().size());
        returnList.setRecordsFiltered(orderList.getOrders().size());
        return returnList;
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while getting orders", e);
    }
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ArrayList(java.util.ArrayList) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) OrderList(com.salesmanager.core.model.order.OrderList)

Example 65 with ServiceRuntimeException

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

the class PaymentApi method configure.

@PostMapping(value = "/private/modules/payment")
public void configure(@RequestBody IntegrationModuleConfiguration configuration, @ApiIgnore MerchantStore merchantStore) {
    try {
        List<IntegrationModule> modules = paymentService.getPaymentMethods(merchantStore);
        Map<String, IntegrationModule> map = modules.stream().collect(Collectors.toMap(IntegrationModule::getCode, module -> module));
        IntegrationModule config = map.get(configuration.getCode());
        if (config == null) {
            throw new ResourceNotFoundException("Payment module [" + configuration.getCode() + "] not found");
        }
        Map<String, IntegrationConfiguration> configuredModules = paymentService.getPaymentModulesConfigured(merchantStore);
        IntegrationConfiguration integrationConfiguration = configuredModules.get(configuration.getCode());
        if (integrationConfiguration == null) {
            integrationConfiguration = new IntegrationConfiguration();
            integrationConfiguration.setModuleCode(configuration.getCode());
        }
        integrationConfiguration.setActive(configuration.isActive());
        integrationConfiguration.setDefaultSelected(configuration.isDefaultSelected());
        integrationConfiguration.setIntegrationKeys(configuration.getIntegrationKeys());
        integrationConfiguration.setIntegrationOptions(configuration.getIntegrationOptions());
        paymentService.savePaymentModuleConfiguration(integrationConfiguration, merchantStore);
    } catch (ServiceException e) {
        LOGGER.error("Error getting payment modules", e);
        throw new ServiceRuntimeException("Error saving payment module", e);
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) IntegrationModuleConfiguration(com.salesmanager.shop.model.system.IntegrationModuleConfiguration) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ServiceException(com.salesmanager.core.business.exception.ServiceException) RequestBody(org.springframework.web.bind.annotation.RequestBody) Language(com.salesmanager.core.model.reference.language.Language) ApiOperation(io.swagger.annotations.ApiOperation) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) PostMapping(org.springframework.web.bind.annotation.PostMapping) Logger(org.slf4j.Logger) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) PaymentService(com.salesmanager.core.business.services.payments.PaymentService) IntegrationModuleSummaryEntity(com.salesmanager.shop.model.system.IntegrationModuleSummaryEntity) ApiIgnore(springfox.documentation.annotations.ApiIgnore) List(java.util.List) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)146 ServiceException (com.salesmanager.core.business.exception.ServiceException)123 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)100 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)37 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)31 List (java.util.List)31 Collectors (java.util.stream.Collectors)31 Language (com.salesmanager.core.model.reference.language.Language)30 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)27 ArrayList (java.util.ArrayList)27 ConversionException (com.salesmanager.core.business.exception.ConversionException)26 Autowired (org.springframework.beans.factory.annotation.Autowired)21 Service (org.springframework.stereotype.Service)20 Optional (java.util.Optional)19 Product (com.salesmanager.core.model.catalog.product.Product)17 IOException (java.io.IOException)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Inject (javax.inject.Inject)16 Page (org.springframework.data.domain.Page)16