Search in sources :

Example 1 with PersonnelLevel

use of org.mifos.customers.personnel.util.helpers.PersonnelLevel in project head by mifos.

the class PersonnelDaoHibernate method search.

@SuppressWarnings("unchecked")
@Override
public SystemUserSearchResultsDto search(UserSearchDto searchDto, MifosUser user) {
    Short userId = Integer.valueOf(user.getUserId()).shortValue();
    PersonnelBO loggedInUser = findPersonnelById(userId);
    final PersonnelLevel level = loggedInUser.getLevelEnum();
    final String searchAllSubOfficesInclusiveOfLoggedInUserOffice = loggedInUser.getOfficeSearchId() + "%";
    final String searchString = org.mifos.framework.util.helpers.SearchUtils.normalizeSearchString(searchDto.getSearchTerm());
    final String username = searchString + "%";
    String firstName = "";
    String secondPartOfName = "";
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("SEARCH_ALL", searchAllSubOfficesInclusiveOfLoggedInUserOffice);
    queryParameters.put("USERID", userId);
    queryParameters.put("LOID", PersonnelLevel.LOAN_OFFICER.getValue());
    queryParameters.put("USERLEVEL_ID", level.getValue());
    queryParameters.put("USER_NAME", username);
    if (searchString.contains(" ")) {
        firstName = searchString.substring(0, searchString.indexOf(" "));
        secondPartOfName = searchString.substring(searchString.indexOf(" ") + 1, searchString.length());
        queryParameters.put("USER_NAME1", firstName);
        queryParameters.put("USER_NAME2", secondPartOfName);
    } else {
        firstName = searchString;
        secondPartOfName = "";
        queryParameters.put("USER_NAME1", searchString);
        queryParameters.put("USER_NAME2", "");
    }
    Long searchResultsCount = (Long) this.genericDao.executeUniqueResultNamedQuery(NamedQueryConstants.PERSONNEL_SEARCH_COUNT, queryParameters);
    Session session = StaticHibernateUtil.getSessionTL();
    Criteria criteriaQuery = session.createCriteria(PersonnelBO.class);
    criteriaQuery.createAlias("office", "o");
    criteriaQuery.createAlias("personnelDetails", "d");
    if (PersonnelLevel.LOAN_OFFICER.getValue().equals(Short.valueOf("2"))) {
        criteriaQuery.add(Restrictions.eq("personnelId", userId));
    }
    criteriaQuery.add(Restrictions.like("o.searchId", searchAllSubOfficesInclusiveOfLoggedInUserOffice));
    LogicalExpression firstOrLastNameMatchUsername = Restrictions.or(Restrictions.like("d.name.firstName", username), Restrictions.like("d.name.lastName", username));
    LogicalExpression firstNameAndLastNameMatchGivenParts = Restrictions.and(Restrictions.like("d.name.firstName", firstName), Restrictions.like("d.name.lastName", secondPartOfName));
    criteriaQuery.add(Restrictions.or(firstOrLastNameMatchUsername, firstNameAndLastNameMatchGivenParts));
    criteriaQuery.addOrder(Order.asc("o.officeName"));
    criteriaQuery.addOrder(Order.asc("d.name.lastName"));
    criteriaQuery.setFetchMode("office", FetchMode.JOIN);
    criteriaQuery.setFetchMode("level", FetchMode.JOIN);
    criteriaQuery.setFetchMode("personnelDetails", FetchMode.JOIN);
    int firstResult = (searchDto.getPage() * searchDto.getPageSize()) - searchDto.getPageSize();
    criteriaQuery.setFirstResult(firstResult);
    criteriaQuery.setMaxResults(searchDto.getPageSize());
    List<PersonnelBO> pagedResults = criteriaQuery.list();
    List<UserDetailDto> pagedUserDetails = new ArrayList<UserDetailDto>();
    for (PersonnelBO personnelBO : pagedResults) {
        pagedUserDetails.add(personnelBO.toDto());
    }
    SystemUserSearchResultsDto resultsDto = new SystemUserSearchResultsDto(searchResultsCount.intValue(), firstResult, searchDto.getPage(), searchDto.getPageSize(), pagedUserDetails);
    return resultsDto;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria) LogicalExpression(org.hibernate.criterion.LogicalExpression) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserDetailDto(org.mifos.dto.domain.UserDetailDto) PersonnelLevel(org.mifos.customers.personnel.util.helpers.PersonnelLevel) SystemUserSearchResultsDto(org.mifos.dto.screen.SystemUserSearchResultsDto) Session(org.hibernate.Session)

Example 2 with PersonnelLevel

use of org.mifos.customers.personnel.util.helpers.PersonnelLevel in project head by mifos.

the class BranchReportPersistenceIntegrationTest method testExtractStaffSummaryGetsOnlyLoanOfficers.

