use of com.salesmanager.core.model.reference.zone.ZoneDescription 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.zone.ZoneDescription in project shopizer by shopizer-ecommerce.
the class ZoneServiceImpl method getZones.
@Override
@SuppressWarnings("unchecked")
public Map<String, Zone> getZones(Language language) throws ServiceException {
Map<String, Zone> zones = null;
try {
String cacheKey = ZONE_CACHE_PREFIX + language.getCode();
zones = (Map<String, Zone>) cache.getFromCache(cacheKey);
if (zones == null) {
zones = new HashMap<String, Zone>();
List<Zone> zns = zoneRepository.listByLanguage(language.getId());
// set names
for (Zone zone : zns) {
ZoneDescription description = zone.getDescriptions().get(0);
zone.setName(description.getName());
zones.put(zone.getCode(), zone);
}
cache.putInCache(zones, cacheKey);
}
} catch (Exception e) {
LOGGER.error("getZones()", e);
}
return zones;
}
use of com.salesmanager.core.model.reference.zone.ZoneDescription in project shopizer by shopizer-ecommerce.
the class ZoneServiceImpl method getZones.
@SuppressWarnings("unchecked")
@Override
public List<Zone> getZones(Country country, Language language) throws ServiceException {
// Validate.notNull(country,"Country cannot be null");
Validate.notNull(language, "Language cannot be null");
List<Zone> zones = null;
try {
String countryCode = Constants.DEFAULT_COUNTRY;
if (country != null) {
countryCode = country.getIsoCode();
}
String cacheKey = ZONE_CACHE_PREFIX + countryCode + Constants.UNDERSCORE + language.getCode();
zones = (List<Zone>) cache.getFromCache(cacheKey);
if (zones == null) {
zones = zoneRepository.listByLanguageAndCountry(countryCode, language.getId());
// set names
for (Zone zone : zones) {
ZoneDescription description = zone.getDescriptions().get(0);
zone.setName(description.getName());
}
cache.putInCache(zones, cacheKey);
}
} catch (Exception e) {
LOGGER.error("getZones()", e);
}
return zones;
}
use of com.salesmanager.core.model.reference.zone.ZoneDescription 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;
}
Aggregations