Search in sources :

Example 6 with LegacyAccountDao

use of org.mifos.accounts.persistence.LegacyAccountDao in project head by mifos.

the class FinancialInitializer method loadCOA.

/**
     * Reads chart of accounts from a configuration file and inserts into the
     * database. Deleting accounts is not currently supported, but if the user
     * tries to do this (by leaving it out of the custom chart of accounts
     * config file), there is currently no error reported.
     * <p>
     * QUESION: what if custom config was missing entries from default config,
     * but then is moved _out_ of the app server classpath?
     * <p>
     * ANSWER: once ChartOfAccountsConfig.isLoaded() returns true, <em>only
     * the custom CoA config file will be considered</em>. Using the custom
     * config will be the only way to add new accounts after the initial CoA
     * data is loaded in the database.
     */
public static void loadCOA() throws FinancialException {
    Session session = StaticHibernateUtil.getSessionTL();
    final String coaLocation;
    try {
        if (!ChartOfAccountsConfig.canLoadCoa(session)) {
            logger.info("Chart of accounts data will not be modified since " + "the custom chart of accounts configuration file was " + "not found on the classpath.");
            return;
        }
        coaLocation = ChartOfAccountsConfig.getCoaUri(session);
        logger.info("going to load or modify chart of accounts " + "configuration from " + coaLocation);
    } catch (IOException e) {
        throw new FinancialException("Charts of accounts loading failed", e);
    }
    ChartOfAccountsConfig coa;
    try {
        coa = ChartOfAccountsConfig.load(coaLocation);
    } catch (ConfigurationException e) {
        throw new FinancialException(coaLocation + " loading failed", e);
    }
    LegacyAccountDao ap = ApplicationContextProvider.getBean(LegacyAccountDao.class);
    for (GLAccount glAccount : coa.getGLAccounts()) {
        Short accountId = ap.getAccountIdFromGlCode(glAccount.glCode);
        if (null == accountId) {
            logger.info("Adding new general ledger account: " + glAccount);
            ap.addGeneralLedgerAccount(glAccount.name, glAccount.glCode, glAccount.parentGlCode, glAccount.categoryType);
        } else {
            COABO account = (COABO) session.load(COABO.class, accountId);
            if (account.getCategoryType() != glAccount.categoryType) {
                throw new FinancialException("category type change not supported");
            }
            if (!accountHierarchyMatch(account, glAccount)) {
                throw new FinancialException("chart of accounts hierarchy change not supported");
            }
            if (!account.getAccountName().equals(glAccount.name)) {
                logger.info("updating general ledger account name. code=" + account.getGlCode() + ". old name=" + account.getAccountName() + ", new name=" + glAccount.name);
                ap.updateAccountName(account, glAccount.name);
            }
        }
    }
}
Also used : ChartOfAccountsConfig(org.mifos.config.ChartOfAccountsConfig) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) COABO(org.mifos.accounts.financial.business.COABO) GLAccount(org.mifos.config.GLAccount) IOException(java.io.IOException) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) Session(org.hibernate.Session)

Example 7 with LegacyAccountDao

use of org.mifos.accounts.persistence.LegacyAccountDao in project head by mifos.

the class ProcessFlowRules method initFromDB.

public static void initFromDB() {
    MifosConfigurationManager cm = MifosConfigurationManager.getInstance();
    CustomerDao customerDao = ApplicationContextProvider.getBean(CustomerDao.class);
    LegacyAccountDao ap = ApplicationContextProvider.getBean(LegacyAccountDao.class);
    CustomerStatusEntity cse = customerDao.findClientPendingStatus();
    cm.setProperty(CLIENT_PENDING_APPROVAL, isClientPendingApprovalStateEnabledOnDatabaseConfiguration(cse));
    cse = customerDao.findGroupPendingStatus();
    cm.setProperty(GROUP_PENDING_APPROVAL, isGroupPendingApprovalStateEnabledOnDatabaseConfiguration(cse));
    AccountStateEntity ase = ap.loadPersistentObject(AccountStateEntity.class, AccountState.LOAN_PENDING_APPROVAL.getValue());
    cm.setProperty(LOAN_PENDING_APPROVAL, isLoanPendingApprovalStateEnabledOnDatabaseConfig(ase));
    ase = ap.loadPersistentObject(AccountStateEntity.class, AccountState.SAVINGS_PENDING_APPROVAL.getValue());
    cm.setProperty(SAVINGS_PENDING_APPROVAL, isSavingPendingApprovalStateEnabledOnDatabaseConfig(ase));
}
Also used : LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) CustomerDao(org.mifos.customers.persistence.CustomerDao) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager)

Example 8 with LegacyAccountDao

use of org.mifos.accounts.persistence.LegacyAccountDao in project head by mifos.

the class ProcessFlowRules method initSavingsPendingApprovalState.

