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