Search in sources :

Example 1 with SystemUserSearchResultsDto

use of org.mifos.dto.screen.SystemUserSearchResultsDto 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 SystemUserSearchResultsDto

use of org.mifos.dto.screen.SystemUserSearchResultsDto in project head by mifos.

the class SystemUserSearchController method displaySystemUsers.

@RequestMapping(method = RequestMethod.GET)
public ModelAndView displaySystemUsers(ModelMap model) {
    ModelAndView mav = new ModelAndView("viewSystemUsers");
    SystemUserSearchFormBean formBean = (SystemUserSearchFormBean) model.get("searchResults");
    SystemUserSearchResultsDto result = (SystemUserSearchResultsDto) model.get("pagedResults");
    if (result == null) {
        List<UserDetailDto> pagedUserDetails = new ArrayList<UserDetailDto>();
        result = new SystemUserSearchResultsDto(0, 0, 0, 0, pagedUserDetails);
        formBean = new SystemUserSearchFormBean();
    }
    mav.addObject("searchResults", formBean);
    mav.addObject("pagedResults", result);
    return mav;
}
Also used : UserDetailDto(org.mifos.dto.domain.UserDetailDto) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) SystemUserSearchResultsDto(org.mifos.dto.screen.SystemUserSearchResultsDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with SystemUserSearchResultsDto

use of org.mifos.dto.screen.SystemUserSearchResultsDto in project head by mifos.

the class SystemUserSearchController method processSearch.

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processSearch(@RequestParam(required = false, value = "next") String next, @RequestParam(required = false, value = "previous") String previous, @RequestParam(required = false, value = "searchbutton") String newSearch, @RequestParam(required = false, value = "lastSearch") String lastSearchTerm, @RequestParam(required = true, value = "lastPage") Integer lastPage, @ModelAttribute("searchResults") SystemUserSearchFormBean searchResultsFormBean) {
    int startingPage = lastPage;
    if (StringUtils.isNotBlank(next)) {
        startingPage++;
        searchResultsFormBean.setSearch(lastSearchTerm);
    } else if (StringUtils.isNotBlank(previous)) {
        startingPage--;
        searchResultsFormBean.setSearch(lastSearchTerm);
    } else if (StringUtils.isNotBlank(newSearch)) {
        startingPage = 1;
    }
    if (startingPage <= 0) {
        startingPage = 1;
    }
    UserSearchDto searchDto = new UserSearchDto(searchResultsFormBean.getSearch(), startingPage, 10);
    SystemUserSearchResultsDto dto = this.personnelServiceFacade.searchUser(searchDto);
    ModelAndView mav = new ModelAndView("redirect:/viewSystemUsers.ftl");
    mav.addObject("searchResults", searchResultsFormBean);
    mav.addObject("pagedResults", dto);
    return mav;
}
Also used : UserSearchDto(org.mifos.dto.domain.UserSearchDto) ModelAndView(org.springframework.web.servlet.ModelAndView) SystemUserSearchResultsDto(org.mifos.dto.screen.SystemUserSearchResultsDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with SystemUserSearchResultsDto

use of org.mifos.dto.screen.SystemUserSearchResultsDto in project head by mifos.

the class PersonnelDaoHibernateIntegrationTest method shouldFindUsersByNameWhenSearching.

@Test
public void shouldFindUsersByNameWhenSearching() {
    // setup
    MifosUser user = personnelDao.findAuthenticatedUserByUsername("mifos");
    // exercise test
    String searchString = "mifos";
    Integer page = 1;
    Integer pageSize = 10;
    UserSearchDto searchDto = new UserSearchDto(searchString, page, pageSize);
    SystemUserSearchResultsDto searchResults = personnelDao.search(searchDto, user);
    // verification
    assertNotNull(searchResults);
//        assertThat(searchResults.size(), is(1));
}
Also used : UserSearchDto(org.mifos.dto.domain.UserSearchDto) MifosUser(org.mifos.security.MifosUser) SystemUserSearchResultsDto(org.mifos.dto.screen.SystemUserSearchResultsDto) Test(org.junit.Test)

Aggregations

SystemUserSearchResultsDto (org.mifos.dto.screen.SystemUserSearchResultsDto)4 ArrayList (java.util.ArrayList)2 UserDetailDto (org.mifos.dto.domain.UserDetailDto)2 UserSearchDto (org.mifos.dto.domain.UserSearchDto)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 HashMap (java.util.HashMap)1 Criteria (org.hibernate.Criteria)1 Session (org.hibernate.Session)1 LogicalExpression (org.hibernate.criterion.LogicalExpression)1 Test (org.junit.Test)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 PersonnelLevel (org.mifos.customers.personnel.util.helpers.PersonnelLevel)1 MifosUser (org.mifos.security.MifosUser)1