Search in sources :

Example 1 with Param

use of org.mifos.customers.util.helpers.Param 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 2 with Param

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

the class CustomerPersistence method mainSearch.

private QueryResult mainSearch(final String searchString, final Short officeId, final Short userId, final Short userOfficeId, final SearchFiltersDto filters) throws PersistenceException, HibernateSearchException {
    String[] namedQuery = new String[2];
    List<Param> paramList = new ArrayList<Param>();
    QueryInputs queryInputs = setQueryInputsValues(namedQuery, paramList);
    QueryResult queryResult = QueryFactory.getQueryResult(CustomerSearchConstants.CUSTOMERSEARCHRESULTS);
    if (officeId.shortValue() != 0) {
        namedQuery[0] = NamedQueryConstants.CUSTOMER_SEARCH_COUNT;
        namedQuery[1] = NamedQueryConstants.CUSTOMER_SEARCH;
        paramList.add(typeNameValue("Short", "OFFICEID", officeId));
    } else {
        namedQuery[0] = NamedQueryConstants.CUSTOMER_SEARCH_COUNT_NOOFFICEID;
        namedQuery[1] = NamedQueryConstants.CUSTOMER_SEARCH_NOOFFICEID;
        paramList.add(typeNameValue("String", "OFFICE_SEARCH_ID", new OfficePersistence().getOffice(userOfficeId).getSearchId() + "%"));
    }
    paramList.add(typeNameValue("String", "SEARCH_STRING", "%" + searchString + "%"));
    if (searchString.contains(" ")) {
        List<String> words = new ArrayList<String>(Arrays.asList(searchString.split(" +")));
        // strings to get exactly 3 words
        if (words.size() > 3) {
            for (int i = 3; i < words.size(); ++i) {
                words.set(2, words.get(2) + " " + words.get(i));
            }
            words = words.subList(0, 3);
        } else if (words.size() < 3) {
            int elementsToAdd = 3 - words.size();
            for (int i = 0; i < elementsToAdd; ++i) {
                words.add("");
            }
        }
        paramList.add(typeNameValue("String", "SEARCH_STRING1", "%" + words.get(0) + "%"));
        paramList.add(typeNameValue("String", "SEARCH_STRING2", "%" + words.get(1) + "%"));
        paramList.add(typeNameValue("String", "SEARCH_STRING3", "%" + words.get(2) + "%"));
    } else {
        paramList.add(typeNameValue("String", "SEARCH_STRING1", searchString));
        paramList.add(typeNameValue("String", "SEARCH_STRING2", ""));
        paramList.add(typeNameValue("String", "SEARCH_STRING3", ""));
    }
    setParams(paramList, userId);
    setSearchFilters(paramList, filters);
    queryResult.setQueryInputs(queryInputs);
    return queryResult;
}
Also used : QueryResult(org.mifos.framework.hibernate.helper.QueryResult) ArrayList(java.util.ArrayList) Param(org.mifos.customers.util.helpers.Param) QueryInputs(org.mifos.framework.hibernate.helper.QueryInputs) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence)

Example 3 with Param

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

the class CustomerDaoHibernate method search.

@Override
public QueryResult search(String searchString, PersonnelBO user) {
    String[] namedQuery = new String[2];
    List<Param> paramList = new ArrayList<Param>();
    QueryInputs queryInputs = new QueryInputs();
    QueryResult queryResult = QueryFactory.getQueryResult(PersonnelConstants.USER_LIST);
    String officeSearchId = user.getOffice().getSearchId();
    namedQuery[0] = NamedQueryConstants.CENTER_SEARCH_COUNT;
    namedQuery[1] = NamedQueryConstants.CENTER_SEARCH;
    paramList.add(typeNameValue("String", "SEARCH_ID", officeSearchId + "%"));
    paramList.add(typeNameValue("String", "CENTER_NAME", "%" + searchString + "%"));
    paramList.add(typeNameValue("Short", "LEVEL_ID", CustomerLevel.CENTER.getValue()));
    paramList.add(typeNameValue("Short", "STATUS_ID", CustomerStatus.CENTER_ACTIVE.getValue()));
    paramList.add(typeNameValue("Short", "USER_ID", user.getPersonnelId()));
    paramList.add(typeNameValue("Short", "USER_LEVEL_ID", user.getLevelEnum().getValue()));
    paramList.add(typeNameValue("Short", "LO_LEVEL_ID", PersonnelConstants.LOAN_OFFICER));
    String[] aliasNames = { "parentOfficeId", "parentOfficeName", "centerSystemId", "centerName" };
    queryInputs.setQueryStrings(namedQuery);
    queryInputs.setPath("org.mifos.customers.center.util.helpers.CenterSearchResultsDto");
    queryInputs.setAliasNames(aliasNames);
    queryInputs.setParamList(paramList);
    try {
        queryResult.setQueryInputs(queryInputs);
    } catch (HibernateSearchException e) {
        throw new MifosRuntimeException(e);
    }
    return queryResult;
}
Also used : QueryResult(org.mifos.framework.hibernate.helper.QueryResult) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) Param(org.mifos.customers.util.helpers.Param) QueryInputs(org.mifos.framework.hibernate.helper.QueryInputs) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 4 with Param

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

the class CustomerPersistence method idSearch.

