use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.
the class StandaloneCatalogMapper method toStandaloneCatalog.
public StandaloneCatalog toStandaloneCatalog(final StandalonePluginCatalog pluginCatalog, @Nullable URI catalogURI) {
final StandaloneCatalog result = new StandaloneCatalog();
result.setCatalogName(catalogName);
result.setEffectiveDate(pluginCatalog.getEffectiveDate().toDate());
result.setProducts(toDefaultProducts(pluginCatalog.getProducts()));
result.setPlans(toDefaultPlans(pluginCatalog.getPlans()));
result.setPriceLists(toDefaultPriceListSet(pluginCatalog.getDefaultPriceList(), pluginCatalog.getChildrenPriceList()));
result.setRecurringBillingMode(recurringBillingMode);
result.setSupportedCurrencies(toArray(pluginCatalog.getCurrencies()));
result.setUnits(toDefaultUnits(pluginCatalog.getUnits()));
result.setPlanRules(toDefaultPlanRules(pluginCatalog.getPlanRules()));
for (final Product cur : pluginCatalog.getProducts()) {
final Product target = result.getCatalogEntityCollectionProduct().findByName(cur.getName());
if (target != null) {
((DefaultProduct) target).setAvailable(toFilteredDefaultProduct(cur.getAvailable()));
((DefaultProduct) target).setIncluded(toFilteredDefaultProduct(cur.getIncluded()));
}
}
result.initialize(result, catalogURI);
return result;
}
use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.
the class VersionedCatalogMapper method toStandaloneCatalogWithPriceOverride.
private StandaloneCatalogWithPriceOverride toStandaloneCatalogWithPriceOverride(final VersionedPluginCatalog pluginCatalog, final StandalonePluginCatalog input, final InternalTenantContext internalTenantContext) {
final StandaloneCatalogMapper mapper = new StandaloneCatalogMapper(pluginCatalog.getCatalogName(), pluginCatalog.getRecurringBillingMode());
final StandaloneCatalog catalog = mapper.toStandaloneCatalog(input, null);
final StandaloneCatalogWithPriceOverride result = new StandaloneCatalogWithPriceOverride(catalog, priceOverride, internalTenantContext.getTenantRecordId(), internalCallContextFactory);
return result;
}
use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.
the class CatalogResource method getCatalogJson.
@TimedResource
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve the catalog as JSON", response = StaticCatalog.class)
@ApiResponses(value = {})
public Response getCatalogJson(@QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @javax.ws.rs.core.Context final HttpServletRequest request) throws Exception {
final TenantContext tenantContext = context.createContext(request);
final DateTime catalogDateVersion = requestedDate != null ? DATE_TIME_FORMATTER.parseDateTime(requestedDate).toDateTime(DateTimeZone.UTC) : null;
// Yack...
final VersionedCatalog catalog = (VersionedCatalog) catalogUserApi.getCatalog(catalogName, tenantContext);
final List<CatalogJson> result = new ArrayList<CatalogJson>();
if (catalogDateVersion != null) {
result.add(new CatalogJson(catalog, catalogDateVersion));
} else {
for (final StandaloneCatalog v : catalog.getVersions()) {
result.add(new CatalogJson(catalog, new DateTime(v.getEffectiveDate())));
}
}
return Response.status(Status.OK).entity(result).build();
}
use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.
the class TestXMLReader method testUsageConsumableInArrear.
@Test(groups = "fast")
public void testUsageConsumableInArrear() {
try {
final StandaloneCatalog catalog = getCatalog("UsageExperimental.xml");
final Usage[] usages = getUsages(catalog, "consumable-in-arrear");
assertEquals(usages.length, 1);
final Usage usage = usages[0];
assertEquals(usage.getName(), "consumable-in-arrear-usage1");
assertEquals(usage.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(usage.getUsageType(), UsageType.CONSUMABLE);
assertEquals(usage.getBillingMode(), BillingMode.IN_ARREAR);
assertEquals(usage.getLimits().length, 0);
assertEquals(usage.getBlocks().length, 0);
assertEquals(usage.getTiers().length, 1);
assertEquals(usage.getTiers()[0].getTieredBlocks().length, 2);
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getUnit().getName(), "cell-phone-minutes");
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getSize(), new Double("1000"));
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getMax(), new Double("10000"));
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getPrice().getPrices().length, 1);
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getPrice().getPrices()[0].getCurrency(), Currency.BTC);
assertEquals(usage.getTiers()[0].getTieredBlocks()[0].getPrice().getPrices()[0].getValue(), new BigDecimal("0.5"));
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getUnit().getName(), "Mbytes");
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getSize(), new Double("512"));
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getMax(), new Double("512000"));
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getPrice().getPrices().length, 1);
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getPrice().getPrices()[0].getCurrency(), Currency.BTC);
assertEquals(usage.getTiers()[0].getTieredBlocks()[1].getPrice().getPrices()[0].getValue(), new BigDecimal("0.3"));
} catch (Exception e) {
Assert.fail(e.toString());
}
}
use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.
the class TestXMLReader method testUsageConsumableInAdvancePrepayCredit.
@Test(groups = "fast")
public void testUsageConsumableInAdvancePrepayCredit() {
try {
final StandaloneCatalog catalog = getCatalog("UsageExperimental.xml");
final Usage[] usages = getUsages(catalog, "consumable-in-advance-prepay-credit-monthly");
assertEquals(usages.length, 1);
final Usage usage = usages[0];
assertEquals(usage.getName(), "consumable-in-advance-prepay-credit-monthly-usage1");
assertEquals(usage.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(usage.getUsageType(), UsageType.CONSUMABLE);
assertEquals(usage.getBillingMode(), BillingMode.IN_ADVANCE);
assertEquals(usage.getLimits().length, 0);
assertEquals(usage.getTiers().length, 0);
assertEquals(usage.getBlocks().length, 1);
assertEquals(usage.getBlocks()[0].getUnit().getName(), "cell-phone-minutes");
assertEquals(usage.getBlocks()[0].getSize(), new Double("1000"));
assertEquals(usage.getBlocks()[0].getPrice().getPrices().length, 1);
assertEquals(usage.getBlocks()[0].getPrice().getPrices()[0].getCurrency(), Currency.BTC);
assertEquals(usage.getBlocks()[0].getPrice().getPrices()[0].getValue(), new BigDecimal("0.10"));
} catch (Exception e) {
Assert.fail(e.toString());
}
}
Aggregations