@Test
public void testExtractStaffSummaryGetsOnlyLoanOfficers() throws Exception {
    List<BranchReportStaffSummaryBO> staffSummaries = branchReportPersistence.extractBranchReportStaffSummary(BRANCH_ID, Integer.valueOf(1), DEFAULT_CURRENCY);
    for (BranchReportStaffSummaryBO summaryBO : staffSummaries) {
        PersonnelLevel retrievedPersonnelLevel = new PersonnelBusinessService().getPersonnel(summaryBO.getPersonnelId()).getLevelEnum();
        Assert.assertEquals(PersonnelLevel.LOAN_OFFICER, retrievedPersonnelLevel);
    }
}
Also used : PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) BranchReportStaffSummaryBO(org.mifos.reports.branchreport.BranchReportStaffSummaryBO) PersonnelLevel(org.mifos.customers.personnel.util.helpers.PersonnelLevel) Test(org.junit.Test)

Example 3 with PersonnelLevel

use of org.mifos.customers.personnel.util.helpers.PersonnelLevel in project head by mifos.

the class PersonAction method translateFormToCreatePersonnelInformationDto.

@SuppressWarnings("unchecked")
private CreateOrUpdatePersonnelInformation translateFormToCreatePersonnelInformationDto(HttpServletRequest request, PersonActionForm personActionForm) throws PageExpiredException, InvalidDateException {
    UserContext userContext = getUserContext(request);
    PersonnelLevel level = PersonnelLevel.fromInt(getShortValue(personActionForm.getLevel()));
    PersonnelStatus personnelStatus = PersonnelStatus.ACTIVE;
    if (StringUtils.isNotBlank(personActionForm.getStatus())) {
        personnelStatus = PersonnelStatus.getPersonnelStatus(getShortValue(personActionForm.getStatus()));
    }
    OfficeBO office = (OfficeBO) SessionUtils.getAttribute(PersonnelConstants.OFFICE, request);
    if (office == null) {
        Short officeId = getShortValue(personActionForm.getOfficeId());
        office = this.officeDao.findOfficeById(officeId);
    }
    Integer title = getIntegerValue(personActionForm.getTitle());
    Short preferredLocale = Localization.getInstance().getConfiguredLocaleId();
    preferredLocale = getPerefferedLocale(personActionForm, userContext);
    Date dob = null;
    if (personActionForm.getDob() != null && !personActionForm.getDob().equals("")) {
        dob = DateUtils.getDate(personActionForm.getDob());
    }
    Date dateOfJoiningMFI = null;
    if (personActionForm.getDateOfJoiningMFI() != null && !personActionForm.getDateOfJoiningMFI().equals("")) {
        dateOfJoiningMFI = DateUtils.getDateAsSentFromBrowser(personActionForm.getDateOfJoiningMFI());
    }
    Date passwordExpirationDate = null;
    if (personActionForm.getPasswordExpirationDate() != null && !personActionForm.getPasswordExpirationDate().equals("")) {
        passwordExpirationDate = DateUtils.getDate(personActionForm.getPasswordExpirationDate());
    }
    List<RoleBO> roles = new ArrayList<RoleBO>();
    boolean addFlag = false;
    List<RoleBO> selectList = new ArrayList<RoleBO>();
    List<RoleBO> masterList = (List<RoleBO>) SessionUtils.getAttribute(PersonnelConstants.ROLEMASTERLIST, request);
    if (personActionForm.getPersonnelRoles() != null) {
        for (RoleBO role : masterList) {
            for (String roleId : personActionForm.getPersonnelRoles()) {
                if (roleId != null && role.getId().intValue() == Integer.valueOf(roleId).intValue()) {
                    selectList.add(role);
                    addFlag = true;
                }
            }
        }
    }
    if (addFlag) {
        roles = selectList;
    }
    List<ListElement> roleList = new ArrayList<ListElement>();
    for (RoleBO element : roles) {
        ListElement listElement = new ListElement(new Integer(element.getId()), element.getName());
        roleList.add(listElement);
    }
    Address address = personActionForm.getAddress();
    AddressDto addressDto = new AddressDto(address.getLine1(), address.getLine2(), address.getLine3(), address.getCity(), address.getState(), address.getCountry(), address.getZip(), address.getPhoneNumber());
    Long id = null;
    if (StringUtils.isNotBlank(personActionForm.getPersonnelId())) {
        id = Long.valueOf(personActionForm.getPersonnelId());
    }
    CreateOrUpdatePersonnelInformation perosonnelInfo = new CreateOrUpdatePersonnelInformation(id, level.getValue(), office.getOfficeId(), title, preferredLocale, personActionForm.getUserPassword(), personActionForm.getLoginName(), personActionForm.getEmailId(), roleList, personActionForm.getCustomFields(), personActionForm.getFirstName(), personActionForm.getMiddleName(), personActionForm.getLastName(), personActionForm.getSecondLastName(), personActionForm.getGovernmentIdNumber(), new DateTime(dob), getIntegerValue(personActionForm.getMaritalStatus()), getIntegerValue(personActionForm.getGender()), new DateTime(dateOfJoiningMFI), new DateTimeService().getCurrentDateTime(), addressDto, personnelStatus.getValue(), new DateTime(passwordExpirationDate));
    return perosonnelInfo;
}
Also used : Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) AddressDto(org.mifos.dto.domain.AddressDto) Date(java.util.Date) DateTime(org.joda.time.DateTime) PersonnelStatus(org.mifos.customers.personnel.util.helpers.PersonnelStatus) CreateOrUpdatePersonnelInformation(org.mifos.dto.domain.CreateOrUpdatePersonnelInformation) OfficeBO(org.mifos.customers.office.business.OfficeBO) ValueListElement(org.mifos.dto.domain.ValueListElement) ListElement(org.mifos.dto.screen.ListElement) List(java.util.List) ArrayList(java.util.ArrayList) PersonnelLevel(org.mifos.customers.personnel.util.helpers.PersonnelLevel) DateTimeService(org.mifos.framework.util.DateTimeService) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 4 with PersonnelLevel

