Search in sources :

Example 6 with BatchJobException

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

the class BranchReportHelper method execute.

@Override
public void execute(long timeInMillis) throws BatchJobException {
    Session session = StaticHibernateUtil.getSessionTL();
    StaticHibernateUtil.startTransaction();
    Date runDate = new Date(timeInMillis);
    try {
        removeExistingBranchReportsForGivenRunDate(runDate);
        populateBranchReportBatch(session, runDate);
        StaticHibernateUtil.commitTransaction();
    } catch (HibernateException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BatchJobException(e);
    } catch (ServiceException e) {
        throw new BatchJobException(e);
    }
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateException(org.hibernate.HibernateException) Date(java.util.Date) Session(org.hibernate.Session)

Example 7 with BatchJobException

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

the class MifosBatchJob method launchJob.

/**
     * A method responsible for the actual launch of the Spring Batch job.
     * @param job Job class
     * @param jobParameters Job parameters
     * @return Batch computation status
     * @throws BatchJobException when something goes wrong
     */
private BatchStatus launchJob(Job job, JobParameters jobParameters) throws BatchJobException {
    BatchStatus exitStatus = BatchStatus.UNKNOWN;
    JobExecution jobExecution = null;
    try {
        batchJobStarted();
        requiresExclusiveAccess();
        jobExecution = jobLauncher.run(job, jobParameters);
        exitStatus = jobExecution.getStatus();
    } catch (JobInstanceAlreadyCompleteException jiace) {
        exitStatus = BatchStatus.COMPLETED;
        return exitStatus;
    } catch (Exception ex) {
        throw new BatchJobException(ex);
    } finally {
        batchJobFinished();
    }
    return exitStatus;
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstanceAlreadyCompleteException(org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) BatchStatus(org.springframework.batch.core.BatchStatus) ParseException(java.text.ParseException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) JobExecutionException(org.quartz.JobExecutionException) JobInstanceAlreadyCompleteException(org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException)

Example 8 with BatchJobException

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

the class ApplyCustomerFeeChangesHelper method execute.

@Override
public void execute(@SuppressWarnings("unused") long timeInMillis) throws BatchJobException {
    List<String> errorList = new ArrayList<String>();
    List<Short> updatedFeeIds = new ArrayList<Short>();
    try {
        updatedFeeIds = getFeeDao().getUpdatedFeesForCustomer();
    } catch (Exception e) {
        errorList.add(e.getMessage());
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
    for (Short feeId : updatedFeeIds) {
        try {
            FeeBO hydratedFee = getFeeDao().findById(feeId);
            if (!hydratedFee.getFeeChangeType().equals(FeeChangeType.NOT_UPDATED)) {
                List<AccountBO> accounts = new CustomerPersistence().getCustomerAccountsForFee(hydratedFee.getFeeId());
                if (accounts != null && accounts.size() > 0) {
                    for (AccountBO account : accounts) {
                        updateAccountFee(account, hydratedFee);
                    }
                }
            }
            hydratedFee.updateFeeChangeType(FeeChangeType.NOT_UPDATED);
            UserContext userContext = new UserContext();
            userContext.setId(PersonnelConstants.SYSTEM_USER);
            hydratedFee.setUserContext(userContext);
            hydratedFee.save();
            StaticHibernateUtil.commitTransaction();
        } catch (Exception e) {
            StaticHibernateUtil.rollbackTransaction();
            errorList.add("feeId: " + feeId);
        }
    }
    if (errorList.size() > 0) {
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) FeeBO(org.mifos.accounts.fees.business.FeeBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException)

Example 9 with BatchJobException

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

the class BranchReportLoanArrearsAgingHelper method populateLoanArrearsAging.

public void populateLoanArrearsAging() throws BatchJobException {
    LoanArrearsAgingPeriod[] values = LoanArrearsAgingPeriod.values();
    for (LoanArrearsAgingPeriod period : values) {
        try {
            BranchReportLoanArrearsAgingBO loanArrears = branchReportService.extractLoanArrearsAgingInfoInPeriod(branchReport.getBranchId(), period, branchReportConfigService.getCurrency());
            branchReport.addLoanArrearsAging(loanArrears);
        } catch (ServiceException e) {
            throw new BatchJobException(e);
        }
    }
}
Also used : BranchReportLoanArrearsAgingBO(org.mifos.reports.branchreport.BranchReportLoanArrearsAgingBO) LoanArrearsAgingPeriod(org.mifos.reports.branchreport.LoanArrearsAgingPeriod) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) ServiceException(org.mifos.framework.exceptions.ServiceException)

Example 10 with BatchJobException

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

the class CustomerAccountBO method updateFee.

public void updateFee(final AccountFeesEntity fee, final FeeBO feeBO) throws BatchJobException {
    boolean feeApplied = isFeeAlreadyApplied(fee, feeBO);
    if (!feeApplied) {
        // update this account fee
        try {
            if (feeBO.getFeeChangeType().equals(FeeChangeType.AMOUNT_AND_STATUS_UPDATED)) {
                if (!feeBO.isActive()) {
                    removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments(feeBO.getFeeId(), Short.valueOf("1"));
                    fee.changeFeesStatus(FeeStatus.INACTIVE, new DateTimeService().getCurrentJavaDateTime());
                    updateAccountFee(fee, (AmountFeeBO) feeBO);
                } else {
                    // generate repayment schedule and enable fee
                    fee.changeFeesStatus(FeeStatus.ACTIVE, new DateTimeService().getCurrentJavaDateTime());
                    updateAccountFee(fee, (AmountFeeBO) feeBO);
                    associateFeeWithAllKnownFutureInstallments(fee);
                }
            } else if (feeBO.getFeeChangeType().equals(FeeChangeType.STATUS_UPDATED)) {
                if (!feeBO.isActive()) {
                    removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments(feeBO.getFeeId(), Short.valueOf("1"));
                } else {
                    fee.changeFeesStatus(FeeStatus.ACTIVE, new DateTimeService().getCurrentJavaDateTime());
                    associateFeeWithAllKnownFutureInstallments(fee);
                }
            } else if (feeBO.getFeeChangeType().equals(FeeChangeType.AMOUNT_UPDATED)) {
                updateAccountFee(fee, (AmountFeeBO) feeBO);
                updateUpcomingAndFutureInstallments(fee);
            }
        } catch (PropertyNotFoundException e) {
            throw new BatchJobException(e);
        } catch (AccountException e) {
            throw new BatchJobException(e);
        }
    }
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) PropertyNotFoundException(org.mifos.framework.exceptions.PropertyNotFoundException) AccountException(org.mifos.accounts.exceptions.AccountException) DateTimeService(org.mifos.framework.util.DateTimeService)

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