Search in sources :

Example 11 with InvoiceJson

use of org.killbill.billing.jaxrs.json.InvoiceJson in project killbill by killbill.

the class InvoiceResource method getInvoices.

@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List invoices", response = InvoiceJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getInvoices(@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 InvoiceApiException {
    final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
    final Pagination<Invoice> invoices = invoiceApi.getInvoices(offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(InvoiceResource.class, "getInvoices", invoices.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString()), ImmutableMap.<String, String>of());
    final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
    return buildStreamingPaginationResponse(invoices, new Function<Invoice, InvoiceJson>() {

        @Override
        public InvoiceJson apply(final Invoice invoice) {
            // Cache audit logs per account
            if (accountsAuditLogs.get().get(invoice.getAccountId()) == null) {
                accountsAuditLogs.get().put(invoice.getAccountId(), auditUserApi.getAccountAuditLogs(invoice.getAccountId(), auditMode.getLevel(), tenantContext));
            }
            return new InvoiceJson(invoice, null, accountsAuditLogs.get().get(invoice.getAccountId()));
        }
    }, nextPageUri);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) TenantContext(org.killbill.billing.util.callcontext.TenantContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) URI(java.net.URI) InvoiceJson(org.killbill.billing.jaxrs.json.InvoiceJson) UUID(java.util.UUID) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) 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 12 with InvoiceJson

use of org.killbill.billing.jaxrs.json.InvoiceJson in project killbill by killbill.

the class InvoiceResource method getInvoiceByNumber.

@TimedResource
@GET
@Path("/byNumber/{invoiceNumber:" + NUMBER_PATTERN + "}/")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve an invoice by number", response = InvoiceJson.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Invoice not found") })
public Response getInvoiceByNumber(@PathParam("invoiceNumber") final Integer invoiceNumber, @QueryParam(QUERY_INVOICE_WITH_CHILDREN_ITEMS) @DefaultValue("false") final boolean withChildrenItems, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws InvoiceApiException {
    final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
    final Invoice invoice = invoiceApi.getInvoiceByNumber(invoiceNumber, tenantContext);
    final List<InvoiceItem> childInvoiceItems = withChildrenItems ? invoiceApi.getInvoiceItemsByParentInvoice(invoice.getId(), tenantContext) : null;
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(invoice.getAccountId(), auditMode.getLevel(), tenantContext);
    final InvoiceJson json = new InvoiceJson(invoice, childInvoiceItems, accountAuditLogs);
    return Response.status(Status.OK).entity(json).build();
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) InvoiceJson(org.killbill.billing.jaxrs.json.InvoiceJson) TenantContext(org.killbill.billing.util.callcontext.TenantContext) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) 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)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 Invoice (org.killbill.billing.invoice.api.Invoice)12 InvoiceJson (org.killbill.billing.jaxrs.json.InvoiceJson)12 TimedResource (org.killbill.commons.metrics.TimedResource)12 GET (javax.ws.rs.GET)10 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)10 TenantContext (org.killbill.billing.util.callcontext.TenantContext)10 UUID (java.util.UUID)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 URI (java.net.URI)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)4 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)4 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)4 LocalDate (org.joda.time.LocalDate)3