use of org.mifos.config.business.MifosConfigurationManager in project head by mifos.
the class ClientRules method getMinimumAge.
/*
* reads the maximum age specified in the application configuration file,
* Also Checks if its in the range of 0 to 150
*/
public static int getMinimumAge() throws ConfigurationException {
int minimumAge = 0;
MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
if (configMgr.containsKey(ClientRules.MinimumAgeForNewClients)) {
minimumAge = Integer.parseInt(configMgr.getString(ClientRules.MinimumAgeForNewClients));
} else {
throw new ConfigurationException("The Minimum Age for a client is not defined in " + MifosConfigurationManager.DEFAULT_CONFIG_PROPS_FILENAME);
}
if (minimumAge < 0 || minimumAge > 150) {
throw new ConfigurationException("The Minimum Age defined in the " + MifosConfigurationManager.DEFAULT_CONFIG_PROPS_FILENAME + "is not within the acceptable range (0 to 150)");
}
return minimumAge;
}
use of org.mifos.config.business.MifosConfigurationManager in project head by mifos.
the class ApplicationInitializer method dbUpgrade.
public void dbUpgrade(ApplicationContext applicationContext) throws ConfigurationException, PersistenceException, FinancialException, TaskSystemException {
logger.info("Logger has been initialised");
initializeHibernate(applicationContext);
logger.info(getDatabaseConnectionInfo());
// if a database upgrade loads an instance of Money then MoneyCompositeUserType needs the default
// currency
MoneyCompositeUserType.setDefaultCurrency(AccountingRules.getMifosCurrency(new ConfigurationPersistence()));
// load the additional currencies
AccountingRules.init();
Money.setDefaultCurrency(AccountingRules.getMifosCurrency(new ConfigurationPersistence()));
final MifosConfigurationManager configuration = MifosConfigurationManager.getInstance();
final String imageStorageConfig = configuration.getString(IMAGESTORE_CONFIG_KEY);
if (imageStorageConfig == null || !imageStorageConfig.equals(DB_CONFIG)) {
ImageStorageManager.initStorage();
}
DatabaseMigrator migrator = new DatabaseMigrator();
initializeDBConnectionForHibernate(migrator);
if (!databaseError.isError) {
try {
migrator.upgrade(applicationContext);
} catch (Throwable t) {
setDatabaseError(DatabaseErrorCode.UPGRADE_FAILURE, "Failed to upgrade database.", t);
}
}
if (databaseError.isError) {
databaseError.logError();
} else {
initializeDB(applicationContext);
/*
* John W - Added in G Release and back patched to F Release.
* Related to jira issue MIFOS-4948
*
* Can find all code and the related query by searching for mifos4948
*
*/
CustomJDBCService customJdbcService = applicationContext.getBean(CustomJDBCService.class);
boolean keyExists = customJdbcService.mifos4948IssueKeyExists();
if (!keyExists) {
try {
StaticHibernateUtil.startTransaction();
applyMifos4948Fix();
customJdbcService.insertMifos4948Issuekey();
StaticHibernateUtil.commitTransaction();
} catch (AccountException e) {
StaticHibernateUtil.rollbackTransaction();
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
boolean key5722Exists = customJdbcService.mifos5722IssueKeyExists();
if (!key5722Exists) {
try {
applyMifos5722Fix();
customJdbcService.insertMifos5722Issuekey();
} catch (Exception e) {
logger.error("Could not apply Mifos-5692 and mifos-5722 fix");
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
boolean key5763Exists = customJdbcService.mifos5763IssueKeyExists();
if (!key5763Exists) {
try {
applyMifos5763Fix();
customJdbcService.insertMifos5763Issuekey();
} catch (Exception e) {
logger.info("Failed to apply Mifos-5763 fix");
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
boolean key5632Exists = customJdbcService.mifos5632IssueKeyExists();
if (!key5632Exists) {
try {
applyMifos5632();
customJdbcService.insertMifos5632IssueKey();
} catch (Exception e) {
logger.info("Failed to apply Mifos-5632 fix");
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
}
}
use of org.mifos.config.business.MifosConfigurationManager in project head by mifos.
the class LoginServiceFacadeWebTier method login.
@Override
public LoginDto login(String username, String password) {
PersonnelBO user = this.personnelDao.findPersonnelByUsername(username);
if (user == null) {
throw new UsernameNotFoundException(LoginConstants.KEYINVALIDUSER);
}
MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
List<ValueListElement> localeList = personnelServiceFacade.getDisplayLocaleList();
Locale preferredLocale = new Locale(configMgr.getString(LANGUAGE_CODE), configMgr.getString(COUNTRY_CODE));
String listElement = "[" + preferredLocale.toString() + "]";
Short localeId = user.getPreferredLocale();
for (ValueListElement element : localeList) {
if (element.getName().contains(listElement)) {
localeId = element.getId().shortValue();
break;
}
}
user.setPreferredLocale(localeId);
UserContext userContext = new UserContext();
userContext.setPreferredLocale(preferredLocale);
userContext.setLocaleId(localeId);
userContext.setId(user.getPersonnelId());
userContext.setName(user.getDisplayName());
userContext.setLevel(user.getLevelEnum());
userContext.setRoles(user.getRoles());
userContext.setLastLogin(user.getLastLogin());
userContext.setPasswordChanged(user.getPasswordChanged());
userContext.setBranchId(user.getOffice().getOfficeId());
userContext.setBranchGlobalNum(user.getOffice().getGlobalOfficeNum());
userContext.setOfficeLevelId(user.getOffice().getLevel().getId());
user.updateDetails(userContext);
try {
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(user);
user.login(password);
this.personnelDao.save(user);
this.transactionHelper.commitTransaction();
boolean isPasswordExpired = new LocalDate(user.getPasswordExpirationDate()).isBefore(new LocalDate());
return new LoginDto(user.getPersonnelId(), user.getOffice().getOfficeId(), user.isPasswordChanged(), isPasswordExpired);
} catch (ApplicationException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.config.business.MifosConfigurationManager in project head by mifos.
the class StandardTestingService method setImport.
@Override
public void setImport(String importParamName, String importParamValue) throws MifosException {
MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
if (importParamValue == null || importParamValue.equals("")) {
configMgr.clearProperty(importParamName);
return;
}
configMgr.setProperty(importParamName, importParamValue);
}
use of org.mifos.config.business.MifosConfigurationManager in project head by mifos.
the class GenerateMeetingsForCustomerAndSavingsHelperIntegrationTest method testExecuteForCustomerAndSavingsAccount.
@Test
public void testExecuteForCustomerAndSavingsAccount() throws Exception {
// jpw - this test is similar to testExecuteForSavingsAccount
// Re-using much of it to test that customer and savings accounts are processed as have made separate queries to
// return the two different types of accounts.
int configuredValue = GeneralConfig.getOutputIntervalForBatchJobs();
MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
int outputInterval = 1;
try {
// force output for every account
configMgr.setProperty(GeneralConfig.OutputIntervalForBatchJobs, outputInterval);
savings = getSavingsAccountForCenter();
int noOfInstallments = savings.getAccountActionDates().size();
AccountTestUtils.changeInstallmentDatesToPreviousDate(savings);
CustomerAccountBO centerCustomerAccount = center.getCustomerAccount();
Integer centerCustomerAccountInstallments = centerCustomerAccount.getAccountActionDates().size();
AccountTestUtils.changeInstallmentDatesToPreviousDate(centerCustomerAccount);
CustomerAccountBO groupCustomerAccount = group.getCustomerAccount();
Integer groupCustomerAccountInstallments = groupCustomerAccount.getAccountActionDates().size();
AccountTestUtils.changeInstallmentDatesToPreviousDate(groupCustomerAccount);
CustomerAccountBO client1CustomerAccount = client1.getCustomerAccount();
Integer client1CustomerAccountInstallments = client1CustomerAccount.getAccountActionDates().size();
AccountTestUtils.changeInstallmentDatesToPreviousDate(client1CustomerAccount);
CustomerAccountBO client2CustomerAccount = client2.getCustomerAccount();
Integer client2CustomerAccountInstallments = client2CustomerAccount.getAccountActionDates().size();
AccountTestUtils.changeInstallmentDatesToPreviousDate(client2CustomerAccount);
StaticHibernateUtil.flushSession();
savings = TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
new GenerateMeetingsForCustomerAndSavingsTask().getTaskHelper().execute(System.currentTimeMillis());
savings = TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
centerCustomerAccount = TestObjectFactory.getObject(CustomerAccountBO.class, centerCustomerAccount.getAccountId());
groupCustomerAccount = TestObjectFactory.getObject(CustomerAccountBO.class, groupCustomerAccount.getAccountId());
client1CustomerAccount = TestObjectFactory.getObject(CustomerAccountBO.class, client1CustomerAccount.getAccountId());
client2CustomerAccount = TestObjectFactory.getObject(CustomerAccountBO.class, client2CustomerAccount.getAccountId());
Assert.assertEquals(noOfInstallments + 20, savings.getAccountActionDates().size());
Assert.assertEquals(centerCustomerAccountInstallments + 10, centerCustomerAccount.getAccountActionDates().size());
Assert.assertEquals(groupCustomerAccountInstallments + 10, groupCustomerAccount.getAccountActionDates().size());
Assert.assertEquals(client1CustomerAccountInstallments + 10, client1CustomerAccount.getAccountActionDates().size());
Assert.assertEquals(client2CustomerAccountInstallments + 10, client2CustomerAccount.getAccountActionDates().size());
} finally {
// restore original output interval value
configMgr.setProperty(GeneralConfig.OutputIntervalForBatchJobs, configuredValue);
}
}
Aggregations