Search in sources :

Example 11 with BatchJobException

use of org.mifos.framework.components.batchjobs.exceptions.BatchJobException in project head by mifos.

the class TaskHelper method execute.

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    checkHibernateSession();
    Date scheduledFireTime = new Date(chunkContext.getStepContext().getStepExecution().getJobParameters().getLong(MifosBatchJob.JOB_EXECUTION_TIME_KEY));
    try {
        execute(scheduledFireTime.getTime());
    } catch (BatchJobException ex) {
        logger.error("Exception during task execution", ex);
        contribution.setExitStatus(ExitStatus.FAILED.addExitDescription(ex.getErrorMessage()));
    }
    return RepeatStatus.FINISHED;
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) Date(java.util.Date)

Example 12 with BatchJobException

use of org.mifos.framework.components.batchjobs.exceptions.BatchJobException in project head by mifos.

the class ApplyHolidayChangesHelper method execute.

@Override
public void execute(long timeInMillis) throws BatchJobException {
    long taskStartTime = new DateTimeService().getCurrentDateTime().getMillis();
    initializeTaskGlobalParameters();
    if (unappliedHolidays != null && !unappliedHolidays.isEmpty()) {
        for (Holiday holiday : unappliedHolidays) {
            logMessage("Processing Holiday: " + holiday.getName() + " From: " + DateUtils.getLocalDateFromDate(holiday.getFromDate().toDate()) + " To: " + DateUtils.getLocalDateFromDate(holiday.getThruDate().toDate()));
            try {
                rescheduleDatesStartingFromUnappliedHoliday(holiday);
            } catch (Exception e) {
                StaticHibernateUtil.rollbackTransaction();
                errorList.add("Failed to apply holiday changes: " + e.toString());
                e.printStackTrace();
                throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
            }
        }
    }
    StaticHibernateUtil.closeSession();
    String finalMessage = "ApplyHolidayChanges task completed in " + (new DateTimeService().getCurrentDateTime().getMillis() - taskStartTime) + " ms";
    logMessage(finalMessage);
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) Holiday(org.mifos.application.holiday.business.Holiday) DateTimeService(org.mifos.framework.util.DateTimeService) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 13 with BatchJobException

use of org.mifos.framework.components.batchjobs.exceptions.BatchJobException in project head by mifos.

the class GenerateMeetingsForCustomerAndSavingsHelper method findActiveCustomerAndSavingsAccountIdsThatRequiredMeetingsToBeGenerated.

private List<Integer> findActiveCustomerAndSavingsAccountIdsThatRequiredMeetingsToBeGenerated() throws BatchJobException {
    List<Integer> customerAndSavingsAccountIds = new ArrayList<Integer>();
    try {
        long time1 = new DateTimeService().getCurrentDateTime().getMillis();
        customerAndSavingsAccountIds = legacyAccountDao.getActiveCustomerAndSavingsAccountIdsForGenerateMeetingTask();
        long duration = new DateTimeService().getCurrentDateTime().getMillis() - time1;
        logMessage("Time to execute the query " + duration + " . Got " + customerAndSavingsAccountIds.size() + " accounts.");
    } catch (PersistenceException e) {
        throw new BatchJobException(e);
    }
    return customerAndSavingsAccountIds;
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 14 with BatchJobException

use of org.mifos.framework.components.batchjobs.exceptions.BatchJobException 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)

Example 15 with BatchJobException

use of org.mifos.framework.components.batchjobs.exceptions.BatchJobException in project head by mifos.

the class PortfolioAtRiskHelper method execute.

@Override
public void execute(long timeInMillis) throws BatchJobException {
    long time1 = new DateTimeService().getCurrentDateTime().getMillis();
    List<BasicGroupInfo> groupInfos = null;
    List<String> errorList = new ArrayList<String>();
    try {
        groupInfos = new CustomerPersistence().getAllBasicGroupInfo();
    } catch (Exception e) {
        throw new BatchJobException(e);
    }
    if (groupInfos != null && !groupInfos.isEmpty()) {
        int groupCount = groupInfos.size();
        getLogger().info("PortfolioAtRisk: got " + groupCount + " groups to process.");
        long startTime = new DateTimeService().getCurrentDateTime().getMillis();
        int i = 1;
        Integer groupId = null;
        GroupPersistence groupPersistence = new GroupPersistence();
        try {
            for (BasicGroupInfo groupInfo : groupInfos) {
                groupId = groupInfo.getGroupId();
                String searchStr = groupInfo.getSearchId() + ".%";
                double portfolioAtRisk = PortfolioAtRiskCalculation.generatePortfolioAtRiskForTask(groupId, groupInfo.getBranchId(), searchStr);
                // updated_by and updated_date
                if (portfolioAtRisk > -1) {
                    groupPersistence.updateGroupInfoAndGroupPerformanceHistoryForPortfolioAtRisk(portfolioAtRisk, groupId);
                }
                if (i % 500 == 0) {
                    long time = new DateTimeService().getCurrentDateTime().getMillis();
                    getLogger().info("500 groups updated in " + (time - startTime) + " milliseconds. There are " + (groupCount - i) + " more groups to be updated.");
                    startTime = time;
                }
                i++;
            }
        } catch (Exception e) {
            getLogger().error("PortfolioAtRiskHelper execute failed with exception " + e.getClass().getName() + ": " + e.getMessage() + " at group " + groupId.toString(), e);
            StaticHibernateUtil.rollbackTransaction();
            errorList.add(groupId.toString());
        } finally {
            StaticHibernateUtil.closeSession();
        }
    }
    long time2 = new DateTimeService().getCurrentDateTime().getMillis();
    getLogger().info("PortfolioAtRiskTask ran in " + (time2 - time1) + " milliseconds");
    if (errorList.size() > 0) {
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
}
Also used : BasicGroupInfo(org.mifos.customers.group.BasicGroupInfo) ArrayList(java.util.ArrayList) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) DateTimeService(org.mifos.framework.util.DateTimeService) GroupPersistence(org.mifos.customers.group.persistence.GroupPersistence)

Aggregations

BatchJobException (org.mifos.framework.components.batchjobs.exceptions.BatchJobException)18 ArrayList (java.util.ArrayList)8 DateTimeService (org.mifos.framework.util.DateTimeService)6 Date (java.util.Date)3 Query (org.hibernate.Query)3 LocalDate (org.joda.time.LocalDate)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 ServiceException (org.mifos.framework.exceptions.ServiceException)3 Session (org.hibernate.Session)2 AccountBO (org.mifos.accounts.business.AccountBO)2 LoanBO (org.mifos.accounts.loan.business.LoanBO)2 Holiday (org.mifos.application.holiday.business.Holiday)2 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)2 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 SQLException (java.sql.SQLException)1