Search in sources :

Example 6 with LoanPrdPersistence

use of org.mifos.accounts.productdefinition.persistence.LoanPrdPersistence in project head by mifos.

the class ConfigurationInitializer method setLateNessAndDormancyDaysForAccount.

private void setLateNessAndDormancyDaysForAccount(Map<Key, Object> officeConfigMap) throws SystemException, ApplicationException {
    Short latenessDays = new LoanPrdPersistence().retrieveLatenessForPrd();
    Short dormancyDays = ApplicationContextProvider.getBean(SavingsProductDao.class).findSavingsProductConfiguration().getDormancyDays();
    officeConfigMap.put(new Key(getHeadOffice().getOfficeId(), ConfigConstants.LATENESS_DAYS), latenessDays);
    officeConfigMap.put(new Key(getHeadOffice().getOfficeId(), ConfigConstants.DORMANCY_DAYS), dormancyDays);
}
Also used : LoanPrdPersistence(org.mifos.accounts.productdefinition.persistence.LoanPrdPersistence) Key(org.mifos.config.cache.Key)

Example 7 with LoanPrdPersistence

use of org.mifos.accounts.productdefinition.persistence.LoanPrdPersistence 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

LoanPrdPersistence (org.mifos.accounts.productdefinition.persistence.LoanPrdPersistence)7 Date (java.util.Date)2 LocalDate (org.joda.time.LocalDate)2 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)2 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)2 Money (org.mifos.framework.util.helpers.Money)2 ArrayList (java.util.ArrayList)1 FeeBO (org.mifos.accounts.fees.business.FeeBO)1 FeeDto (org.mifos.accounts.fees.business.FeeDto)1 FeeDao (org.mifos.accounts.fees.persistence.FeeDao)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 LegacyAccountDao (org.mifos.accounts.persistence.LegacyAccountDao)1 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)1 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)1 Key (org.mifos.config.cache.Key)1 BatchJobException (org.mifos.framework.components.batchjobs.exceptions.BatchJobException)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1 DateTimeService (org.mifos.framework.util.DateTimeService)1