Search in sources :

Example 21 with Country

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

the class ZonesLoader method loadZones.

public Map<String, Zone> loadZones(String jsonFilePath) throws Exception {
    List<Language> languages = languageService.list();
    List<Country> countries = countryService.list();
    Map<String, Country> countriesMap = new HashMap<String, Country>();
    for (Country country : countries) {
        countriesMap.put(country.getIsoCode(), country);
    }
    ObjectMapper mapper = new ObjectMapper();
    try {
        InputStream in = this.getClass().getClassLoader().getResourceAsStream(jsonFilePath);
        @SuppressWarnings("unchecked") Map<String, Object> data = mapper.readValue(in, Map.class);
        Map<String, Zone> zonesMap = new HashMap<String, Zone>();
        Map<String, List<ZoneDescription>> zonesDescriptionsMap = new HashMap<String, List<ZoneDescription>>();
        Map<String, String> zonesMark = new HashMap<String, String>();
        for (Language l : languages) {
            @SuppressWarnings("rawtypes") List langList = (List) data.get(l.getCode());
            if (langList != null) {
                /**
                 * submethod
                 */
                for (Object z : langList) {
                    @SuppressWarnings("unchecked") Map<String, String> e = (Map<String, String>) z;
                    this.mapZone(l, zonesDescriptionsMap, countriesMap, zonesMap, zonesMark, e);
                /**
                 * String zoneCode = e.get("zoneCode"); ZoneDescription
                 * zoneDescription = new ZoneDescription();
                 * zoneDescription.setLanguage(l);
                 * zoneDescription.setName(e.get("zoneName")); Zone zone
                 * = null; List<ZoneDescription> descriptions = null; if
                 * (!zonesMap.containsKey(zoneCode)) { zone = new
                 * Zone(); Country country =
                 * countriesMap.get(e.get("countryCode")); if (country
                 * == null) { LOGGER.warn("Country is null for " +
                 * zoneCode + " and country code " +
                 * e.get("countryCode")); continue; }
                 * zone.setCountry(country); zonesMap.put(zoneCode,
                 * zone); zone.setCode(zoneCode);
                 *
                 * }
                 *
                 * if (zonesMark.containsKey(l.getCode() + "_" +
                 * zoneCode)) { LOGGER.warn("This zone seems to be a
                 * duplicate ! " + zoneCode + " and language code " +
                 * l.getCode()); continue; }
                 *
                 * zonesMark.put(l.getCode() + "_" + zoneCode,
                 * l.getCode() + "_" + zoneCode);
                 *
                 * if (zonesDescriptionsMap.containsKey(zoneCode)) {
                 * descriptions = zonesDescriptionsMap.get(zoneCode); }
                 * else { descriptions = new
                 * ArrayList<ZoneDescription>();
                 * zonesDescriptionsMap.put(zoneCode, descriptions); }
                 *
                 * descriptions.add(zoneDescription);
                 */
                }
            }
        }
        for (Map.Entry<String, Zone> entry : zonesMap.entrySet()) {
            String key = entry.getKey();
            Zone value = entry.getValue();
            // get descriptions
            List<ZoneDescription> descriptions = zonesDescriptionsMap.get(key);
            if (descriptions != null) {
                value.setDescriptons(descriptions);
            }
        }
        return zonesMap;
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InputStream(java.io.InputStream) Zone(com.salesmanager.core.model.reference.zone.Zone) IOException(java.io.IOException) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) ServiceException(com.salesmanager.core.business.exception.ServiceException) Country(com.salesmanager.core.model.reference.country.Country) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ZoneDescription(com.salesmanager.core.model.reference.zone.ZoneDescription)

Example 22 with Country

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

the class ZonesLoader method loadIndividualZones.

// 
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Map<String, Zone>> loadIndividualZones() throws Exception {
    List<Map<String, Zone>> loadedZones = new ArrayList<Map<String, Zone>>();
    try {
        List<Resource> files = geZoneFiles(PATH);
        List<Language> languages = languageService.list();
        ObjectMapper mapper = new ObjectMapper();
        List<Country> countries = countryService.list();
        Map<String, Country> countriesMap = new HashMap<String, Country>();
        for (Country country : countries) {
            countriesMap.put(country.getIsoCode(), country);
        }
        Map<String, Zone> zonesMap = new LinkedHashMap<String, Zone>();
        Map<String, List<ZoneDescription>> zonesDescriptionsMap = new LinkedHashMap<String, List<ZoneDescription>>();
        Map<String, String> zonesMark = new LinkedHashMap<String, String>();
        // load files individually
        for (Resource resource : files) {
            InputStream in = resource.getInputStream();
            if (in == null) {
                continue;
            }
            Map<String, Object> data = mapper.readValue(in, Map.class);
            if (resource.getFilename().contains("_")) {
                for (Language l : languages) {
                    if (resource.getFilename().contains("_" + l.getCode())) {
                        // lead for this
                        // language
                        List langList = (List) data.get(l.getCode());
                        if (langList != null) {
                            /**
                             * submethod
                             */
                            for (Object z : langList) {
                                Map<String, String> e = (Map<String, String>) z;
                                mapZone(l, zonesDescriptionsMap, countriesMap, zonesMap, zonesMark, e);
                            }
                        }
                    }
                }
            } else {
                List langList = (List) data.get(ALL_REGIONS);
                if (langList != null) {
                    /**
                     * submethod
                     */
                    for (Language l : languages) {
                        for (Object z : langList) {
                            Map<String, String> e = (Map<String, String>) z;
                            mapZone(l, zonesDescriptionsMap, countriesMap, zonesMap, zonesMark, e);
                        }
                    }
                }
            }
            for (Map.Entry<String, Zone> entry : zonesMap.entrySet()) {
                String key = entry.getKey();
                Zone value = entry.getValue();
                // get descriptions
                List<ZoneDescription> descriptions = zonesDescriptionsMap.get(key);
                if (descriptions != null) {
                    value.setDescriptons(descriptions);
                }
            }
            loadedZones.add(zonesMap);
        }
        return loadedZones;
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Language(com.salesmanager.core.model.reference.language.Language) ArrayList(java.util.ArrayList) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ZoneDescription(com.salesmanager.core.model.reference.zone.ZoneDescription) Zone(com.salesmanager.core.model.reference.zone.Zone) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceException(com.salesmanager.core.business.exception.ServiceException) Country(com.salesmanager.core.model.reference.country.Country) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 23 with Country

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

the class CountryServiceImpl method getCountries.

@SuppressWarnings("unchecked")
@Override
public List<Country> getCountries(Language language) throws ServiceException {
    List<Country> countries = null;
    try {
        countries = (List<Country>) cache.getFromCache("COUNTRIES_" + language.getCode());
        if (countries == null) {
            countries = countryRepository.listByLanguage(language.getId());
            // set names
            for (Country country : countries) {
                CountryDescription description = country.getDescriptions().iterator().next();
                country.setName(description.getName());
            }
            cache.putInCache(countries, "COUNTRIES_" + language.getCode());
        }
    } catch (Exception e) {
        LOGGER.error("getCountries()", e);
    }
    return countries;
}
Also used : CountryDescription(com.salesmanager.core.model.reference.country.CountryDescription) Country(com.salesmanager.core.model.reference.country.Country) ServiceException(com.salesmanager.core.business.exception.ServiceException)

Example 24 with Country

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

the class CountryServiceImpl method getCountries.

@Override
public List<Country> getCountries(final List<String> isoCodes, final Language language) throws ServiceException {
    List<Country> countryList = getCountries(language);
    List<Country> requestedCountryList = new ArrayList<Country>();
    if (!CollectionUtils.isEmpty(countryList)) {
        for (Country c : countryList) {
            if (isoCodes.contains(c.getIsoCode())) {
                requestedCountryList.add(c);
            }
        }
    }
    return requestedCountryList;
}
Also used : ArrayList(java.util.ArrayList) Country(com.salesmanager.core.model.reference.country.Country)

Example 25 with Country

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

the class ReferenceController method getProvinces.

@SuppressWarnings("unchecked")
@RequestMapping(value = { "/admin/reference/provinces.html", "/shop/reference/provinces.html" }, method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<String> getProvinces(HttpServletRequest request, HttpServletResponse response) {
    String countryCode = request.getParameter("countryCode");
    String lang = request.getParameter("lang");
    LOGGER.debug("Province Country Code " + countryCode);
    AjaxResponse resp = new AjaxResponse();
    try {
        Language language = null;
        if (!StringUtils.isBlank(lang)) {
            language = languageService.getByCode(lang);
        }
        if (language == null) {
            language = (Language) request.getAttribute("LANGUAGE");
        }
        if (language == null) {
            language = languageService.getByCode(Constants.DEFAULT_LANGUAGE);
        }
        Map<String, Country> countriesMap = countryService.getCountriesMap(language);
        Country country = countriesMap.get(countryCode);
        List<Zone> zones = zoneService.getZones(country, language);
        if (zones != null && zones.size() > 0) {
            for (Zone zone : zones) {
                @SuppressWarnings("rawtypes") Map entry = new HashMap();
                entry.put("name", zone.getName());
                entry.put("code", zone.getCode());
                entry.put("id", zone.getId());
                resp.addDataEntry(entry);
            }
        }
        resp.setStatus(AjaxResponse.RESPONSE_STATUS_SUCCESS);
    } catch (Exception e) {
        LOGGER.error("GetProvinces()", e);
        resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
    }
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
    String returnString = resp.toJSONString();
    return new ResponseEntity<String>(returnString, httpHeaders, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Zone(com.salesmanager.core.model.reference.zone.Zone) AjaxResponse(com.salesmanager.core.business.utils.ajax.AjaxResponse) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResponseEntity(org.springframework.http.ResponseEntity) Language(com.salesmanager.core.model.reference.language.Language) Country(com.salesmanager.core.model.reference.country.Country) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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