Search in sources :

Example 86 with InternalTenantContext

use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.

the class DefaultOverdueConfigCache method initializeCacheLoaderArgument.

private CacheLoaderArgument initializeCacheLoaderArgument() {
    final LoaderCallback loaderCallback = new LoaderCallback() {

        @Override
        public OverdueConfig loadOverdueConfig(final String overdueConfigXML) throws OverdueApiException {
            final InputStream overdueConfigStream = new ByteArrayInputStream(overdueConfigXML.getBytes());
            try {
                return XMLLoader.getObjectFromStream(overdueConfigStream, DefaultOverdueConfig.class);
            } catch (final Exception e) {
                throw new OverdueApiException(ErrorCode.OVERDUE_INVALID_FOR_TENANT, "Problem encountered loading overdue config ", e);
            }
        }
    };
    final Object[] args = new Object[1];
    args[0] = loaderCallback;
    final ObjectType irrelevant = null;
    final InternalTenantContext notUsed = null;
    return new CacheLoaderArgument(irrelevant, args, notUsed);
}
Also used : ObjectType(org.killbill.billing.ObjectType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) LoaderCallback(org.killbill.billing.util.cache.TenantOverdueConfigCacheLoader.LoaderCallback) OverdueApiException(org.killbill.billing.overdue.api.OverdueApiException) CacheLoaderArgument(org.killbill.billing.util.cache.CacheLoaderArgument) OverdueApiException(org.killbill.billing.overdue.api.OverdueApiException)

Example 87 with InternalTenantContext

use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.

the class OverdueListener method insertBusEventIntoNotificationQueue.

private void insertBusEventIntoNotificationQueue(final UUID accountId, final OverdueAsyncBusNotificationAction action, final InternalCallContext callContext) {
    final boolean shouldInsertNotification = shouldInsertNotification(callContext);
    if (!shouldInsertNotification) {
        log.debug("OverdueListener: shouldInsertNotification=false");
        return;
    }
    OverdueAsyncBusNotificationKey notificationKey = new OverdueAsyncBusNotificationKey(accountId, action);
    asyncPoster.insertOverdueNotification(accountId, callContext.getCreatedDate(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, callContext);
    try {
        // Refresh parent
        final Account account = accountApi.getAccountById(accountId, callContext);
        if (account.getParentAccountId() != null && account.isPaymentDelegatedToParent()) {
            final InternalTenantContext parentAccountInternalTenantContext = internalCallContextFactory.createInternalTenantContext(account.getParentAccountId(), callContext);
            final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(parentAccountInternalTenantContext.getAccountRecordId(), callContext);
            notificationKey = new OverdueAsyncBusNotificationKey(account.getParentAccountId(), action);
            asyncPoster.insertOverdueNotification(account.getParentAccountId(), callContext.getCreatedDate(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, parentAccountContext);
        }
        // Refresh children
        final List<Account> childrenAccounts = accountApi.getChildrenAccounts(accountId, callContext);
        if (childrenAccounts != null) {
            for (final Account childAccount : childrenAccounts) {
                if (childAccount.isPaymentDelegatedToParent()) {
                    final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(childAccount.getId(), callContext);
                    final InternalCallContext accountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), callContext);
                    notificationKey = new OverdueAsyncBusNotificationKey(childAccount.getId(), action);
                    asyncPoster.insertOverdueNotification(childAccount.getId(), callContext.getCreatedDate(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, accountContext);
                }
            }
        }
    } catch (final Exception e) {
        log.error("Error loading child accounts from accountId='{}'", accountId);
    }
}
Also used : Account(org.killbill.billing.account.api.Account) OverdueAsyncBusNotificationKey(org.killbill.billing.overdue.notification.OverdueAsyncBusNotificationKey) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) OverdueApiException(org.killbill.billing.overdue.api.OverdueApiException)

Example 88 with InternalTenantContext

use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.

the class OverdueWrapper method billingState.

