use of org.mifos.customers.office.exceptions.OfficeException 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.customers.office.exceptions.OfficeException 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.customers.office.exceptions.OfficeException in project head by mifos.
the class TestObjectFactory method generateOfficeGlobalNo.
private static String generateOfficeGlobalNo() throws OfficeException {
try {
/*
* TODO: Why not auto-increment? Fetching the max and adding one would seem to have a race condition.
*/
String officeGlobelNo = String.valueOf(new OfficePersistence().getMaxOfficeId().intValue() + 1);
if (officeGlobelNo.length() > 4) {
throw new OfficeException(OfficeConstants.MAXOFFICELIMITREACHED);
}
StringBuilder temp = new StringBuilder("");
for (int i = officeGlobelNo.length(); i < 4; i++) {
temp.append("0");
}
return officeGlobelNo = temp.append(officeGlobelNo).toString();
} catch (PersistenceException e) {
throw new OfficeException(e);
}
}
use of org.mifos.customers.office.exceptions.OfficeException in project head by mifos.
the class OfficeDaoHibernate method validateOfficeShortNameIsNotTaken.
@SuppressWarnings("unchecked")
@Override
public void validateOfficeShortNameIsNotTaken(String shortName) throws OfficeException {
HashMap<String, Object> queryParameters = new HashMap<String, Object>();
queryParameters.put("SHORT_NAME", shortName);
List queryResult = this.genericDao.executeNamedQuery("office.getOfficeWithShortName", queryParameters);
int officeCount = ((Number) queryResult.get(0)).intValue();
if (officeCount > 0) {
throw new OfficeException(OfficeConstants.OFFICESHORTNAMEEXIST);
}
}
use of org.mifos.customers.office.exceptions.OfficeException in project head by mifos.
the class OfficeServiceFacadeWebTier method updateOffice.
@Override
public boolean updateOffice(Short officeId, Integer versionNum, OfficeUpdateRequest officeUpdateRequest) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
try {
boolean isParentOfficeChanged = false;
OfficeBO office = officeDao.findOfficeById(officeId);
office.validateVersion(versionNum);
OfficeBO parentOffice = null;
if (officeUpdateRequest.getParentOfficeId() != null) {
parentOffice = officeDao.findOfficeById(officeUpdateRequest.getParentOfficeId());
if (office.isDifferentParentOffice(parentOffice)) {
holidayDao.validateNoExtraFutureHolidaysApplicableOnParentOffice(office.getParentOffice().getOfficeId(), officeUpdateRequest.getParentOfficeId());
}
}
if (office.isNameDifferent(officeUpdateRequest.getOfficeName())) {
officeDao.validateOfficeNameIsNotTaken(officeUpdateRequest.getOfficeName());
}
if (office.isShortNameDifferent(officeUpdateRequest.getShortName())) {
officeDao.validateOfficeShortNameIsNotTaken(officeUpdateRequest.getShortName());
}
OfficeStatus newStatus = OfficeStatus.getOfficeStatus(officeUpdateRequest.getNewStatus());
if (!office.isStatusDifferent(newStatus)) {
if (OfficeStatus.INACTIVE.equals(officeUpdateRequest.getNewStatus())) {
officeDao.validateNoActiveChildrenExist(office.getOfficeId());
officeDao.validateNoActivePeronnelExist(office.getOfficeId());
}
if (parentOffice != null) {
if (parentOffice.isInActive()) {
throw new OfficeException(OfficeConstants.KEYPARENTNOTACTIVE);
}
}
}
StaticHibernateUtil.startTransaction();
office.update(userContext, officeUpdateRequest, parentOffice);
StaticHibernateUtil.commitTransaction();
return isParentOfficeChanged;
} catch (OfficeException e1) {
throw new BusinessRuleException(e1.getKey(), e1);
} catch (ApplicationException e) {
StaticHibernateUtil.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e.getMessage(), e);
} finally {
StaticHibernateUtil.closeSession();
}
}
Aggregations