Search in sources :

Example 1 with SearchFiltersDto

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

the class CustomerPersistenceIntegrationTest method clearFilters.

private void clearFilters() {
    Map<String, Boolean> customerLevelIds = new HashMap<String, Boolean>() {

        {
            put(CustomerLevel.CLIENT.toString(), true);
            put(CustomerLevel.GROUP.toString(), true);
            put(CustomerLevel.CENTER.toString(), true);
        }
    };
    Map<String, Integer> customerStates = new HashMap<String, Integer>() {

        {
            put(CustomerLevel.CLIENT.toString(), 0);
            put(CustomerLevel.GROUP.toString(), 0);
            put(CustomerLevel.CENTER.toString(), 0);
        }
    };
    filters = new SearchFiltersDto(customerLevelIds, customerStates, "", "", "", "", 0, "");
}
Also used : HashMap(java.util.HashMap) SearchFiltersDto(org.mifos.dto.screen.SearchFiltersDto)

Example 2 with SearchFiltersDto

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

the class CustSearchAction method mainSearch.

@TransactionDemarcate(joinToken = true)
public ActionForward mainSearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    CustSearchActionForm actionForm = (CustSearchActionForm) form;
    Short officeId = getShortValue(actionForm.getOfficeId());
    String searchString = actionForm.getSearchString();
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USERCONTEXT, request.getSession());
    super.search(mapping, form, request, response);
    if (searchString == null || searchString.equals("")) {
        ActionErrors errors = new ActionErrors();
        errors.add(CustomerSearchConstants.NAMEMANDATORYEXCEPTION, new ActionMessage(CustomerSearchConstants.NAMEMANDATORYEXCEPTION));
        request.setAttribute(Globals.ERROR_KEY, errors);
        return mapping.findForward(ActionForwards.mainSearch_success.toString());
    }
    if (officeId != null && officeId != 0) {
        addSeachValues(searchString, officeId.toString(), new OfficePersistence().getOffice(officeId).getOfficeName(), request);
    } else {
        addSeachValues(searchString, officeId.toString(), new OfficePersistence().getOffice(userContext.getBranchId()).getOfficeName(), request);
    }
    searchString = SearchUtils.normalizeSearchString(searchString);
    if (searchString.equals("")) {
        throw new CustomerException(CustomerSearchConstants.NAMEMANDATORYEXCEPTION);
    }
    if (actionForm.getFilters() == null) {
        actionForm.setFilters(new SearchFiltersDto());
    }
    QueryResult customerSearchResult = new CustomerPersistence().search(searchString, officeId, userContext.getId(), userContext.getBranchId(), actionForm.getFilters());
    SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, customerSearchResult, request);
    return mapping.findForward(ActionForwards.mainSearch_success.toString());
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) CustSearchActionForm(org.mifos.customers.struts.actionforms.CustSearchActionForm) UserContext(org.mifos.security.util.UserContext) ActionMessage(org.apache.struts.action.ActionMessage) SearchFiltersDto(org.mifos.dto.screen.SearchFiltersDto) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) ActionErrors(org.apache.struts.action.ActionErrors) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 3 with SearchFiltersDto

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

the class SearchResultController method legacyShowSearchResults.

@RequestMapping(value = "/legacySearchResult", method = { RequestMethod.POST, RequestMethod.GET })
public ModelAndView legacyShowSearchResults(HttpServletRequest request, @ModelAttribute("customerSearch") @Valid CustomerSearchFormBean customerSearchFormBean, BindingResult result) throws PersistenceException {
    ModelAndView modelAndView = new ModelAndView();
    sitePreferenceHelper.resolveSiteType(modelAndView, "legacySearchResult", request);
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    CustomerHierarchyDto customerHierarchyDto = null;
    List<OfficeDto> officeDtoList = officeServiceFacade.retrieveActiveBranchesUnderUser((short) user.getUserId());
    Map<String, String> officesMap = new HashMap<String, String>();
    for (OfficeDto officeDto : officeDtoList) {
        officesMap.put(officeDto.getId().toString(), officeDto.getName());
    }
    customerSearchFormBean.setOffices(officesMap);
    boolean isCenterHierarchyExists = configurationServiceFacade.getBooleanConfig("ClientRules.CenterHierarchyExists");
    modelAndView.addObject("isCenterHierarchyExists", isCenterHierarchyExists);
    HashMap<String, ArrayList<CustomerStatusDetailDto>> customerStates = new HashMap<String, ArrayList<CustomerStatusDetailDto>>();
    customerStates.putAll(customerSearchServiceFacade.getAvailibleCustomerStates());
    modelAndView.addObject("availibleCustomerStates", customerStates);
    List<ValueListElement> availibleClientGenders = clientServiceFacade.getClientGenders();
    modelAndView.addObject("availibleClientGenders", availibleClientGenders);
    if (result.hasErrors()) {
        return modelAndView;
    }
    int currentPage = 0;
    if (request.getParameter("currentPage") != null) {
        currentPage = new Integer(request.getParameter("currentPage")).intValue();
    }
    modelAndView.addObject("customerSearch", customerSearchFormBean);
    if (customerSearchFormBean.getFilters() == null) {
        customerSearchFormBean.setFilters(new SearchFiltersDto());
    }
    customerHierarchyDto = customerSearchServiceFacade.search(customerSearchFormBean.getSearchString(), customerSearchFormBean.getOfficeId(), currentPage * PAGE_SIZE, PAGE_SIZE, customerSearchFormBean.getFilters());
    boolean prevPageAvailable = false;
    if (currentPage > 0) {
        prevPageAvailable = true;
    }
    boolean nextPageAvailable = false;
    if (customerHierarchyDto.getSize() / PAGE_SIZE > 0 && customerHierarchyDto.getSize() / PAGE_SIZE >= currentPage + 1) {
        nextPageAvailable = true;
    }
    modelAndView.addObject("isPrevPageAvailable", prevPageAvailable);
    modelAndView.addObject("isNextPageAvailable", nextPageAvailable);
    modelAndView.addObject("currentPage", currentPage);
    modelAndView.addObject("pageSize", PAGE_SIZE);
    modelAndView.addObject("customerHierarchy", customerHierarchyDto);
    return modelAndView;
}
Also used : OfficeDto(org.mifos.dto.domain.OfficeDto) CustomerStatusDetailDto(org.mifos.dto.screen.CustomerStatusDetailDto) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) SearchFiltersDto(org.mifos.dto.screen.SearchFiltersDto) CustomerHierarchyDto(org.mifos.dto.screen.CustomerHierarchyDto) ValueListElement(org.mifos.dto.domain.ValueListElement) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with SearchFiltersDto

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

