protected SubscriptionBundle getLatestSubscriptionBundleForExternalKey(final String bundleExternalKey, final TenantContext context) throws OSGIServiceNotAvailable { final SubscriptionApi subscriptionApi = getSubscriptionApi(); try { final List<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundlesForExternalKey(bundleExternalKey, context); if (bundles.isEmpty()) { throw new OSGIServiceNotAvailable("Unable to retrieve latest bundle for bundle external key " + bundleExternalKey); } return bundles.get(bundles.size() - 1); } catch (final SubscriptionApiException e) { logService.log(LogService.LOG_WARNING, "Error retrieving bundles for bundle external key " + bundleExternalKey, e); throw new OSGIServiceNotAvailable(e); } }
@TimedResource @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a bundle by external key", response = BundleJson.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 404, message = "Bundle not found")}) public Response getBundleByKey(@ApiParam(required=true) @QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @QueryParam(QUERY_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, AccountApiException, CatalogApiException { final TenantContext tenantContext = this.context.createTenantContextNoAccountId(request); final List<SubscriptionBundle> bundles; if (includedDeleted) { bundles = subscriptionApi.getSubscriptionBundlesForExternalKey(externalKey, tenantContext); } else { final SubscriptionBundle activeBundle = subscriptionApi.getActiveSubscriptionBundleForExternalKey(externalKey, tenantContext); bundles = ImmutableList.of(activeBundle); } final List<BundleJson> result = new ArrayList<BundleJson>(bundles.size()); for (final SubscriptionBundle bundle : bundles) { final Account account = accountUserApi.getAccountById(bundle.getAccountId(), tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(bundle.getAccountId(), auditMode.getLevel(), tenantContext); final BundleJson json = new BundleJson(bundle, account.getCurrency(), accountAuditLogs); result.add(json); } return Response.status(Status.OK).entity(result).build(); }
final DefaultEntitlement newBaseEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", newProductName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE); final List<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundlesForExternalKey("bundleKey", callContext); Assert.assertEquals(bundles.size(), 2); assertEquals(newerBaseEntitlement.getState(), EntitlementState.ACTIVE); final List<SubscriptionBundle> bundlesAgain = subscriptionApi.getSubscriptionBundlesForExternalKey("bundleKey", callContext); Assert.assertEquals(bundlesAgain.size(), 3);
assertNull(entitlement.getEffectiveEndDate()); final List<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundlesForExternalKey(externalKey, callContext); assertEquals(bundles.size(), 1); assertEquals(entitlement2.getExternalKey(), externalKey); final List<SubscriptionBundle> bundles2 = subscriptionApi.getSubscriptionBundlesForExternalKey(externalKey, callContext); assertEquals(bundles2.size(), 2); assertListenerStatus(); final List<SubscriptionBundle> bundles3 = subscriptionApi.getSubscriptionBundlesForExternalKey(externalKey, callContext); assertEquals(bundles3.size(), 3);