Search in sources :

Example 1 with StandaloneCatalog

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;
}
Also used : DefaultProduct(org.killbill.billing.catalog.DefaultProduct) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) Product(org.killbill.billing.catalog.api.Product)

Example 2 with StandaloneCatalog

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;
}
Also used : StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog)

Example 3 with StandaloneCatalog

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();
}
Also used : VersionedCatalog(org.killbill.billing.catalog.VersionedCatalog) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) CatalogJson(org.killbill.billing.jaxrs.json.CatalogJson) DateTime(org.joda.time.DateTime) 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 4 with StandaloneCatalog

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());
    }
}
Also used : Usage(org.killbill.billing.catalog.api.Usage) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) BigDecimal(java.math.BigDecimal) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) Test(org.testng.annotations.Test)

Example 5 with StandaloneCatalog

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());
    }
}
Also used : Usage(org.killbill.billing.catalog.api.Usage) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) BigDecimal(java.math.BigDecimal) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) Test(org.testng.annotations.Test)

Aggregations

StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)27 Test (org.testng.annotations.Test)16 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)11 BigDecimal (java.math.BigDecimal)10 DateTime (org.joda.time.DateTime)6 StandaloneCatalogWithPriceOverride (org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride)6 Plan (org.killbill.billing.catalog.api.Plan)6 DefaultPlanPhasePriceOverride (org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)5 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)5 Usage (org.killbill.billing.catalog.api.Usage)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)4 VersionedCatalog (org.killbill.billing.catalog.VersionedCatalog)4 DefaultVersionedCatalog (org.killbill.billing.catalog.DefaultVersionedCatalog)3 Product (org.killbill.billing.catalog.api.Product)3 InputStream (java.io.InputStream)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ExecutionException (java.util.concurrent.ExecutionException)2