Search in sources :

Example 1 with OfficeCacheDto

use of org.mifos.security.util.OfficeCacheDto in project head by mifos.

the class HierarchyManager method compareOfficeInHierarchy.

public BranchLocation compareOfficeInHierarchy(UserContext user, Short officeId) {
    Assert.notNull(officeId, "officeId should not be null");
    Assert.notNull(user, "userContext should not be null");
    short userBranch = user.getBranchId().shortValue();
    if (userBranch == officeId) {
        return BranchLocation.SAME;
    }
    /*
         * Look into the map now if the passed officeid's searchid on which user wants to perform action starts with the
         * user's office searchid it means that office falls under that user hiererchy
         */
    String userOfficeSearchId = hierarchyMap.get(user.getBranchId()).getSearchId();
    OfficeCacheDto cachedOffice = hierarchyMap.get(officeId);
    if (cachedOffice == null) {
        try {
            // repopulate cachedmap
            init();
            cachedOffice = hierarchyMap.get(officeId);
        } catch (SystemException e) {
            throw new MifosRuntimeException(e);
        } catch (OfficeException e) {
            throw new MifosRuntimeException(e);
        }
        if (cachedOffice == null) {
            throw new IllegalArgumentException("office with id [" + officeId + "] does not exist");
        }
    }
    String operatedOfficeSearchId = cachedOffice.getSearchId();
    if (operatedOfficeSearchId.startsWith(userOfficeSearchId)) {
        return BranchLocation.BELOW;
    }
    return BranchLocation.ABOVE_OR_DIFFERENT;
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) SystemException(org.mifos.framework.exceptions.SystemException) OfficeCacheDto(org.mifos.security.util.OfficeCacheDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with OfficeCacheDto

use of org.mifos.security.util.OfficeCacheDto in project head by mifos.

the class HierarchyManager method init.

public void init() throws SystemException, OfficeException {
    List<OfficeCacheDto> officeList;
    try {
        officeList = new OfficePersistence().getAllOffices();
    } catch (PersistenceException e) {
        throw new OfficeException(e);
    }
    hierarchyMap.clear();
    for (int i = 0; i < officeList.size(); i++) {
        addToMap(officeList.get(i));
    }
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficeCacheDto(org.mifos.security.util.OfficeCacheDto) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence)

Example 3 with OfficeCacheDto

use of org.mifos.security.util.OfficeCacheDto in project head by mifos.

the class HierarchyManager method convertToOfficeCacheList.

private List<OfficeCacheDto> convertToOfficeCacheList(List<OfficeSearch> officeList) {
    List<OfficeCacheDto> officeCacheList = new ArrayList<OfficeCacheDto>();
    for (int i = 0; i < officeList.size(); i++) {
        OfficeCacheDto cacheView = new OfficeCacheDto(officeList.get(i).getOfficeId(), officeList.get(i).getParentOfficeId(), officeList.get(i).getSearchId());
        officeCacheList.add(cacheView);
    }
    return officeCacheList;
}
Also used : ArrayList(java.util.ArrayList) OfficeCacheDto(org.mifos.security.util.OfficeCacheDto)

Aggregations

OfficeCacheDto (org.mifos.security.util.OfficeCacheDto)3 OfficeException (org.mifos.customers.office.exceptions.OfficeException)2 ArrayList (java.util.ArrayList)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 OfficePersistence (org.mifos.customers.office.persistence.OfficePersistence)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1 SystemException (org.mifos.framework.exceptions.SystemException)1