Search in sources :

Example 81 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class PaymentMethodResource method getPaymentMethodByKey.

@TimedResource(name = "getPaymentMethod")
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a payment method by external key", response = PaymentMethodJson.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Account or payment method not found") })
public Response getPaymentMethodByKey(@QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final TenantContext tenantContext = context.createContext(request);
    final PaymentMethod paymentMethod = paymentApi.getPaymentMethodByExternalKey(externalKey, false, withPluginInfo, pluginProperties, tenantContext);
    final Account account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext);
    final PaymentMethodJson json = PaymentMethodJson.toPaymentMethodJson(account, paymentMethod, accountAuditLogs);
    return Response.status(Status.OK).entity(json).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) PaymentMethodJson(org.killbill.billing.jaxrs.json.PaymentMethodJson) TenantContext(org.killbill.billing.util.callcontext.TenantContext) PaymentMethod(org.killbill.billing.payment.api.PaymentMethod) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) 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 82 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class PaymentResource method getPayments.

@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Get payments", response = PaymentJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getPayments(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_PAYMENT_PLUGIN_NAME) final String pluginName, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final TenantContext tenantContext = context.createContext(request);
    final Pagination<Payment> payments;
    if (Strings.isNullOrEmpty(pluginName)) {
        payments = paymentApi.getPayments(offset, limit, withPluginInfo, withAttempts, pluginProperties, tenantContext);
    } else {
        payments = paymentApi.getPayments(offset, limit, pluginName, withPluginInfo, withAttempts, pluginProperties, tenantContext);
    }
    final URI nextPageUri = uriBuilder.nextPage(PaymentResource.class, "getPayments", payments.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_PAYMENT_METHOD_PLUGIN_NAME, Strings.nullToEmpty(pluginName), QUERY_AUDIT, auditMode.getLevel().toString()));
    final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
    return buildStreamingPaginationResponse(payments, new Function<Payment, PaymentJson>() {

        @Override
        public PaymentJson apply(final Payment payment) {
            // Cache audit logs per account
            if (accountsAuditLogs.get().get(payment.getAccountId()) == null) {
                accountsAuditLogs.get().put(payment.getAccountId(), auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext));
            }
            final AccountAuditLogs accountAuditLogs = accountsAuditLogs.get().get(payment.getAccountId());
            return new PaymentJson(payment, accountAuditLogs);
        }
    }, nextPageUri);
}
Also used : TenantContext(org.killbill.billing.util.callcontext.TenantContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) URI(java.net.URI) PluginProperty(org.killbill.billing.payment.api.PluginProperty) Payment(org.killbill.billing.payment.api.Payment) PaymentJson(org.killbill.billing.jaxrs.json.PaymentJson) 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) 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 83 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class InvoiceResource method triggerEmailNotificationForInvoice.

@TimedResource
@POST
@Path("/{invoiceId:" + UUID_PATTERN + "}/" + EMAIL_NOTIFICATIONS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Trigger an email notification for invoice")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid invoice id supplied"), @ApiResponse(code = 404, message = "Account or invoice not found") })
public Response triggerEmailNotificationForInvoice(@PathParam("invoiceId") final String invoiceId, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws InvoiceApiException, AccountApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final Invoice invoice = invoiceApi.getInvoice(UUID.fromString(invoiceId), callContext);
    if (invoice == null) {
        throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, invoiceId);
    }
    final Account account = accountUserApi.getAccountById(invoice.getAccountId(), callContext);
    // Send the email (synchronous send)
    invoiceNotifier.notify(account, invoice, callContext);
    return Response.status(Status.OK).build();
}
Also used : Account(org.killbill.billing.account.api.Account) InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) Invoice(org.killbill.billing.invoice.api.Invoice) CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 84 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class InvoiceResource method commitInvoice.

@TimedResource
@PUT
@Path("/{invoiceId:" + UUID_PATTERN + "}/" + COMMIT_INVOICE)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Perform the invoice status transition from DRAFT to COMMITTED")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Invoice not found") })
public Response commitInvoice(@PathParam("invoiceId") final String invoiceIdString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws InvoiceApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID invoiceId = UUID.fromString(invoiceIdString);
    invoiceApi.commitInvoice(invoiceId, callContext);
    return Response.status(Response.Status.OK).build();
}
Also used : UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 85 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class InvoiceResource method getInvoiceByNumber.

@TimedResource
@GET
@Path("/{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_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.getInvoiceByNumber(invoiceNumber, 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, invoiceNumber);
    } 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)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)112 TimedResource (org.killbill.commons.metrics.TimedResource)112 ApiResponses (io.swagger.annotations.ApiResponses)111 Produces (javax.ws.rs.Produces)109 Path (javax.ws.rs.Path)95 UUID (java.util.UUID)59 GET (javax.ws.rs.GET)58 TenantContext (org.killbill.billing.util.callcontext.TenantContext)54 Consumes (javax.ws.rs.Consumes)48 CallContext (org.killbill.billing.util.callcontext.CallContext)48 Account (org.killbill.billing.account.api.Account)47 POST (javax.ws.rs.POST)36 PluginProperty (org.killbill.billing.payment.api.PluginProperty)35 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)31 Payment (org.killbill.billing.payment.api.Payment)19 LocalDate (org.joda.time.LocalDate)16 URI (java.net.URI)15 Invoice (org.killbill.billing.invoice.api.Invoice)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)11