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