use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class LoanAccountServiceFacadeWebTier method reverseLoanDisbursal.
@Override
public void reverseLoanDisbursal(String globalAccountNum, String note) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
PersonnelBO personnel = this.personnelDao.findPersonnelById(userContext.getId());
loan.updateDetails(userContext);
try {
this.transactionHelper.startTransaction();
loan.reverseLoanDisbursal(personnel, note);
this.loanDao.save(loan);
this.transactionHelper.commitTransaction();
} catch (BusinessRuleException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (AccountException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class LoginServiceFacadeWebTier method updatePassword.
@Override
public boolean updatePassword(String username, String oldPassword, String newPassword) {
MifosUser appUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(appUser);
PersonnelBO user = this.personnelDao.findPersonnelByUsername(username);
boolean passwordIsAlreadyChanged = user.isPasswordChanged();
this.personnelService.changePassword(user, newPassword, true);
Date newExpirationDate = null;
if (user.getPasswordExpirationDate() != null) {
newExpirationDate = new LocalDateTime().plusDays(PasswordRules.getPasswordExpirationDatePrelongation()).toDateTime().toDate();
}
personnelService.changePasswordExpirationDate(user, newExpirationDate);
return passwordIsAlreadyChanged;
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class PersonnelServiceFacadeWebTier method retrieveUserSettings.
@Override
public UserSettingsDto retrieveUserSettings() {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
PersonnelBO personnel = this.personnelDao.findPersonnelById(userContext.getId());
String gender = getNameForBusinessActivityEntity(personnel.getPersonnelDetails().getGender());
String martialStatus = getNameForBusinessActivityEntity(personnel.getPersonnelDetails().getMaritalStatus());
String language = Localization.getInstance().getDisplayName(personnel.getPreferredLocale());
String sitePreference = SitePreferenceType.getSitePreference(personnel.getSitePreference()).name();
List<ValueListElement> genders = this.customerDao.retrieveGenders();
List<ValueListElement> martialStatuses = this.customerDao.retrieveMaritalStatuses();
List<ValueListElement> languages = Localization.getInstance().getLocaleForUI();
List<ValueListElement> sitePreferenceTypes = new ArrayList<ValueListElement>();
for (short i = 0; i < SitePreferenceType.values().length; i++) {
SitePreferenceType sitePreferenceType = SitePreferenceType.values()[i];
ValueListElement valueListElement = new BusinessActivityEntity(sitePreferenceType.getValue().intValue(), sitePreferenceType.name(), sitePreferenceType.name());
sitePreferenceTypes.add(valueListElement);
}
int age = DateUtils.DateDiffInYears(((Date) personnel.getPersonnelDetails().getDob()));
if (age < 0) {
age = 0;
}
return new UserSettingsDto(gender, martialStatus, language, age, sitePreference, genders, martialStatuses, languages, sitePreferenceTypes);
}
use of org.mifos.accounts.servicefacade.UserContextFactory 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();
}
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class PersonnelServiceFacadeWebTier method unLockUserAccount.
@Override
public void unLockUserAccount(String globalAccountNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
PersonnelBO personnel = this.personnelDao.findByGlobalPersonnelNum(globalAccountNum);
personnel.updateDetails(userContext);
try {
this.transactionHelper.startTransaction();
personnel.unlockPersonnel();
this.personnelDao.save(personnel);
this.transactionHelper.commitTransaction();
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
}
}
Aggregations