Search in sources :

Example 1 with Listing

use of org.killbill.billing.catalog.api.Listing 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 2 with Listing

use of org.killbill.billing.catalog.api.Listing 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 3 with Listing

use of org.killbill.billing.catalog.api.Listing in project killbill by killbill.

the class TestPlanDetailJson method testFromListing.

@Test(groups = "fast")
public void testFromListing() throws Exception {
    final Product product = Mockito.mock(Product.class);
    Mockito.when(product.getName()).thenReturn(UUID.randomUUID().toString());
    final InternationalPrice price = Mockito.mock(InternationalPrice.class);
    final Price[] mock = {};
    Mockito.when(price.getPrices()).thenReturn(mock);
    final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
    final Recurring recurring = Mockito.mock(Recurring.class);
    Mockito.when(recurring.getRecurringPrice()).thenReturn(price);
    Mockito.when(planPhase.getRecurring()).thenReturn(recurring);
    final Plan plan = Mockito.mock(Plan.class);
    Mockito.when(plan.getProduct()).thenReturn(product);
    Mockito.when(plan.getName()).thenReturn(UUID.randomUUID().toString());
    Mockito.when(plan.getRecurringBillingPeriod()).thenReturn(BillingPeriod.QUARTERLY);
    Mockito.when(plan.getFinalPhase()).thenReturn(planPhase);
    final PriceList priceList = Mockito.mock(PriceList.class);
    Mockito.when(priceList.getName()).thenReturn(UUID.randomUUID().toString());
    final Listing listing = Mockito.mock(Listing.class);
    Mockito.when(listing.getPlan()).thenReturn(plan);
    Mockito.when(listing.getPriceList()).thenReturn(priceList);
    final PlanDetailJson planDetailJson = new PlanDetailJson(listing);
    Assert.assertEquals(planDetailJson.getProduct(), plan.getProduct().getName());
    Assert.assertEquals(planDetailJson.getPlan(), plan.getName());
    Assert.assertEquals(planDetailJson.getFinalPhaseBillingPeriod(), plan.getRecurringBillingPeriod());
    Assert.assertEquals(planDetailJson.getPriceList(), priceList.getName());
    Assert.assertEquals(planDetailJson.getFinalPhaseRecurringPrice().size(), 0);
}
Also used : Recurring(org.killbill.billing.catalog.api.Recurring) InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) Price(org.killbill.billing.catalog.api.Price) Listing(org.killbill.billing.catalog.api.Listing) Product(org.killbill.billing.catalog.api.Product) InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList) Test(org.testng.annotations.Test)

Example 4 with Listing

use of org.killbill.billing.catalog.api.Listing 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(@QueryParam(QUERY_ACCOUNT_ID) final UUID accountId, @javax.ws.rs.core.Context final HttpServletRequest request) throws CatalogApiException {
    final TenantContext tenantContext = accountId != null ? context.createTenantContextWithAccountId(accountId, request) : context.createTenantContextNoAccountId(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 5 with Listing

use of org.killbill.billing.catalog.api.Listing 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, @QueryParam(QUERY_ACCOUNT_ID) final UUID accountId, @javax.ws.rs.core.Context final HttpServletRequest request) throws CatalogApiException {
    final TenantContext tenantContext = accountId != null ? context.createTenantContextWithAccountId(accountId, request) : context.createTenantContextNoAccountId(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)

Aggregations

Listing (org.killbill.billing.catalog.api.Listing)5 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 ArrayList (java.util.ArrayList)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 StaticCatalog (org.killbill.billing.catalog.api.StaticCatalog)4 PlanDetailJson (org.killbill.billing.jaxrs.json.PlanDetailJson)4 TenantContext (org.killbill.billing.util.callcontext.TenantContext)4 TimedResource (org.killbill.commons.metrics.TimedResource)4 InternationalPrice (org.killbill.billing.catalog.api.InternationalPrice)1 Plan (org.killbill.billing.catalog.api.Plan)1 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)1 Price (org.killbill.billing.catalog.api.Price)1 PriceList (org.killbill.billing.catalog.api.PriceList)1 Product (org.killbill.billing.catalog.api.Product)1 Recurring (org.killbill.billing.catalog.api.Recurring)1 Test (org.testng.annotations.Test)1