Search in sources :

Example 1 with InvoiceJson

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

the class AccountResource method getInvoices.

/*
     * ************************** INVOICES ********************************
     */
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + INVOICES)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve account invoices", response = InvoiceJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response getInvoices(@PathParam("accountId") final String accountIdString, @QueryParam(QUERY_INVOICE_WITH_ITEMS) @DefaultValue("false") final boolean withItems, @QueryParam(QUERY_WITH_MIGRATION_INVOICES) @DefaultValue("false") final boolean withMigrationInvoices, @QueryParam(QUERY_UNPAID_INVOICES_ONLY) @DefaultValue("false") final boolean unpaidInvoicesOnly, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException {
    final TenantContext tenantContext = context.createContext(request);
    // Verify the account exists
    final UUID accountId = UUID.fromString(accountIdString);
    accountUserApi.getAccountById(accountId, tenantContext);
    final List<Invoice> invoices = unpaidInvoicesOnly ? new ArrayList<Invoice>(invoiceApi.getUnpaidInvoicesByAccountId(accountId, null, tenantContext)) : invoiceApi.getInvoicesByAccount(accountId, withMigrationInvoices, tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(accountId, auditMode.getLevel(), tenantContext);
    final List<InvoiceJson> result = new LinkedList<InvoiceJson>();
    for (final Invoice invoice : invoices) {
        result.add(new InvoiceJson(invoice, withItems, null, accountAuditLogs));
    }
    return Response.status(Status.OK).entity(result).build();
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) InvoiceJson(org.killbill.billing.jaxrs.json.InvoiceJson) TenantContext(org.killbill.billing.util.callcontext.TenantContext) UUID(java.util.UUID) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) LinkedList(java.util.LinkedList) 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 2 with InvoiceJson

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

the class InvoiceResource method getInvoice.

@TimedResource
@GET
@Path("/{invoiceId:" + UUID_PATTERN + "}/")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve an invoice by id", response = InvoiceJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid invoice id supplied"), @ApiResponse(code = 404, message = "Invoice not found") })
public Response getInvoice(@PathParam("invoiceId") final String invoiceId, @QueryParam(QUERY_INVOICE_WITH_ITEMS) @DefaultValue("false") final boolean withItems, @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.createContext(request);
    final Invoice invoice = invoiceApi.getInvoice(UUID.fromString(invoiceId), tenantContext);
    final List<InvoiceItem> childInvoiceItems = withChildrenItems ? invoiceApi.getInvoiceItemsByParentInvoice(invoice.getId(), tenantContext) : null;
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(invoice.getAccountId(), auditMode.getLevel(), tenantContext);
    if (invoice == null) {
        throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, invoiceId);
    } else {
        final InvoiceJson json = new InvoiceJson(invoice, withItems, childInvoiceItems, accountAuditLogs);
        return Response.status(Status.OK).entity(json).build();
    }
}
Also used : InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) 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)

Example 3 with InvoiceJson

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

the class InvoiceResource method searchInvoices.

@TimedResource
@GET
@Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search invoices", response = InvoiceJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchInvoices(@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_INVOICE_WITH_ITEMS) @DefaultValue("false") final Boolean withItems, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException {
    final TenantContext tenantContext = context.createContext(request);
    final Pagination<Invoice> invoices = invoiceApi.searchInvoices(searchKey, offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(InvoiceResource.class, "searchInvoices", invoices.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_INVOICE_WITH_ITEMS, withItems.toString(), QUERY_AUDIT, auditMode.getLevel().toString()));
    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, withItems, 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) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) 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 4 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_INVOICE_WITH_ITEMS) @DefaultValue("false") final Boolean withItems, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws InvoiceApiException {
    final TenantContext tenantContext = context.createContext(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_INVOICE_WITH_ITEMS, withItems.toString(), QUERY_AUDIT, auditMode.getLevel().toString()));
    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, withItems, 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) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) 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 5 with InvoiceJson

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

the class InvoiceResource method searchInvoices.

@TimedResource
@GET
@Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search invoices", response = InvoiceJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchInvoices(@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 SubscriptionApiException {
    final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
    final Pagination<Invoice> invoices = invoiceApi.searchInvoices(searchKey, offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(InvoiceResource.class, "searchInvoices", invoices.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString()), ImmutableMap.<String, String>of("searchKey", searchKey));
    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)

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