@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();
}