Search in sources :

Example 1 with Localization

use of org.mifos.config.Localization in project head by mifos.

the class StandardTestingService method setLocale.

@Override
public void setLocale(String languageCode, String countryCode) throws MifosException {
    try {
        LocaleSetting configLocale = new LocaleSetting();
        configLocale.setLanguageCode(languageCode);
        configLocale.setCountryCode(countryCode);
        Localization localization = Localization.getInstance();
        localization.setConfigLocale(configLocale);
        if (SecurityContextHolder.getContext() != null) {
            if (SecurityContextHolder.getContext().getAuthentication() != null) {
                if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() != null) {
                    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
                    user.setPreferredLocaleId(Localization.getInstance().getLocaleId(Localization.getInstance().getConfiguredLocale()));
                }
            }
        }
        StaticHibernateUtil.startTransaction();
        PersonnelBO p = (PersonnelBO) StaticHibernateUtil.getSessionTL().get(PersonnelBO.class, (short) 1);
        p.setPreferredLocale(Localization.getInstance().getConfiguredLocaleId());
        StaticHibernateUtil.getSessionTL().update(p);
        StaticHibernateUtil.commitTransaction();
        MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
        configMgr.setProperty("Localization.LanguageCode", languageCode);
        configMgr.setProperty("Localization.CountryCode", countryCode);
    } catch (MifosRuntimeException e) {
        throw new MifosException("The locale " + languageCode + "_" + countryCode + " is not supported by Mifos.");
    }
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosException(org.mifos.core.MifosException) LocaleSetting(org.mifos.config.LocaleSetting) MifosUser(org.mifos.security.MifosUser) Localization(org.mifos.config.Localization) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

LocaleSetting (org.mifos.config.LocaleSetting)1 Localization (org.mifos.config.Localization)1 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)1 MifosException (org.mifos.core.MifosException)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 MifosUser (org.mifos.security.MifosUser)1