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