FINERACT-2152: fix overlapping for update interest pause
This commit is contained in:
committed by
Adam Saghy
parent
5729af5e76
commit
9a8db7e82e
+13
-28
@@ -114,14 +114,13 @@ public class InterestPauseWritePlatformServiceImpl implements InterestPauseWrite
|
||||
LocalDate endDate = parseDate(endDateString, dateFormat, locale);
|
||||
|
||||
validateActiveLoan(loan);
|
||||
validateInterestPauseDates(loan, startDate, endDate, dateFormat, locale);
|
||||
|
||||
LoanTermVariations variation = loanTermVariationsRepository
|
||||
.findByIdAndLoanIdAndTermType(variationId, loan.getId(), INTEREST_PAUSE.getValue())
|
||||
.orElseThrow(() -> new GeneralPlatformDomainRuleException("error.msg.variation.not.found",
|
||||
"Variation not found for the given loan ID"));
|
||||
|
||||
validateVariations(loan, variation);
|
||||
validateInterestPauseDates(loan, startDate, endDate, dateFormat, locale, variation.getId());
|
||||
|
||||
variation.setTermApplicableFrom(startDate);
|
||||
variation.setDateValue(endDate);
|
||||
@@ -135,7 +134,7 @@ public class InterestPauseWritePlatformServiceImpl implements InterestPauseWrite
|
||||
private CommandProcessingResult processInterestPause(Loan loan, LocalDate startDate, LocalDate endDate, String dateFormat,
|
||||
String locale) {
|
||||
validateActiveLoan(loan);
|
||||
validateInterestPauseDates(loan, startDate, endDate, dateFormat, locale);
|
||||
validateInterestPauseDates(loan, startDate, endDate, dateFormat, locale, null);
|
||||
|
||||
LoanTermVariations variation = new LoanTermVariations(INTEREST_PAUSE.getValue(), startDate, null, endDate, false, loan);
|
||||
|
||||
@@ -144,7 +143,8 @@ public class InterestPauseWritePlatformServiceImpl implements InterestPauseWrite
|
||||
return new CommandProcessingResultBuilder().withEntityId(savedVariation.getId()).build();
|
||||
}
|
||||
|
||||
private void validateInterestPauseDates(Loan loan, LocalDate startDate, LocalDate endDate, String dateFormat, String locale) {
|
||||
private void validateInterestPauseDates(Loan loan, LocalDate startDate, LocalDate endDate, String dateFormat, String locale,
|
||||
Long currentVariationId) {
|
||||
|
||||
validateOrThrow(baseDataValidator -> {
|
||||
baseDataValidator.reset().parameter("startDate").value(startDate).notBlank();
|
||||
@@ -182,11 +182,15 @@ public class InterestPauseWritePlatformServiceImpl implements InterestPauseWrite
|
||||
"Interest pause is only supported for loans with recalculate interest enabled.");
|
||||
}
|
||||
|
||||
for (LoanTermVariations existingVariation : loan.getLoanTermVariations()) {
|
||||
if (Objects.equals(existingVariation.getTermType().getValue(), INTEREST_PAUSE.getValue())) {
|
||||
if (!(endDate.isBefore(existingVariation.getTermApplicableFrom()) || startDate.isAfter(existingVariation.getDateValue()))) {
|
||||
throw new GeneralPlatformDomainRuleException("interest.pause.overlapping",
|
||||
"Overlapping interest pauses are not allowed.");
|
||||
List<LoanTermVariations> existingVariations = loan.getLoanTermVariations();
|
||||
for (LoanTermVariations existingVariation : existingVariations) {
|
||||
if (currentVariationId == null || !existingVariation.getId().equals(currentVariationId)) {
|
||||
if (Objects.equals(existingVariation.getTermType().getValue(), INTEREST_PAUSE.getValue())) {
|
||||
if (!(endDate.isBefore(existingVariation.getTermApplicableFrom())
|
||||
|| startDate.isAfter(existingVariation.getDateValue()))) {
|
||||
throw new GeneralPlatformDomainRuleException("interest.pause.overlapping",
|
||||
"Overlapping interest pauses are not allowed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,25 +203,6 @@ public class InterestPauseWritePlatformServiceImpl implements InterestPauseWrite
|
||||
}
|
||||
}
|
||||
|
||||
private void validateVariations(Loan loan, LoanTermVariations variation) {
|
||||
if (variation == null) {
|
||||
throw new GeneralPlatformDomainRuleException("interest.pause.not.found",
|
||||
"The specified interest pause does not exist for the given loan.");
|
||||
}
|
||||
|
||||
List<LoanTermVariations> existingVariations = loan.getLoanTermVariations();
|
||||
for (LoanTermVariations existingVariation : existingVariations) {
|
||||
if (!existingVariation.equals(variation)
|
||||
&& Objects.equals(existingVariation.getTermType().getValue(), INTEREST_PAUSE.getValue())) {
|
||||
if (!(variation.getDateValue().isBefore(existingVariation.getTermApplicableFrom())
|
||||
|| variation.getTermApplicableFrom().isAfter(existingVariation.getDateValue()))) {
|
||||
throw new GeneralPlatformDomainRuleException("interest.pause.overlapping",
|
||||
"Overlapping interest pauses are not allowed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LocalDate parseDate(String date, String dateFormat, String locale) {
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat, Locale.forLanguageTag(locale));
|
||||
|
||||
Reference in New Issue
Block a user