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; } }
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()); }
log.debug("OverdueStateApplicator:apply <enter> : time = " + clock.getUTCNow() + ", previousState = " + previousOverdueState.getName() + ", nextState = " + nextOverdueState); final boolean conditionForNextNotfication = !nextOverdueState.isClearState() || final Period reevaluationInterval = nextOverdueState.isClearState() ? overdueStateSet.getInitialReevaluationInterval() : nextOverdueState.getReevaluationInterval(); } else if (nextOverdueState.isClearState()) { clearFutureNotification(account, context); 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) {
private boolean blockBilling(final OverdueState nextOverdueState) { return nextOverdueState.disableEntitlementAndChangesBlocked(); }
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 blockChanges(final OverdueState nextOverdueState) { return nextOverdueState.blockChanges(); }
public String generateEmail(final Account account, final BillingState billingState, final Account overdueable, final OverdueState nextOverdueState) throws IOException { final Map<String, Object> data = new HashMap<String, Object>(); // TODO raw objects for now. We eventually should respect the account locale and support translations data.put("account", account); data.put("billingState", overdueEmailFormatterFactory.createBillingStateFormatter(billingState)); data.put("overdueable", overdueable); data.put("nextOverdueState", nextOverdueState); // TODO single template for all languages for now return templateEngine.executeTemplate(nextOverdueState.getEnterStateEmailNotification().getTemplateName(), data); } }
private void cancelSubscriptionsIfRequired(final Account account, final OverdueState nextOverdueState, final InternalCallContext context) throws OverdueException { if (nextOverdueState.getSubscriptionCancellationPolicy() == OverdueCancellationPolicy.NONE) { return; switch (nextOverdueState.getSubscriptionCancellationPolicy()) { case END_OF_TERM: actionPolicy = BillingActionPolicy.END_OF_TERM; break; default: throw new IllegalStateException("Unexpected OverdueCancellationPolicy " + nextOverdueState.getSubscriptionCancellationPolicy());
@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()); } }
private boolean blockEntitlement(final OverdueState nextOverdueState) { return nextOverdueState.disableEntitlementAndChangesBlocked(); }
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()); } }
private void sendEmailIfRequired(final BillingState billingState, final Account account, final OverdueState nextOverdueState, final InternalTenantContext context) { // Note: we don't want to fail the full refresh call because sending the email failed. // That's the reason why we catch all exceptions here. // The alternative would be to: throw new OverdueApiException(e, ErrorCode.EMAIL_SENDING_FAILED); // If sending is not configured, skip if (nextOverdueState.getEnterStateEmailNotification() == null) { return; } final List<String> to = ImmutableList.<String>of(account.getEmail()); // TODO - should we look at the account CC: list? final List<String> cc = ImmutableList.<String>of(); final String subject = nextOverdueState.getEnterStateEmailNotification().getSubject(); try { // Generate and send the email final String emailBody = overdueEmailGenerator.generateEmail(account, billingState, account, nextOverdueState); if (nextOverdueState.getEnterStateEmailNotification().isHTML()) { emailSender.sendHTMLEmail(to, cc, subject, emailBody); } else { emailSender.sendPlainTextEmail(to, cc, subject, emailBody); } } catch (IOException e) { log.warn(String.format("Unable to generate or send overdue notification email for account %s and overdueable %s", account.getId(), account.getId()), e); } catch (EmailApiException e) { log.warn(String.format("Unable to send overdue notification email for account %s and overdueable %s", account.getId(), account.getId()), e); } catch (MustacheException e) { log.warn(String.format("Unable to generate overdue notification email for account %s and overdueable %s", account.getId(), account.getId()), e); } }