Search in sources :

Example 11 with SubscriptionBundle

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();
}
Also used : Account(org.killbill.billing.account.api.Account) SubscriptionBundle(org.killbill.billing.entitlement.api.SubscriptionBundle) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) BundleJson(org.killbill.billing.jaxrs.json.BundleJson) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with SubscriptionBundle

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();
}
Also used : InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) SubscriptionBundle(org.killbill.billing.entitlement.api.SubscriptionBundle) UUID(java.util.UUID) HashSet(java.util.HashSet)

Aggregations

SubscriptionBundle (org.killbill.billing.entitlement.api.SubscriptionBundle)12 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 Produces (javax.ws.rs.Produces)9 TimedResource (org.killbill.commons.metrics.TimedResource)9 UUID (java.util.UUID)8 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 TenantContext (org.killbill.billing.util.callcontext.TenantContext)7 Account (org.killbill.billing.account.api.Account)6 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)6 BundleJson (org.killbill.billing.jaxrs.json.BundleJson)5 LocalDate (org.joda.time.LocalDate)3 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2