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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations