Skip to content

Commit

Permalink
catalog: Change default catalog name (Simple Plan Api) to DEFAULT ins…
Browse files Browse the repository at this point in the history
…tead of dummy
  • Loading branch information
sbrossie committed Dec 28, 2016
1 parent d1c26e1 commit 7c8411a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Expand Up @@ -51,11 +51,13 @@


public class CatalogUpdater { public class CatalogUpdater {


private static URI DUMMY_URI; public static String DEFAULT_CATALOG_NAME = "DEFAULT";

private static URI DEFAULT_URI;


static { static {
try { try {
DUMMY_URI = new URI("dummy"); DEFAULT_URI = new URI(DEFAULT_CATALOG_NAME);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
} }
} }
Expand All @@ -68,11 +70,11 @@ public CatalogUpdater(final StandaloneCatalog standaloneCatalog) {
this.catalog = new DefaultMutableStaticCatalog(standaloneCatalog); this.catalog = new DefaultMutableStaticCatalog(standaloneCatalog);
} }


public CatalogUpdater(final String catalogName, final BillingMode billingMode, final DateTime effectiveDate, final Currency... currencies) { public CatalogUpdater(final BillingMode billingMode, final DateTime effectiveDate, final Currency... currencies) {


final DefaultPriceList defaultPriceList = new DefaultPriceList().setName(PriceListSet.DEFAULT_PRICELIST_NAME); final DefaultPriceList defaultPriceList = new DefaultPriceList().setName(PriceListSet.DEFAULT_PRICELIST_NAME);
final StandaloneCatalog tmp = new StandaloneCatalog() final StandaloneCatalog tmp = new StandaloneCatalog()
.setCatalogName(catalogName) .setCatalogName(DEFAULT_CATALOG_NAME)
.setEffectiveDate(effectiveDate.toDate()) .setEffectiveDate(effectiveDate.toDate())
.setRecurringBillingMode(billingMode) .setRecurringBillingMode(billingMode)
.setProducts(ImmutableList.<Product>of()) .setProducts(ImmutableList.<Product>of())
Expand All @@ -84,7 +86,7 @@ public CatalogUpdater(final String catalogName, final BillingMode billingMode, f
} else { } else {
tmp.setSupportedCurrencies(new Currency[0]); tmp.setSupportedCurrencies(new Currency[0]);
} }
tmp.initialize(tmp, DUMMY_URI); tmp.initialize(tmp, DEFAULT_URI);


this.catalog = new DefaultMutableStaticCatalog(tmp); this.catalog = new DefaultMutableStaticCatalog(tmp);
} }
Expand Down Expand Up @@ -118,7 +120,7 @@ public void addSimplePlanDescriptor(final SimplePlanDescriptor desc) throws Cata
product = new DefaultProduct(); product = new DefaultProduct();
product.setName(desc.getProductName()); product.setName(desc.getProductName());
product.setCatagory(desc.getProductCategory()); product.setCatagory(desc.getProductCategory());
product.initialize(catalog, DUMMY_URI); product.initialize(catalog, DEFAULT_URI);
catalog.addProduct(product); catalog.addProduct(product);
} }


Expand Down Expand Up @@ -192,7 +194,7 @@ public void addSimplePlanDescriptor(final SimplePlanDescriptor desc) throws Cata
} }


// Reinit catalog // Reinit catalog
catalog.initialize(catalog, DUMMY_URI); catalog.initialize(catalog, DEFAULT_URI);
} }


private boolean isPriceForCurrencyExists(final InternationalPrice price, final Currency currency) { private boolean isPriceForCurrencyExists(final InternationalPrice price, final Currency currency) {
Expand Down
Expand Up @@ -224,7 +224,7 @@ public void addAll(final List<StandaloneCatalog> inputVersions) throws CatalogAp
} }


