Search in sources :

Example 66 with TenantContext

use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.

the class TagResource method searchTags.

@TimedResource
@GET
@Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search tags", response = TagJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchTags(@PathParam("searchKey") final String searchKey, @QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagApiException {
    final TenantContext tenantContext = context.createContext(request);
    final Pagination<Tag> tags = tagUserApi.searchTags(searchKey, offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(TagResource.class, "searchTags", tags.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_AUDIT, auditMode.getLevel().toString()));
    final Map<UUID, TagDefinition> tagDefinitionsCache = new HashMap<UUID, TagDefinition>();
    for (final TagDefinition tagDefinition : tagUserApi.getTagDefinitions(tenantContext)) {
        tagDefinitionsCache.put(tagDefinition.getId(), tagDefinition);
    }
    return buildStreamingPaginationResponse(tags, new Function<Tag, TagJson>() {

        @Override
        public TagJson apply(final Tag tag) {
            final TagDefinition tagDefinition = tagDefinitionsCache.get(tag.getTagDefinitionId());
            // TODO Really slow - we should instead try to figure out the account id
            final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tag.getId(), ObjectType.TAG, auditMode.getLevel(), tenantContext);
            return new TagJson(tag, tagDefinition, auditLogs);
        }
    }, nextPageUri);
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TagJson(org.killbill.billing.jaxrs.json.TagJson) HashMap(java.util.HashMap) TenantContext(org.killbill.billing.util.callcontext.TenantContext) List(java.util.List) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) URI(java.net.URI) Path(javax.ws.rs.Path) 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 67 with TenantContext

use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.

the class TagResource method getTags.

@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List tags", response = TagJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getTags(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagApiException {
    final TenantContext tenantContext = context.createContext(request);
    final Pagination<Tag> tags = tagUserApi.getTags(offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(TagResource.class, "getTags", tags.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString()));
    final Map<UUID, TagDefinition> tagDefinitionsCache = new HashMap<UUID, TagDefinition>();
    for (final TagDefinition tagDefinition : tagUserApi.getTagDefinitions(tenantContext)) {
        tagDefinitionsCache.put(tagDefinition.getId(), tagDefinition);
    }
    return buildStreamingPaginationResponse(tags, new Function<Tag, TagJson>() {

        @Override
        public TagJson apply(final Tag tag) {
            final TagDefinition tagDefinition = tagDefinitionsCache.get(tag.getTagDefinitionId());
            // TODO Really slow - we should instead try to figure out the account id
            final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tag.getId(), ObjectType.TAG, auditMode.getLevel(), tenantContext);
            return new TagJson(tag, tagDefinition, auditLogs);
        }
    }, nextPageUri);
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TagJson(org.killbill.billing.jaxrs.json.TagJson) HashMap(java.util.HashMap) TenantContext(org.killbill.billing.util.callcontext.TenantContext) List(java.util.List) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) URI(java.net.URI) Path(javax.ws.rs.Path) 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 68 with TenantContext

use of org.killbill.billing.util.callcontext.TenantContext 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 69 with TenantContext

use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.

the class CreditResource method getCredit.

@GET
@Path("/{creditId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a credit by id", response = CreditJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid credit id supplied"), @ApiResponse(code = 404, message = "Credit not found") })
public Response getCredit(@PathParam("creditId") final String creditId, @javax.ws.rs.core.Context final HttpServletRequest request) throws InvoiceApiException, AccountApiException {
    final TenantContext tenantContext = context.createContext(request);
    final InvoiceItem credit = invoiceUserApi.getCreditById(UUID.fromString(creditId), tenantContext);
    final Invoice invoice = invoiceUserApi.getInvoice(credit.getInvoiceId(), tenantContext);
    final CreditJson creditJson = new CreditJson(invoice, credit);
    return Response.status(Response.Status.OK).entity(creditJson).build();
}
Also used : InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) Invoice(org.killbill.billing.invoice.api.Invoice) TenantContext(org.killbill.billing.util.callcontext.TenantContext) CreditJson(org.killbill.billing.jaxrs.json.CreditJson) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

TenantContext (org.killbill.billing.util.callcontext.TenantContext)69 ApiOperation (io.swagger.annotations.ApiOperation)58 ApiResponses (io.swagger.annotations.ApiResponses)58 Produces (javax.ws.rs.Produces)58 GET (javax.ws.rs.GET)57 TimedResource (org.killbill.commons.metrics.TimedResource)54 Path (javax.ws.rs.Path)51 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)31 UUID (java.util.UUID)30 Account (org.killbill.billing.account.api.Account)17 PluginProperty (org.killbill.billing.payment.api.PluginProperty)15 URI (java.net.URI)14 Payment (org.killbill.billing.payment.api.Payment)13 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Invoice (org.killbill.billing.invoice.api.Invoice)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 Map (java.util.Map)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 List (java.util.List)7