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;
}
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));
}
}
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;
}
Aggregations