private QueryResult idSearch(final String searchString, final Short officeId, final Short userId) throws HibernateSearchException, SystemException, PersistenceException {
    if (!isCustomerExist(searchString)) {
        return null;
    }
    String[] namedQuery = new String[2];
    List<Param> paramList = new ArrayList<Param>();
    QueryInputs queryInputs = new QueryInputs();
    String[] Names = { "customerId", "centerName", "centerGlobalCustNum", "customerType", "branchGlobalNum", "branchName", "loanOfficerName", "loanOffcerGlobalNum", "customerStatus", "groupName", "groupGlobalCustNum", "clientName", "clientGlobalCustNum", "loanGlobalAccountNumber" };
    QueryResult queryResult = QueryFactory.getQueryResult(CustomerSearchConstants.CUSTOMERSEARCHRESULTS);
    queryInputs.setPath("org.mifos.customers.business.CustomerSearchDto");
    queryInputs.setAliasNames(Names);
    queryResult.setQueryInputs(queryInputs);
    queryInputs.setQueryStrings(namedQuery);
    queryInputs.setParamList(paramList);
    PersonnelBO personnel = getLegacyPersonnelDao().getPersonnel(userId);
    if (officeId != null && officeId.shortValue() == 0) {
        namedQuery[0] = NamedQueryConstants.CUSTOMER_ID_SEARCH_NOOFFICEID_COUNT;
        namedQuery[1] = NamedQueryConstants.CUSTOMER_ID_SEARCH_NOOFFICEID;
        if (personnel.getLevelEnum() == PersonnelLevel.LOAN_OFFICER) {
            paramList.add(typeNameValue("String", "SEARCH_ID", personnel.getOffice().getSearchId()));
        } else {
            paramList.add(typeNameValue("String", "SEARCH_ID", personnel.getOffice().getSearchId() + "%"));
        }
    } else {
        paramList.add(typeNameValue("Short", "OFFICEID", officeId));
        if (personnel.getLevelEnum() == PersonnelLevel.LOAN_OFFICER) {
            paramList.add(typeNameValue("String", "ID", personnel.getPersonnelId()));
            namedQuery[0] = NamedQueryConstants.CUSTOMER_ID_SEARCH_COUNT;
            namedQuery[1] = NamedQueryConstants.CUSTOMER_ID_SEARCH;
        } else {
            paramList.add(typeNameValue("String", "SEARCH_ID", personnel.getOffice().getSearchId() + "%"));
            namedQuery[0] = NamedQueryConstants.CUSTOMER_ID_SEARCH_COUNT_NONLO;
            namedQuery[1] = NamedQueryConstants.CUSTOMER_ID_SEARCH_NONLO;
        }
    }
    paramList.add(typeNameValue("String", "SEARCH_STRING", searchString));
    return queryResult;
}
Also used : QueryResult(org.mifos.framework.hibernate.helper.QueryResult) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ArrayList(java.util.ArrayList) Param(org.mifos.customers.util.helpers.Param) QueryInputs(org.mifos.framework.hibernate.helper.QueryInputs)

Example 5 with Param

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

the class CustomerPersistence method searchCustForSavings.

public QueryResult searchCustForSavings(final String searchString, final Short userId) throws PersistenceException {
    String[] namedQuery = new String[2];
    List<Param> paramList = new ArrayList<Param>();
    QueryInputs queryInputs = new QueryInputs();
    QueryResult queryResult = QueryFactory.getQueryResult(CustomerSearchConstants.CUSTOMERSFORSAVINGSACCOUNT);
    PersonnelBO personnel = getLegacyPersonnelDao().getPersonnel(userId);
    if (personnel.getLevelEnum() == PersonnelLevel.LOAN_OFFICER) {
        namedQuery[0] = NamedQueryConstants.SEARCH_CUSTOMER_FOR_SAVINGS_COUNT;
        namedQuery[1] = NamedQueryConstants.SEARCH_CUSTOMER_FOR_SAVINGS;
        paramList.add(typeNameValue("Short", "PERSONNEL_ID", userId));
    } else {
        namedQuery[0] = NamedQueryConstants.SEARCH_CUSTOMER_FOR_SAVINGS_COUNT_NOLO;
        namedQuery[1] = NamedQueryConstants.SEARCH_CUSTOMER_FOR_SAVINGS_NOLO;
    }
    paramList.add(typeNameValue("String", "SEARCH_ID", personnel.getOffice().getSearchId() + "%"));
    paramList.add(typeNameValue("String", "SEARCH_STRING", "%" + searchString + "%"));
    String[] aliasNames = { "clientName", "clientId", "groupName", "centerName", "officeName", "globelNo" };
    queryInputs.setQueryStrings(namedQuery);
    queryInputs.setPath("org.mifos.accounts.util.helpers.AccountSearchResultsDto");
    queryInputs.setAliasNames(aliasNames);
    queryInputs.setParamList(paramList);
    try {
        queryResult.setQueryInputs(queryInputs);
    } catch (HibernateSearchException e) {
        throw new PersistenceException(e);
    }
    return queryResult;
}
Also used : QueryResult(org.mifos.framework.hibernate.helper.QueryResult) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) 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)

Aggregations

ArrayList (java.util.ArrayList)10 Param (org.mifos.customers.util.helpers.Param)10 QueryInputs (org.mifos.framework.hibernate.helper.QueryInputs)9 QueryResult (org.mifos.framework.hibernate.helper.QueryResult)9 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)8 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)6 PersistenceException (org.mifos.framework.exceptions.PersistenceException)6 List (java.util.List)1 Query (org.hibernate.Query)1 AccountBO (org.mifos.accounts.business.AccountBO)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 OfficePersistence (org.mifos.customers.office.persistence.OfficePersistence)1 QueryResultAccountIdSearch (org.mifos.framework.hibernate.helper.QueryResultAccountIdSearch)1