Search in sources :

Example 26 with StandaloneCatalog

use of org.killbill.billing.catalog.StandaloneCatalog in project killbill by killbill.

the class DefaultCatalogUserApi method addSimplePlan.

@Override
public void addSimplePlan(final SimplePlanDescriptor descriptor, @Nullable final DateTime effectiveDate, final CallContext callContext) throws CatalogApiException {
    try {
        final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(callContext);
        final StandaloneCatalog currentCatalog = getCurrentStandaloneCatalogForTenant(internalTenantContext);
        final CatalogUpdater catalogUpdater = (currentCatalog != null) ? new CatalogUpdater(currentCatalog) : new CatalogUpdater(getSafeFirstCatalogEffectiveDate(effectiveDate, callContext), descriptor.getCurrency());
        catalogUpdater.addSimplePlanDescriptor(descriptor);
        tenantApi.updateTenantKeyValue(TenantKey.CATALOG.toString(), catalogUpdater.getCatalogXML(internalTenantContext), callContext);
        catalogCache.clearCatalog(internalTenantContext);
    } catch (TenantApiException e) {
        throw new CatalogApiException(e);
    }
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) TenantApiException(org.killbill.billing.tenant.api.TenantApiException) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) CatalogUpdater(org.killbill.billing.catalog.CatalogUpdater)

Example 27 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) {
    final StandaloneCatalog result = new StandaloneCatalog();
    result.setCatalogName(catalogName);
    result.setEffectiveDate(pluginCatalog.getEffectiveDate().toDate());
    result.setProducts(toDefaultProducts(pluginCatalog.getProducts()));
    result.setPlans(toDefaultPlans(result, pluginCatalog.getPlans()));
    result.setPriceLists(toDefaultPriceListSet(pluginCatalog.getDefaultPriceList(), pluginCatalog.getChildrenPriceList()));
    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);
    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)

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