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()));
}
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;
}
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();
}
}
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;
}
Aggregations