Search in sources :

Example 6 with InternalTenantContext

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

the class DefaultAccountInternalApi method createBCDCacheLoaderArgument.

private CacheLoaderArgument createBCDCacheLoaderArgument(final InternalTenantContext context) {
    final AccountBCDCacheLoader.LoaderCallback loaderCallback = new AccountBCDCacheLoader.LoaderCallback() {

        @Override
        public Object loadAccountBCD(final UUID accountId, final InternalTenantContext context) {
            Object result = accountDao.getAccountBCD(accountId, context);
            if (result != null) {
                // If the value is 0, then account BCD was not set so we don't want to create a cache entry
                result = result.equals(DefaultMutableAccountData.DEFAULT_BILLING_CYCLE_DAY_LOCAL) ? null : result;
            }
            return result;
        }
    };
    final Object[] args = new Object[1];
    args[0] = loaderCallback;
    final ObjectType irrelevant = null;
    return new CacheLoaderArgument(irrelevant, args, context);
}
Also used : ObjectType(org.killbill.billing.ObjectType) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) AccountBCDCacheLoader(org.killbill.billing.util.cache.AccountBCDCacheLoader) UUID(java.util.UUID) CacheLoaderArgument(org.killbill.billing.util.cache.CacheLoaderArgument)

Example 7 with InternalTenantContext

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

the class DefaultEntitlementApi method getDryRunStatusForChange.

@Override
public List<EntitlementAOStatusDryRun> getDryRunStatusForChange(final UUID bundleId, final String targetProductName, @Nullable final LocalDate effectiveDate, final TenantContext context) throws EntitlementApiException {
    final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(bundleId, ObjectType.BUNDLE, context);
    try {
        final SubscriptionBaseBundle bundle = subscriptionBaseInternalApi.getBundleFromId(bundleId, internalContext);
        final SubscriptionBase baseSubscription = subscriptionBaseInternalApi.getBaseSubscription(bundleId, internalContext);
        final InternalTenantContext contextWithValidAccountRecordId = internalCallContextFactory.createInternalTenantContext(bundle.getAccountId(), context);
        final DateTime requestedDate = dateHelper.fromLocalDateAndReferenceTime(effectiveDate, contextWithValidAccountRecordId);
        return subscriptionBaseInternalApi.getDryRunChangePlanStatus(baseSubscription.getId(), targetProductName, requestedDate, contextWithValidAccountRecordId);
    } catch (final SubscriptionBaseApiException e) {
        throw new EntitlementApiException(e);
    }
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) DateTime(org.joda.time.DateTime) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 8 with InternalTenantContext

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

the class DefaultEntitlementApi method getAllEntitlementsForBundle.

@Override
public List<Entitlement> getAllEntitlementsForBundle(final UUID bundleId, final TenantContext tenantContext) throws EntitlementApiException {
    final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(bundleId, ObjectType.BUNDLE, tenantContext);
    final UUID accountId;
    try {
        accountId = subscriptionBaseInternalApi.getBundleFromId(bundleId, internalContext).getAccountId();
    } catch (final SubscriptionBaseApiException e) {
        throw new EntitlementApiException(e);
    }
    return ImmutableList.<Entitlement>copyOf(Iterables.<Entitlement>filter(getAllEntitlementsForAccountId(accountId, tenantContext), new Predicate<Entitlement>() {

        @Override
        public boolean apply(final Entitlement input) {
            return bundleId.equals(input.getBundleId());
        }
    }));
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) UUID(java.util.UUID) EntitlementLoggingHelper.logPauseResumeEntitlement(org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logPauseResumeEntitlement) EntitlementLoggingHelper.logTransferEntitlement(org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logTransferEntitlement) EntitlementLoggingHelper.logCreateEntitlement(org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logCreateEntitlement) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException) Predicate(com.google.common.base.Predicate) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 9 with InternalTenantContext

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

the class DefaultSubscriptionApi method getSubscriptionBundlesForAccount.

