Search in sources :

Example 6 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO 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;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 7 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO 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;
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ArrayList(java.util.ArrayList) PersonnelDto(org.mifos.dto.domain.PersonnelDto) DefinePersonnelDto(org.mifos.dto.screen.DefinePersonnelDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO 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();
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MessageLookup(org.mifos.application.master.MessageLookup) MifosUser(org.mifos.security.MifosUser) ValidationException(org.mifos.framework.exceptions.ValidationException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 9 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO 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);
}
Also used : SitePreferenceType(org.mifos.config.SitePreferenceType) BusinessActivityEntity(org.mifos.application.master.business.BusinessActivityEntity) UserContext(org.mifos.security.util.UserContext) UserSettingsDto(org.mifos.dto.screen.UserSettingsDto) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) Date(java.sql.Date) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ValueListElement(org.mifos.dto.domain.ValueListElement)

Example 10 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO 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();
    }
}
Also used : Address(org.mifos.framework.business.util.Address) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ValidationException(org.mifos.framework.exceptions.ValidationException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)239 Test (org.junit.Test)91 UserContext (org.mifos.security.util.UserContext)65 ArrayList (java.util.ArrayList)62 Money (org.mifos.framework.util.helpers.Money)46 MifosRuntimeException (org.mifos.core.MifosRuntimeException)44 OfficeBO (org.mifos.customers.office.business.OfficeBO)44 MifosUser (org.mifos.security.MifosUser)44 PersistenceException (org.mifos.framework.exceptions.PersistenceException)41 Date (java.util.Date)39 LocalDate (org.joda.time.LocalDate)37 AccountException (org.mifos.accounts.exceptions.AccountException)37 DateTime (org.joda.time.DateTime)36 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)34 BusinessRuleException (org.mifos.service.BusinessRuleException)33 PersonnelBuilder (org.mifos.domain.builders.PersonnelBuilder)31 MeetingBO (org.mifos.application.meeting.business.MeetingBO)30 CustomerBO (org.mifos.customers.business.CustomerBO)27 ServiceException (org.mifos.framework.exceptions.ServiceException)27 LoanBO (org.mifos.accounts.loan.business.LoanBO)25