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); } }
private boolean isBlockBillingTransition(final OverdueState prevOverdueState, final OverdueState nextOverdueState) { return !blockBilling(prevOverdueState) && blockBilling(nextOverdueState); }
try { if (isAccountTaggedWith_OVERDUE_ENFORCEMENT_OFF(context)) { log.debug("OverdueStateApplicator:apply returns because account (recordId = " + context.getAccountRecordId() + ") is set with OVERDUE_ENFORCEMENT_OFF "); return; createFutureNotification(account, clock.getUTCNow().plus(reevaluationInterval), context); clearFutureNotification(account, context); storeNewState(account, nextOverdueState, context); cancelSubscriptionsIfRequired(account, nextOverdueState, context); sendEmailIfRequired(billingState, account, nextOverdueState, context); avoid_extra_credit_by_toggling_AUTO_INVOICE_OFF(account, previousOverdueState, nextOverdueState, context); bus.post(createOverdueEvent(account, previousOverdueState.getName(), nextOverdueState.getName(), isBlockBillingTransition(previousOverdueState, nextOverdueState), isUnblockBillingTransition(previousOverdueState, nextOverdueState), 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()); } }
public OverdueState refresh(final InternalCallContext context) throws OverdueException, OverdueApiException { if (overdueStateSet.size() < 1) { // No configuration available return overdueStateSet.getClearState(); } final BillingState billingState = billingState(context); final String previousOverdueStateName = api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context).getStateName(); final OverdueState currentOverdueState = overdueStateSet.findState(previousOverdueStateName); final OverdueState nextOverdueState = overdueStateSet.calculateOverdueState(billingState, clock.getToday(billingState.getAccountTimeZone())); overdueStateApplicator.apply(overdueStateSet, billingState, overdueable, currentOverdueState, nextOverdueState, context); return nextOverdueState; }
public void clear(final InternalCallContext context) throws OverdueException, OverdueApiException { final String previousOverdueStateName = api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context).getStateName(); final OverdueState previousOverdueState = overdueStateSet.findState(previousOverdueStateName); overdueStateApplicator.clear(overdueable, previousOverdueState, overdueStateSet.getClearState(), context); }
computeEntitlementsToCancel(account, toBeCancelled, context);
@Test(groups = "slow") public void testApplicator() throws Exception { final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes()); final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class); overdueWrapperFactory.setOverdueConfig(config); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(UUID.randomUUID()); final OverdueStateSet overdueStateSet = config.getStateSet(); final OverdueState clearState = config.getStateSet().findState(DefaultBlockingState.CLEAR_STATE_NAME); OverdueState state; state = config.getStateSet().findState("OD1"); applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext); testOverdueHelper.checkStateApplied(state); checkBussEvent("OD1"); state = config.getStateSet().findState("OD2"); applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext); testOverdueHelper.checkStateApplied(state); checkBussEvent("OD2"); state = config.getStateSet().findState("OD3"); applicator.apply(overdueStateSet, null, account, clearState, state, internalCallContext); testOverdueHelper.checkStateApplied(state); checkBussEvent("OD3"); }
private boolean isUnblockBillingTransition(final OverdueState prevOverdueState, final OverdueState nextOverdueState) { return blockBilling(prevOverdueState) && !blockBilling(nextOverdueState); }