killbill-uncached
overdue: fix swallowed exception when final state has no autoReevaluationInterval This …
12/16/2015 11:37:04 AM
Changes
Details
diff --git a/overdue/src/main/java/org/killbill/billing/overdue/applicator/OverdueStateApplicator.java b/overdue/src/main/java/org/killbill/billing/overdue/applicator/OverdueStateApplicator.java
index 384686c..e2b3604 100644
--- a/overdue/src/main/java/org/killbill/billing/overdue/applicator/OverdueStateApplicator.java
+++ b/overdue/src/main/java/org/killbill/billing/overdue/applicator/OverdueStateApplicator.java
@@ -138,7 +138,7 @@ public class OverdueStateApplicator {
(firstOverdueState != null && billingState != null && billingState.getDateOfEarliestUnpaidInvoice() != null);
if (conditionForNextNotfication) {
- final Period reevaluationInterval = nextOverdueState.isClearState() ? overdueStateSet.getInitialReevaluationInterval() : nextOverdueState.getAutoReevaluationInterval();
+ final Period reevaluationInterval = getReevaluationInterval(overdueStateSet, nextOverdueState);
// If there is no configuration in the config, we assume this is because the overdue conditions are not time based and so there is nothing to retry
if (reevaluationInterval == null) {
log.debug("OverdueStateApplicator <notificationQ> : Missing InitialReevaluationInterval from config, NOT inserting notification for account " + account.getId());
@@ -147,7 +147,6 @@ public class OverdueStateApplicator {
log.debug("OverdueStateApplicator <notificationQ> : inserting notification for account " + account.getId() + ", time = " + clock.getUTCNow().plus(reevaluationInterval));
createFutureNotification(account, clock.getUTCNow().plus(reevaluationInterval), context);
}
-
} else if (nextOverdueState.isClearState()) {
clearFutureNotification(account, context);
}
@@ -166,11 +165,7 @@ public class OverdueStateApplicator {
// on the bus to which invoice will react. We need the latest state (including AUTO_INVOICE_OFF tag for example)
// to be present in the database first.
storeNewState(account, nextOverdueState, context);
- } catch (final OverdueApiException e) {
- if (e.getCode() != ErrorCode.OVERDUE_NO_REEVALUATION_INTERVAL.getCode()) {
- throw new OverdueException(e);
- }
- } catch (AccountApiException e) {
+ } catch (final AccountApiException e) {
throw new OverdueException(e);
}
try {
@@ -181,6 +176,22 @@ public class OverdueStateApplicator {
}
}
+ private Period getReevaluationInterval(final OverdueStateSet overdueStateSet, final OverdueState nextOverdueState) throws OverdueException {
+ try {
+ if (nextOverdueState.isClearState()) {
+ return overdueStateSet.getInitialReevaluationInterval();
+ } else {
+ return nextOverdueState.getAutoReevaluationInterval();
+ }
+ } catch (final OverdueApiException e) {
+ if (e.getCode() == ErrorCode.OVERDUE_NO_REEVALUATION_INTERVAL.getCode()) {
+ return null;
+ } else {
+ throw new OverdueException(e);
+ }
+ }
+ }
+
private void avoid_extra_credit_by_toggling_AUTO_INVOICE_OFF(final ImmutableAccountData account, final OverdueState previousOverdueState,
final OverdueState nextOverdueState, final InternalCallContext context) throws OverdueApiException {
if (isBlockBillingTransition(previousOverdueState, nextOverdueState)) {
diff --git a/overdue/src/test/java/org/killbill/billing/overdue/TestOverdueHelper.java b/overdue/src/test/java/org/killbill/billing/overdue/TestOverdueHelper.java
index bb01c4d..0e74a22 100644
--- a/overdue/src/test/java/org/killbill/billing/overdue/TestOverdueHelper.java
+++ b/overdue/src/test/java/org/killbill/billing/overdue/TestOverdueHelper.java
@@ -58,9 +58,6 @@ public class TestOverdueHelper {
" <externalMessage>Reached OD3</externalMessage>" +
" <blockChanges>true</blockChanges>" +
" <disableEntitlementAndChangesBlocked>true</disableEntitlementAndChangesBlocked>" +
- " <autoReevaluationInterval>" +
- " <unit>DAYS</unit><number>5</number>" +
- " </autoReevaluationInterval>" +
" </state>" +
" <state name=\"OD2\">" +
" <condition>" +