Search in sources :

Example 1 with OfficeLevelEntity

use of org.mifos.customers.office.business.OfficeLevelEntity 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 2 with OfficeLevelEntity

use of org.mifos.customers.office.business.OfficeLevelEntity in project head by mifos.

the class AuditConfiguration method fetchMasterData.

private void fetchMasterData(String entityName, Short localeId, String classPath) throws SystemException {
    Class clazz = null;
    try {
        clazz = Thread.currentThread().getContextClassLoader().loadClass(classPath);
    } catch (ClassNotFoundException e) {
        throw new SystemException(e);
    }
    List<MasterDataEntity> masterDataList = legacyMasterDao.findMasterDataEntities(clazz);
    for (MasterDataEntity masterDataEntity : masterDataList) {
        if (masterDataEntity instanceof PersonnelStatusEntity) {
            String name = ApplicationContextProvider.getBean(MessageLookup.class).lookup(masterDataEntity.getLookUpValue());
            ((PersonnelStatusEntity) masterDataEntity).setName(name);
        }
        if (masterDataEntity instanceof PersonnelLevelEntity) {
            String name = ApplicationContextProvider.getBean(MessageLookup.class).lookup(masterDataEntity.getLookUpValue());
            ((PersonnelLevelEntity) masterDataEntity).setName(name);
        }
        if (masterDataEntity instanceof OfficeLevelEntity) {
            String name = ApplicationContextProvider.getBean(MessageLookup.class).lookup(masterDataEntity.getLookUpValue());
            ((OfficeLevelEntity) masterDataEntity).setName(name);
        }
        if (masterDataEntity instanceof OfficeStatusEntity) {
            String name = ApplicationContextProvider.getBean(MessageLookup.class).lookup(masterDataEntity.getLookUpValue());
            ((OfficeStatusEntity) masterDataEntity).setName(name);
        }
        valueMap.put(masterDataEntity.getId().toString(), masterDataEntity.getName());
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) MessageLookup(org.mifos.application.master.MessageLookup) PersonnelLevelEntity(org.mifos.customers.personnel.business.PersonnelLevelEntity) OfficeStatusEntity(org.mifos.customers.office.business.OfficeStatusEntity) PersonnelStatusEntity(org.mifos.customers.personnel.business.PersonnelStatusEntity) OfficeLevelEntity(org.mifos.customers.office.business.OfficeLevelEntity)

Example 3 with OfficeLevelEntity

use of org.mifos.customers.office.business.OfficeLevelEntity in project head by mifos.

the class OfficeHierarchyServiceImpl method updateApplicationLabels.

@Override
public void updateApplicationLabels(List<OfficeLevelEntity> changedOfficeLabels, List<LookUpEntity> lookupEntities, List<GracePeriodTypeEntity> gracePeriods, List<LookUpValueEntity> accountStatuses) {
    try {
        transactionHelper.startTransaction();
        for (OfficeLevelEntity entity : changedOfficeLabels) {
            officeDao.save(entity);
            LookUpValueEntity lookupValue = entity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValueInCache(entity.getLookUpValue().getLookUpName(), messageText);
        }
        for (GracePeriodTypeEntity entity : gracePeriods) {
            applicationConfigurationDao.save(entity);
            LookUpValueEntity lookupValue = entity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValueInCache(entity.getLookUpValue().getLookUpName(), messageText);
        }
        for (LookUpEntity entity : lookupEntities) {
            applicationConfigurationDao.save(entity);
            ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValueInCache(entity.getEntityType(), entity.findLabel());
        }
        for (LookUpValueEntity entity : accountStatuses) {
            applicationConfigurationDao.save(entity);
        }
        transactionHelper.commitTransaction();
        if (!accountStatuses.isEmpty()) {
            MenuRepository.getInstance().removeMenuForAllLocale();
        }
    } 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) LookUpEntity(org.mifos.application.master.business.LookUpEntity) MessageLookup(org.mifos.application.master.MessageLookup) GracePeriodTypeEntity(org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException) BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeLevelEntity(org.mifos.customers.office.business.OfficeLevelEntity) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 4 with OfficeLevelEntity

use of org.mifos.customers.office.business.OfficeLevelEntity 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 5 with OfficeLevelEntity

use of org.mifos.customers.office.business.OfficeLevelEntity in project head by mifos.

the class OfficeDaoHibernateIntegrationTest method shouldRetrieveOfficeLevelById.

@Test
public void shouldRetrieveOfficeLevelById() throws Exception {
    OfficeLevelEntity officeLevel = officeDao.retrieveOfficeLevel(OfficeLevel.AREAOFFICE);
    // verification
    assertThat(officeLevel.isConfigured(), is(true));
}
Also used : OfficeLevelEntity(org.mifos.customers.office.business.OfficeLevelEntity) Test(org.junit.Test)

Aggregations

OfficeLevelEntity (org.mifos.customers.office.business.OfficeLevelEntity)5 MessageLookup (org.mifos.application.master.MessageLookup)2 LookUpValueEntity (org.mifos.application.master.business.LookUpValueEntity)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 OfficeLevelDto (org.mifos.dto.domain.OfficeLevelDto)2 BusinessRuleException (org.mifos.service.BusinessRuleException)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 GracePeriodTypeEntity (org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity)1 LookUpEntity (org.mifos.application.master.business.LookUpEntity)1 MasterDataEntity (org.mifos.application.master.business.MasterDataEntity)1 OfficeStatusEntity (org.mifos.customers.office.business.OfficeStatusEntity)1 OfficeLevel (org.mifos.customers.office.util.helpers.OfficeLevel)1 PersonnelLevelEntity (org.mifos.customers.personnel.business.PersonnelLevelEntity)1 PersonnelStatusEntity (org.mifos.customers.personnel.business.PersonnelStatusEntity)1 SystemException (org.mifos.framework.exceptions.SystemException)1