public void add(final StandaloneCatalog e) throws CatalogApiException { public void add(final StandaloneCatalog e) throws CatalogApiException {
if (catalogName == null) { if (catalogName == null && e.getCatalogName() != null) {
catalogName = e.getCatalogName(); catalogName = e.getCatalogName();
} }
if (recurringBillingMode == null) { if (recurringBillingMode == null) {
Expand Down
Expand Up @@ -146,7 +146,7 @@ public void createDefaultEmptyCatalog(final DateTime effectiveDate, final CallCo
final StandaloneCatalog currentCatalog = getCurrentStandaloneCatalogForTenant(internalTenantContext); final StandaloneCatalog currentCatalog = getCurrentStandaloneCatalogForTenant(internalTenantContext);
final CatalogUpdater catalogUpdater = (currentCatalog != null) ? final CatalogUpdater catalogUpdater = (currentCatalog != null) ?
new CatalogUpdater(currentCatalog) : new CatalogUpdater(currentCatalog) :
new CatalogUpdater("dummy", BillingMode.IN_ADVANCE, effectiveDate, null); new CatalogUpdater(BillingMode.IN_ADVANCE, effectiveDate, null);


catalogCache.clearCatalog(internalTenantContext); catalogCache.clearCatalog(internalTenantContext);
tenantApi.updateTenantKeyValue(TenantKey.CATALOG.toString(), catalogUpdater.getCatalogXML(), callContext); tenantApi.updateTenantKeyValue(TenantKey.CATALOG.toString(), catalogUpdater.getCatalogXML(), callContext);
Expand All @@ -163,7 +163,7 @@ public void addSimplePlan(final SimplePlanDescriptor descriptor, final DateTime
final StandaloneCatalog currentCatalog = getCurrentStandaloneCatalogForTenant(internalTenantContext); final StandaloneCatalog currentCatalog = getCurrentStandaloneCatalogForTenant(internalTenantContext);
final CatalogUpdater catalogUpdater = (currentCatalog != null) ? final CatalogUpdater catalogUpdater = (currentCatalog != null) ?
new CatalogUpdater(currentCatalog) : new CatalogUpdater(currentCatalog) :
new CatalogUpdater("dummy", BillingMode.IN_ADVANCE, effectiveDate, descriptor.getCurrency()); new CatalogUpdater(BillingMode.IN_ADVANCE, effectiveDate, descriptor.getCurrency());


catalogUpdater.addSimplePlanDescriptor(descriptor); catalogUpdater.addSimplePlanDescriptor(descriptor);


Expand Down
Expand Up @@ -55,7 +55,7 @@ public void testEmptyDefaultCatalog() throws Exception {


final DateTime now = clock.getUTCNow(); final DateTime now = clock.getUTCNow();


final CatalogUpdater catalogUpdater = new CatalogUpdater("dummy", BillingMode.IN_ADVANCE, now, null); final CatalogUpdater catalogUpdater = new CatalogUpdater(BillingMode.IN_ADVANCE, now, null);
final String catalogXML = catalogUpdater.getCatalogXML(); final String catalogXML = catalogUpdater.getCatalogXML();
final StandaloneCatalog catalog = XMLLoader.getObjectFromStream(new URI("dummy"), new ByteArrayInputStream(catalogXML.getBytes(Charset.forName("UTF-8"))), StandaloneCatalog.class); final StandaloneCatalog catalog = XMLLoader.getObjectFromStream(new URI("dummy"), new ByteArrayInputStream(catalogXML.getBytes(Charset.forName("UTF-8"))), StandaloneCatalog.class);
assertEquals(catalog.getCurrentPlans().size(), 0); assertEquals(catalog.getCurrentPlans().size(), 0);
Expand All @@ -67,7 +67,7 @@ public void testAddNoTrialPlanOnFirstCatalog() throws CatalogApiException {
final DateTime now = clock.getUTCNow(); final DateTime now = clock.getUTCNow();
final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of()); final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());


final CatalogUpdater catalogUpdater = new CatalogUpdater("dummy", BillingMode.IN_ADVANCE, now, desc.getCurrency()); final CatalogUpdater catalogUpdater = new CatalogUpdater(BillingMode.IN_ADVANCE, now, desc.getCurrency());


catalogUpdater.addSimplePlanDescriptor(desc); catalogUpdater.addSimplePlanDescriptor(desc);


Expand Down Expand Up @@ -108,7 +108,7 @@ public void testAddTrialPlanOnFirstCatalog() throws CatalogApiException {
final DateTime now = clock.getUTCNow(); final DateTime now = clock.getUTCNow();
final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of()); final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of());


final CatalogUpdater catalogUpdater = new CatalogUpdater("dummy", BillingMode.IN_ADVANCE, now, desc.getCurrency()); final CatalogUpdater catalogUpdater = new CatalogUpdater(BillingMode.IN_ADVANCE, now, desc.getCurrency());


catalogUpdater.addSimplePlanDescriptor(desc); catalogUpdater.addSimplePlanDescriptor(desc);


Expand Down

0 comments on commit 7c8411a

Please sign in to comment.