Search in sources :

Example 16 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration in project shopizer by shopizer-ecommerce.

the class ShippingConfigurationApi method integrationModule.

private IntegrationModuleSummaryEntity integrationModule(IntegrationModule module, Map<String, IntegrationConfiguration> configuredModules) {
    IntegrationModuleSummaryEntity readable = null;
    readable = new IntegrationModuleSummaryEntity();
    readable.setCode(module.getCode());
    readable.setImage(module.getImage());
    if (configuredModules.containsKey(module.getCode())) {
        IntegrationConfiguration conf = configuredModules.get(module.getCode());
        readable.setConfigured(true);
        if (conf.isActive()) {
            readable.setActive(true);
        }
    }
    return readable;
}
Also used : IntegrationModuleSummaryEntity(com.salesmanager.shop.model.system.IntegrationModuleSummaryEntity) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration)

Example 17 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration in project shopizer by shopizer-ecommerce.

the class ShippingConfigurationApi method shippingModules.

/**
 * Get available shipping modules
 *
 * @param merchantStore
 * @param language
 * @return
 */
@GetMapping("/private/modules/shipping")
@ApiOperation(httpMethod = "GET", value = "List list of shipping modules", notes = "Requires administration access", produces = "application/json", response = List.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") })
public List<IntegrationModuleSummaryEntity> shippingModules(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    try {
        List<IntegrationModule> modules = shippingService.getShippingMethods(merchantStore);
        // configured modules
        Map<String, IntegrationConfiguration> configuredModules = shippingService.getShippingModulesConfigured(merchantStore);
        return modules.stream().map(m -> integrationModule(m, configuredModules)).collect(Collectors.toList());
    } catch (ServiceException e) {
        LOGGER.error("Error getting shipping modules", e);
        throw new ServiceRuntimeException("Error getting shipping modules", 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) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation)

Example 18 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration 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 19 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration in project shopizer by shopizer-ecommerce.

the class ShippingServiceImpl method getShippingModulesConfigured.

@Override
public Map<String, IntegrationConfiguration> getShippingModulesConfigured(MerchantStore store) throws ServiceException {
    try {
        Map<String, IntegrationConfiguration> modules = new HashMap<String, IntegrationConfiguration>();
        MerchantConfiguration merchantConfiguration = merchantConfigurationService.getMerchantConfiguration(SHIPPING_MODULES, store);
        if (merchantConfiguration != null) {
            if (!StringUtils.isBlank(merchantConfiguration.getValue())) {
                String decrypted = encryption.decrypt(merchantConfiguration.getValue());
                modules = ConfigurationModulesLoader.loadIntegrationConfigurations(decrypted);
            }
        }
        return modules;
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) HashMap(java.util.HashMap) CustomIntegrationConfiguration(com.salesmanager.core.model.system.CustomIntegrationConfiguration) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 20 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration in project shopizer by shopizer-ecommerce.

the class ShippingServiceImpl method getShippingMetaData.

@Override
public ShippingMetaData getShippingMetaData(MerchantStore store) throws ServiceException {
    try {
        ShippingMetaData metaData = new ShippingMetaData();
        // configured country
        List<Country> countries = getShipToCountryList(store, store.getDefaultLanguage());
        metaData.setShipToCountry(countries);
        // configured modules
        Map<String, IntegrationConfiguration> modules = Optional.ofNullable(getShippingModulesConfigured(store)).orElse(Collections.emptyMap());
        metaData.setModules(new ArrayList<>(modules.keySet()));
        // pre processors
        List<ShippingQuotePrePostProcessModule> preProcessors = this.shippingModulePreProcessors;
        List<String> preProcessorKeys = new ArrayList<String>();
        if (preProcessors != null) {
            for (ShippingQuotePrePostProcessModule processor : preProcessors) {
                preProcessorKeys.add(processor.getModuleCode());
                if (SHIPPING_DISTANCE.equals(processor.getModuleCode())) {
                    metaData.setUseDistanceModule(true);
                }
            }
        }
        metaData.setPreProcessors(preProcessorKeys);
        // post processors
        List<ShippingQuotePrePostProcessModule> postProcessors = this.shippingModulePostProcessors;
        List<String> postProcessorKeys = new ArrayList<String>();
        if (postProcessors != null) {
            for (ShippingQuotePrePostProcessModule processor : postProcessors) {
                postProcessorKeys.add(processor.getModuleCode());
            }
        }
        metaData.setPostProcessors(postProcessorKeys);
        return metaData;
    } catch (Exception e) {
        throw new ServiceException("Exception while getting shipping metadata ", e);
    }
}
Also used : CustomIntegrationConfiguration(com.salesmanager.core.model.system.CustomIntegrationConfiguration) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) ShippingMetaData(com.salesmanager.core.model.shipping.ShippingMetaData) ServiceException(com.salesmanager.core.business.exception.ServiceException) Country(com.salesmanager.core.model.reference.country.Country) ShippingQuotePrePostProcessModule(com.salesmanager.core.modules.integration.shipping.model.ShippingQuotePrePostProcessModule)

Aggregations

IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)27 ServiceException (com.salesmanager.core.business.exception.ServiceException)20 IntegrationModule (com.salesmanager.core.model.system.IntegrationModule)16 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)10 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 List (java.util.List)9 Language (com.salesmanager.core.model.reference.language.Language)8 BigDecimal (java.math.BigDecimal)8 Map (java.util.Map)8 CustomIntegrationConfiguration (com.salesmanager.core.model.system.CustomIntegrationConfiguration)7 PaymentModule (com.salesmanager.core.modules.integration.payment.model.PaymentModule)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 PackageDetails (com.salesmanager.core.model.shipping.PackageDetails)6 MerchantConfiguration (com.salesmanager.core.model.system.MerchantConfiguration)6 IntegrationModuleConfiguration (com.salesmanager.shop.model.system.IntegrationModuleConfiguration)6 IntegrationModuleSummaryEntity (com.salesmanager.shop.model.system.IntegrationModuleSummaryEntity)6 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)6 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)6 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)6