use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method updateAuthCustomer.
private PersistableCustomer updateAuthCustomer(PersistableCustomer customer, MerchantStore store) {
if (customer.getId() == null || customer.getId() == 0) {
throw new ServiceRuntimeException("Can't update a customer with null id");
}
Customer cust = customerService.getById(customer.getId());
try {
customerPopulator.populate(customer, cust, store, store.getDefaultLanguage());
} catch (ConversionException e) {
throw new ConversionRuntimeException(e);
}
saveCustomer(cust);
customer.setId(cust.getId());
return customer;
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method populateOrderList.
private com.salesmanager.shop.model.order.v0.ReadableOrderList populateOrderList(final OrderList orderList, final MerchantStore store, final Language language) {
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)) {
LOGGER.info("Order list if empty..Returning empty list");
returnList.setRecordsTotal(0);
// returnList.setMessage("No results for store code " + store);
return returnList;
}
// ReadableOrderPopulator orderPopulator = new ReadableOrderPopulator();
Locale locale = LocaleUtils.getLocale(language);
readableOrderPopulator.setLocale(locale);
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();
try {
readableOrderPopulator.populate(order, readableOrder, store, language);
setOrderProductList(order, locale, store, language, readableOrder);
} catch (ConversionException ex) {
LOGGER.error("Error while converting order to order data", ex);
}
readableOrders.add(readableOrder);
}
returnList.setOrders(readableOrders);
return returnList;
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class SearchFacadeImpl method convertCategoryToReadableCategory.
private ReadableCategory convertCategoryToReadableCategory(MerchantStore merchantStore, Language language, Map<String, Long> productCategoryCount, Category category) {
ReadableCategoryPopulator populator = new ReadableCategoryPopulator();
try {
ReadableCategory categoryProxy = populator.populate(category, new ReadableCategory(), merchantStore, language);
Long total = productCategoryCount.get(categoryProxy.getCode());
if (total != null) {
categoryProxy.setProductCount(total.intValue());
}
return categoryProxy;
} catch (ConversionException e) {
throw new ConversionRuntimeException(e);
}
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class ReadableTransactionPopulator method populate.
@Override
public ReadableTransaction populate(Transaction source, ReadableTransaction target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(source, "PersistableTransaction must not be null");
Validate.notNull(orderService, "OrderService must not be null");
Validate.notNull(pricingService, "OrderService must not be null");
if (target == null) {
target = new ReadableTransaction();
}
try {
target.setAmount(pricingService.getDisplayAmount(source.getAmount(), store));
target.setDetails(source.getDetails());
target.setPaymentType(source.getPaymentType());
target.setTransactionType(source.getTransactionType());
target.setTransactionDate(DateUtil.formatDate(source.getTransactionDate()));
target.setId(source.getId());
if (source.getOrder() != null) {
target.setOrderId(source.getOrder().getId());
}
return target;
} catch (Exception e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class PersistableMerchantStorePopulator method populate.
@Override
public MerchantStore populate(PersistableMerchantStore source, MerchantStore target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(source, "PersistableMerchantStore mst not be null");
if (target == null) {
target = new MerchantStore();
}
target.setCode(source.getCode());
if (source.getId() != 0) {
target.setId(source.getId());
}
if (store.getStoreLogo() != null) {
target.setStoreLogo(store.getStoreLogo());
}
if (!StringUtils.isEmpty(source.getInBusinessSince())) {
try {
Date dt = DateUtil.getDate(source.getInBusinessSince());
target.setInBusinessSince(dt);
} catch (Exception e) {
throw new ConversionException("Cannot parse date [" + source.getInBusinessSince() + "]", e);
}
}
if (source.getDimension() != null) {
target.setSeizeunitcode(source.getDimension().name());
}
if (source.getWeight() != null) {
target.setWeightunitcode(source.getWeight().name());
}
target.setCurrencyFormatNational(source.isCurrencyFormatNational());
target.setStorename(source.getName());
target.setStorephone(source.getPhone());
target.setStoreEmailAddress(source.getEmail());
target.setUseCache(source.isUseCache());
target.setRetailer(source.isRetailer());
// get parent store
if (!StringUtils.isBlank(source.getRetailerStore())) {
if (source.getRetailerStore().equals(source.getCode())) {
throw new ConversionException("Parent store [" + source.getRetailerStore() + "] cannot be parent of current store");
}
try {
MerchantStore parent = merchantStoreService.getByCode(source.getRetailerStore());
if (parent == null) {
throw new ConversionException("Parent store [" + source.getRetailerStore() + "] does not exist");
}
target.setParent(parent);
} catch (ServiceException e) {
throw new ConversionException(e);
}
}
try {
if (!StringUtils.isEmpty(source.getDefaultLanguage())) {
Language l = languageService.getByCode(source.getDefaultLanguage());
target.setDefaultLanguage(l);
}
if (!StringUtils.isEmpty(source.getCurrency())) {
Currency c = currencyService.getByCode(source.getCurrency());
target.setCurrency(c);
} else {
target.setCurrency(currencyService.getByCode(Constants.DEFAULT_CURRENCY.getCurrencyCode()));
}
List<String> languages = source.getSupportedLanguages();
if (!CollectionUtils.isEmpty(languages)) {
for (String lang : languages) {
Language ll = languageService.getByCode(lang);
target.getLanguages().add(ll);
}
}
} catch (Exception e) {
throw new ConversionException(e);
}
// address population
PersistableAddress address = source.getAddress();
if (address != null) {
Country country;
try {
country = countryService.getByCode(address.getCountry());
Zone zone = zoneService.getByCode(address.getStateProvince());
if (zone != null) {
target.setZone(zone);
} else {
target.setStorestateprovince(address.getStateProvince());
}
target.setStoreaddress(address.getAddress());
target.setStorecity(address.getCity());
target.setCountry(country);
target.setStorepostalcode(address.getPostalCode());
} catch (ServiceException e) {
throw new ConversionException(e);
}
}
if (StringUtils.isNotEmpty(source.getTemplate()))
target.setStoreTemplate(source.getTemplate());
return target;
}
Aggregations