Search in sources :

Example 1 with DefaultOverdueStatesAccount

use of org.killbill.billing.overdue.config.DefaultOverdueStatesAccount in project killbill by killbill.

the class OverdueJson method toOverdueConfigWithValidation.

public static OverdueConfig toOverdueConfigWithValidation(final OverdueJson input) {
    final DefaultOverdueConfig result = new DefaultOverdueConfig();
    final DefaultOverdueStatesAccount overdueStateAccount = new DefaultOverdueStatesAccount();
    result.setOverdueStates(overdueStateAccount);
    final DefaultOverdueState[] states = new DefaultOverdueState[input.getOverdueStates().size()];
    int i = 0;
    int prevTimeSinceEarliestUnpaidInvoice = -1;
    for (final OverdueStateConfigJson cur : input.getOverdueStates()) {
        Preconditions.checkNotNull(cur.getName());
        // We only support timeSinceEarliestUnpaidInvoiceEqualsOrExceeds condition (see #611)
        Preconditions.checkNotNull(cur.getCondition());
        Preconditions.checkNotNull(cur.getCondition().getTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds());
        Preconditions.checkNotNull(cur.getCondition().getTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds().getUnit());
        Preconditions.checkState(cur.getCondition().getTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds().getUnit() == TimeUnit.DAYS);
        Preconditions.checkState(cur.getCondition().getTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds().getNumber() > 0);
        final DefaultOverdueState state = new DefaultOverdueState();
        state.setName(cur.getName());
        state.setExternalMessage(cur.getExternalMessage());
        state.setBlockChanges(cur.getBlockChanges());
        state.setDisableEntitlement(cur.getDisableEntitlement());
        state.setSubscriptionCancellationPolicy(cur.getSubscriptionCancellationPolicy());
        state.setClearState(cur.isClearState());
        state.setAutoReevaluationInterval(computeReevaluationInterval(cur.getAutoReevaluationIntervalDays(), prevTimeSinceEarliestUnpaidInvoice, cur.getCondition().getTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds().getNumber()));
        state.setCondition(OverdueConditionJson.toOverdueCondition(cur.getCondition()));
        states[i++] = state;
        prevTimeSinceEarliestUnpaidInvoice = cur.getCondition().getTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds().getNumber();
    }
    overdueStateAccount.setAccountOverdueStates(states);
    overdueStateAccount.setInitialReevaluationInterval(computeReevaluationInterval(null, prevTimeSinceEarliestUnpaidInvoice, 0));
    return result;
}
Also used : DefaultOverdueStatesAccount(org.killbill.billing.overdue.config.DefaultOverdueStatesAccount) DefaultOverdueState(org.killbill.billing.overdue.config.DefaultOverdueState) DefaultOverdueConfig(org.killbill.billing.overdue.config.DefaultOverdueConfig)

Aggregations

DefaultOverdueConfig (org.killbill.billing.overdue.config.DefaultOverdueConfig)1 DefaultOverdueState (org.killbill.billing.overdue.config.DefaultOverdueState)1 DefaultOverdueStatesAccount (org.killbill.billing.overdue.config.DefaultOverdueStatesAccount)1