Search in sources :

Example 11 with Country

use of com.salesmanager.core.model.reference.country.Country in project shopizer by shopizer-ecommerce.

the class PersistableOrderPopulator method populate.

@Override
public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(productService, "productService must be set");
    Validate.notNull(digitalProductService, "digitalProductService must be set");
    Validate.notNull(productAttributeService, "productAttributeService must be set");
    Validate.notNull(customerService, "customerService must be set");
    Validate.notNull(countryService, "countryService must be set");
    Validate.notNull(zoneService, "zoneService must be set");
    Validate.notNull(currencyService, "currencyService must be set");
    try {
        Map<String, Country> countriesMap = countryService.getCountriesMap(language);
        Map<String, Zone> zonesMap = zoneService.getZones(language);
        /**
         * customer *
         */
        PersistableCustomer customer = source.getCustomer();
        if (customer != null) {
            if (customer.getId() != null && customer.getId() > 0) {
                Customer modelCustomer = customerService.getById(customer.getId());
                if (modelCustomer == null) {
                    throw new ConversionException("Customer id " + customer.getId() + " does not exists");
                }
                if (modelCustomer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Customer id " + customer.getId() + " does not exists for store " + store.getCode());
                }
                target.setCustomerId(modelCustomer.getId());
                target.setBilling(modelCustomer.getBilling());
                target.setDelivery(modelCustomer.getDelivery());
                target.setCustomerEmailAddress(source.getCustomer().getEmailAddress());
            }
        }
        target.setLocale(LocaleUtils.getLocale(store));
        CreditCard creditCard = source.getCreditCard();
        if (creditCard != null) {
            String maskedNumber = CreditCardUtils.maskCardNumber(creditCard.getCcNumber());
            creditCard.setCcNumber(maskedNumber);
            target.setCreditCard(creditCard);
        }
        Currency currency = null;
        try {
            currency = currencyService.getByCode(source.getCurrency());
        } catch (Exception e) {
            throw new ConversionException("Currency not found for code " + source.getCurrency());
        }
        if (currency == null) {
            throw new ConversionException("Currency not found for code " + source.getCurrency());
        }
        target.setCurrency(currency);
        target.setDatePurchased(source.getDatePurchased());
        // target.setCurrency(store.getCurrency());
        target.setCurrencyValue(new BigDecimal(0));
        target.setMerchant(store);
        target.setStatus(source.getOrderStatus());
        target.setPaymentModuleCode(source.getPaymentModule());
        target.setPaymentType(source.getPaymentType());
        target.setShippingModuleCode(source.getShippingModule());
        target.setCustomerAgreement(source.isCustomerAgreed());
        target.setConfirmedAddress(source.isConfirmedAddress());
        if (source.getPreviousOrderStatus() != null) {
            List<OrderStatus> orderStatusList = source.getPreviousOrderStatus();
            for (OrderStatus status : orderStatusList) {
                OrderStatusHistory statusHistory = new OrderStatusHistory();
                statusHistory.setStatus(status);
                statusHistory.setOrder(target);
                target.getOrderHistory().add(statusHistory);
            }
        }
        if (!StringUtils.isBlank(source.getComments())) {
            OrderStatusHistory statusHistory = new OrderStatusHistory();
            statusHistory.setStatus(null);
            statusHistory.setOrder(target);
            statusHistory.setComments(source.getComments());
            target.getOrderHistory().add(statusHistory);
        }
        List<PersistableOrderProduct> products = source.getOrderProductItems();
        if (CollectionUtils.isEmpty(products)) {
            throw new ConversionException("Requires at least 1 PersistableOrderProduct");
        }
        com.salesmanager.shop.populator.order.PersistableOrderProductPopulator orderProductPopulator = new PersistableOrderProductPopulator();
        orderProductPopulator.setProductAttributeService(productAttributeService);
        orderProductPopulator.setProductService(productService);
        orderProductPopulator.setDigitalProductService(digitalProductService);
        for (PersistableOrderProduct orderProduct : products) {
            OrderProduct modelOrderProduct = new OrderProduct();
            orderProductPopulator.populate(orderProduct, modelOrderProduct, store, language);
            target.getOrderProducts().add(modelOrderProduct);
        }
        List<OrderTotal> orderTotals = source.getTotals();
        if (CollectionUtils.isNotEmpty(orderTotals)) {
            for (OrderTotal total : orderTotals) {
                com.salesmanager.core.model.order.OrderTotal totalModel = new com.salesmanager.core.model.order.OrderTotal();
                totalModel.setModule(total.getModule());
                totalModel.setOrder(target);
                totalModel.setOrderTotalCode(total.getCode());
                totalModel.setTitle(total.getTitle());
                totalModel.setValue(total.getValue());
                target.getOrderTotal().add(totalModel);
            }
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) OrderStatus(com.salesmanager.core.model.order.orderstatus.OrderStatus) Currency(com.salesmanager.core.model.reference.currency.Currency) ConversionException(com.salesmanager.core.business.exception.ConversionException) Zone(com.salesmanager.core.model.reference.zone.Zone) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) ConversionException(com.salesmanager.core.business.exception.ConversionException) BigDecimal(java.math.BigDecimal) Country(com.salesmanager.core.model.reference.country.Country) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) OrderTotal(com.salesmanager.shop.model.order.total.OrderTotal)

