Search in sources :

Example 1 with OfficePersistence

use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.

the class OfficeServiceFacadeWebTier method retrieveActiveBranchesUnderUser.

@Override
public List<OfficeDto> retrieveActiveBranchesUnderUser(Short userId) {
    PersonnelBO personnel = personnelDao.findPersonnelById(userId);
    try {
        List<OfficeBO> officesListBO = new OfficePersistence().getActiveBranchesUnderUser(personnel.getOfficeSearchId());
        List<OfficeDto> officesList = new ArrayList<OfficeDto>();
        for (OfficeBO officeBO : officesListBO) {
            OfficeDto officeDto = new OfficeDto(officeBO.getOfficeId(), officeBO.getOfficeName(), officeBO.getSearchId(), officeBO.getShortName(), officeBO.getGlobalOfficeNum(), officeBO.getParentOffice().getOfficeId(), officeBO.getStatus().getId(), officeBO.getLevel().getId());
            officesList.add(officeDto);
        }
        return officesList;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : OfficeDto(org.mifos.dto.domain.OfficeDto) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) OfficeBO(org.mifos.customers.office.business.OfficeBO) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with OfficePersistence

use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.

the class OfficeServiceFacadeWebTier method retrieveOfficeDetailsForEdit.

@Override
public OfficeDetailsForEdit retrieveOfficeDetailsForEdit(String officeLevel) {
    List<OfficeDetailsDto> parents = new ArrayList<OfficeDetailsDto>();
    if (StringUtils.isNotBlank(officeLevel)) {
        parents = retrieveActiveParentOffices(Short.valueOf(officeLevel));
    }
    try {
        List<OfficeDetailsDto> configuredOfficeLevels = new OfficePersistence().getActiveLevels();
        for (OfficeDetailsDto officeDetailsDto : configuredOfficeLevels) {
            String levelName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(officeDetailsDto.getLevelNameKey());
            officeDetailsDto.setLevelName(levelName);
        }
        List<OfficeDetailsDto> statusList = new OfficePersistence().getStatusList();
        for (OfficeDetailsDto officeDetailsDto : statusList) {
            officeDetailsDto.setLevelName(ApplicationContextProvider.getBean(MessageLookup.class).lookup(officeDetailsDto.getLevelNameKey()));
        }
        return new OfficeDetailsForEdit(parents, statusList, configuredOfficeLevels);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : MessageLookup(org.mifos.application.master.MessageLookup) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficeDetailsForEdit(org.mifos.dto.screen.OfficeDetailsForEdit) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) OfficeDetailsDto(org.mifos.dto.domain.OfficeDetailsDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with OfficePersistence

use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.

the class OfficeServiceFacadeWebTier method generateSearchId.

private String generateSearchId(OfficeBO parentOffice) throws OfficeException {
    Integer noOfChildern;
    try {
        noOfChildern = new OfficePersistence().getChildCount(parentOffice.getOfficeId());
    } catch (PersistenceException e) {
        throw new OfficeException(e);
    }
    String parentSearchId = HierarchyManager.getInstance().getSearchId(parentOffice.getOfficeId());
    parentSearchId += ++noOfChildern;
    parentSearchId += ".";
    return parentSearchId;
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence)

Example 4 with OfficePersistence

use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.

the class OfficeServiceFacadeWebTier method retrieveActiveParentOffices.

@Override
public List<OfficeDetailsDto> retrieveActiveParentOffices(Short officeLevelId) {
    OfficeLevel Level = OfficeLevel.getOfficeLevel(officeLevelId);
    try {
        List<OfficeDetailsDto> officeParents = new OfficePersistence().getActiveParents(Level);
        for (OfficeDetailsDto officeDetailsDto : officeParents) {
            String levelName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(officeDetailsDto.getLevelNameKey());
            officeDetailsDto.setLevelName(levelName);
        }
        return officeParents;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : MessageLookup(org.mifos.application.master.MessageLookup) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) OfficeDetailsDto(org.mifos.dto.domain.OfficeDetailsDto) OfficeLevel(org.mifos.customers.office.util.helpers.OfficeLevel) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with OfficePersistence

use of org.mifos.customers.office.persistence.OfficePersistence 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)

Aggregations

OfficePersistence (org.mifos.customers.office.persistence.OfficePersistence)37 PersistenceException (org.mifos.framework.exceptions.PersistenceException)17 OfficeBO (org.mifos.customers.office.business.OfficeBO)16 Test (org.junit.Test)11 MifosRuntimeException (org.mifos.core.MifosRuntimeException)11 OfficeException (org.mifos.customers.office.exceptions.OfficeException)11 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)8 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)8 ClientPersonalDetailDto (org.mifos.dto.screen.ClientPersonalDetailDto)8 ArrayList (java.util.ArrayList)7 CustomerException (org.mifos.customers.exceptions.CustomerException)7 ClientBO (org.mifos.customers.client.business.ClientBO)6 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)5 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)5 OfficeDetailsDto (org.mifos.dto.domain.OfficeDetailsDto)5 Date (java.util.Date)4 MessageLookup (org.mifos.application.master.MessageLookup)4 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)4 Address (org.mifos.framework.business.util.Address)4 ApplicationException (org.mifos.framework.exceptions.ApplicationException)4