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