Search in sources :

Example 1 with OfficeLevelDto

use of org.mifos.dto.domain.OfficeLevelDto in project head by mifos.

the class OfficeDaoHibernateIntegrationTest method shouldRetrieveOfficeLevels.

@Test
public void shouldRetrieveOfficeLevels() throws Exception {
    OfficeLevelDto allOffices = officeDao.findOfficeLevelsWithConfiguration();
    // verification
    assertThat(allOffices.isHeadOfficeEnabled(), is(true));
    assertThat(allOffices.isBranchOfficeEnabled(), is(true));
    assertThat(allOffices.getHeadOfficeNameKey(), is(notNullValue()));
    assertThat(allOffices.getBranchOfficeNameKey(), is(notNullValue()));
}
Also used : OfficeLevelDto(org.mifos.dto.domain.OfficeLevelDto) Test(org.junit.Test)

Example 2 with OfficeLevelDto

use of org.mifos.dto.domain.OfficeLevelDto in project head by mifos.

the class OfficeDaoHibernate method findOfficeLevelsWithConfiguration.

@SuppressWarnings("unchecked")
@Override
public OfficeLevelDto findOfficeLevelsWithConfiguration() {
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    List<OfficeLevelEntity> officeLevelEntities = (List<OfficeLevelEntity>) genericDao.executeNamedQuery("officeLevel.getOfficeLevelsWithConfiguration", queryParameters);
    if (officeLevelEntities == null) {
        officeLevelEntities = new ArrayList<OfficeLevelEntity>();
    }
    OfficeLevelDto officeLevels = new OfficeLevelDto();
    for (OfficeLevelEntity officeLevelEntity : officeLevelEntities) {
        LookUpValueEntity lookupValue = officeLevelEntity.getLookUpValue();
        String messageText = lookupValue.getMessageText();
        if (StringUtils.isBlank(messageText)) {
            messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
        }
        OfficeLevel level = OfficeLevel.getOfficeLevel(officeLevelEntity.getId());
        switch(level) {
            case HEADOFFICE:
                officeLevels.setHeadOfficeEnabled(officeLevelEntity.isConfigured());
                officeLevels.setHeadOfficeNameKey(messageText);
                break;
            case REGIONALOFFICE:
                officeLevels.setRegionalOfficeEnabled(officeLevelEntity.isConfigured());
                officeLevels.setRegionalOfficeNameKey(messageText);
                break;
            case SUBREGIONALOFFICE:
                officeLevels.setSubRegionalOfficeEnabled(officeLevelEntity.isConfigured());
                officeLevels.setSubRegionalOfficeNameKey(messageText);
                break;
            case AREAOFFICE:
                officeLevels.setAreaOfficeEnabled(officeLevelEntity.isConfigured());
                officeLevels.setAreaOfficeNameKey(messageText);
                break;
            case BRANCHOFFICE:
                officeLevels.setBranchOfficeEnabled(officeLevelEntity.isConfigured());
                officeLevels.setBranchOfficeNameKey(messageText);
                break;
            default:
                break;
        }
    }
    return officeLevels;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) OfficeLevelDto(org.mifos.dto.domain.OfficeLevelDto) OfficeLevel(org.mifos.customers.office.util.helpers.OfficeLevel) OfficeLevelEntity(org.mifos.customers.office.business.OfficeLevelEntity) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity)

Example 3 with OfficeLevelDto

use of org.mifos.dto.domain.OfficeLevelDto in project head by mifos.

the class OfficeHierarchyServiceImpl method updateOfficeHierarchyConfiguration.

@Override
public void updateOfficeHierarchyConfiguration(UpdateConfiguredOfficeLevelRequest updateRequest) {
    try {
        transactionHelper.startTransaction();
        OfficeLevelDto existingOfficeLevels = officeDao.findOfficeLevelsWithConfiguration();
        if (updateRequest.isRegionalOfficeEnabled() != existingOfficeLevels.isRegionalOfficeEnabled()) {
            OfficeLevelEntity entity = officeDao.retrieveOfficeLevel(OfficeLevel.REGIONALOFFICE);
            entity.updateTo(updateRequest.isRegionalOfficeEnabled());
            if (existingOfficeLevels.isRegionalOfficeEnabled()) {
                officeDao.validateNoOfficesExistGivenOfficeLevel(OfficeLevel.REGIONALOFFICE);
            }
            this.officeDao.save(entity);
            transactionHelper.flushAndClearSession();
        }
        if (updateRequest.isSubRegionalOfficeEnabled() != existingOfficeLevels.isSubRegionalOfficeEnabled()) {
            OfficeLevelEntity entity = officeDao.retrieveOfficeLevel(OfficeLevel.SUBREGIONALOFFICE);
            entity.updateTo(updateRequest.isSubRegionalOfficeEnabled());
            if (existingOfficeLevels.isSubRegionalOfficeEnabled()) {
                officeDao.validateNoOfficesExistGivenOfficeLevel(OfficeLevel.SUBREGIONALOFFICE);
            }
            this.officeDao.save(entity);
            transactionHelper.flushAndClearSession();
        }
        if (updateRequest.isAreaOfficeEnabled() != existingOfficeLevels.isAreaOfficeEnabled()) {
            OfficeLevelEntity entity = officeDao.retrieveOfficeLevel(OfficeLevel.AREAOFFICE);
            entity.updateTo(updateRequest.isAreaOfficeEnabled());
            if (existingOfficeLevels.isSubRegionalOfficeEnabled()) {
                officeDao.validateNoOfficesExistGivenOfficeLevel(OfficeLevel.AREAOFFICE);
            }
            this.officeDao.save(entity);
            transactionHelper.flushAndClearSession();
        }
        transactionHelper.commitTransaction();
    } catch (BusinessRuleException e) {
        transactionHelper.rollbackTransaction();
        throw e;
    } catch (Exception e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        transactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeLevelDto(org.mifos.dto.domain.OfficeLevelDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException) BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeLevelEntity(org.mifos.customers.office.business.OfficeLevelEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 4 with OfficeLevelDto

use of org.mifos.dto.domain.OfficeLevelDto in project head by mifos.

the class ViewOfficeHierarchyController method showPopulatedCheckboxForm.

@RequestMapping(method = RequestMethod.GET)
@ModelAttribute("formBean")
public ViewOfficeHierarchyFormBean showPopulatedCheckboxForm() {
    OfficeLevelDto officeLevels = adminServiceFacade.retrieveOfficeLevelsWithConfiguration();
    ViewOfficeHierarchyFormBean formBean = new ViewOfficeHierarchyFormBean();
    formBean.setHeadOffice(officeLevels.isHeadOfficeEnabled());
    formBean.setRegionalOffice(officeLevels.isRegionalOfficeEnabled());
    formBean.setSubRegionalOffice(officeLevels.isSubRegionalOfficeEnabled());
    formBean.setAreaOffice(officeLevels.isAreaOfficeEnabled());
    formBean.setBranchOffice(officeLevels.isBranchOfficeEnabled());
    return formBean;
}
Also used : OfficeLevelDto(org.mifos.dto.domain.OfficeLevelDto) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

OfficeLevelDto (org.mifos.dto.domain.OfficeLevelDto)4 OfficeLevelEntity (org.mifos.customers.office.business.OfficeLevelEntity)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Test (org.junit.Test)1 LookUpValueEntity (org.mifos.application.master.business.LookUpValueEntity)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 OfficeLevel (org.mifos.customers.office.util.helpers.OfficeLevel)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1