private List<SubscriptionBundle> getSubscriptionBundlesForAccount(final UUID accountId, final TenantContext tenantContext) throws SubscriptionApiException {
    final InternalTenantContext internalTenantContextWithValidAccountRecordId = internalCallContextFactory.createInternalTenantContext(accountId, tenantContext);
    // Retrieve entitlements
    final AccountEntitlements accountEntitlements;
    try {
        accountEntitlements = entitlementInternalApi.getAllEntitlementsForAccount(internalTenantContextWithValidAccountRecordId);
    } catch (final EntitlementApiException e) {
        throw new SubscriptionApiException(e);
    }
    // Build subscriptions
    final Map<UUID, List<Subscription>> subscriptionsPerBundle = buildSubscriptionsFromEntitlements(accountEntitlements);
    // Build subscription bundles
    final List<SubscriptionBundle> bundles = new LinkedList<SubscriptionBundle>();
    for (final UUID bundleId : subscriptionsPerBundle.keySet()) {
        final List<Subscription> subscriptionsForBundle = subscriptionsPerBundle.get(bundleId);
        final String externalKey = subscriptionsForBundle.get(0).getExternalKey();
        final SubscriptionBundleTimeline timeline = new DefaultSubscriptionBundleTimeline(accountId, bundleId, externalKey, accountEntitlements.getEntitlements().get(bundleId), internalTenantContextWithValidAccountRecordId);
        final SubscriptionBaseBundle baseBundle = accountEntitlements.getBundles().get(bundleId);
        final SubscriptionBundle subscriptionBundle = new DefaultSubscriptionBundle(bundleId, accountId, externalKey, subscriptionsForBundle, timeline, baseBundle.getOriginalCreatedDate(), baseBundle.getCreatedDate(), baseBundle.getUpdatedDate());
        bundles.add(subscriptionBundle);
    }
    // Sort the results for predictability
    return Ordering.<SubscriptionBundle>from(SUBSCRIPTION_BUNDLE_COMPARATOR).sortedCopy(bundles);
}
Also used : LinkedList(java.util.LinkedList) AccountEntitlements(org.killbill.billing.entitlement.AccountEntitlements) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) UUID(java.util.UUID)

Example 10 with InternalTenantContext

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

the class DefaultSubscriptionApi method getSubscriptionBundlesForExternalKey.

@Override
public List<SubscriptionBundle> getSubscriptionBundlesForExternalKey(final String externalKey, final TenantContext context) throws SubscriptionApiException {
    final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(context);
    final List<SubscriptionBaseBundle> baseBundles = subscriptionBaseInternalApi.getBundlesForKey(externalKey, internalContext);
    final List<SubscriptionBundle> result = new ArrayList<SubscriptionBundle>(baseBundles.size());
    for (final SubscriptionBaseBundle cur : baseBundles) {
        final SubscriptionBundle bundle = getSubscriptionBundle(cur.getId(), context);
        result.add(bundle);
    }
    // Sorting by createdDate will likely place the active bundle last, but this is the same ordering we already use for getSubscriptionBundlesForAccount
    return Ordering.from(SUBSCRIPTION_BUNDLE_COMPARATOR).sortedCopy(result);
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) ArrayList(java.util.ArrayList) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle)

Aggregations

InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)56 UUID (java.util.UUID)9 ArrayList (java.util.ArrayList)8 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)8 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)7 CacheLoaderArgument (org.killbill.billing.util.cache.CacheLoaderArgument)7 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 LocalDate (org.joda.time.LocalDate)6 Predicate (com.google.common.base.Predicate)5 IOException (java.io.IOException)5 ObjectType (org.killbill.billing.ObjectType)5 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)5 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)5 InputStream (java.io.InputStream)4 URI (java.net.URI)4 DateTime (org.joda.time.DateTime)4 Account (org.killbill.billing.account.api.Account)4 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)4 Invoice (org.killbill.billing.invoice.api.Invoice)4