Search in sources :

Example 76 with ServiceRuntimeException

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

the class ShippingConfigurationApi method configure.

@PostMapping(value = "/private/modules/shipping")
public void configure(@RequestBody IntegrationModuleConfiguration configuration, @ApiIgnore MerchantStore merchantStore) {
    try {
        List<IntegrationModule> modules = shippingService.getShippingMethods(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("Shipping module [" + configuration.getCode() + "] not found");
        }
        Map<String, IntegrationConfiguration> configuredModules = shippingService.getShippingModulesConfigured(merchantStore);
        IntegrationConfiguration integrationConfiguration = configuredModules.get(configuration.getCode());
        if (integrationConfiguration == null) {
            integrationConfiguration = new IntegrationConfiguration();
        }
        /**
         * Build return object for now this is a read copy
         */
        integrationConfiguration.setActive(configuration.isActive());
        integrationConfiguration.setDefaultSelected(configuration.isDefaultSelected());
        integrationConfiguration.setIntegrationKeys(configuration.getIntegrationKeys());
        integrationConfiguration.setIntegrationOptions(configuration.getIntegrationOptions());
        shippingService.saveShippingQuoteModuleConfiguration(integrationConfiguration, merchantStore);
    } catch (ServiceException e) {
        LOGGER.error("Error saving shipping modules", e);
        throw new ServiceRuntimeException("Error saving shipping module", e);
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) IntegrationModuleConfiguration(com.salesmanager.shop.model.system.IntegrationModuleConfiguration) ShippingFacade(com.salesmanager.shop.store.controller.shipping.facade.ShippingFacade) Constants(com.salesmanager.shop.constants.Constants) 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) AuthorizationUtils(com.salesmanager.shop.utils.AuthorizationUtils) 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) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ShippingService(com.salesmanager.core.business.services.shipping.ShippingService) PostMapping(org.springframework.web.bind.annotation.PostMapping) Logger(org.slf4j.Logger) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) IntegrationModuleSummaryEntity(com.salesmanager.shop.model.system.IntegrationModuleSummaryEntity) ApiIgnore(springfox.documentation.annotations.ApiIgnore) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Stream(java.util.stream.Stream) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) ReadableAddress(com.salesmanager.shop.model.references.ReadableAddress) 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)

Example 77 with ServiceRuntimeException

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

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

the class StoreFacadeImpl method findAll.

@Override
public ReadableMerchantStoreList findAll(MerchantStoreCriteria criteria, Language language, int page, int count) {
    try {
        Page<MerchantStore> stores = null;
        List<ReadableMerchantStore> readableStores = new ArrayList<ReadableMerchantStore>();
        ReadableMerchantStoreList readableList = new ReadableMerchantStoreList();
        Optional<String> code = Optional.ofNullable(criteria.getStoreCode());
        Optional<String> name = Optional.ofNullable(criteria.getName());
        if (code.isPresent()) {
            stores = merchantStoreService.listByGroup(name, code.get(), page, count);
        } else {
            if (criteria.isRetailers()) {
                stores = merchantStoreService.listAllRetailers(name, page, count);
            } else {
                stores = merchantStoreService.listAll(name, page, count);
            }
        }
        if (!CollectionUtils.isEmpty(stores.getContent())) {
            for (MerchantStore store : stores) readableStores.add(convertMerchantStoreToReadableMerchantStore(language, store));
        }
        readableList.setData(readableStores);
        readableList.setRecordsTotal(stores.getTotalElements());
        readableList.setTotalPages(stores.getTotalPages());
        readableList.setNumber(stores.getSize());
        readableList.setRecordsFiltered(stores.getSize());
        return readableList;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while finding all merchant", e);
    }
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ArrayList(java.util.ArrayList) 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 79 with ServiceRuntimeException

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

the class StoreFacadeImpl method deleteLogo.

@Override
public void deleteLogo(String code) {
    MerchantStore store = getByCode(code);
    String image = store.getStoreLogo();
    store.setStoreLogo(null);
    try {
        updateMerchantStore(store);
        if (!StringUtils.isEmpty(image)) {
            contentService.removeFile(store.getCode(), image);
        }
    } catch (ServiceException e) {
        throw new ServiceRuntimeException(e.getMessage());
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) 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 80 with ServiceRuntimeException

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

the class StoreFacadeImpl method createBrand.

@Override
public void createBrand(String merchantStoreCode, PersistableBrand brand) {
    MerchantStore mStore = getMerchantStoreByCode(merchantStoreCode);
    List<MerchantConfigEntity> createdConfigs = brand.getSocialNetworks();
    List<MerchantConfiguration> configurations = createdConfigs.stream().map(config -> convertToMerchantConfiguration(config, MerchantConfigurationType.SOCIAL)).collect(Collectors.toList());
    try {
        for (MerchantConfiguration mConfigs : configurations) {
            mConfigs.setMerchantStore(mStore);
            if (!StringUtils.isEmpty(mConfigs.getValue())) {
                mConfigs.setMerchantConfigurationType(MerchantConfigurationType.SOCIAL);
                merchantConfigurationService.saveOrUpdate(mConfigs);
            } else {
                // remove if submited blank and exists
                MerchantConfiguration config = merchantConfigurationService.getMerchantConfiguration(mConfigs.getKey(), mStore);
                if (config != null) {
                    merchantConfigurationService.delete(config);
                }
            }
        }
    } catch (ServiceException se) {
        throw new ServiceRuntimeException(se);
    }
}
Also used : MerchantConfigEntity(com.salesmanager.shop.model.store.MerchantConfigEntity) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) PersistableMerchantStorePopulator(com.salesmanager.shop.populator.store.PersistableMerchantStorePopulator) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ReadableBrand(com.salesmanager.shop.model.store.ReadableBrand) CollectionUtils(org.apache.commons.collections4.CollectionUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) PersistableBrand(com.salesmanager.shop.model.store.PersistableBrand) MerchantStoreCriteria(com.salesmanager.core.model.merchant.MerchantStoreCriteria) HttpServletRequest(javax.servlet.http.HttpServletRequest) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) GenericEntityList(com.salesmanager.core.model.common.GenericEntityList) ReadableMerchantStorePopulator(com.salesmanager.shop.populator.store.ReadableMerchantStorePopulator) MerchantStoreService(com.salesmanager.core.business.services.merchant.MerchantStoreService) MeasureUnit(com.salesmanager.core.constants.MeasureUnit) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) Logger(org.slf4j.Logger) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Page(org.springframework.data.domain.Page) InputContentFile(com.salesmanager.core.model.content.InputContentFile) Collectors(java.util.stream.Collectors) MerchantConfigurationService(com.salesmanager.core.business.services.system.MerchantConfigurationService) ContentService(com.salesmanager.core.business.services.content.ContentService) List(java.util.List) ReadableImage(com.salesmanager.shop.model.content.ReadableImage) Validate(org.apache.commons.lang3.Validate) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) LanguageUtils(com.salesmanager.shop.utils.LanguageUtils) MerchantConfigurationType(com.salesmanager.core.model.system.MerchantConfigurationType) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) Optional(java.util.Optional) ConversionException(com.salesmanager.core.business.exception.ConversionException) Collections(java.util.Collections) StringUtils(org.drools.core.util.StringUtils) MerchantConfigEntity(com.salesmanager.shop.model.store.MerchantConfigEntity) ServiceException(com.salesmanager.core.business.exception.ServiceException) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) 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)

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