use of org.mifos.customers.personnel.util.helpers.PersonnelLevel in project head by mifos.

the class PersonnelServiceFacadeWebTier method updatePersonnel.

@Override
public UserDetailDto updatePersonnel(CreateOrUpdatePersonnelInformation personnel) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    PersonnelBO userForUpdate = this.personnelDao.findPersonnelById(personnel.getId().shortValue());
    userForUpdate.updateDetails(userContext);
    AddressDto addressDto = personnel.getAddress();
    Address address = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
    PersonnelStatus status = PersonnelStatus.getPersonnelStatus(personnel.getPersonnelStatusId());
    PersonnelLevel userHierarchyLevel = PersonnelLevel.fromInt(personnel.getPersonnelLevelId().intValue());
    OfficeBO newOffice = this.officeDao.findOfficeById(personnel.getOfficeId());
    validateForUpdate(userForUpdate, status, newOffice, userHierarchyLevel);
    List<RoleBO> selectedRoles = new ArrayList<RoleBO>();
    try {
        List<RoleBO> allRoles = new PersonnelBusinessService().getRoles();
        for (RoleBO role : allRoles) {
            if (isRoleSelected(role, personnel.getRoles())) {
                selectedRoles.add(role);
            }
        }
        PersonnelStatusEntity personnelStatus = legacyMasterDao.getPersistentObject(PersonnelStatusEntity.class, status.getValue());
        PersonnelLevelEntity personnelLevel = legacyMasterDao.getPersistentObject(PersonnelLevelEntity.class, userHierarchyLevel.getValue());
        Short preferredLocaleId = personnel.getPreferredLocale();
        transactionHelper.startTransaction();
        transactionHelper.beginAuditLoggingFor(userForUpdate);
        userForUpdate.updateUserDetails(personnel.getFirstName(), personnel.getMiddleName(), personnel.getSecondLastName(), personnel.getLastName(), personnel.getEmailId(), personnel.getGender(), personnel.getMaritalStatus(), preferredLocaleId, personnelStatus, address, personnel.getTitle(), personnelLevel, selectedRoles, newOffice);
        userForUpdate.getPersonnelDetails().setDob(personnel.getDob().toDate());
        userForUpdate.setPasswordExpirationDate(personnel.getPasswordExpirationDate().toDate());
        if (!StringUtils.isEmpty(personnel.getPassword())) {
            this.personelService.changePassword(userForUpdate, personnel.getPassword(), false);
        }
        this.personnelDao.save(userForUpdate);
        transactionHelper.commitTransaction();
        return userForUpdate.toDto();
    } catch (BusinessRuleException e) {
        transactionHelper.rollbackTransaction();
        throw e;
    } catch (PersistenceException e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (Exception e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        transactionHelper.closeSession();
    }
}
Also used : PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AddressDto(org.mifos.dto.domain.AddressDto) PersonnelLevelEntity(org.mifos.customers.personnel.business.PersonnelLevelEntity) 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) PersonnelStatusEntity(org.mifos.customers.personnel.business.PersonnelStatusEntity) PersonnelStatus(org.mifos.customers.personnel.util.helpers.PersonnelStatus) BusinessRuleException(org.mifos.service.BusinessRuleException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) PersonnelLevel(org.mifos.customers.personnel.util.helpers.PersonnelLevel) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

PersonnelLevel (org.mifos.customers.personnel.util.helpers.PersonnelLevel)4 ArrayList (java.util.ArrayList)3 OfficeBO (org.mifos.customers.office.business.OfficeBO)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 PersonnelBusinessService (org.mifos.customers.personnel.business.service.PersonnelBusinessService)2 PersonnelStatus (org.mifos.customers.personnel.util.helpers.PersonnelStatus)2 AddressDto (org.mifos.dto.domain.AddressDto)2 Address (org.mifos.framework.business.util.Address)2 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)2 UserContext (org.mifos.security.util.UserContext)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Criteria (org.hibernate.Criteria)1 Session (org.hibernate.Session)1 LogicalExpression (org.hibernate.criterion.LogicalExpression)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)1 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)1