Search in sources :

Example 1 with OfficeException

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;
}
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 OfficeException

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

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

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);
    }
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 5 with OfficeException

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();
    }
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) OfficeBO(org.mifos.customers.office.business.OfficeBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) OfficeStatus(org.mifos.customers.office.util.helpers.OfficeStatus) OfficeValidationException(org.mifos.customers.office.exceptions.OfficeValidationException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficeException(org.mifos.customers.office.exceptions.OfficeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

OfficeException (org.mifos.customers.office.exceptions.OfficeException)12 PersistenceException (org.mifos.framework.exceptions.PersistenceException)7 OfficePersistence (org.mifos.customers.office.persistence.OfficePersistence)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 MifosRuntimeException (org.mifos.core.MifosRuntimeException)3 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)2 OfficeBO (org.mifos.customers.office.business.OfficeBO)2 OfficeValidationException (org.mifos.customers.office.exceptions.OfficeValidationException)2 MifosUser (org.mifos.security.MifosUser)2 OfficeCacheDto (org.mifos.security.util.OfficeCacheDto)2 UserContext (org.mifos.security.util.UserContext)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 CustomFieldDefinitionEntity (org.mifos.application.master.business.CustomFieldDefinitionEntity)1 OffActionForm (org.mifos.customers.office.struts.actionforms.OffActionForm)1 OfficeLevel (org.mifos.customers.office.util.helpers.OfficeLevel)1 OfficeStatus (org.mifos.customers.office.util.helpers.OfficeStatus)1 AddressDto (org.mifos.dto.domain.AddressDto)1