Search in sources :

Example 1 with CountryDescription

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

the class InitializationDatabaseImpl method createCountries.

private void createCountries() throws ServiceException {
    LOGGER.info(String.format("%s : Populating Countries ", name));
    List<Language> languages = languageService.list();
    for (String code : SchemaConstant.COUNTRY_ISO_CODE) {
        Locale locale = SchemaConstant.LOCALES.get(code);
        if (locale != null) {
            Country country = new Country(code);
            countryService.create(country);
            for (Language language : languages) {
                String name = locale.getDisplayCountry(new Locale(language.getCode()));
                // byte[] ptext = value.getBytes(Constants.ISO_8859_1);
                // String name = new String(ptext, Constants.UTF_8);
                CountryDescription description = new CountryDescription(language, name);
                countryService.addCountryDescription(country, description);
            }
        }
    }
}
Also used : Locale(java.util.Locale) CountryDescription(com.salesmanager.core.model.reference.country.CountryDescription) Language(com.salesmanager.core.model.reference.language.Language) Country(com.salesmanager.core.model.reference.country.Country)

Example 2 with CountryDescription

use of com.salesmanager.core.model.reference.country.CountryDescription 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 3 with CountryDescription

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

the class ReferencesTest method testReferences.

// @Test
@Ignore
public void testReferences() throws ServiceException {
    Language en = new Language();
    en.setCode("en");
    en.setSortOrder(0);
    languageService.save(en);
    Language fr = new Language();
    fr.setCode("fr");
    fr.setSortOrder(0);
    languageService.save(fr);
    List<Language> langs = languageService.getLanguages();
    System.out.println("Language size " + langs.size());
    Country us = new Country();
    us.setIsoCode("US");
    CountryDescription us_en = new CountryDescription();
    us_en.setLanguage(en);
    us_en.setCountry(us);
    us_en.setName("United States");
    us.getDescriptions().add(us_en);
    CountryDescription us_fr = new CountryDescription();
    us_fr.setLanguage(fr);
    us_fr.setCountry(us);
    us_fr.setName("Etats Unis");
    us.getDescriptions().add(us_fr);
    countryService.save(us);
    Country c = countryService.getByCode("US");
    System.out.println(c.getId());
    System.out.println("***********Done**************");
}
Also used : CountryDescription(com.salesmanager.core.model.reference.country.CountryDescription) Language(com.salesmanager.core.model.reference.language.Language) Country(com.salesmanager.core.model.reference.country.Country) Ignore(org.junit.Ignore)

Aggregations

Country (com.salesmanager.core.model.reference.country.Country)3 CountryDescription (com.salesmanager.core.model.reference.country.CountryDescription)3 Language (com.salesmanager.core.model.reference.language.Language)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Locale (java.util.Locale)1 Ignore (org.junit.Ignore)1