use of org.killbill.billing.entitlement.api.SubscriptionBundle in project killbill by killbill.
the class BundleResource method getBundleByKey.
@TimedResource
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a bundle by external key", response = BundleJson.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Bundle not found") })
public Response getBundleByKey(@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.createContext(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();
}
use of org.killbill.billing.entitlement.api.SubscriptionBundle in project killbill by killbill.
the class AccountTimelineJson method getBundleExternalKey.
private String getBundleExternalKey(final Invoice invoice, final List<SubscriptionBundle> bundles) {
final Set<UUID> b = new HashSet<UUID>();
for (final InvoiceItem cur : invoice.getInvoiceItems()) {
b.add(cur.getBundleId());
}
boolean first = true;
final StringBuilder tmp = new StringBuilder();
for (final UUID cur : b) {
for (final SubscriptionBundle bt : bundles) {
if (bt.getId().equals(cur)) {
if (!first) {
tmp.append(",");
}
tmp.append(bt.getExternalKey());
first = false;
break;
}
}
}
return tmp.toString();
}
Aggregations