Search in sources :

Example 16 with MifosConfigurationManager

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;
}
Also used : ConfigurationException(org.mifos.config.exceptions.ConfigurationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager)

Example 17 with MifosConfigurationManager

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();
            }
        }
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) DatabaseMigrator(org.mifos.framework.persistence.DatabaseMigrator) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) CustomJDBCService(org.mifos.application.servicefacade.CustomJDBCService) SystemException(org.mifos.framework.exceptions.SystemException) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) XMLReaderException(org.mifos.framework.exceptions.XMLReaderException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) AppNotConfiguredException(org.mifos.framework.exceptions.AppNotConfiguredException) AccountException(org.mifos.accounts.exceptions.AccountException) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) HibernateStartUpException(org.mifos.framework.exceptions.HibernateStartUpException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager)

Example 18 with MifosConfigurationManager

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();
    }
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) Locale(java.util.Locale) UserContext(org.mifos.security.util.UserContext) LocalDate(org.joda.time.LocalDate) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersonnelException(org.mifos.customers.personnel.exceptions.PersonnelException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoginDto(org.mifos.dto.domain.LoginDto) ValueListElement(org.mifos.dto.domain.ValueListElement) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 19 with MifosConfigurationManager

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);
}
Also used : MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager)

Example 20 with MifosConfigurationManager

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);
    }
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Aggregations

MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)66 Test (org.junit.Test)18 ConfigurationException (org.mifos.config.exceptions.ConfigurationException)8 Properties (java.util.Properties)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)5 PersistenceException (org.mifos.framework.exceptions.PersistenceException)5 ApplicationException (org.mifos.framework.exceptions.ApplicationException)4 RoundingMode (java.math.RoundingMode)3 ConfigurationPersistence (org.mifos.config.persistence.ConfigurationPersistence)3 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)3 SystemException (org.mifos.framework.exceptions.SystemException)3 BigDecimal (java.math.BigDecimal)2 Ignore (org.junit.Ignore)2 AccountBO (org.mifos.accounts.business.AccountBO)2 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)2 ConfigurationKeyValue (org.mifos.config.business.ConfigurationKeyValue)2 CurrencyMismatchException (org.mifos.core.CurrencyMismatchException)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1