public void clear(final Account account, final OverdueState previousOverdueState, final OverdueState clearState, final InternalCallContext context) throws OverdueException { log.debug("OverdueStateApplicator:clear : time = " + clock.getUTCNow() + ", previousState = " + previousOverdueState.getName()); storeNewState(account, clearState, context); clearFutureNotification(account, context); try { avoid_extra_credit_by_toggling_AUTO_INVOICE_OFF(account, previousOverdueState, clearState, context); } catch (OverdueApiException e) { throw new OverdueException(e); } try { bus.post(createOverdueEvent(account, previousOverdueState.getName(), clearState.getName(), isBlockBillingTransition(previousOverdueState, clearState), isUnblockBillingTransition(previousOverdueState, clearState), context)); } catch (Exception e) { log.error("Error posting overdue change event to bus", e); } }
protected void storeNewState(final Account blockable, final OverdueState nextOverdueState, final InternalCallContext context) throws OverdueException { try { blockingApi.setBlockingState(new DefaultBlockingState(blockable.getId(), BlockingStateType.ACCOUNT, nextOverdueState.getName(), OverdueService.OVERDUE_SERVICE_NAME, blockChanges(nextOverdueState), blockEntitlement(nextOverdueState), blockBilling(nextOverdueState), clock.getUTCNow()), context); } catch (Exception e) { throw new OverdueException(e, ErrorCode.OVERDUE_CAT_ERROR_ENCOUNTERED, blockable.getId(), blockable.getClass().getName()); } }
log.debug("OverdueStateApplicator:apply <enter> : time = " + clock.getUTCNow() + ", previousState = " + previousOverdueState.getName() + ", nextState = " + nextOverdueState); if (previousOverdueState.getName().equals(nextOverdueState.getName())) { return; bus.post(createOverdueEvent(account, previousOverdueState.getName(), nextOverdueState.getName(), isBlockBillingTransition(previousOverdueState, nextOverdueState), isUnblockBillingTransition(previousOverdueState, nextOverdueState), context)); } catch (Exception e) {
public void checkStateApplied(final BlockingState result, final OverdueState state) { Assert.assertEquals(result.getStateName(), state.getName()); Assert.assertEquals(result.isBlockChange(), state.blockChanges()); Assert.assertEquals(result.isBlockEntitlement(), state.disableEntitlementAndChangesBlocked()); Assert.assertEquals(result.isBlockBilling(), state.disableEntitlementAndChangesBlocked()); }
public OverdueStateJson(final OverdueState overdueState) { this.name = overdueState.getName(); this.externalMessage = overdueState.getExternalMessage(); this.daysBetweenPaymentRetries = overdueState.getDaysBetweenPaymentRetries(); this.disableEntitlementAndChangesBlocked = overdueState.disableEntitlementAndChangesBlocked(); this.blockChanges = overdueState.blockChanges(); this.isClearState = overdueState.isClearState(); Period reevaluationIntervalPeriod = null; try { reevaluationIntervalPeriod = overdueState.getReevaluationInterval(); } catch (OverdueApiException ignored) { } if (reevaluationIntervalPeriod != null) { this.reevaluationIntervalDays = reevaluationIntervalPeriod.getDays(); } else { this.reevaluationIntervalDays = null; } }
@Test(groups = "slow") public void testWrapperNoConfig() throws Exception { overdueWrapperFactory.setOverdueConfig(null); final Account account; final OverdueWrapper wrapper; final OverdueState state; final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes()); final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class); state = config.getStateSet().findState(DefaultBlockingState.CLEAR_STATE_NAME); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); final OverdueState result = wrapper.refresh(internalCallContext); Assert.assertEquals(result.getName(), state.getName()); Assert.assertEquals(result.blockChanges(), state.blockChanges()); Assert.assertEquals(result.disableEntitlementAndChangesBlocked(), state.disableEntitlementAndChangesBlocked()); } }