Example 12 with Country

use of com.salesmanager.core.model.reference.country.Country in project shopizer by shopizer-ecommerce.

the class CustomerPopulator method populate.

/**
 * Creates a Customer entity ready to be saved
 */
@Override
public Customer populate(PersistableCustomer source, Customer target, MerchantStore store, Language language) throws ConversionException {
    try {
        if (source.getId() != null && source.getId() > 0) {
            target.setId(source.getId());
        }
        if (!StringUtils.isBlank(source.getPassword())) {
            target.setPassword(passwordEncoder.encode(source.getPassword()));
            target.setNick(source.getUserName());
            target.setAnonymous(false);
        }
        if (source.getBilling() != null) {
            target.setBilling(new Billing());
            if (!StringUtils.isEmpty(source.getFirstName())) {
                target.getBilling().setFirstName(source.getFirstName());
            }
            if (!StringUtils.isEmpty(source.getLastName())) {
                target.getBilling().setLastName(source.getLastName());
            }
        }
        if (!StringUtils.isBlank(source.getProvider())) {
            target.setProvider(source.getProvider());
        }
        if (!StringUtils.isBlank(source.getEmailAddress())) {
            target.setEmailAddress(source.getEmailAddress());
        }
        if (source.getGender() != null && target.getGender() == null) {
            target.setGender(com.salesmanager.core.model.customer.CustomerGender.valueOf(source.getGender()));
        }
        if (target.getGender() == null) {
            target.setGender(com.salesmanager.core.model.customer.CustomerGender.M);
        }
        Map<String, Country> countries = countryService.getCountriesMap(language);
        Map<String, Zone> zones = zoneService.getZones(language);
        target.setMerchantStore(store);
        Address sourceBilling = source.getBilling();
        if (sourceBilling != null) {
            Billing billing = target.getBilling();
            billing.setAddress(sourceBilling.getAddress());
            billing.setCity(sourceBilling.getCity());
            billing.setCompany(sourceBilling.getCompany());
            // billing.setCountry(country);
            if (!StringUtils.isEmpty(sourceBilling.getFirstName()))
                billing.setFirstName(sourceBilling.getFirstName());
            if (!StringUtils.isEmpty(sourceBilling.getLastName()))
                billing.setLastName(sourceBilling.getLastName());
            billing.setTelephone(sourceBilling.getPhone());
            billing.setPostalCode(sourceBilling.getPostalCode());
            billing.setState(sourceBilling.getStateProvince());
            Country billingCountry = null;
            if (!StringUtils.isBlank(sourceBilling.getCountry())) {
                billingCountry = countries.get(sourceBilling.getCountry());
                if (billingCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceBilling.getCountry());
                }
                billing.setCountry(billingCountry);
            }
            if (billingCountry != null && !StringUtils.isBlank(sourceBilling.getZone())) {
                Zone zone = zoneService.getByCode(sourceBilling.getZone());
                if (zone == null) {
                    throw new ConversionException("Unsuported zone code " + sourceBilling.getZone());
                }
                Zone zoneDescription = zones.get(zone.getCode());
                billing.setZone(zoneDescription);
            }
        // target.setBilling(billing);
        }
        if (target.getBilling() == null && source.getBilling() != null) {
            LOG.info("Setting default values for billing");
            Billing billing = new Billing();
            Country billingCountry = null;
            if (StringUtils.isNotBlank(source.getBilling().getCountry())) {
                billingCountry = countries.get(source.getBilling().getCountry());
                if (billingCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceBilling.getCountry());
                }
                billing.setCountry(billingCountry);
                target.setBilling(billing);
            }
        }
        Address sourceShipping = source.getDelivery();
        if (sourceShipping != null) {
            Delivery delivery = new Delivery();
            delivery.setAddress(sourceShipping.getAddress());
            delivery.setCity(sourceShipping.getCity());
            delivery.setCompany(sourceShipping.getCompany());
            delivery.setFirstName(sourceShipping.getFirstName());
            delivery.setLastName(sourceShipping.getLastName());
            delivery.setTelephone(sourceShipping.getPhone());
            delivery.setPostalCode(sourceShipping.getPostalCode());
            delivery.setState(sourceShipping.getStateProvince());
            Country deliveryCountry = null;
            if (!StringUtils.isBlank(sourceShipping.getCountry())) {
                deliveryCountry = countries.get(sourceShipping.getCountry());
                if (deliveryCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceShipping.getCountry());
                }
                delivery.setCountry(deliveryCountry);
            }
            if (deliveryCountry != null && !StringUtils.isBlank(sourceShipping.getZone())) {
                Zone zone = zoneService.getByCode(sourceShipping.getZone());
                if (zone == null) {
                    throw new ConversionException("Unsuported zone code " + sourceShipping.getZone());
                }
                Zone zoneDescription = zones.get(zone.getCode());
                delivery.setZone(zoneDescription);
            }
            target.setDelivery(delivery);
        }
        if (source.getRating() != null && source.getRating().doubleValue() > 0) {
            target.setCustomerReviewAvg(new BigDecimal(source.getRating().doubleValue()));
        }
        if (source.getRatingCount() > 0) {
            target.setCustomerReviewCount(source.getRatingCount());
        }
        if (target.getDelivery() == null && source.getDelivery() != null) {
            LOG.info("Setting default value for delivery");
            Delivery delivery = new Delivery();
            Country deliveryCountry = null;
            if (StringUtils.isNotBlank(source.getDelivery().getCountry())) {
                deliveryCountry = countries.get(source.getDelivery().getCountry());
                if (deliveryCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceShipping.getCountry());
                }
                delivery.setCountry(deliveryCountry);
                target.setDelivery(delivery);
            }
        }
        if (source.getAttributes() != null) {
            for (PersistableCustomerAttribute attr : source.getAttributes()) {
                CustomerOption customerOption = customerOptionService.getById(attr.getCustomerOption().getId());
                if (customerOption == null) {
                    throw new ConversionException("Customer option id " + attr.getCustomerOption().getId() + " does not exist");
                }
                CustomerOptionValue customerOptionValue = customerOptionValueService.getById(attr.getCustomerOptionValue().getId());
                if (customerOptionValue == null) {
                    throw new ConversionException("Customer option value id " + attr.getCustomerOptionValue().getId() + " does not exist");
                }
                if (customerOption.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Invalid customer option id ");
                }
                if (customerOptionValue.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Invalid customer option value id ");
                }
                CustomerAttribute attribute = new CustomerAttribute();
                attribute.setCustomer(target);
                attribute.setCustomerOption(customerOption);
                attribute.setCustomerOptionValue(customerOptionValue);
                attribute.setTextValue(attr.getTextValue());
                target.getAttributes().add(attribute);
            }
        }
        if (target.getDefaultLanguage() == null) {
            Language lang = source.getLanguage() == null ? language : languageService.getByCode(source.getLanguage());
            target.setDefaultLanguage(lang);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Address(com.salesmanager.shop.model.customer.address.Address) Zone(com.salesmanager.core.model.reference.zone.Zone) BigDecimal(java.math.BigDecimal) ConversionException(com.salesmanager.core.business.exception.ConversionException) CustomerOption(com.salesmanager.core.model.customer.attribute.CustomerOption) CustomerOptionValue(com.salesmanager.core.model.customer.attribute.CustomerOptionValue) Language(com.salesmanager.core.model.reference.language.Language) PersistableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.PersistableCustomerAttribute) CustomerAttribute(com.salesmanager.core.model.customer.attribute.CustomerAttribute) Billing(com.salesmanager.core.model.common.Billing) Country(com.salesmanager.core.model.reference.country.Country) Delivery(com.salesmanager.core.model.common.Delivery) PersistableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.PersistableCustomerAttribute)