public BillingState billingState(final InternalCallContext context) throws OverdueException {
    if ((overdueable.getParentAccountId() != null) && (overdueable.isPaymentDelegatedToParent())) {
        // calculate billing state from parent account
        final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(overdueable.getParentAccountId(), context);
        final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), context);
        return billingStateCalcuator.calculateBillingState(overdueable, parentAccountContext);
    }
    return billingStateCalcuator.calculateBillingState(overdueable, context);
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 89 with InternalTenantContext

use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.

the class DefaultPaymentDao method getByTransactionStatusAcrossTenants.

@Override
public Pagination<PaymentTransactionModelDao> getByTransactionStatusAcrossTenants(final Iterable<TransactionStatus> transactionStatuses, final DateTime createdBeforeDate, final DateTime createdAfterDate, final Long offset, final Long limit) {
    final Collection<String> allTransactionStatus = ImmutableList.copyOf(Iterables.transform(transactionStatuses, Functions.toStringFunction()));
    final Date createdBefore = createdBeforeDate.toDate();
    final Date createdAfter = createdAfterDate.toDate();
    return paginationHelper.getPagination(TransactionSqlDao.class, new PaginationIteratorBuilder<PaymentTransactionModelDao, PaymentTransaction, TransactionSqlDao>() {

        @Override
        public Long getCount(final TransactionSqlDao sqlDao, final InternalTenantContext context) {
            return sqlDao.getCountByTransactionStatusPriorDateAcrossTenants(allTransactionStatus, createdBefore, createdAfter);
        }

        @Override
        public Iterator<PaymentTransactionModelDao> build(final TransactionSqlDao sqlDao, final Long offset, final Long limit, final Ordering ordering, final InternalTenantContext context) {
            return sqlDao.getByTransactionStatusPriorDateAcrossTenants(allTransactionStatus, createdBefore, createdAfter, offset, limit, ordering.toString());
        }
    }, offset, limit, null);
}
Also used : PaymentTransaction(org.killbill.billing.payment.api.PaymentTransaction) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) Ordering(org.killbill.billing.util.entity.dao.DefaultPaginationSqlDaoHelper.Ordering) Iterator(java.util.Iterator) Date(java.util.Date)

Example 90 with InternalTenantContext

use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.

the class InternalCallContextFactory method createInternalTenantContext.

/**
 * Create an internal tenant callcontext
 *
 * @param tenantRecordId  tenant_record_id (cannot be null)
 * @param accountRecordId account_record_id (cannot be null for INSERT operations)
 * @return internal tenant callcontext
 */
public InternalTenantContext createInternalTenantContext(final Long tenantRecordId, @Nullable final Long accountRecordId) {
    populateMDCContext(null, accountRecordId, tenantRecordId);
    if (accountRecordId == null) {
        return new InternalTenantContext(tenantRecordId);
    } else {
        final ImmutableAccountData immutableAccountData = getImmutableAccountData(accountRecordId, tenantRecordId);
        final DateTimeZone fixedOffsetTimeZone = immutableAccountData.getFixedOffsetTimeZone();
        final DateTime referenceTime = immutableAccountData.getReferenceTime();
        return new InternalTenantContext(tenantRecordId, accountRecordId, fixedOffsetTimeZone, referenceTime);
    }
}
Also used : ImmutableAccountData(org.killbill.billing.account.api.ImmutableAccountData) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime)

Aggregations

InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)92 UUID (java.util.UUID)15 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)13 CacheLoaderArgument (org.killbill.billing.util.cache.CacheLoaderArgument)11 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)10 ArrayList (java.util.ArrayList)9 ObjectType (org.killbill.billing.ObjectType)9 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)9 TenantContext (org.killbill.billing.util.callcontext.TenantContext)9 ImmutableList (com.google.common.collect.ImmutableList)8 List (java.util.List)8 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 DateTime (org.joda.time.DateTime)7 LocalDate (org.joda.time.LocalDate)7 Predicate (com.google.common.base.Predicate)6 AccountApiException (org.killbill.billing.account.api.AccountApiException)6 VersionedCatalog (org.killbill.billing.catalog.api.VersionedCatalog)6 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)6