private void computeEntitlementsToCancel(final ImmutableAccountData account, final List<Entitlement> result, final CallContext context) throws EntitlementApiException { final List<Entitlement> allEntitlementsForAccountId = entitlementApi.getAllEntitlementsForAccountId(account.getId(), context); // Entitlement is smart enough and will cancel the associated add-ons. See also discussion in https://github.com/killbill/killbill/issues/94 final Collection<Entitlement> allEntitlementsButAddonsForAccountId = Collections2.<Entitlement>filter(allEntitlementsForAccountId, new Predicate<Entitlement>() { @Override public boolean apply(final Entitlement entitlement) { // Note: this would miss add-ons created in the future. We should expose a new API to do something similar to EventsStreamBuilder#findBaseSubscription return !ProductCategory.ADD_ON.equals(entitlement.getLastActiveProductCategory()); } }); result.addAll(allEntitlementsButAddonsForAccountId); }
private void computeEntitlementsToCancel(final ImmutableAccountData account, final List<Entitlement> result, final CallContext context) throws EntitlementApiException { final List<Entitlement> allEntitlementsForAccountId = entitlementApi.getAllEntitlementsForAccountId(account.getId(), context); // Entitlement is smart enough and will cancel the associated add-ons. See also discussion in https://github.com/killbill/killbill/issues/94 final Collection<Entitlement> allEntitlementsButAddonsForAccountId = Collections2.<Entitlement>filter(allEntitlementsForAccountId, new Predicate<Entitlement>() { @Override public boolean apply(final Entitlement entitlement) { // Note: this would miss add-ons created in the future. We should expose a new API to do something similar to EventsStreamBuilder#findBaseSubscription return !ProductCategory.ADD_ON.equals(entitlement.getLastActiveProductCategory()); } }); result.addAll(allEntitlementsButAddonsForAccountId); }
@Override public Response doResponseOk(final List<UUID> entitlementIds) { if (responseObject == ObjectType.SUBSCRIPTION) { return uriBuilder.buildResponse(uriInfo, SubscriptionResource.class, "getSubscription", Iterables.getFirst(entitlementIds, null), request); } final Collection<String> bundleIds = new LinkedHashSet<String>(); try { for (final Entitlement entitlement : entitlementApi.getAllEntitlementsForAccountId(account.getId(), callContext)) { if (entitlementIds.contains(entitlement.getId())) { bundleIds.add(entitlement.getBundleId().toString()); } } } catch (final EntitlementApiException e) { return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } if (responseObject == ObjectType.ACCOUNT) { return uriBuilder.buildResponse(uriInfo, AccountResource.class, "getAccountBundles", account.getId(), buildQueryParams(bundleIds), request); } else if (responseObject == ObjectType.BUNDLE) { return uriBuilder.buildResponse(uriInfo, BundleResource.class, "getBundle", Iterables.getFirst(bundleIds, null), request); } else { throw new IllegalStateException("Unexpected input responseObject " + responseObject); } } };
final List<Entitlement> accountEntitlements = entitlementApi.getAllEntitlementsForAccountId(account.getId(), callContext); assertEquals(accountEntitlements.size(), 1);