Example 13 with Country

use of com.salesmanager.core.model.reference.country.Country in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method updateAddress.

@Override
public void updateAddress(Long userId, MerchantStore merchantStore, Address address, final Language language) throws Exception {
    Customer customerModel = customerService.getById(userId);
    Map<String, Country> countriesMap = countryService.getCountriesMap(language);
    Country country = countriesMap.get(address.getCountry());
    if (customerModel == null) {
        LOG.error("Customer with ID {} does not exists..", userId);
        // throw new CustomerNotFoundException( "customer with given id does not exists" );
        throw new Exception("customer with given id does not exists");
    }
    if (address.isBillingAddress()) {
        LOG.info("updating customer billing address..");
        PersistableCustomerBillingAddressPopulator billingAddressPopulator = new PersistableCustomerBillingAddressPopulator();
        customerModel = billingAddressPopulator.populate(address, customerModel, merchantStore, merchantStore.getDefaultLanguage());
        customerModel.getBilling().setCountry(country);
        if (StringUtils.isNotBlank(address.getZone())) {
            Zone zone = zoneService.getByCode(address.getZone());
            if (zone == null) {
                throw new ConversionException("Unsuported zone code " + address.getZone());
            }
            customerModel.getBilling().setZone(zone);
            customerModel.getBilling().setState(null);
        } else {
            customerModel.getBilling().setZone(null);
        }
    } else {
        LOG.info("updating customer shipping address..");
        PersistableCustomerShippingAddressPopulator shippingAddressPopulator = new PersistableCustomerShippingAddressPopulator();
        customerModel = shippingAddressPopulator.populate(address, customerModel, merchantStore, merchantStore.getDefaultLanguage());
        customerModel.getDelivery().setCountry(country);
        if (StringUtils.isNotBlank(address.getZone())) {
            Zone zone = zoneService.getByCode(address.getZone());
            if (zone == null) {
                throw new ConversionException("Unsuported zone code " + address.getZone());
            }
            customerModel.getDelivery().setZone(zone);
            customerModel.getDelivery().setState(null);
        } else {
            customerModel.getDelivery().setZone(null);
        }
    }
    // same update address with customer model
    this.customerService.saveOrUpdate(customerModel);
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) Zone(com.salesmanager.core.model.reference.zone.Zone) Country(com.salesmanager.core.model.reference.country.Country) PersistableCustomerBillingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerBillingAddressPopulator) ServiceException(com.salesmanager.core.business.exception.ServiceException) UserAlreadyExistException(com.salesmanager.shop.model.customer.UserAlreadyExistException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistableCustomerShippingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerShippingAddressPopulator)

