private void recordFutureNotification(final DateTime effectiveDate, final NotificationEvent notificationEvent, final InternalCallContext context) { try { final NotificationQueue subscriptionEventQueue = notificationQueueService.getNotificationQueue(DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, DefaultEntitlementService.NOTIFICATION_QUEUE_NAME); subscriptionEventQueue.recordFutureNotification(effectiveDate, notificationEvent, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } catch (NoSuchNotificationQueue e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } }
private boolean scheduleRetryInternal(final UUID paymentId, final DateTime timeOfRetry, final EntitySqlDaoWrapperFactory<EntitySqlDao> transactionalDao) { final InternalCallContext context = createCallContextFromPaymentId(paymentId); try { final NotificationQueue retryQueue = notificationQueueService.getNotificationQueue(DefaultPaymentService.SERVICE_NAME, getQueueName()); final NotificationEvent key = new PaymentRetryNotificationKey(paymentId); if (retryQueue != null) { if (transactionalDao == null) { retryQueue.recordFutureNotification(timeOfRetry, key, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } else { retryQueue.recordFutureNotificationFromTransaction(transactionalDao.getSqlDao(), timeOfRetry, key, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } } } catch (NoSuchNotificationQueue e) { log.error(String.format("Failed to retrieve notification queue %s:%s", DefaultPaymentService.SERVICE_NAME, getQueueName())); return false; } catch (IOException e) { log.error(String.format("Failed to serialize notificationQueue event for paymentId %s", paymentId)); return false; } return true; }
private void recordFutureNotification(final DateTime effectiveDate, final NotificationEvent notificationEvent, final InternalCallContext context) { try { final NotificationQueue subscriptionEventQueue = notificationQueueService.getNotificationQueue(DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, DefaultEntitlementService.NOTIFICATION_QUEUE_NAME); subscriptionEventQueue.recordFutureNotification(effectiveDate, notificationEvent, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } catch (NoSuchNotificationQueue e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } }
@Override public void insertNextBillingNotification(final UUID accountId, final UUID subscriptionId, final DateTime futureNotificationTime, final UUID userToken) { final InternalCallContext context = createCallContext(accountId, userToken); final NotificationQueue nextBillingQueue; try { nextBillingQueue = notificationQueueService.getNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME, DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE); log.info("Queuing next billing date notification at {} for subscriptionId {}", futureNotificationTime.toString(), subscriptionId.toString()); nextBillingQueue.recordFutureNotification(futureNotificationTime, new NextBillingDateNotificationKey(subscriptionId), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } catch (NoSuchNotificationQueue e) { log.error("Attempting to put items on a non-existent queue (NextBillingDateNotifier).", e); } catch (IOException e) { log.error("Failed to serialize notificationKey for subscriptionId {}", subscriptionId); } }
private void recordPauseResumeNotificationEntry(final UUID entitlementId, final UUID bundleId, final DateTime effectiveDate, final boolean isPause, final InternalCallContext contextWithValidAccountRecordId) throws EntitlementApiException { final NotificationEvent notificationEvent = new EntitlementNotificationKey(entitlementId, bundleId, isPause ? EntitlementNotificationKeyAction.PAUSE : EntitlementNotificationKeyAction.RESUME, effectiveDate); try { final NotificationQueue subscriptionEventQueue = notificationQueueService.getNotificationQueue(DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, DefaultEntitlementService.NOTIFICATION_QUEUE_NAME); subscriptionEventQueue.recordFutureNotification(effectiveDate, notificationEvent, contextWithValidAccountRecordId.getUserToken(), contextWithValidAccountRecordId.getAccountRecordId(), contextWithValidAccountRecordId.getTenantRecordId()); } catch (final NoSuchNotificationQueue e) { throw new EntitlementApiException(e, ErrorCode.__UNKNOWN_ERROR_CODE); } catch (final IOException e) { throw new EntitlementApiException(e, ErrorCode.__UNKNOWN_ERROR_CODE); } }
@Test(groups = "slow") public void testInvoiceNotifier() throws Exception { final UUID accountId = UUID.randomUUID(); final SubscriptionBase subscription = invoiceUtil.createSubscription(); final UUID subscriptionId = subscription.getId(); final DateTime now = clock.getUTCNow(); final NotificationQueue nextBillingQueue = notificationQueueService.getNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME, DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE); nextBillingQueue.recordFutureNotification(now, new NextBillingDateNotificationKey(subscriptionId), internalCallContext.getUserToken(), internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId()); // Move time in the future after the notification effectiveDate ((ClockMock) clock).setDeltaFromReality(3000); await().atMost(1, MINUTES).until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return testInvoiceNotificationQListener.getEventCount() == 1; } }); Assert.assertEquals(testInvoiceNotificationQListener.getEventCount(), 1); Assert.assertEquals(testInvoiceNotificationQListener.getLatestSubscriptionId(), subscriptionId); } }