use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveAccountStatuses.
@Override
public AccountStatusDto retrieveAccountStatuses(Long loanAccountId) {
LoanBO loanAccount = this.loanDao.findById(loanAccountId.intValue());
try {
List<ListElement> loanStatesList = new ArrayList<ListElement>();
AccountStateMachines.getInstance().initializeLoanStates();
List<AccountStateEntity> statusList = AccountStateMachines.getInstance().getLoanStatusList(loanAccount.getAccountState());
for (AccountStateEntity accountState : statusList) {
loanStatesList.add(new ListElement(accountState.getId().intValue(), accountState.getName()));
}
return new AccountStatusDto(loanStatesList);
} catch (StatesInitializationException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class LoginServiceFacadeWebTier method login.
@Override
public LoginDto login(String username, String password) {
PersonnelBO user = this.personnelDao.findPersonnelByUsername(username);
if (user == null) {
throw new UsernameNotFoundException(LoginConstants.KEYINVALIDUSER);
}
MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
List<ValueListElement> localeList = personnelServiceFacade.getDisplayLocaleList();
Locale preferredLocale = new Locale(configMgr.getString(LANGUAGE_CODE), configMgr.getString(COUNTRY_CODE));
String listElement = "[" + preferredLocale.toString() + "]";
Short localeId = user.getPreferredLocale();
for (ValueListElement element : localeList) {
if (element.getName().contains(listElement)) {
localeId = element.getId().shortValue();
break;
}
}
user.setPreferredLocale(localeId);
UserContext userContext = new UserContext();
userContext.setPreferredLocale(preferredLocale);
userContext.setLocaleId(localeId);
userContext.setId(user.getPersonnelId());
userContext.setName(user.getDisplayName());
userContext.setLevel(user.getLevelEnum());
userContext.setRoles(user.getRoles());
userContext.setLastLogin(user.getLastLogin());
userContext.setPasswordChanged(user.getPasswordChanged());
userContext.setBranchId(user.getOffice().getOfficeId());
userContext.setBranchGlobalNum(user.getOffice().getGlobalOfficeNum());
userContext.setOfficeLevelId(user.getOffice().getLevel().getId());
user.updateDetails(userContext);
try {
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(user);
user.login(password);
this.personnelDao.save(user);
this.transactionHelper.commitTransaction();
boolean isPasswordExpired = new LocalDate(user.getPasswordExpirationDate()).isBefore(new LocalDate());
return new LoginDto(user.getPersonnelId(), user.getOffice().getOfficeId(), user.isPasswordChanged(), isPasswordExpired);
} catch (ApplicationException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class PersonnelServiceFacadeWebTier method retrieveActiveLoanOfficersUnderOffice.
@Override
public List<PersonnelDto> retrieveActiveLoanOfficersUnderOffice(Short officeId) {
List<PersonnelBO> personnelList;
try {
personnelList = legacyPersonnelDao.getActiveLoanOfficersUnderOffice(officeId);
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
}
List<PersonnelDto> personnelDtoList = new ArrayList<PersonnelDto>();
for (PersonnelBO personnelBO : personnelList) {
personnelDtoList.add(new PersonnelDto(personnelBO.getPersonnelId(), personnelBO.getDisplayName()));
}
return personnelDtoList;
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class PersonnelServiceFacadeWebTier method changeUserLocale.
@Override
public Short changeUserLocale(Short id, HttpServletRequest request) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (id != null) {
Short newLocaleId = id;
if (Localization.getInstance().getLocaleById(newLocaleId) != null) {
user.setPreferredLocaleId(newLocaleId);
try {
this.transactionHelper.startTransaction();
PersonnelBO p = this.personnelDao.findPersonnelById((short) user.getUserId());
p.setPreferredLocale(newLocaleId);
this.personnelDao.update(p);
this.transactionHelper.commitTransaction();
UserContext userContext = (UserContext) request.getSession().getAttribute(LoginConstants.USERCONTEXT);
userContext.setLocaleId(newLocaleId);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
}
ApplicationContextProvider.getBean(MessageLookup.class).updateLabelCache();
}
}
return user.getPreferredLocaleId();
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class PersonnelServiceFacadeWebTier method updateUserSettings.
@Override
public void updateUserSettings(Short personnelId, String emailId, Name name, Integer maritalStatusValue, Integer genderValue, AddressDto address, Short preferredLocale, Short sitePreference) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
PersonnelBO personnel = this.personnelDao.findPersonnelById(personnelId);
try {
personnel.updateDetails(userContext);
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(personnel);
Address theAddress = null;
if (address != null) {
theAddress = new Address(address.getLine1(), address.getLine2(), address.getLine3(), address.getCity(), address.getState(), address.getCountry(), address.getZip(), address.getPhoneNumber());
}
personnel.update(emailId, name, maritalStatusValue, genderValue, theAddress, preferredLocale, sitePreference);
if (preferredLocale != null && preferredLocale != 0) {
user.setPreferredLocaleId(preferredLocale);
}
this.transactionHelper.commitTransaction();
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
Aggregations