Search in sources :

Example 1 with NoSuchNotificationQueue

use of org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue in project killbill by killbill.

the class DefaultSubscriptionDao method recordFutureNotificationFromTransaction.

private void recordFutureNotificationFromTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final DateTime effectiveDate, final NotificationEvent notificationKey, final InternalCallContext context) {
    try {
        final NotificationQueue subscriptionEventQueue = notificationQueueService.getNotificationQueue(DefaultSubscriptionBaseService.SUBSCRIPTION_SERVICE_NAME, DefaultSubscriptionBaseService.NOTIFICATION_QUEUE_NAME);
        subscriptionEventQueue.recordFutureNotificationFromTransaction(entitySqlDaoWrapperFactory.getHandle().getConnection(), effectiveDate, notificationKey, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
    } catch (final NoSuchNotificationQueue e) {
        throw new RuntimeException(e);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) NotificationQueue(org.killbill.notificationq.api.NotificationQueue) NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) IOException(java.io.IOException)

Example 2 with NoSuchNotificationQueue

use of org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue in project killbill by killbill.

the class PaymentProcessor method getPaymentAttempts.

private List<PaymentAttempt> getPaymentAttempts(final List<PaymentAttemptModelDao> pastPaymentAttempts, final InternalTenantContext internalTenantContext) {
    List<PaymentAttempt> paymentAttempts = new ArrayList<PaymentAttempt>();
    // Add Past Payment Attempts
    for (PaymentAttemptModelDao pastPaymentAttempt : pastPaymentAttempts) {
        DefaultPaymentAttempt paymentAttempt = new DefaultPaymentAttempt(pastPaymentAttempt.getAccountId(), pastPaymentAttempt.getPaymentMethodId(), pastPaymentAttempt.getId(), pastPaymentAttempt.getCreatedDate(), pastPaymentAttempt.getUpdatedDate(), pastPaymentAttempt.getCreatedDate(), pastPaymentAttempt.getPaymentExternalKey(), pastPaymentAttempt.getTransactionId(), pastPaymentAttempt.getTransactionExternalKey(), pastPaymentAttempt.getTransactionType(), pastPaymentAttempt.getStateName(), pastPaymentAttempt.getAmount(), pastPaymentAttempt.getCurrency(), pastPaymentAttempt.getPluginName(), buildPluginProperties(pastPaymentAttempt));
        paymentAttempts.add(paymentAttempt);
    }
    // Get Future Payment Attempts from Notification Queue and add them to the list
    try {
        final NotificationQueue retryQueue = notificationQueueService.getNotificationQueue(DefaultPaymentService.SERVICE_NAME, DefaultRetryService.QUEUE_NAME);
        final Iterable<NotificationEventWithMetadata<NotificationEvent>> notificationEventWithMetadatas = retryQueue.getFutureNotificationForSearchKeys(internalTenantContext.getAccountRecordId(), internalTenantContext.getTenantRecordId());
        for (final NotificationEventWithMetadata<NotificationEvent> notificationEvent : notificationEventWithMetadatas) {
            // Last Attempt
            PaymentAttemptModelDao lastPaymentAttempt = getLastPaymentAttempt(pastPaymentAttempts, ((PaymentRetryNotificationKey) notificationEvent.getEvent()).getAttemptId());
            if (lastPaymentAttempt != null) {
                DefaultPaymentAttempt futurePaymentAttempt = new DefaultPaymentAttempt(// accountId
                lastPaymentAttempt.getAccountId(), // paymentMethodId
                lastPaymentAttempt.getPaymentMethodId(), // id
                ((PaymentRetryNotificationKey) notificationEvent.getEvent()).getAttemptId(), // createdDate
                null, // updatedDate
                null, // effectiveDate
                notificationEvent.getEffectiveDate(), // paymentExternalKey
                lastPaymentAttempt.getPaymentExternalKey(), // transactionId
                null, // transactionExternalKey
                lastPaymentAttempt.getTransactionExternalKey(), // transactionType
                lastPaymentAttempt.getTransactionType(), // stateName
                SCHEDULED, // amount
                lastPaymentAttempt.getAmount(), // currency
                lastPaymentAttempt.getCurrency(), // pluginName,
                ((PaymentRetryNotificationKey) notificationEvent.getEvent()).getPaymentControlPluginNames().get(0), // pluginProperties
                buildPluginProperties(lastPaymentAttempt));
                paymentAttempts.add(futurePaymentAttempt);
            }
        }
    } catch (NoSuchNotificationQueue noSuchNotificationQueue) {
        log.error("ERROR Loading Notification Queue - " + noSuchNotificationQueue.getMessage());
    }
    return paymentAttempts;
}
Also used : PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) DefaultPaymentAttempt(org.killbill.billing.payment.api.DefaultPaymentAttempt) ArrayList(java.util.ArrayList) PaymentRetryNotificationKey(org.killbill.billing.payment.retry.PaymentRetryNotificationKey) DefaultPaymentAttempt(org.killbill.billing.payment.api.DefaultPaymentAttempt) PaymentAttempt(org.killbill.billing.payment.api.PaymentAttempt) NotificationEventWithMetadata(org.killbill.notificationq.api.NotificationEventWithMetadata) NotificationEvent(org.killbill.notificationq.api.NotificationEvent) NotificationQueue(org.killbill.notificationq.api.NotificationQueue) NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue)

Example 3 with NoSuchNotificationQueue

use of org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue in project killbill by killbill.

the class DefaultBlockingStateDao method recordFutureNotificationFromTransaction.

