use of org.killbill.billing.entitlement.AccountEntitlements 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);
}
use of org.killbill.billing.entitlement.AccountEntitlements in project killbill by killbill.
the class DefaultSubscriptionApi method getSubscriptionForEntitlementId.
@Override
public Subscription getSubscriptionForEntitlementId(final UUID entitlementId, final TenantContext tenantContext) throws SubscriptionApiException {
// Retrieve entitlements
final AccountEntitlements accountEntitlements;
try {
final UUID accountId = internalCallContextFactory.getAccountId(entitlementId, ObjectType.SUBSCRIPTION, tenantContext);
final InternalTenantContext internalTenantContextWithValidAccountRecordId = internalCallContextFactory.createInternalTenantContext(accountId, tenantContext);
accountEntitlements = entitlementInternalApi.getAllEntitlementsForAccount(internalTenantContextWithValidAccountRecordId);
} catch (final EntitlementApiException e) {
throw new SubscriptionApiException(e);
}
// Build subscriptions
final Iterable<Subscription> accountSubscriptions = Iterables.<Subscription>concat(buildSubscriptionsFromEntitlements(accountEntitlements).values());
return Iterables.<Subscription>find(accountSubscriptions, new Predicate<Subscription>() {
@Override
public boolean apply(final Subscription subscription) {
return subscription.getId().equals(entitlementId);
}
});
}
Aggregations