use of org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue in project killbill by killbill.
the class DefaultOverduePosterBase method clearOverdueCheckNotifications.
@Override
public <T extends OverdueCheckNotificationKey> void clearOverdueCheckNotifications(final UUID accountId, final String overdueQueueName, final Class<T> clazz, final InternalCallContext context) {
try {
final NotificationQueue checkOverdueQueue = notificationQueueService.getNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME, overdueQueueName);
transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<Void>() {
@Override
public Void inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception {
final Iterable<NotificationEventWithMetadata<T>> futureNotifications = getFutureNotificationsForAccountInTransaction(entitySqlDaoWrapperFactory, checkOverdueQueue, clazz, context);
for (final NotificationEventWithMetadata<T> notification : futureNotifications) {
checkOverdueQueue.removeNotificationFromTransaction(entitySqlDaoWrapperFactory.getHandle().getConnection(), notification.getRecordId());
}
return null;
}
});
} catch (final NoSuchNotificationQueue e) {
log.error("Attempting to clear items from a non-existent queue (DefaultOverdueCheck).", e);
}
}
use of org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue in project killbill by killbill.
the class PaymentProcessor method cancelScheduledPaymentTransaction.
public void cancelScheduledPaymentTransaction(final UUID lastPaymentAttemptId, final InternalCallContext internalCallContext) throws PaymentApiException {
try {
final NotificationQueue retryQueue = notificationQueueService.getNotificationQueue(DefaultPaymentService.SERVICE_NAME, DefaultRetryService.QUEUE_NAME);
final Iterable<NotificationEventWithMetadata<NotificationEvent>> notificationEventWithMetadatas = retryQueue.getFutureNotificationForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
for (final NotificationEventWithMetadata<NotificationEvent> notificationEvent : notificationEventWithMetadatas) {
if (((PaymentRetryNotificationKey) notificationEvent.getEvent()).getAttemptId().equals(lastPaymentAttemptId)) {
retryQueue.removeNotification(notificationEvent.getRecordId());
}
// Go through all results to close the connection
}
} catch (final NoSuchNotificationQueue noSuchNotificationQueue) {
log.error("ERROR Loading Notification Queue - " + noSuchNotificationQueue.getMessage());
throw new IllegalStateException(noSuchNotificationQueue);
}
}
use of org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue in project killbill by killbill.
the class DefaultNextBillingDatePoster method insertNextBillingFromTransactionInternal.
private void insertNextBillingFromTransactionInternal(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final UUID subscriptionId, final Boolean isDryRunForInvoiceNotification, final DateTime futureNotificationTime, final DateTime targetDate, final InternalCallContext internalCallContext) {
final NotificationQueue nextBillingQueue;
try {
nextBillingQueue = notificationQueueService.getNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME, DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE);
// If we see existing notification for the same date (and isDryRunForInvoiceNotification mode), we don't insert a new notification
final Iterable<NotificationEventWithMetadata<NextBillingDateNotificationKey>> futureNotifications = nextBillingQueue.getFutureNotificationFromTransactionForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId(), entitySqlDaoWrapperFactory.getHandle().getConnection());
boolean existingFutureNotificationWithSameDate = false;
for (final NotificationEventWithMetadata<NextBillingDateNotificationKey> input : futureNotifications) {
final boolean isEventDryRunForNotifications = input.getEvent().isDryRunForInvoiceNotification() != null ? input.getEvent().isDryRunForInvoiceNotification() : false;
final LocalDate notificationEffectiveLocaleDate = internalCallContext.toLocalDate(futureNotificationTime);
final LocalDate eventEffectiveLocaleDate = internalCallContext.toLocalDate(input.getEffectiveDate());
if (notificationEffectiveLocaleDate.compareTo(eventEffectiveLocaleDate) == 0 && ((isDryRunForInvoiceNotification && isEventDryRunForNotifications) || (!isDryRunForInvoiceNotification && !isEventDryRunForNotifications))) {
existingFutureNotificationWithSameDate = true;
}
// Go through all results to close the connection
}
if (!existingFutureNotificationWithSameDate) {
log.info("Queuing next billing date notification at {} for subscriptionId {}", futureNotificationTime.toString(), subscriptionId.toString());
nextBillingQueue.recordFutureNotificationFromTransaction(entitySqlDaoWrapperFactory.getHandle().getConnection(), futureNotificationTime, new NextBillingDateNotificationKey(subscriptionId, targetDate, isDryRunForInvoiceNotification), internalCallContext.getUserToken(), internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
} else if (log.isDebugEnabled()) {
log.debug("********************* SKIPPING Queuing next billing date notification at {} for subscriptionId {} *******************", futureNotificationTime.toString(), subscriptionId.toString());
}
} catch (final NoSuchNotificationQueue e) {
log.error("Attempting to put items on a non-existent queue (NextBillingDateNotifier).", e);
} catch (final IOException e) {
log.error("Failed to serialize notificationKey for subscriptionId {}", subscriptionId);
}
}
use of org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue in project killbill by killbill.
the class ParentInvoiceCommitmentPoster method insertParentInvoiceFromTransactionInternal.
public void insertParentInvoiceFromTransactionInternal(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final UUID invoiceId, final DateTime futureNotificationTime, final InternalCallContext internalCallContext) {
final NotificationQueue commitInvoiceQueue;
try {
commitInvoiceQueue = notificationQueueService.getNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME, ParentInvoiceCommitmentNotifier.PARENT_INVOICE_COMMITMENT_NOTIFIER_QUEUE);
// If we see existing notification for the same date we don't insert a new notification
final Iterable<NotificationEventWithMetadata<ParentInvoiceCommitmentNotificationKey>> futureNotifications = commitInvoiceQueue.getFutureNotificationFromTransactionForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId(), entitySqlDaoWrapperFactory.getHandle().getConnection());
boolean existingFutureNotificationWithSameDate = false;
for (final NotificationEventWithMetadata<ParentInvoiceCommitmentNotificationKey> input : futureNotifications) {
final LocalDate notificationEffectiveLocaleDate = internalCallContext.toLocalDate(futureNotificationTime);
final LocalDate eventEffectiveLocaleDate = internalCallContext.toLocalDate(input.getEffectiveDate());
if (notificationEffectiveLocaleDate.compareTo(eventEffectiveLocaleDate) == 0) {
existingFutureNotificationWithSameDate = true;
}
// Go through all results to close the connection
}
if (!existingFutureNotificationWithSameDate) {
log.info("Queuing parent invoice commitment notification at {} for invoiceId {}", futureNotificationTime.toString(), invoiceId.toString());
commitInvoiceQueue.recordFutureNotificationFromTransaction(entitySqlDaoWrapperFactory.getHandle().getConnection(), futureNotificationTime, new ParentInvoiceCommitmentNotificationKey(invoiceId), internalCallContext.getUserToken(), internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
} else if (log.isDebugEnabled()) {
log.debug("********************* SKIPPING Queuing parent invoice commitment notification at {} for invoiceId {} *******************", futureNotificationTime.toString(), invoiceId.toString());
}
} catch (final NoSuchNotificationQueue e) {
log.error("Attempting to put items on a non-existent queue (ParentInvoiceCommitmentNotifier).", e);
} catch (final IOException e) {
log.error("Failed to serialize notificationKey for invoiceId {}", invoiceId);
}
}
use of org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue in project killbill by killbill.
the class DefaultSubscriptionInternalApi method getFutureNotificationsForAccount.
@Override
public Iterable<DateTime> getFutureNotificationsForAccount(final InternalCallContext internalCallContext) {
try {
final NotificationQueue notificationQueue = notificationQueueService.getNotificationQueue(DefaultSubscriptionBaseService.SUBSCRIPTION_SERVICE_NAME, DefaultSubscriptionBaseService.NOTIFICATION_QUEUE_NAME);
final Iterable<NotificationEventWithMetadata<NotificationEvent>> futureNotifications = notificationQueue.getFutureNotificationForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
return Iterables.transform(futureNotifications, new Function<NotificationEventWithMetadata<NotificationEvent>, DateTime>() {
@Nullable
@Override
public DateTime apply(final NotificationEventWithMetadata<NotificationEvent> input) {
return input.getEffectiveDate();
}
});
} catch (final NoSuchNotificationQueue noSuchNotificationQueue) {
throw new IllegalStateException(noSuchNotificationQueue);
}
}
Aggregations