private static void initSavingsPendingApprovalState() throws ConfigurationException {
    LegacyAccountDao ap = ApplicationContextProvider.getBean(LegacyAccountDao.class);
    AccountStateEntity ase = ap.loadPersistentObject(AccountStateEntity.class, AccountState.SAVINGS_PENDING_APPROVAL.getValue());
    boolean fromDb = isSavingPendingApprovalStateEnabledOnDatabaseConfig(ase);
    boolean fromCfg = isSavingsPendingApprovalStateEnabled();
    if (databaseAndCustomConfigurationAreNotTheSame(fromDb, fromCfg)) {
        int count = ApplicationContextProvider.getBean(LegacyLoanDao.class).countOfSavingsAccounts();
        if (count > 0) {
            String errMsg = getBadOverrideMsg(SAVINGS_PENDING_APPROVAL, "Records for savings accounts in the 'pending approval' state" + " may already exist.");
            throw new ConfigurationException(errMsg);
        }
        makeDatabaseConfigurationMatchPropertiesFileConfiguration(ap, ase, fromCfg);
    }
}
Also used : LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) LegacyLoanDao(org.mifos.accounts.loan.persistance.LegacyLoanDao)

Example 9 with LegacyAccountDao

use of org.mifos.accounts.persistence.LegacyAccountDao in project head by mifos.

the class LoanArrearsHelper method execute.

@Override
public void execute(long timeInMillis) throws BatchJobException {
    long time1 = new DateTimeService().getCurrentDateTime().getMillis();
    LegacyAccountDao legacyAccountDao = ApplicationContextProvider.getBean(LegacyAccountDao.class);
    List<String> errorList = new ArrayList<String>();
    List<Integer> listAccountIds = null;
    int accountNumber = 0;
    try {
        Short latenessDays = new LoanPrdPersistence().retrieveLatenessForPrd();
        long time3 = new DateTimeService().getCurrentDateTime().getMillis();
        listAccountIds = ApplicationContextProvider.getBean(LegacyLoanDao.class).getLoanAccountsInArrearsInGoodStanding(latenessDays);
        long duration2 = new DateTimeService().getCurrentDateTime().getMillis() - time3;
        accountNumber = listAccountIds.size();
        getLogger().info("LoanArrearsTask: getLoanAccountsInArrearsInGoodStanding ran in " + duration2 + " milliseconds" + " got " + accountNumber + " accounts to update.");
    } catch (Exception e) {
        throw new BatchJobException(e);
    }
    LoanBO loanBO = null;
    int i = 1;
    int batchSize = GeneralConfig.getBatchSizeForBatchJobs();
    int recordCommittingSize = GeneralConfig.getRecordCommittingSizeForBatchJobs();
    try {
        long startTime = new DateTimeService().getCurrentDateTime().getMillis();
        for (Integer accountId : listAccountIds) {
            loanBO = (LoanBO) legacyAccountDao.getAccount(accountId);
            assert (loanBO.getAccountState().getId().shortValue() == AccountState.LOAN_ACTIVE_IN_GOOD_STANDING.getValue().shortValue());
            loanBO.handleArrears();
            if (i % batchSize == 0) {
                StaticHibernateUtil.flushAndClearSession();
            }
            if (i % recordCommittingSize == 0) {
                StaticHibernateUtil.commitTransaction();
            }
            if (i % 1000 == 0) {
                long time = new DateTimeService().getCurrentDateTime().getMillis();
                getLogger().info("1000 accounts updated in " + (time - startTime) + " milliseconds. There are " + (accountNumber - i) + " more accounts to be updated.");
                startTime = time;
            }
            i++;
        }
        StaticHibernateUtil.commitTransaction();
    } catch (Exception e) {
        getLogger().debug("LoanArrearsTask " + e.getMessage());
        StaticHibernateUtil.rollbackTransaction();
        if (loanBO != null) {
            errorList.add(loanBO.getAccountId().toString());
        }
    } finally {
        StaticHibernateUtil.closeSession();
    }
    long time2 = new DateTimeService().getCurrentDateTime().getMillis();
    long duration = time2 - time1;
    getLogger().info("LoanArrearsTask ran in " + duration + " milliseconds");
    if (errorList.size() > 0) {
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) LoanPrdPersistence(org.mifos.accounts.productdefinition.persistence.LoanPrdPersistence) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) DateTimeService(org.mifos.framework.util.DateTimeService)

Aggregations

LegacyAccountDao (org.mifos.accounts.persistence.LegacyAccountDao)9 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)3 COABO (org.mifos.accounts.financial.business.COABO)3 ConfigurationException (org.mifos.config.exceptions.ConfigurationException)3 Test (org.junit.Test)2 LegacyLoanDao (org.mifos.accounts.loan.persistance.LegacyLoanDao)2 PersistenceException (org.mifos.framework.exceptions.PersistenceException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Session (org.hibernate.Session)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 FinancialException (org.mifos.accounts.financial.exceptions.FinancialException)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 LoanPrdPersistence (org.mifos.accounts.productdefinition.persistence.LoanPrdPersistence)1 ChartOfAccountsConfig (org.mifos.config.ChartOfAccountsConfig)1 GLAccount (org.mifos.config.GLAccount)1 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)1 CustomerStatusEntity (org.mifos.customers.business.CustomerStatusEntity)1 CustomerDao (org.mifos.customers.persistence.CustomerDao)1 BatchJobException (org.mifos.framework.components.batchjobs.exceptions.BatchJobException)1