Example 14 with Country

use of com.salesmanager.core.model.reference.country.Country 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;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) Zone(com.salesmanager.core.model.reference.zone.Zone) Currency(com.salesmanager.core.model.reference.currency.Currency) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) Country(com.salesmanager.core.model.reference.country.Country) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) Date(java.util.Date) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 15 with Country

use of com.salesmanager.core.model.reference.country.Country in project shopizer by shopizer-ecommerce.

the class ReadableMerchantStorePopulator method populate.

@Override
public ReadableMerchantStore populate(MerchantStore source, ReadableMerchantStore target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(countryService, "Must use setter for countryService");
    Validate.notNull(zoneService, "Must use setter for zoneService");
    if (target == null) {
        target = new ReadableMerchantStore();
    }
    target.setId(source.getId());
    target.setCode(source.getCode());
    if (source.getDefaultLanguage() != null) {
        target.setDefaultLanguage(source.getDefaultLanguage().getCode());
    }
    target.setCurrency(source.getCurrency().getCode());
    target.setPhone(source.getStorephone());
    ReadableAddress address = new ReadableAddress();
    address.setAddress(source.getStoreaddress());
    address.setCity(source.getStorecity());
    if (source.getCountry() != null) {
        try {
            address.setCountry(source.getCountry().getIsoCode());
            Country c = countryService.getCountriesMap(language).get(source.getCountry().getIsoCode());
            if (c != null) {
                address.setCountry(c.getIsoCode());
            }
        } catch (ServiceException e) {
            logger.error("Cannot get Country", e);
        }
    }
    if (source.getParent() != null) {
        ReadableMerchantStore parent = populate(source.getParent(), new ReadableMerchantStore(), source, language);
        target.setParent(parent);
    }
    if (target.getParent() == null) {
        target.setRetailer(true);
    } else {
        target.setRetailer(source.isRetailer() != null ? source.isRetailer().booleanValue() : false);
    }
    target.setDimension(MeasureUnit.valueOf(source.getSeizeunitcode()));
    target.setWeight(WeightUnit.valueOf(source.getWeightunitcode()));
    if (source.getZone() != null) {
        address.setStateProvince(source.getZone().getCode());
        try {
            Zone z = zoneService.getZones(language).get(source.getZone().getCode());
            address.setStateProvince(z.getCode());
        } catch (ServiceException e) {
            logger.error("Cannot get Zone", e);
        }
    }
    if (!StringUtils.isBlank(source.getStorestateprovince())) {
        address.setStateProvince(source.getStorestateprovince());
    }
    if (!StringUtils.isBlank(source.getStoreLogo())) {
        ReadableImage image = new ReadableImage();
        image.setName(source.getStoreLogo());
        if (filePath != null) {
            image.setPath(filePath.buildStoreLogoFilePath(source));
        }
        target.setLogo(image);
    }
    address.setPostalCode(source.getStorepostalcode());
    target.setAddress(address);
    target.setCurrencyFormatNational(source.isCurrencyFormatNational());
    target.setEmail(source.getStoreEmailAddress());
    target.setName(source.getStorename());
    target.setId(source.getId());
    target.setInBusinessSince(DateUtil.formatDate(source.getInBusinessSince()));
    target.setUseCache(source.isUseCache());
    if (!CollectionUtils.isEmpty(source.getLanguages())) {
        List<ReadableLanguage> supported = new ArrayList<ReadableLanguage>();
        for (Language lang : source.getLanguages()) {
            try {
                Language langObject = languageService.getLanguagesMap().get(lang.getCode());
                if (langObject != null) {
                    ReadableLanguage l = new ReadableLanguage();
                    l.setId(langObject.getId());
                    l.setCode(langObject.getCode());
                    supported.add(l);
                }
            } catch (ServiceException e) {
                logger.error("Cannot get Language [" + lang.getId() + "]");
            }
        }
        target.setSupportedLanguages(supported);
    }
    if (source.getAuditSection() != null) {
        ReadableAudit audit = new ReadableAudit();
        if (source.getAuditSection().getDateCreated() != null) {
            audit.setCreated(DateUtil.formatDate(source.getAuditSection().getDateCreated()));
        }
        if (source.getAuditSection().getDateModified() != null) {
            audit.setModified(DateUtil.formatDate(source.getAuditSection().getDateCreated()));
        }
        audit.setUser(source.getAuditSection().getModifiedBy());
        target.setReadableAudit(audit);
    }
    return target;
}
Also used : ReadableImage(com.salesmanager.shop.model.content.ReadableImage) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableLanguage(com.salesmanager.shop.model.references.ReadableLanguage) Language(com.salesmanager.core.model.reference.language.Language) Zone(com.salesmanager.core.model.reference.zone.Zone) ReadableAudit(com.salesmanager.shop.model.entity.ReadableAudit) ArrayList(java.util.ArrayList) ReadableAddress(com.salesmanager.shop.model.references.ReadableAddress) Country(com.salesmanager.core.model.reference.country.Country) ReadableLanguage(com.salesmanager.shop.model.references.ReadableLanguage)

Aggregations

Country (com.salesmanager.core.model.reference.country.Country)33 Zone (com.salesmanager.core.model.reference.zone.Zone)21 Language (com.salesmanager.core.model.reference.language.Language)18 ArrayList (java.util.ArrayList)15 ServiceException (com.salesmanager.core.business.exception.ServiceException)14 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)11 Delivery (com.salesmanager.core.model.common.Delivery)10 ShippingQuote (com.salesmanager.core.model.shipping.ShippingQuote)9 BigDecimal (java.math.BigDecimal)8 List (java.util.List)7 ConversionException (com.salesmanager.core.business.exception.ConversionException)6 Billing (com.salesmanager.core.model.common.Billing)6 Customer (com.salesmanager.core.model.customer.Customer)6 ShippingOption (com.salesmanager.core.model.shipping.ShippingOption)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 PackageDetails (com.salesmanager.core.model.shipping.PackageDetails)5 ShippingConfiguration (com.salesmanager.core.model.shipping.ShippingConfiguration)5 ShippingOrigin (com.salesmanager.core.model.shipping.ShippingOrigin)5 IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)5 Date (java.util.Date)5