the class SearchResultController method showSearchResults.

@RequestMapping(value = "/searchResult", method = { RequestMethod.POST, RequestMethod.GET })
public ModelAndView showSearchResults(HttpServletRequest request, @ModelAttribute("customerSearch") @Valid CustomerSearchFormBean customerSearchFormBean, BindingResult result) throws PersistenceException {
    ModelAndView modelAndView = new ModelAndView();
    sitePreferenceHelper.resolveSiteType(modelAndView, "searchResult", request);
    // mobile search result view doesn't use ajax search
    if (sitePreferenceHelper.isMobile(request)) {
        return legacyShowSearchResults(request, customerSearchFormBean, result);
    }
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    List<OfficeDto> officeDtoList = officeServiceFacade.retrieveActiveBranchesUnderUser((short) user.getUserId());
    Map<String, String> officesMap = new HashMap<String, String>();
    for (OfficeDto officeDto : officeDtoList) {
        officesMap.put(officeDto.getId().toString(), officeDto.getName());
    }
    customerSearchFormBean.setOffices(officesMap);
    modelAndView.addObject("customerSearch", customerSearchFormBean);
    boolean isCenterHierarchyExists = configurationServiceFacade.getBooleanConfig("ClientRules.CenterHierarchyExists");
    modelAndView.addObject("isCenterHierarchyExists", isCenterHierarchyExists);
    HashMap<String, ArrayList<CustomerStatusDetailDto>> customerStates = new HashMap<String, ArrayList<CustomerStatusDetailDto>>();
    customerStates.putAll(customerSearchServiceFacade.getAvailibleCustomerStates());
    modelAndView.addObject("availibleCustomerStates", customerStates);
    List<ValueListElement> availibleClientGenders = clientServiceFacade.getClientGenders();
    modelAndView.addObject("availibleClientGenders", availibleClientGenders);
    if (result.hasErrors()) {
        return modelAndView;
    }
    CustomerHierarchyDto customerHierarchyDto = new CustomerHierarchyDto();
    if (customerSearchFormBean.getFilters() == null) {
        customerSearchFormBean.setFilters(new SearchFiltersDto());
    }
    if (customerSearchFormBean.getSearchString() != null && !customerSearchFormBean.getSearchString().isEmpty()) {
        customerHierarchyDto = customerSearchServiceFacade.search(customerSearchFormBean.getSearchString(), customerSearchFormBean.getOfficeId(), 0, 10, customerSearchFormBean.getFilters());
    }
    modelAndView.addObject("customerHierarchy", customerHierarchyDto);
    modelAndView.addObject("startIndex", 0);
    return modelAndView;
}
Also used : OfficeDto(org.mifos.dto.domain.OfficeDto) CustomerStatusDetailDto(org.mifos.dto.screen.CustomerStatusDetailDto) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) SearchFiltersDto(org.mifos.dto.screen.SearchFiltersDto) CustomerHierarchyDto(org.mifos.dto.screen.CustomerHierarchyDto) ValueListElement(org.mifos.dto.domain.ValueListElement) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SearchFiltersDto (org.mifos.dto.screen.SearchFiltersDto)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 OfficeDto (org.mifos.dto.domain.OfficeDto)2 ValueListElement (org.mifos.dto.domain.ValueListElement)2 CustomerHierarchyDto (org.mifos.dto.screen.CustomerHierarchyDto)2 CustomerStatusDetailDto (org.mifos.dto.screen.CustomerStatusDetailDto)2 MifosUser (org.mifos.security.MifosUser)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 ActionErrors (org.apache.struts.action.ActionErrors)1 ActionMessage (org.apache.struts.action.ActionMessage)1 CustomerException (org.mifos.customers.exceptions.CustomerException)1 OfficePersistence (org.mifos.customers.office.persistence.OfficePersistence)1 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)1 CustSearchActionForm (org.mifos.customers.struts.actionforms.CustSearchActionForm)1 QueryResult (org.mifos.framework.hibernate.helper.QueryResult)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1 UserContext (org.mifos.security.util.UserContext)1