Search in sources :

Example 16 with QueryResult

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

the class CustomerPersistenceIntegrationTest method testSearchClosedClients.

@Test
public void testSearchClosedClients() throws Exception {
    createCustomers(CustomerStatus.GROUP_ACTIVE, CustomerStatus.CLIENT_CLOSED);
    StaticHibernateUtil.flushSession();
    Integer activeStatus = CustomerStatus.CLIENT_CLOSED.getValue().intValue();
    filters.getCustomerStates().put(CustomerLevel.CLIENT.toString(), activeStatus);
    QueryResult queryResult = new CustomerPersistence().search("Client", Short.valueOf("0"), Short.valueOf("1"), Short.valueOf("1"), filters);
    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 17 with QueryResult

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

the class CustomerPersistenceIntegrationTest method testSearchWithoutCenters.

@Test
public void testSearchWithoutCenters() throws Exception {
    createCustomers(CustomerStatus.GROUP_ACTIVE, CustomerStatus.CLIENT_ACTIVE);
    StaticHibernateUtil.flushSession();
    setCustomerSearch(CustomerLevel.CENTER, false);
    QueryResult queryResult = new CustomerPersistence().search("C", Short.valueOf("0"), Short.valueOf("1"), Short.valueOf("1"), filters);
    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 18 with QueryResult

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

the class CustomerServiceFacadeWebTier method search.

@Override
public CustomerSearch search(String searchString) throws ApplicationException {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    if (searchString == null) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    String normalisedSearchString = org.mifos.framework.util.helpers.SearchUtils.normalizeSearchString(searchString);
    if (normalisedSearchString.equals("")) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    String officeId = userContext.getBranchId().toString();
    String officeName = this.officeDao.findOfficeDtoById(userContext.getBranchId()).getName();
    PersonnelBO loggedInUser = personnelDao.findPersonnelById(userContext.getId());
    QueryResult searchResult = customerDao.search(normalisedSearchString, loggedInUser);
    return new CustomerSearch(searchResult, searchString, officeId, officeName);
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser)

Example 19 with QueryResult

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

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

the class LegacyPersonnelDao method getAllPersonnelNotes.

public QueryResult getAllPersonnelNotes(Short personnelId) throws PersistenceException {
    QueryResult notesResult = null;
    try {
        Session session = null;
        notesResult = QueryFactory.getQueryResult("NotesSearch");
        session = StaticHibernateUtil.getSessionTL();
        Query query = session.getNamedQuery(NamedQueryConstants.GETALLPERSONNELNOTES);
        query.setInteger("PERSONNEL_ID", personnelId);
        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)

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