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