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