Search in sources :

Example 26 with QueryResult

use of org.mifos.framework.hibernate.helper.QueryResult 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 27 with QueryResult

use of org.mifos.framework.hibernate.helper.QueryResult in project head by mifos.

the class LegacyAccountDaoIntegrationTest method testSearchCustomerAccount.

@Test
public void testSearchCustomerAccount() throws Exception {
    QueryResult queryResult = null;
    queryResult = legacyAccountDao.search(center.getCustomerAccount().getGlobalAccountNum(), (short) 3);
    Assert.assertNull(queryResult);
}
Also used : QueryResult(org.mifos.framework.hibernate.helper.QueryResult) Test(org.junit.Test)

Example 28 with QueryResult

use of org.mifos.framework.hibernate.helper.QueryResult in project head by mifos.

the class LegacyAccountDaoIntegrationTest method testSearchAccount.

@Test
public void testSearchAccount() throws Exception {
    savingsBO = createSavingsAccount();
    QueryResult queryResult = null;
    queryResult = legacyAccountDao.search(savingsBO.getGlobalAccountNum(), (short) 3);
    Assert.assertNotNull(queryResult);
    Assert.assertEquals(1, queryResult.getSize());
    Assert.assertEquals(1, queryResult.get(0, 10).size());
}
Also used : QueryResult(org.mifos.framework.hibernate.helper.QueryResult) Test(org.junit.Test)

Example 29 with QueryResult

use of org.mifos.framework.hibernate.helper.QueryResult in project head by mifos.

the class CustomerServiceFacadeWebTier method searchGroups.

