Search in sources :

Example 1 with ReadableCountry

use of com.salesmanager.shop.model.references.ReadableCountry in project shopizer by shopizer-ecommerce.

the class ShippingFacadeImpl method shipToCountry.

@Override
public List<ReadableCountry> shipToCountry(MerchantStore store, Language language) {
    try {
        List<Country> countries = shippingService.getShipToCountryList(store, language);
        List<ReadableCountry> countryList = new ArrayList<ReadableCountry>();
        if (!CollectionUtils.isEmpty(countries)) {
            countryList = countries.stream().map(c -> {
                try {
                    return convert(c, store, language);
                } catch (ConversionException e) {
                    throw new ConversionRuntimeException("Error converting Country to readable country,e");
                }
            }).sorted(Comparator.comparing(ReadableCountry::getName)).collect(Collectors.toList());
        }
        return countryList;
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error getting shipping country", e);
    }
}
Also used : ExpeditionConfiguration(com.salesmanager.shop.model.shipping.ExpeditionConfiguration) ShippingOrigin(com.salesmanager.core.model.shipping.ShippingOrigin) ShippingType(com.salesmanager.core.model.shipping.ShippingType) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Zone(com.salesmanager.core.model.reference.zone.Zone) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ShippingOriginService(com.salesmanager.core.business.services.shipping.ShippingOriginService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ReadableCountryPopulator(com.salesmanager.shop.populator.references.ReadableCountryPopulator) ShippingService(com.salesmanager.core.business.services.shipping.ShippingService) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) Validate(org.jsoup.helper.Validate) Logger(org.slf4j.Logger) Country(com.salesmanager.core.model.reference.country.Country) Collectors(java.util.stream.Collectors) List(java.util.List) ShippingPackageType(com.salesmanager.core.model.shipping.ShippingPackageType) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) ReadableAddress(com.salesmanager.shop.model.references.ReadableAddress) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration) Comparator(java.util.Comparator) ConversionException(com.salesmanager.core.business.exception.ConversionException) ArrayList(java.util.ArrayList) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) Country(com.salesmanager.core.model.reference.country.Country) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with ReadableCountry

use of com.salesmanager.shop.model.references.ReadableCountry in project shopizer by shopizer-ecommerce.

the class ReadableCountryPopulator method populate.

@Override
public ReadableCountry populate(Country source, ReadableCountry target, MerchantStore store, Language language) throws ConversionException {
    if (target == null) {
        target = new ReadableCountry();
    }
    target.setId(new Long(source.getId()));
    target.setCode(source.getIsoCode());
    target.setSupported(source.getSupported());
    if (!CollectionUtils.isEmpty(source.getDescriptions())) {
        target.setName(source.getDescriptions().iterator().next().getName());
    }
    if (!CollectionUtils.isEmpty(source.getZones())) {
        for (Zone z : source.getZones()) {
            ReadableZone readableZone = new ReadableZone();
            readableZone.setCountryCode(target.getCode());
            readableZone.setId(z.getId());
            if (!CollectionUtils.isEmpty(z.getDescriptions())) {
                for (ZoneDescription d : z.getDescriptions()) {
                    if (d.getLanguage().getId() == language.getId()) {
                        readableZone.setName(d.getName());
                        continue;
                    }
                }
            }
            target.getZones().add(readableZone);
        }
    }
    return target;
}
Also used : Zone(com.salesmanager.core.model.reference.zone.Zone) ReadableZone(com.salesmanager.shop.model.references.ReadableZone) ReadableZone(com.salesmanager.shop.model.references.ReadableZone) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) ZoneDescription(com.salesmanager.core.model.reference.zone.ZoneDescription)

Aggregations

Zone (com.salesmanager.core.model.reference.zone.Zone)2 ReadableCountry (com.salesmanager.shop.model.references.ReadableCountry)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 CountryService (com.salesmanager.core.business.services.reference.country.CountryService)1 ZoneService (com.salesmanager.core.business.services.reference.zone.ZoneService)1 ShippingOriginService (com.salesmanager.core.business.services.shipping.ShippingOriginService)1 ShippingService (com.salesmanager.core.business.services.shipping.ShippingService)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Country (com.salesmanager.core.model.reference.country.Country)1 Language (com.salesmanager.core.model.reference.language.Language)1 ZoneDescription (com.salesmanager.core.model.reference.zone.ZoneDescription)1 PackageDetails (com.salesmanager.core.model.shipping.PackageDetails)1 ShippingConfiguration (com.salesmanager.core.model.shipping.ShippingConfiguration)1 ShippingOrigin (com.salesmanager.core.model.shipping.ShippingOrigin)1 ShippingPackageType (com.salesmanager.core.model.shipping.ShippingPackageType)1 ShippingType (com.salesmanager.core.model.shipping.ShippingType)1 PersistableAddress (com.salesmanager.shop.model.references.PersistableAddress)1 ReadableAddress (com.salesmanager.shop.model.references.ReadableAddress)1 ReadableZone (com.salesmanager.shop.model.references.ReadableZone)1