private void recordFutureNotificationFromTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final DateTime effectiveDate, final NotificationEvent notificationEvent, final InternalCallContext context) {
    try {
        final NotificationQueue subscriptionEventQueue = notificationQueueService.getNotificationQueue(DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, DefaultEntitlementService.NOTIFICATION_QUEUE_NAME);
        subscriptionEventQueue.recordFutureNotificationFromTransaction(entitySqlDaoWrapperFactory.getHandle().getConnection(), effectiveDate, notificationEvent, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
    } catch (final NoSuchNotificationQueue e) {
        throw new RuntimeException(e);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) NotificationQueue(org.killbill.notificationq.api.NotificationQueue) NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) IOException(java.io.IOException)

Example 4 with NoSuchNotificationQueue

use of org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue in project killbill by killbill.

the class InvoiceDispatcher method getNextScheduledInvoiceEffectiveDate.

private Iterable<DateTime> getNextScheduledInvoiceEffectiveDate(final Iterable<UUID> filteredSubscriptionIds, final InternalCallContext internalCallContext) {
    try {
        final NotificationQueue notificationQueue = notificationQueueService.getNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME, DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE);
        final Iterable<NotificationEventWithMetadata<NextBillingDateNotificationKey>> futureNotifications = notificationQueue.getFutureNotificationForSearchKeys(internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
        final Collection<DateTime> effectiveDates = new LinkedList<DateTime>();
        for (final NotificationEventWithMetadata<NextBillingDateNotificationKey> input : futureNotifications) {
            final boolean isEventForSubscription = !filteredSubscriptionIds.iterator().hasNext() || Iterables.contains(filteredSubscriptionIds, input.getEvent().getUuidKey());
            final boolean isEventDryRunForNotifications = input.getEvent().isDryRunForInvoiceNotification() != null ? input.getEvent().isDryRunForInvoiceNotification() : false;
            if (isEventForSubscription && !isEventDryRunForNotifications) {
                effectiveDates.add(input.getEffectiveDate());
            }
        }
        return effectiveDates;
    } catch (final NoSuchNotificationQueue noSuchNotificationQueue) {
        throw new IllegalStateException(noSuchNotificationQueue);
    }
}
Also used : NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) NextBillingDateNotificationKey(org.killbill.billing.invoice.notification.NextBillingDateNotificationKey) NotificationEventWithMetadata(org.killbill.notificationq.api.NotificationEventWithMetadata) NotificationQueue(org.killbill.notificationq.api.NotificationQueue) NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) LinkedList(java.util.LinkedList) DateTime(org.joda.time.DateTime)

Example 5 with NoSuchNotificationQueue

use of org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue in project killbill by killbill.

the class DefaultOverduePosterBase method insertOverdueNotification.

@Override
public <T extends OverdueCheckNotificationKey> void insertOverdueNotification(final UUID accountId, final DateTime futureNotificationTime, final String overdueQueueName, final T notificationKey, final InternalCallContext context) {
    try {
        final NotificationQueue overdueQueue = notificationQueueService.getNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME, overdueQueueName);
        transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<Void>() {

            @Override
            public Void inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception {
                // Check if we already have notifications for that key
                final Class<T> clazz = (Class<T>) notificationKey.getClass();
                final Iterable<NotificationEventWithMetadata<T>> futureNotifications = getFutureNotificationsForAccountInTransaction(entitySqlDaoWrapperFactory, overdueQueue, clazz, context);
                final boolean shouldInsertNewNotification = cleanupFutureNotificationsFormTransaction(entitySqlDaoWrapperFactory, futureNotifications, futureNotificationTime, overdueQueue);
                if (shouldInsertNewNotification) {
                    log.debug("Queuing overdue check notification. Account id: {}, timestamp: {}", accountId.toString(), futureNotificationTime.toString());
                    overdueQueue.recordFutureNotificationFromTransaction(entitySqlDaoWrapperFactory.getHandle().getConnection(), futureNotificationTime, notificationKey, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
                } else {
                    log.debug("Skipping queuing overdue check notification. Account id: {}, timestamp: {}", accountId.toString(), futureNotificationTime.toString());
                }
                return null;
            }
        });
    } catch (final NoSuchNotificationQueue e) {
        log.error("Attempting to put items on a non-existent queue (DefaultOverdueCheck).", e);
    }
}
Also used : NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) EntitySqlDaoWrapperFactory(org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperFactory) NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) NotificationQueue(org.killbill.notificationq.api.NotificationQueue)

Aggregations

NotificationQueue (org.killbill.notificationq.api.NotificationQueue)15 NoSuchNotificationQueue (org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue)15 IOException (java.io.IOException)9 NotificationEventWithMetadata (org.killbill.notificationq.api.NotificationEventWithMetadata)7 DateTime (org.joda.time.DateTime)3 NotificationEvent (org.killbill.notificationq.api.NotificationEvent)3 LocalDate (org.joda.time.LocalDate)2 EntitySqlDaoWrapperFactory (org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperFactory)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Nullable (javax.annotation.Nullable)1 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)1 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)1 NextBillingDateNotificationKey (org.killbill.billing.invoice.notification.NextBillingDateNotificationKey)1 DefaultPaymentAttempt (org.killbill.billing.payment.api.DefaultPaymentAttempt)1 PaymentAttempt (org.killbill.billing.payment.api.PaymentAttempt)1 PaymentAttemptModelDao (org.killbill.billing.payment.dao.PaymentAttemptModelDao)1 PaymentRetryNotificationKey (org.killbill.billing.payment.retry.PaymentRetryNotificationKey)1 TenantContext (org.killbill.billing.util.callcontext.TenantContext)1