use of org.mifos.application.holiday.business.Holiday in project head by mifos.
the class GenerateMeetingsForCustomerAndSavingsHelper method execute.
@Override
public void execute(@SuppressWarnings("unused") final long timeInMillis) throws BatchJobException {
workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
officeCurrentAndFutureHolidays = new HashMap<Short, List<Holiday>>();
long taskStartTime = new DateTimeService().getCurrentDateTime().getMillis();
List<Integer> customerAndSavingsAccountIds = findActiveCustomerAndSavingsAccountIdsThatRequiredMeetingsToBeGenerated();
int accountCount = customerAndSavingsAccountIds.size();
if (accountCount == 0) {
return;
}
List<String> errorList = new ArrayList<String>();
int currentRecordNumber = 0;
int outputIntervalForBatchJobs = GeneralConfig.getOutputIntervalForBatchJobs();
int batchSize = GeneralConfig.getBatchSizeForBatchJobs();
// jpw - hardcoded recordCommittingSize to 500 because now only accounts that need more schedules are returned
int recordCommittingSize = 500;
infoLogBatchParameters(accountCount, outputIntervalForBatchJobs, batchSize, recordCommittingSize);
long startTime = new DateTimeService().getCurrentDateTime().getMillis();
Integer currentAccountId = null;
int updatedRecordCount = 0;
try {
StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
for (Integer accountId : customerAndSavingsAccountIds) {
currentRecordNumber++;
currentAccountId = accountId;
AccountBO accountBO = legacyAccountDao.getAccount(accountId);
List<Holiday> currentAndFutureHolidays = getOfficeCurrentAndFutureHolidays(accountBO.getOffice().getOfficeId());
ScheduledDateGeneration scheduleGenerationStrategy = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, currentAndFutureHolidays);
if (accountBO instanceof CustomerAccountBO) {
((CustomerAccountBO) accountBO).generateNextSetOfMeetingDates(scheduleGenerationStrategy);
updatedRecordCount++;
} else if (accountBO instanceof SavingsBO) {
((SavingsBO) accountBO).generateNextSetOfMeetingDates(workingDays, currentAndFutureHolidays);
updatedRecordCount++;
}
if (currentRecordNumber % batchSize == 0) {
StaticHibernateUtil.flushAndClearSession();
getLogger().debug("completed HibernateUtil.flushAndClearSession()");
}
if (updatedRecordCount > 0) {
if (updatedRecordCount % recordCommittingSize == 0) {
StaticHibernateUtil.commitTransaction();
StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
}
}
if (currentRecordNumber % outputIntervalForBatchJobs == 0) {
long time = System.currentTimeMillis();
String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
logMessage(message);
startTime = time;
}
}
StaticHibernateUtil.commitTransaction();
long time = System.currentTimeMillis();
String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
logMessage(message);
} catch (Exception e) {
logMessage("account " + currentAccountId.intValue() + " exception " + e.getMessage());
StaticHibernateUtil.rollbackTransaction();
errorList.add(currentAccountId.toString());
getLogger().error("Unable to generate schedules for account with ID " + currentAccountId, e);
} finally {
StaticHibernateUtil.closeSession();
}
if (errorList.size() > 0) {
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
logMessage("GenerateMeetingsForCustomerAndSavings ran in " + (new DateTimeService().getCurrentDateTime().getMillis() - taskStartTime));
}
use of org.mifos.application.holiday.business.Holiday in project head by mifos.
the class HolidayDaoHibernate method findCalendarEventsForThisYearAndNext.
@Override
public final CalendarEvent findCalendarEventsForThisYearAndNext(short officeId) {
List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
List<Holiday> upcomingHolidays = retrieveCurrentAndFutureHolidaysForOfficeHierarchyInAscendingOrder(officeId);
return new CalendarEvent(workingDays, upcomingHolidays);
}
use of org.mifos.application.holiday.business.Holiday in project head by mifos.
the class HolidayServiceFacadeWebTier method validateDisbursementDateForNewLoan.
@Override
public void validateDisbursementDateForNewLoan(Short officeId, DateTime disbursementDate) {
List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
validateDisbursementDateIsWorkingDay(disbursementDate, workingDays);
List<Holiday> holidays = holidayDao.findAllHolidaysFromDateAndNext(officeId, new LocalDate(disbursementDate).toString());
validateDisbursementDateIsNotInHoliday(disbursementDate, holidays);
}
use of org.mifos.application.holiday.business.Holiday in project head by mifos.
the class MoratoriumStrategy method shiftDatePastNonMoratoriumHoliday.
/**
* Given that the date is in a non-moratorium holiday, shift it past the holiday until either it is no longer
* in a holiday or moratorium, or until it no longer moves (e.g., lands in a same-day holiday).
*
* <p> If the date shifts into a moratorium period, then shift it out using the RepaymentRuleType of
* the most recent non-moratorium holiday that the date was shifted out of. For example, if shifting
* the date out of a next-working-day holiday lands it in a moratorium period, then use the
* next-working-day repayment rule to shift it past the moratorium period.</p>
*
* @param date the DateTime to be shifted
* @return the shifted date
*/
private DateTime shiftDatePastNonMoratoriumHoliday(DateTime date) {
assert date != null;
assert isEnclosedByAHoliday(date);
assert !isEnclosedByAHolidayWithRepaymentRule(date, RepaymentRuleTypes.REPAYMENT_MORATORIUM);
Holiday currentlyEnclosingHoliday = getHolidayEnclosing(date);
RepaymentRuleTypes mostRecentNonMoratoriumRepaymentRule = //never REPAYMENT_MORATORIUM
currentlyEnclosingHoliday.getRepaymentRuleType();
DateTime previousDate = null;
DateTime adjustedDate = date;
do {
previousDate = adjustedDate;
if (currentlyEnclosingHoliday.getRepaymentRuleType() == RepaymentRuleTypes.REPAYMENT_MORATORIUM) {
adjustedDate = buildHolidayFromCurrentHolidayWithRepaymentRule(currentlyEnclosingHoliday, mostRecentNonMoratoriumRepaymentRule).adjust(previousDate, workingDays, scheduledEvent);
} else {
adjustedDate = (new BasicWorkingDayStrategy(workingDays)).adjust(currentlyEnclosingHoliday.adjust(previousDate, workingDays, scheduledEvent));
mostRecentNonMoratoriumRepaymentRule = currentlyEnclosingHoliday.getRepaymentRuleType();
}
if (isEnclosedByAHoliday(adjustedDate)) {
currentlyEnclosingHoliday = getHolidayEnclosing(adjustedDate);
}
} while (isEnclosedByAHoliday(adjustedDate) && (!adjustedDate.equals(previousDate)));
return adjustedDate;
}
use of org.mifos.application.holiday.business.Holiday in project head by mifos.
the class AnyScheduledEventLoanInstallmentGenerator method generate.
@Override
public List<InstallmentDate> generate(LocalDate actualDisbursementDate, int numberOfInstallments, GraceType graceType, int gracePeriodDuration, Short officeId) {
List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
if (numberOfInstallments > 0) {
List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
List<Holiday> holidays = new ArrayList<Holiday>();
LocalDate startFromMeetingDate = null;
if (scheduledEvent instanceof DailyScheduledEvent) {
startFromMeetingDate = actualDisbursementDate.plusDays(scheduledEvent.getEvery());
} else {
startFromMeetingDate = actualDisbursementDate.plusDays(1);
}
holidays = holidayDao.findAllHolidaysFromDateAndNext(officeId, startFromMeetingDate.toString());
int occurrences = numberOfInstallments;
if (graceType == GraceType.GRACEONALLREPAYMENTS) {
occurrences += gracePeriodDuration;
}
ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
List<Date> dueDates = new ArrayList<Date>();
List<DateTime> installmentDateTimes = dateGeneration.generateScheduledDates(occurrences, startFromMeetingDate.toDateMidnight().toDateTime(), scheduledEvent, false);
for (DateTime installmentDate : installmentDateTimes) {
dueDates.add(installmentDate.toDate());
}
installmentDates = createInstallmentDates(dueDates);
if (graceType == GraceType.GRACEONALLREPAYMENTS) {
removeInstallmentsNeedNotPay(gracePeriodDuration, installmentDates);
}
}
return installmentDates;
}
Aggregations