private void processOverdue(final UUID accountId, final InternalCallContext context) { try { factory.createOverdueWrapperFor(accountId, context).refresh(context); } catch (BillingExceptionBase e) { log.error(String.format("Error processing Overdue for blockable %s", accountId), e); } }
@SuppressWarnings("unchecked") public OverdueWrapper createOverdueWrapperFor(final Account blockable) throws OverdueException { return (OverdueWrapper) new OverdueWrapper(blockable, api, getOverdueStateSet(), clock, billingStateCalculator, overdueStateApplicator); }
@Override public BillingState getBillingStateFor(final Account overdueable, final TenantContext context) throws OverdueException { log.debug("Billing state of of {} requested", overdueable.getId()); final OverdueWrapper wrapper = factory.createOverdueWrapperFor(overdueable); return wrapper.billingState(internalCallContextFactory.createInternalTenantContext(context)); }
private void clearOverdue(final UUID accountId, final InternalCallContext context) { try { factory.createOverdueWrapperFor(accountId, context).clear(context); } catch (BillingExceptionBase e) { log.error(String.format("Error processing Overdue for blockable %s (type %s)", accountId), e); } } }
@Override public OverdueState refreshOverdueStateFor(final Account blockable, final CallContext context) throws OverdueException, OverdueApiException { log.info("Refresh of blockable {} ({}) requested", blockable.getId(), blockable.getClass()); final OverdueWrapper wrapper = factory.createOverdueWrapperFor(blockable); return wrapper.refresh(createInternalCallContext(blockable, context)); }
@SuppressWarnings("unchecked") public OverdueWrapper createOverdueWrapperFor(final UUID id, final InternalTenantContext context) throws OverdueException { try { Account account = accountApi.getAccountById(id, context); return new OverdueWrapper(account, api, getOverdueStateSet(), clock, billingStateCalculator, overdueStateApplicator); } catch (AccountApiException e) { throw new OverdueException(e); } }
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; }
@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()); } }
@Test(groups = "slow") public void testWrapperBasic() throws Exception { final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes()); final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class); overdueWrapperFactory.setOverdueConfig(config); Account account; OverdueWrapper wrapper; OverdueState state; state = config.getStateSet().findState("OD1"); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); wrapper.refresh(internalCallContext); testOverdueHelper.checkStateApplied(state); state = config.getStateSet().findState("OD2"); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(41)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); wrapper.refresh(internalCallContext); testOverdueHelper.checkStateApplied(state); state = config.getStateSet().findState("OD3"); account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(51)); wrapper = overdueWrapperFactory.createOverdueWrapperFor(account); wrapper.refresh(internalCallContext); testOverdueHelper.checkStateApplied(state); }