Search in sources :

Example 6 with QueryResult

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

the class CustomerPersistence method getAllCustomerNotes.

public QueryResult getAllCustomerNotes(final Integer customerId) throws PersistenceException {
    QueryResult notesResult = null;
    try {
        Session session = null;
        notesResult = QueryFactory.getQueryResult("NotesSearch");
        session = StaticHibernateUtil.getSessionTL();
        Query query = session.getNamedQuery(NamedQueryConstants.GETALLCUSTOMERNOTES);
        query.setInteger("CUSTOMER_ID", customerId);
        notesResult.executeQuery(query);
    } catch (HibernateProcessException hpe) {
        throw new PersistenceException(hpe);
    } catch (HibernateSearchException hse) {
        throw new PersistenceException(hse);
    }
    return notesResult;
}
Also used : QueryResult(org.mifos.framework.hibernate.helper.QueryResult) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) Query(org.hibernate.Query) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) Session(org.hibernate.Session)

Example 7 with QueryResult

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

the class SavingsServiceFacadeWebTier method retrieveCustomerThatQualifyForSavings.

@Override
public List<CustomerSearchResultDto> retrieveCustomerThatQualifyForSavings(CustomerSearchDto customerSearchDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        List<CustomerSearchResultDto> pagedDetails = new ArrayList<CustomerSearchResultDto>();
        QueryResult customerForSavings = new CustomerPersistence().searchCustForSavings(customerSearchDto.getSearchTerm(), userContext.getId());
        int position = this.resultsetOffset(customerSearchDto.getPage(), customerSearchDto.getPageSize());
        List<AccountSearchResultsDto> pagedResults = customerForSavings.get(position, customerSearchDto.getPageSize());
        int i = 1;
        for (AccountSearchResultsDto customerBO : pagedResults) {
            CustomerSearchResultDto customer = new CustomerSearchResultDto();
            customer.setCustomerId(customerBO.getClientId());
            customer.setBranchName(customerBO.getOfficeName());
            customer.setGlobalId(customerBO.getGlobelNo());
            customer.setSearchIndex(i);
            customer.setCenterName(StringUtils.defaultIfEmpty(customerBO.getCenterName(), "--"));
            customer.setGroupName(StringUtils.defaultIfEmpty(customerBO.getGroupName(), "--"));
            customer.setClientName(customerBO.getClientName());
            pagedDetails.add(customer);
            i++;
        }
        return pagedDetails;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (HibernateSearchException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) AccountSearchResultsDto(org.mifos.accounts.util.helpers.AccountSearchResultsDto) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerSearchResultDto(org.mifos.dto.domain.CustomerSearchResultDto) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with QueryResult

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

the class CustSearchAction method search.

/**
     * FIXME: KEITHW - When replacing search functionality for customers with spring/ftl implementation,
     * find cleaner way of implementing search that returns a non domain related class (data only object)
     */
@Override
@TransactionDemarcate(joinToken = true)
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (request.getParameter("perspective") != null) {
        request.setAttribute("perspective", request.getParameter("perspective"));
    }
    ActionForward actionForward = super.search(mapping, form, request, response);
    CustSearchActionForm actionForm = (CustSearchActionForm) form;
    UserContext userContext = getUserContext(request);
    String searchString = actionForm.getSearchString();
    if (searchString == null) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    String officeName = this.centerServiceFacade.retrieveOfficeName(userContext.getBranchId());
    addSeachValues(searchString, userContext.getBranchId().toString(), officeName, request);
    searchString = SearchUtils.normalizeSearchString(searchString);
    if (StringUtils.isBlank(searchString)) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    if (actionForm.getInput() != null && actionForm.getInput().equals("loan")) {
        QueryResult groupClients = new CustomerPersistence().searchGroupClient(searchString, userContext.getId(), false);
        SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, groupClients, request);
    } else if (actionForm.getInput() != null && actionForm.getInput().equals("savings")) {
        QueryResult customerForSavings = new CustomerPersistence().searchCustForSavings(searchString, userContext.getId());
        SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, customerForSavings, request);
    }
    return actionForward;
}
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) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) ActionForward(org.apache.struts.action.ActionForward) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 9 with QueryResult

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

the class LegacyAccountDao method search.

public QueryResult search(String queryString, Short officeId) throws PersistenceException {
    AccountBO accountBO = findBySystemId(queryString);
    if (accountBO == null) {
        return null;
    }
    if (accountBO.getType() == AccountTypes.CUSTOMER_ACCOUNT || accountBO.getType() == AccountTypes.INDIVIDUAL_LOAN_ACCOUNT) {
        return null;
    }
    QueryResult queryResult = QueryFactory.getQueryResult(CustomerSearchConstants.LOANACCOUNTIDSEARCH);
    ((QueryResultAccountIdSearch) queryResult).setSearchString(queryString);
    String[] namedQuery = new String[2];
    List<Param> paramList = new ArrayList<Param>();
    QueryInputs queryInputs = new QueryInputs();
    String[] aliasNames = { "customerId", "centerName", "centerGlobalCustNum", "customerType", "branchGlobalNum", "branchName", "loanOfficerName", "loanOffcerGlobalNum", "customerStatus", "groupName", "groupGlobalCustNum", "clientName", "clientGlobalCustNum", "loanGlobalAccountNumber" };
    queryInputs.setPath("org.mifos.customers.business.CustomerSearchDto");
    queryInputs.setAliasNames(aliasNames);
    if (officeId != null) {
        if (officeId.shortValue() == 0) {
            namedQuery[0] = NamedQueryConstants.ACCOUNT_ID_SEARCH_NOOFFICEID_COUNT;
            namedQuery[1] = NamedQueryConstants.ACCOUNT_ID_SEARCH_NOOFFICEID;
        } else {
            namedQuery[0] = NamedQueryConstants.ACCOUNT_ID_SEARCH_COUNT;
            namedQuery[1] = NamedQueryConstants.ACCOUNT_ID_SEARCH;
            paramList.add(typeNameValue("Short", "OFFICEID", officeId));
        }
        paramList.add(typeNameValue("String", "SEARCH_STRING", queryString));
    }
    queryInputs.setQueryStrings(namedQuery);
    queryInputs.setParamList(paramList);
    try {
        queryResult.setQueryInputs(queryInputs);
    } catch (HibernateSearchException e) {
        throw new PersistenceException(e);
    }
    return queryResult;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) QueryResultAccountIdSearch(org.mifos.framework.hibernate.helper.QueryResultAccountIdSearch) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) Param(org.mifos.customers.util.helpers.Param) QueryInputs(org.mifos.framework.hibernate.helper.QueryInputs) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 10 with QueryResult

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

the class LegacyAccountDao method getAllAccountNotes.

public QueryResult getAllAccountNotes(Integer accountId) throws PersistenceException {
    QueryResult notesResult = null;
    try {
        Session session = null;
        notesResult = QueryFactory.getQueryResult("NotesSearch");
        session = StaticHibernateUtil.getSessionTL();
        Query query = session.getNamedQuery(NamedQueryConstants.GETALLACCOUNTNOTES);
        query.setInteger("accountId", accountId);
        notesResult.executeQuery(query);
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
    return notesResult;
}
Also used : QueryResult(org.mifos.framework.hibernate.helper.QueryResult) Query(org.hibernate.Query) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) Session(org.hibernate.Session)

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