@Override
public GroupSearchResultsDto searchGroups(boolean searchForAddingClientsToGroup, String normalizedSearchString, Short loggedInUserId) {
    try {
        // FIXME - #000001 - keithw - move search logic off group business service over to customerDAO
        QueryResult searchResults = new GroupBusinessService().search(normalizedSearchString, loggedInUserId);
        QueryResult searchForAddingClientToGroupResults = null;
        if (searchForAddingClientsToGroup) {
            searchForAddingClientToGroupResults = new GroupBusinessService().searchForAddingClientToGroup(normalizedSearchString, loggedInUserId);
        }
        return new GroupSearchResultsDto(searchResults, searchForAddingClientToGroupResults);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : QueryResult(org.mifos.framework.hibernate.helper.QueryResult) ServiceException(org.mifos.framework.exceptions.ServiceException) GroupBusinessService(org.mifos.customers.group.business.service.GroupBusinessService) GroupSearchResultsDto(org.mifos.customers.group.struts.action.GroupSearchResultsDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 30 with QueryResult

use of org.mifos.framework.hibernate.helper.QueryResult in project head by mifos.

the class CustomerSearchServiceFacadeWebTier method search.

@Override
public CustomerHierarchyDto search(String searchString, Short officeId, int pageNumber, int pageSize, SearchFiltersDto filters) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    if (searchString == null) {
        throw new MifosRuntimeException(CenterConstants.NO_SEARCH_STRING);
    }
    String normalisedSearchString = org.mifos.framework.util.helpers.SearchUtils.normalizeSearchString(searchString);
    if (normalisedSearchString.equals("")) {
        throw new MifosRuntimeException(CenterConstants.NO_SEARCH_STRING);
    }
    CustomerHierarchyDto customerHierarchyDto = new CustomerHierarchyDto();
    QueryResult searchResult = null;
    List<CustomerSearchDto> resultList = null;
    try {
        searchResult = new CustomerPersistence().search(normalisedSearchString, officeId, userContext.getId(), userContext.getBranchId(), filters);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
    try {
        resultList = searchResult.get(pageNumber, pageSize);
        customerHierarchyDto.setSize(searchResult.getSize());
        customerHierarchyDto.setSearchResultSize(resultList.size());
    } catch (HibernateSearchException e) {
        throw new MifosRuntimeException(e);
    }
    /* FIXME: QueryResult.get returns CustomerSearchDto with messed up customers and accounts data.
		 */
    for (CustomerSearchDto customerSearchDto : resultList) {
        if (customerSearchDto.getCustomerType() == 1) {
            ClientSearchResultDto clientSearchResultDto = new ClientSearchResultDto();
            clientSearchResultDto.setOfficeId(customerSearchDto.getOfficeId());
            clientSearchResultDto.setOfficeName(customerSearchDto.getOfficeName());
            /* QueryResult.get returns CustomerSearchDto (as Client) with clientName as centerName, 
        		 * clientGobalCustNum as centerGobalCustNum and vice versa 
        		 */
            clientSearchResultDto.setClientName(customerSearchDto.getCenterName());
            clientSearchResultDto.setClientGlobalCustNum(customerSearchDto.getCenterGlobalCustNum());
            clientSearchResultDto.setGroupName(customerSearchDto.getGroupName());
            clientSearchResultDto.setGroupGlobalCustNum(customerSearchDto.getGroupGlobalCustNum());
            clientSearchResultDto.setCenterName(customerSearchDto.getClientName());
            clientSearchResultDto.setCenterGlobalCustNum(customerSearchDto.getClientGlobalCustNum());
            clientSearchResultDto.setBranchName(customerSearchDto.getBranchName());
            clientSearchResultDto.setBranchId(customerSearchDto.getBranchGlobalNum());
            clientSearchResultDto.setCustomerStatusId(customerSearchDto.getCustomerStatus());
            clientSearchResultDto.setLoanOfficerName(customerSearchDto.getLoanOfficerName());
            clientSearchResultDto.setLoanOfficerId(customerSearchDto.getLoanOffcerGlobalNum());
            for (Object loanGlobalAccount : customerSearchDto.getLoanGlobalAccountNum()) {
                String accountStr = (String) loanGlobalAccount;
                clientSearchResultDto.getLoanGlobalAccountNum().add(accountStr);
                clientSearchResultDto.getLoanGlobalAccountStateIds().put(accountStr, loanDao.findByGlobalAccountNum(accountStr).getAccountState().getId());
            }
            for (Object savingGlobalAccount : customerSearchDto.getSavingsGlobalAccountNum()) {
                String accountStr = (String) savingGlobalAccount;
                clientSearchResultDto.getSavingsGlobalAccountNum().add(accountStr);
                clientSearchResultDto.getSavingsGlobalAccountStateIds().put(accountStr, savingsDao.findBySystemId(accountStr).getState().getValue());
            }
            for (Object groupLoanAccount : customerSearchDto.getGroupLoanGlobalAccountNum()) {
                String accountStr = (String) groupLoanAccount;
                clientSearchResultDto.getGroupLoanGlobalAccountNum().add(accountStr);
                clientSearchResultDto.getGroupLoanGlobalAccountStateIds().put(accountStr, loanDao.findByGlobalAccountNum(accountStr).getAccountState().getId());
            }
            clientSearchResultDto.setStatus(customerSearchDto.getStatus());
            customerHierarchyDto.getClients().add(clientSearchResultDto);
        } else if (customerSearchDto.getCustomerType() == 2) {
            GroupSearchResultDto groupSearchResultDto = new GroupSearchResultDto();
            groupSearchResultDto.setOfficeId(customerSearchDto.getOfficeId());
            groupSearchResultDto.setOfficeName(customerSearchDto.getOfficeName());
            /* QueryResult.get returns CustomerSearchDto (as Group) with groupName as centerName, 
        		 * groupGobalCustNum as centerGobalCustNum and vice versa 
        		 */
            groupSearchResultDto.setGroupName(customerSearchDto.getCenterName());
            groupSearchResultDto.setGroupGlobalCustNum(customerSearchDto.getCenterGlobalCustNum());
            groupSearchResultDto.setCenterName(customerSearchDto.getGroupName());
            groupSearchResultDto.setCenterGlobalCustNum(customerSearchDto.getGroupGlobalCustNum());
            groupSearchResultDto.setBranchName(customerSearchDto.getBranchName());
            groupSearchResultDto.setBranchId(customerSearchDto.getBranchGlobalNum());
            groupSearchResultDto.setCustomerStatusId(customerSearchDto.getCustomerStatus());
            groupSearchResultDto.setLoanOfficerName(customerSearchDto.getLoanOfficerName());
            groupSearchResultDto.setLoanOfficerId(customerSearchDto.getLoanOffcerGlobalNum());
            for (Object loanGlobalAccount : customerSearchDto.getLoanGlobalAccountNum()) {
                String accountStr = (String) loanGlobalAccount;
                groupSearchResultDto.getLoanGlobalAccountNum().add(accountStr);
                groupSearchResultDto.getLoanGlobalAccountStateIds().put(accountStr, loanDao.findByGlobalAccountNum(accountStr).getAccountState().getId());
            }
            for (Object savingGlobalAccount : customerSearchDto.getSavingsGlobalAccountNum()) {
                String accountStr = (String) savingGlobalAccount;
                groupSearchResultDto.getSavingsGlobalAccountNum().add(accountStr);
                groupSearchResultDto.getSavingsGlobalAccountStateIds().put(accountStr, savingsDao.findBySystemId(accountStr).getState().getValue());
            }
            for (Object groupLoanAccount : customerSearchDto.getGroupLoanGlobalAccountNum()) {
                String accountStr = (String) groupLoanAccount;
                groupSearchResultDto.getGroupLoanGlobalAccountNum().add(accountStr);
                groupSearchResultDto.getGroupLoanGlobalAccountStateIds().put(accountStr, loanDao.findByGlobalAccountNum(accountStr).getAccountState().getId());
            }
            groupSearchResultDto.setStatus(customerSearchDto.getStatus());
            customerHierarchyDto.getGroups().add(groupSearchResultDto);
        } else if (customerSearchDto.getCustomerType() == 3) {
            CenterSearchResultDto centerSearchResultDto = new CenterSearchResultDto();
            centerSearchResultDto.setOfficeId(customerSearchDto.getOfficeId());
            centerSearchResultDto.setOfficeName(customerSearchDto.getOfficeName());
            centerSearchResultDto.setCenterName(customerSearchDto.getCenterName());
            centerSearchResultDto.setCenterGlobalCustNum(customerSearchDto.getCenterGlobalCustNum());
            centerSearchResultDto.setBranchName(customerSearchDto.getBranchName());
            centerSearchResultDto.setBranchId(customerSearchDto.getBranchGlobalNum());
            centerSearchResultDto.setCustomerStatusId(customerSearchDto.getCustomerStatus());
            centerSearchResultDto.setLoanOfficerName(customerSearchDto.getLoanOfficerName());
            centerSearchResultDto.setLoanOfficerId(customerSearchDto.getLoanOffcerGlobalNum());
            for (Object savingGlobalAccount : customerSearchDto.getSavingsGlobalAccountNum()) {
                String accountStr = (String) savingGlobalAccount;
                centerSearchResultDto.getSavingsGlobalAccountNum().add(accountStr);
                centerSearchResultDto.getSavingsGlobalAccountStateIds().put(accountStr, savingsDao.findBySystemId(accountStr).getState().getValue());
            }
            centerSearchResultDto.setStatus(customerSearchDto.getStatus());
            customerHierarchyDto.getCenters().add(centerSearchResultDto);
        } else if (customerSearchDto.getLoanGlobalAccountNumber() != null && (customerSearchDto.getCustomerType() == 5 || customerSearchDto.getCustomerType() == 4 || customerSearchDto.getCustomerType() == 9) || customerSearchDto.getCustomerType() == 10) {
            LoanAccountSearchResultDto loanAccountSearchResultDto = new LoanAccountSearchResultDto();
            loanAccountSearchResultDto.setLoanGlobalAccountNum(customerSearchDto.getLoanGlobalAccountNumber());
            loanAccountSearchResultDto.setOfficeId(customerSearchDto.getOfficeId());
            loanAccountSearchResultDto.setOfficeName(customerSearchDto.getOfficeName());
            loanAccountSearchResultDto.setBranchName(customerSearchDto.getBranchName());
            loanAccountSearchResultDto.setBranchId(customerSearchDto.getBranchGlobalNum());
            loanAccountSearchResultDto.setAccountStatusId(customerSearchDto.getCustomerStatus());
            loanAccountSearchResultDto.setLoanOfficerName(customerSearchDto.getLoanOfficerName());
            loanAccountSearchResultDto.setLoanOfficerId(customerSearchDto.getLoanOffcerGlobalNum());
            //new group loan group or client account
            if (customerSearchDto.getCustomerType() == 9 || customerSearchDto.getCustomerType() == 10) {
                loanAccountSearchResultDto.setGroupLoan(Boolean.TRUE);
                loanAccountSearchResultDto.setAccountStatusId(AccountTypes.GROUP_LOAN_ACCOUNT.getValue());
            }
            if (customerSearchDto.getClientGlobalCustNum() != null) {
                loanAccountSearchResultDto.setCenterName(customerSearchDto.getClientName());
                loanAccountSearchResultDto.setCenterGlobalCustNum(customerSearchDto.getClientGlobalCustNum());
                loanAccountSearchResultDto.setClientName(customerSearchDto.getCenterName());
                loanAccountSearchResultDto.setClientGlobalCustNum(customerSearchDto.getCenterGlobalCustNum());
                loanAccountSearchResultDto.setGroupName(customerSearchDto.getGroupName());
                loanAccountSearchResultDto.setGroupGlobalCustNum(customerSearchDto.getGroupGlobalCustNum());
            } else if (customerSearchDto.getCustomerType() == 5 || customerSearchDto.getCustomerType() == 9) {
                loanAccountSearchResultDto.setGroupName(customerSearchDto.getCenterName());
                loanAccountSearchResultDto.setGroupGlobalCustNum(customerSearchDto.getCenterGlobalCustNum());
                loanAccountSearchResultDto.setCenterName(customerSearchDto.getGroupName());
                loanAccountSearchResultDto.setCenterGlobalCustNum(customerSearchDto.getGroupGlobalCustNum());
            } else {
                loanAccountSearchResultDto.setClientName(customerSearchDto.getCenterName());
                loanAccountSearchResultDto.setClientGlobalCustNum(customerSearchDto.getCenterGlobalCustNum());
                loanAccountSearchResultDto.setGroupName(customerSearchDto.getClientName());
                loanAccountSearchResultDto.setGroupGlobalCustNum(customerSearchDto.getClientGlobalCustNum());
                loanAccountSearchResultDto.setCenterName(customerSearchDto.getGroupName());
                loanAccountSearchResultDto.setCenterGlobalCustNum(customerSearchDto.getGroupGlobalCustNum());
            }
            loanAccountSearchResultDto.setStatus(customerSearchDto.getStatus());
            customerHierarchyDto.setLoan(loanAccountSearchResultDto);
        } else if (customerSearchDto.getLoanGlobalAccountNumber() != null || customerSearchDto.getCustomerType() == 6) {
            SavingsAccountSearchResultDto savingsAccountSearchResultDto = new SavingsAccountSearchResultDto();
            savingsAccountSearchResultDto.setSavingsGlobalAccountNum(customerSearchDto.getLoanGlobalAccountNumber());
            savingsAccountSearchResultDto.setOfficeId(customerSearchDto.getOfficeId());
            savingsAccountSearchResultDto.setOfficeName(customerSearchDto.getOfficeName());
            savingsAccountSearchResultDto.setBranchName(customerSearchDto.getBranchName());
            savingsAccountSearchResultDto.setBranchId(customerSearchDto.getBranchGlobalNum());
            savingsAccountSearchResultDto.setAccountStatusId(customerSearchDto.getCustomerStatus());
            savingsAccountSearchResultDto.setLoanOfficerName(customerSearchDto.getLoanOfficerName());
            savingsAccountSearchResultDto.setLoanOfficerId(customerSearchDto.getLoanOffcerGlobalNum());
            if (customerSearchDto.getClientGlobalCustNum() != null) {
                savingsAccountSearchResultDto.setCenterName(customerSearchDto.getClientName());
                savingsAccountSearchResultDto.setCenterGlobalCustNum(customerSearchDto.getClientGlobalCustNum());
                savingsAccountSearchResultDto.setClientName(customerSearchDto.getCenterName());
                savingsAccountSearchResultDto.setClientGlobalCustNum(customerSearchDto.getCenterGlobalCustNum());
                savingsAccountSearchResultDto.setGroupName(customerSearchDto.getGroupName());
                savingsAccountSearchResultDto.setGroupGlobalCustNum(customerSearchDto.getGroupGlobalCustNum());
            } else if (customerSearchDto.getGroupGlobalCustNum() != null) {
                savingsAccountSearchResultDto.setClientName(customerSearchDto.getClientName());
                savingsAccountSearchResultDto.setClientGlobalCustNum(customerSearchDto.getClientGlobalCustNum());
                savingsAccountSearchResultDto.setGroupName(customerSearchDto.getCenterName());
                savingsAccountSearchResultDto.setGroupGlobalCustNum(customerSearchDto.getCenterGlobalCustNum());
                savingsAccountSearchResultDto.setCenterName(customerSearchDto.getGroupName());
                savingsAccountSearchResultDto.setCenterGlobalCustNum(customerSearchDto.getGroupGlobalCustNum());
            } else {
                savingsAccountSearchResultDto.setCenterName(customerSearchDto.getCenterName());
                savingsAccountSearchResultDto.setCenterGlobalCustNum(customerSearchDto.getCenterGlobalCustNum());
            }
            savingsAccountSearchResultDto.setStatus(customerSearchDto.getStatus());
            customerHierarchyDto.setSavings(savingsAccountSearchResultDto);
        }
    }
    return customerHierarchyDto;
}
Also used : SavingsAccountSearchResultDto(org.mifos.dto.screen.SavingsAccountSearchResultDto) UserContext(org.mifos.security.util.UserContext) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) LoanAccountSearchResultDto(org.mifos.dto.screen.LoanAccountSearchResultDto) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) CenterSearchResultDto(org.mifos.dto.screen.CenterSearchResultDto) ClientSearchResultDto(org.mifos.dto.screen.ClientSearchResultDto) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) CustomerHierarchyDto(org.mifos.dto.screen.CustomerHierarchyDto) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerSearchDto(org.mifos.customers.business.CustomerSearchDto) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) GroupSearchResultDto(org.mifos.dto.screen.GroupSearchResultDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

QueryResult (org.mifos.framework.hibernate.helper.QueryResult)53 Test (org.junit.Test)30 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)14 ArrayList (java.util.ArrayList)13 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)10 QueryInputs (org.mifos.framework.hibernate.helper.QueryInputs)10 Param (org.mifos.customers.util.helpers.Param)9 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 UserContext (org.mifos.security.util.UserContext)7 MifosUser (org.mifos.security.MifosUser)5 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)4 List (java.util.List)3 Query (org.hibernate.Query)3 Session (org.hibernate.Session)3 AccountSearchResultsDto (org.mifos.accounts.util.helpers.AccountSearchResultsDto)3 CustomerSearchDto (org.mifos.customers.business.CustomerSearchDto)3 CustomerException (org.mifos.customers.exceptions.CustomerException)3 CustomerSearchResultDto (org.mifos.dto.domain.CustomerSearchResultDto)3 Date (java.sql.Date)2