use of org.mifos.application.holiday.util.helpers.RepaymentRuleTypes 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.util.helpers.RepaymentRuleTypes in project head by mifos.
the class HolidayAdjustmentRuleFactoryTest method givenRepaymentMoratoriumRuleFactoryShouldReturnNearestNearestScheduledEventBeginningOnStrategy.
@Test
public void givenRepaymentMoratoriumRuleFactoryShouldReturnNearestNearestScheduledEventBeginningOnStrategy() {
RepaymentRuleTypes holidayAdjustmentRule = RepaymentRuleTypes.REPAYMENT_MORATORIUM;
// exercise test
DateAdjustmentStrategy adjustmentStrategy = holidayAdjustmentRuleFactory.createStrategy(originalScheduledDate, workingDays, scheduledEvent, holidayAdjustmentRule);
assertThat(adjustmentStrategy, is(instanceOf(NextScheduledEventStrategy.class)));
}
use of org.mifos.application.holiday.util.helpers.RepaymentRuleTypes in project head by mifos.
the class HolidayAdjustmentRuleFactoryTest method factoryShouldReturnNearestScheduledEventBeginningOnStrategy.
@Test
public void factoryShouldReturnNearestScheduledEventBeginningOnStrategy() {
RepaymentRuleTypes holidayAdjustmentRule = RepaymentRuleTypes.NEXT_MEETING_OR_REPAYMENT;
// exercise test
DateAdjustmentStrategy adjustmentStrategy = holidayAdjustmentRuleFactory.createStrategy(originalScheduledDate, workingDays, scheduledEvent, holidayAdjustmentRule);
assertThat(adjustmentStrategy, is(instanceOf(NextScheduledEventStrategy.class)));
}
use of org.mifos.application.holiday.util.helpers.RepaymentRuleTypes in project head by mifos.
the class HolidayAdjustmentRuleFactoryTest method factoryShouldReturnNextWorkingDayStrategyForSameDayRule.
@Test
public void factoryShouldReturnNextWorkingDayStrategyForSameDayRule() {
RepaymentRuleTypes holidayAdjustmentRule = RepaymentRuleTypes.SAME_DAY;
// exercise test
DateAdjustmentStrategy adjustmentStrategy = holidayAdjustmentRuleFactory.createStrategy(originalScheduledDate, workingDays, scheduledEvent, holidayAdjustmentRule);
assertThat(adjustmentStrategy, is(instanceOf(SameDayStrategy.class)));
}
use of org.mifos.application.holiday.util.helpers.RepaymentRuleTypes in project head by mifos.
the class HolidayAdjustmentRuleFactoryTest method factoryShouldReturnNextWorkingDayStrategy.
@Test
public void factoryShouldReturnNextWorkingDayStrategy() {
RepaymentRuleTypes holidayAdjustmentRule = RepaymentRuleTypes.NEXT_WORKING_DAY;
// exercise test
DateAdjustmentStrategy adjustmentStrategy = holidayAdjustmentRuleFactory.createStrategy(originalScheduledDate, workingDays, scheduledEvent, holidayAdjustmentRule);
assertThat(adjustmentStrategy, is(instanceOf(NextWorkingDayStrategy.class)));
}
Aggregations