Search in sources :

Example 36 with TimedResource

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

the class CatalogResource method getAvailableAddons.

// Need to figure out dependency on StandaloneCatalog
//    @GET
//    @Path("/xsd")
//    @Produces(APPLICATION_XML)
//    public String getCatalogXsd() throws Exception
//    {
//        InputStream stream = XMLSchemaGenerator.xmlSchema(StandaloneCatalog.class);
//        StringWriter writer = new StringWriter();
//        IOUtils.copy(stream, writer);
//        String result = writer.toString();
//
//        return result;
//    }
@TimedResource
@GET
@Path("/availableAddons")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve available add-ons for a given product", response = PlanDetailJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getAvailableAddons(@QueryParam("baseProductName") final String baseProductName, @Nullable @QueryParam("priceListName") final String priceListName, @javax.ws.rs.core.Context final HttpServletRequest request) throws CatalogApiException {
    final TenantContext tenantContext = context.createContext(request);
    final StaticCatalog catalog = catalogUserApi.getCurrentCatalog(catalogName, tenantContext);
    final List<Listing> listings = catalog.getAvailableAddOnListings(baseProductName, priceListName);
    final List<PlanDetailJson> details = new ArrayList<PlanDetailJson>();
    for (final Listing listing : listings) {
        details.add(new PlanDetailJson(listing));
    }
    return Response.status(Status.OK).entity(details).build();
}
Also used : PlanDetailJson(org.killbill.billing.jaxrs.json.PlanDetailJson) Listing(org.killbill.billing.catalog.api.Listing) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) 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 37 with TimedResource

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

the class CatalogResource method getAvailableBasePlans.

@TimedResource
@GET
@Path("/availableBasePlans")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve available base plans", response = PlanDetailJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getAvailableBasePlans(@javax.ws.rs.core.Context final HttpServletRequest request) throws CatalogApiException {
    final TenantContext tenantContext = context.createContext(request);
    final StaticCatalog catalog = catalogUserApi.getCurrentCatalog(catalogName, tenantContext);
    final List<Listing> listings = catalog.getAvailableBasePlanListings();
    final List<PlanDetailJson> details = new ArrayList<PlanDetailJson>();
    for (final Listing listing : listings) {
        details.add(new PlanDetailJson(listing));
    }
    return Response.status(Status.OK).entity(details).build();
}
Also used : PlanDetailJson(org.killbill.billing.jaxrs.json.PlanDetailJson) Listing(org.killbill.billing.catalog.api.Listing) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) 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 38 with TimedResource

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

the class CustomFieldResource method searchCustomFields.

@TimedResource
@GET
@Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search custom fields", response = CustomFieldJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchCustomFields(@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 CustomFieldApiException {
    final TenantContext tenantContext = context.createContext(request);
    final Pagination<CustomField> customFields = customFieldUserApi.searchCustomFields(searchKey, offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(CustomFieldResource.class, "searchCustomFields", customFields.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_AUDIT, auditMode.getLevel().toString()));
    return buildStreamingPaginationResponse(customFields, new Function<CustomField, CustomFieldJson>() {

        @Override
        public CustomFieldJson apply(final CustomField customField) {
            // TODO Really slow - we should instead try to figure out the account id
            final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(customField.getId(), ObjectType.CUSTOM_FIELD, auditMode.getLevel(), tenantContext);
            return new CustomFieldJson(customField, auditLogs);
        }
    }, nextPageUri);
}
Also used : CustomField(org.killbill.billing.util.customfield.CustomField) TenantContext(org.killbill.billing.util.callcontext.TenantContext) List(java.util.List) CustomFieldJson(org.killbill.billing.jaxrs.json.CustomFieldJson) 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 39 with TimedResource

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

the class CustomFieldResource method getCustomFields.

@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List custom fields", response = CustomFieldJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getCustomFields(@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 CustomFieldApiException {
    final TenantContext tenantContext = context.createContext(request);
    final Pagination<CustomField> customFields = customFieldUserApi.getCustomFields(offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(CustomFieldResource.class, "getCustomFields", customFields.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString()));
    return buildStreamingPaginationResponse(customFields, new Function<CustomField, CustomFieldJson>() {

        @Override
        public CustomFieldJson apply(final CustomField customField) {
            // TODO Really slow - we should instead try to figure out the account id
            final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(customField.getId(), ObjectType.CUSTOM_FIELD, auditMode.getLevel(), tenantContext);
            return new CustomFieldJson(customField, auditLogs);
        }
    }, nextPageUri);
}
Also used : CustomField(org.killbill.billing.util.customfield.CustomField) TenantContext(org.killbill.billing.util.callcontext.TenantContext) List(java.util.List) CustomFieldJson(org.killbill.billing.jaxrs.json.CustomFieldJson) 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 40 with TimedResource

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

the class InvoicePaymentResource method getInvoicePayment.

@TimedResource
@GET
@Path("/{paymentId:" + UUID_PATTERN + "}/")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a payment by id", response = InvoicePaymentJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid payment id supplied"), @ApiResponse(code = 404, message = "Payment not found") })
public Response getInvoicePayment(@PathParam("paymentId") final String paymentIdStr, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final UUID paymentIdId = UUID.fromString(paymentIdStr);
    final TenantContext tenantContext = context.createContext(request);
    final Payment payment = paymentApi.getPayment(paymentIdId, withPluginInfo, withAttempts, pluginProperties, tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext);
    final List<InvoicePayment> invoicePayments = invoicePaymentApi.getInvoicePayments(paymentIdId, tenantContext);
    final InvoicePayment invoicePayment = Iterables.tryFind(invoicePayments, new Predicate<InvoicePayment>() {

        @Override
        public boolean apply(final InvoicePayment input) {
            return input.getType() == InvoicePaymentType.ATTEMPT && input.isSuccess();
        }
    }).orNull();
    final UUID invoiceId = invoicePayment != null ? invoicePayment.getInvoiceId() : null;
    final InvoicePaymentJson result = new InvoicePaymentJson(payment, invoiceId, accountAuditLogs);
    return Response.status(Response.Status.OK).entity(result).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) InvoicePayment(org.killbill.billing.invoice.api.InvoicePayment) InvoicePayment(org.killbill.billing.invoice.api.InvoicePayment) Payment(org.killbill.billing.payment.api.Payment) InvoicePaymentJson(org.killbill.billing.jaxrs.json.InvoicePaymentJson) TenantContext(org.killbill.billing.util.callcontext.TenantContext) UUID(java.util.UUID) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) Predicate(com.google.common.base.Predicate) 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