Search in sources :

Example 6 with OfficeException

use of org.mifos.customers.office.exceptions.OfficeException 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 7 with OfficeException

use of org.mifos.customers.office.exceptions.OfficeException in project head by mifos.

the class OfficeDaoHibernate method validateOfficeNameIsNotTaken.

@SuppressWarnings("unchecked")
@Override
public void validateOfficeNameIsNotTaken(String officeName) throws OfficeException {
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("OFFICE_NAME", officeName);
    List queryResult = this.genericDao.executeNamedQuery("office.getOfficeWithName", queryParameters);
    int officeCount = ((Number) queryResult.get(0)).intValue();
    if (officeCount > 0) {
        throw new OfficeException(OfficeConstants.OFFICENAMEEXIST);
    }
}
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 8 with OfficeException

use of org.mifos.customers.office.exceptions.OfficeException in project head by mifos.

the class OfficeServiceFacadeWebTier method generateOfficeGlobalNo.

private 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 9 with OfficeException

use of org.mifos.customers.office.exceptions.OfficeException in project head by mifos.

the class OfficeServiceFacadeWebTier method createOffice.

@Override
public ListElement createOffice(Short operationMode, OfficeDto officeDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    OfficeLevel level = OfficeLevel.getOfficeLevel(officeDto.getLevelId());
    OfficeBO parentOffice = officeDao.findOfficeById(officeDto.getParentId());
    AddressDto addressDto = officeDto.getAddress();
    Address address = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
    try {
        OfficeBO officeBO = new OfficeBO(userContext, level, parentOffice, officeDto.getCustomFields(), officeDto.getName(), officeDto.getOfficeShortName(), address, OperationMode.fromInt(operationMode.intValue()));
        OfficePersistence officePersistence = new OfficePersistence();
        if (officePersistence.isOfficeNameExist(officeDto.getName())) {
            throw new OfficeValidationException(OfficeConstants.OFFICENAMEEXIST);
        }
        if (officePersistence.isOfficeShortNameExist(officeDto.getOfficeShortName())) {
            throw new OfficeValidationException(OfficeConstants.OFFICESHORTNAMEEXIST);
        }
        String searchId = generateSearchId(parentOffice);
        officeBO.setSearchId(searchId);
        String globalOfficeNum = generateOfficeGlobalNo();
        officeBO.setGlobalOfficeNum(globalOfficeNum);
        StaticHibernateUtil.startTransaction();
        this.officeDao.save(officeBO);
        StaticHibernateUtil.commitTransaction();
        //Shahid - this is hackish solution to return officeId and globalOfficeNum via ListElement, it should be fixed, at least
        //a proper data storage class can be created
        ListElement element = new ListElement(new Integer(officeBO.getOfficeId()), officeBO.getGlobalOfficeNum());
        // if we are here it means office created sucessfully
        // we need to update hierarchy manager cache
        OfficeSearch os = new OfficeSearch(officeBO.getOfficeId(), officeBO.getSearchId(), officeBO.getParentOffice().getOfficeId());
        List<OfficeSearch> osList = new ArrayList<OfficeSearch>();
        osList.add(os);
        EventManger.postEvent(Constants.CREATE, osList, SecurityConstants.OFFICECHANGEEVENT);
        return element;
    } catch (OfficeValidationException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BusinessRuleException(e.getMessage());
    } catch (PersistenceException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (OfficeException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) OfficeValidationException(org.mifos.customers.office.exceptions.OfficeValidationException) Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) OfficeSearch(org.mifos.security.util.OfficeSearch) AddressDto(org.mifos.dto.domain.AddressDto) BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeBO(org.mifos.customers.office.business.OfficeBO) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) OfficeLevel(org.mifos.customers.office.util.helpers.OfficeLevel) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 10 with OfficeException

use of org.mifos.customers.office.exceptions.OfficeException in project head by mifos.

the class OfficeDaoHibernate method validateNoActiveChildrenExist.

@SuppressWarnings("unchecked")
@Override
public void validateNoActiveChildrenExist(Short officeId) throws OfficeException {
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("OFFICE_ID", officeId);
    List queryResult = this.genericDao.executeNamedQuery("getCountOfActiveChildren", queryParameters);
    int activeChildren = ((Number) queryResult.get(0)).intValue();
    if (activeChildren > 0) {
        throw new OfficeException(OfficeConstants.KEYHASACTIVECHILDREN);
    }
}
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)

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