Search in sources :

Example 16 with BatchJobException

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

the class ProductStatusHelper method execute.

@Override
public void execute(long timeInMillis) throws BatchJobException {
    Session session;
    String hqlUpdate;
    Query query;
    try {
        session = StaticHibernateUtil.getSessionTL();
        StaticHibernateUtil.startTransaction();
        hqlUpdate = "update PrdOfferingBO p set p.prdStatus=:activeLoanStatus " + "where p.prdType.productTypeID=:loan and p.startDate=:currentDate";
        query = session.createQuery(hqlUpdate);
        query.setShort("activeLoanStatus", PrdStatus.LOAN_ACTIVE.getValue());
        query.setShort("loan", ProductType.LOAN.getValue());
        query.setDate("currentDate", new Date(timeInMillis));
        query.executeUpdate();
        hqlUpdate = "update PrdOfferingBO p set p.prdStatus=:inActiveLoanStatus " + "where p.prdType.productTypeID=:loan and p.endDate=:currentDate";
        query = session.createQuery(hqlUpdate);
        query.setShort("inActiveLoanStatus", PrdStatus.LOAN_INACTIVE.getValue());
        query.setShort("loan", ProductType.LOAN.getValue());
        query.setDate("currentDate", new Date(timeInMillis));
        query.executeUpdate();
        hqlUpdate = "update PrdOfferingBO p set p.prdStatus=:activeSavingStatus " + "where p.prdType.productTypeID=:saving and p.startDate=:currentDate";
        query = session.createQuery(hqlUpdate);
        query.setShort("activeSavingStatus", PrdStatus.SAVINGS_ACTIVE.getValue());
        query.setShort("saving", ProductType.SAVINGS.getValue());
        query.setDate("currentDate", new Date(timeInMillis));
        query.executeUpdate();
        hqlUpdate = "update PrdOfferingBO p set p.prdStatus=:inActiveSavingStatus " + "where p.prdType.productTypeID=:saving and p.endDate=:currentDate";
        query = session.createQuery(hqlUpdate);
        query.setShort("inActiveSavingStatus", PrdStatus.SAVINGS_INACTIVE.getValue());
        query.setShort("saving", ProductType.SAVINGS.getValue());
        query.setDate("currentDate", new Date(timeInMillis));
        query.executeUpdate();
        StaticHibernateUtil.commitTransaction();
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BatchJobException(e);
    }
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) Query(org.hibernate.Query) Date(java.util.Date) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) Session(org.hibernate.Session)

Example 17 with BatchJobException

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

the class SavingsIntPostingHelper method execute.

@Override
public void execute(final long scheduledFireTime) throws BatchJobException {
    MifosUser principal = createMifosAdminUser();
    SecurityContext securityContext = SecurityContextHolder.getContext();
    if (securityContext == null) {
        securityContext = new SecurityContextImpl();
        SecurityContextHolder.setContext(securityContext);
    }
    if (securityContext.getAuthentication() == null || !securityContext.getAuthentication().isAuthenticated()) {
        Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal, principal.getAuthorities());
        securityContext.setAuthentication(authentication);
    }
    LocalDate dateOfBatchJob = new LocalDate(scheduledFireTime);
    List<String> errorList = new ArrayList<String>();
    try {
        this.savingsServiceFacade.postInterestForLastPostingPeriod(dateOfBatchJob);
    } catch (BusinessRuleException e) {
        errorList.add(e.getMessageKey());
    }
    if (errorList.size() > 0) {
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) BusinessRuleException(org.mifos.service.BusinessRuleException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) LocalDate(org.joda.time.LocalDate)

Example 18 with BatchJobException

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

the class BranchReportStaffSummaryHelper method populateStaffSummary.

public void populateStaffSummary() throws BatchJobException {
    try {
        List<BranchReportStaffSummaryBO> staffSummaries = branchReportService.extractBranchReportStaffSummary(branchReport.getBranchId(), branchReportConfigService.getGracePeriodDays(), branchReportConfigService.getCurrency());
        branchReport.addStaffSummaries(staffSummaries);
    } catch (ServiceException e) {
        throw new BatchJobException(e);
    }
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) ServiceException(org.mifos.framework.exceptions.ServiceException) BranchReportStaffSummaryBO(org.mifos.reports.branchreport.BranchReportStaffSummaryBO)

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