Skip to content

Commit

Permalink
catalog: first set of API changes for #1009
Browse files Browse the repository at this point in the history
This gets rid of the following dependencies in JAXRS:

  org.killbill.billing.catalog.StandaloneCatalog
  org.killbill.billing.catalog.VersionedCatalog

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
  • Loading branch information
pierre committed Jun 22, 2018
1 parent c022c91 commit 13094ab
Show file tree
Hide file tree
Showing 24 changed files with 171 additions and 210 deletions.
@@ -1,6 +1,6 @@
/* /*
* Copyright 2014-2017 Groupon, Inc * Copyright 2014-2018 Groupon, Inc
* Copyright 2014-2017 The Billing Project, LLC * Copyright 2014-2018 The Billing Project, LLC
* *
* The Billing Project licenses this file to you under the Apache License, version 2.0 * The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the * (the "License"); you may not use this file except in compliance with the
Expand All @@ -23,7 +23,6 @@ public interface CatalogInternalApi {


public Catalog getFullCatalog(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException; public Catalog getFullCatalog(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException;



public StaticCatalog getCurrentCatalog(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException; public StaticCatalog getCurrentCatalog(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException;


} }
Expand Up @@ -31,16 +31,17 @@
import org.killbill.billing.api.TestApiListener.NextEvent; import org.killbill.billing.api.TestApiListener.NextEvent;
import org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck; import org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck;
import org.killbill.billing.callcontext.InternalTenantContext; import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.catalog.DefaultVersionedCatalog;
import org.killbill.billing.catalog.StandaloneCatalog; import org.killbill.billing.catalog.StandaloneCatalog;
import org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride; import org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride;
import org.killbill.billing.catalog.VersionedCatalog;
import org.killbill.billing.catalog.api.BillingPeriod; import org.killbill.billing.catalog.api.BillingPeriod;
import org.killbill.billing.catalog.api.Catalog; import org.killbill.billing.catalog.api.Catalog;
import org.killbill.billing.catalog.api.CatalogUserApi; import org.killbill.billing.catalog.api.CatalogUserApi;
import org.killbill.billing.catalog.api.Plan; import org.killbill.billing.catalog.api.Plan;
import org.killbill.billing.catalog.api.PriceList; import org.killbill.billing.catalog.api.PriceList;
import org.killbill.billing.catalog.api.Product; import org.killbill.billing.catalog.api.Product;
import org.killbill.billing.catalog.api.ProductCategory; import org.killbill.billing.catalog.api.ProductCategory;
import org.killbill.billing.catalog.api.VersionedCatalog;
import org.killbill.billing.catalog.override.PriceOverride; import org.killbill.billing.catalog.override.PriceOverride;
import org.killbill.billing.catalog.plugin.TestModelStandalonePluginCatalog; import org.killbill.billing.catalog.plugin.TestModelStandalonePluginCatalog;
import org.killbill.billing.catalog.plugin.TestModelVersionedPluginCatalog; import org.killbill.billing.catalog.plugin.TestModelVersionedPluginCatalog;
Expand Down Expand Up @@ -149,38 +150,38 @@ public void testWithMultipleVersions() throws Exception {


testCatalogPluginApi.addCatalogVersion("versionedCatalog/WeaponsHireSmall-1.xml"); testCatalogPluginApi.addCatalogVersion("versionedCatalog/WeaponsHireSmall-1.xml");


final VersionedCatalog catalog1 = (VersionedCatalog) catalogUserApi.getCatalog("whatever", callContext); final VersionedCatalog catalog1 = catalogUserApi.getCatalog("whatever", null, callContext);
Assert.assertEquals(testCatalogPluginApi.getNbLatestCatalogVersionApiCalls(), 1); Assert.assertEquals(testCatalogPluginApi.getNbLatestCatalogVersionApiCalls(), 1);
Assert.assertEquals(testCatalogPluginApi.getNbVersionedPluginCatalogApiCalls(), 1); Assert.assertEquals(testCatalogPluginApi.getNbVersionedPluginCatalogApiCalls(), 1);
Assert.assertEquals(catalog1.getEffectiveDate().compareTo(testCatalogPluginApi.getLatestCatalogUpdate().toDate()), 0); Assert.assertEquals(catalog1.getEffectiveDate().compareTo(testCatalogPluginApi.getLatestCatalogUpdate().toDate()), 0);


// Retrieve 3 more times // Retrieve 3 more times
catalogUserApi.getCatalog("whatever", callContext); catalogUserApi.getCatalog("whatever", null, callContext);
catalogUserApi.getCatalog("whatever", callContext); catalogUserApi.getCatalog("whatever", null, callContext);
catalogUserApi.getCatalog("whatever", callContext); catalogUserApi.getCatalog("whatever", null, callContext);
Assert.assertEquals(testCatalogPluginApi.getNbLatestCatalogVersionApiCalls(), 4); Assert.assertEquals(testCatalogPluginApi.getNbLatestCatalogVersionApiCalls(), 4);
Assert.assertEquals(testCatalogPluginApi.getNbVersionedPluginCatalogApiCalls(), 1); Assert.assertEquals(testCatalogPluginApi.getNbVersionedPluginCatalogApiCalls(), 1);


testCatalogPluginApi.addCatalogVersion("versionedCatalog/WeaponsHireSmall-2.xml"); testCatalogPluginApi.addCatalogVersion("versionedCatalog/WeaponsHireSmall-2.xml");


final VersionedCatalog catalog2 = (VersionedCatalog) catalogUserApi.getCatalog("whatever", callContext); final VersionedCatalog catalog2 = catalogUserApi.getCatalog("whatever", null, callContext);
Assert.assertEquals(testCatalogPluginApi.getNbLatestCatalogVersionApiCalls(), 5); Assert.assertEquals(testCatalogPluginApi.getNbLatestCatalogVersionApiCalls(), 5);
Assert.assertEquals(testCatalogPluginApi.getNbVersionedPluginCatalogApiCalls(), 2); Assert.assertEquals(testCatalogPluginApi.getNbVersionedPluginCatalogApiCalls(), 2);
Assert.assertEquals(catalog2.getEffectiveDate().compareTo(testCatalogPluginApi.getLatestCatalogUpdate().toDate()), 0); Assert.assertEquals(catalog2.getEffectiveDate().compareTo(testCatalogPluginApi.getLatestCatalogUpdate().toDate()), 0);


testCatalogPluginApi.addCatalogVersion("versionedCatalog/WeaponsHireSmall-3.xml"); testCatalogPluginApi.addCatalogVersion("versionedCatalog/WeaponsHireSmall-3.xml");


final VersionedCatalog catalog3 = (VersionedCatalog) catalogUserApi.getCatalog("whatever", callContext); final VersionedCatalog catalog3 = catalogUserApi.getCatalog("whatever", null, callContext);
Assert.assertEquals(testCatalogPluginApi.getNbLatestCatalogVersionApiCalls(), 6); Assert.assertEquals(testCatalogPluginApi.getNbLatestCatalogVersionApiCalls(), 6);
Assert.assertEquals(testCatalogPluginApi.getNbVersionedPluginCatalogApiCalls(), 3); Assert.assertEquals(testCatalogPluginApi.getNbVersionedPluginCatalogApiCalls(), 3);
Assert.assertEquals(catalog3.getEffectiveDate().compareTo(testCatalogPluginApi.getLatestCatalogUpdate().toDate()), 0); Assert.assertEquals(catalog3.getEffectiveDate().compareTo(testCatalogPluginApi.getLatestCatalogUpdate().toDate()), 0);




// Retrieve 4 more times // Retrieve 4 more times
catalogUserApi.getCatalog("whatever", callContext); catalogUserApi.getCatalog("whatever", null, callContext);
catalogUserApi.getCatalog("whatever", callContext); catalogUserApi.getCatalog("whatever", null, callContext);
catalogUserApi.getCatalog("whatever", callContext); catalogUserApi.getCatalog("whatever", null, callContext);
catalogUserApi.getCatalog("whatever", callContext); catalogUserApi.getCatalog("whatever", null, callContext);
Assert.assertEquals(testCatalogPluginApi.getNbLatestCatalogVersionApiCalls(), 10); Assert.assertEquals(testCatalogPluginApi.getNbLatestCatalogVersionApiCalls(), 10);
Assert.assertEquals(testCatalogPluginApi.getNbVersionedPluginCatalogApiCalls(), 3); Assert.assertEquals(testCatalogPluginApi.getNbVersionedPluginCatalogApiCalls(), 3);


Expand Down Expand Up @@ -225,7 +226,7 @@ public void addCatalogVersion(final String catalogResource) throws Exception {


this.latestCatalogUpdate = new DateTime(inputCatalogVersion.getEffectiveDate()); this.latestCatalogUpdate = new DateTime(inputCatalogVersion.getEffectiveDate());
if (versionedCatalog == null) { if (versionedCatalog == null) {
versionedCatalog = new VersionedCatalog(getClock()); versionedCatalog = new DefaultVersionedCatalog(getClock());
} }
versionedCatalog.add(inputCatalogVersionWithOverride); versionedCatalog.add(inputCatalogVersionWithOverride);
} }
Expand Down
@@ -1,7 +1,7 @@
/* /*
* Copyright 2010-2013 Ning, Inc. * Copyright 2010-2013 Ning, Inc.
* Copyright 2014 Groupon, Inc * Copyright 2014-2018 Groupon, Inc
* Copyright 2014 The Billing Project, LLC * Copyright 2014-2018 The Billing Project, LLC
* *
* The Billing Project licenses this file to you under the Apache License, version 2.0 * The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the * (the "License"); you may not use this file except in compliance with the
Expand All @@ -21,10 +21,8 @@
import javax.inject.Named; import javax.inject.Named;


import org.killbill.billing.callcontext.InternalTenantContext; import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.catalog.api.Catalog;
import org.killbill.billing.catalog.api.CatalogApiException; import org.killbill.billing.catalog.api.CatalogApiException;
import org.killbill.billing.catalog.api.CatalogService; import org.killbill.billing.catalog.api.CatalogService;
import org.killbill.billing.catalog.api.StaticCatalog;
import org.killbill.billing.catalog.caching.CatalogCache; import org.killbill.billing.catalog.caching.CatalogCache;
import org.killbill.billing.catalog.glue.CatalogModule; import org.killbill.billing.catalog.glue.CatalogModule;
import org.killbill.billing.platform.api.KillbillService; import org.killbill.billing.platform.api.KillbillService;
Expand All @@ -45,12 +43,10 @@ public class DefaultCatalogService implements KillbillService, CatalogService {
private static final String CATALOG_SERVICE_NAME = "catalog-service"; private static final String CATALOG_SERVICE_NAME = "catalog-service";


private final CatalogConfig config; private final CatalogConfig config;
private boolean isInitialized;

private final TenantInternalApi tenantInternalApi; private final TenantInternalApi tenantInternalApi;

private final CatalogCache catalogCache; private final CatalogCache catalogCache;
private final CacheInvalidationCallback cacheInvalidationCallback; private final CacheInvalidationCallback cacheInvalidationCallback;
private boolean isInitialized;


@Inject @Inject
public DefaultCatalogService(final CatalogConfig config, public DefaultCatalogService(final CatalogConfig config,
Expand All @@ -74,7 +70,7 @@ public synchronized void loadCatalog() throws ServiceException {
log.info("Successfully loaded the default catalog {}", config.getCatalogURI()); log.info("Successfully loaded the default catalog {}", config.getCatalogURI());
} }
isInitialized = true; isInitialized = true;
} catch (Exception e) { } catch (final Exception e) {
throw new ServiceException(e); throw new ServiceException(e);
} }
} }
Expand All @@ -91,26 +87,26 @@ public String getName() {
} }


@Override @Override
public Catalog getFullCatalog(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final InternalTenantContext context) throws CatalogApiException { public DefaultVersionedCatalog getFullCatalog(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final InternalTenantContext context) throws CatalogApiException {
return getCatalog(useDefaultCatalog, filterTemplateCatalog, false, context); return getCatalog(useDefaultCatalog, filterTemplateCatalog, false, context);
} }


@Override @Override
public Catalog getFullCatalogForInternalUse(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final InternalTenantContext context) throws CatalogApiException { public DefaultVersionedCatalog getFullCatalogForInternalUse(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final InternalTenantContext context) throws CatalogApiException {
return getCatalog(useDefaultCatalog, filterTemplateCatalog, true, context); return getCatalog(useDefaultCatalog, filterTemplateCatalog, true, context);
} }


@Override @Override
public StaticCatalog getCurrentCatalog(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final InternalTenantContext context) throws CatalogApiException { public DefaultVersionedCatalog getCurrentCatalog(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final InternalTenantContext context) throws CatalogApiException {
return getCatalog(useDefaultCatalog, filterTemplateCatalog, false, context); return getCatalog(useDefaultCatalog, filterTemplateCatalog, false, context);
} }


@Override @Override
public StaticCatalog getCurrentCatalogForInternalUse(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final InternalTenantContext context) throws CatalogApiException { public DefaultVersionedCatalog getCurrentCatalogForInternalUse(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final InternalTenantContext context) throws CatalogApiException {
return getCatalog(useDefaultCatalog, filterTemplateCatalog, true, context); return getCatalog(useDefaultCatalog, filterTemplateCatalog, true, context);
} }


private VersionedCatalog getCatalog(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final boolean internalUse, final InternalTenantContext context) throws CatalogApiException { private DefaultVersionedCatalog getCatalog(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final boolean internalUse, final InternalTenantContext context) throws CatalogApiException {
return catalogCache.getCatalog(useDefaultCatalog, filterTemplateCatalog, internalUse, context); return catalogCache.getCatalog(useDefaultCatalog, filterTemplateCatalog, internalUse, context);
} }
} }
Expand Up @@ -28,7 +28,6 @@
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
Expand All @@ -49,7 +48,6 @@
import org.killbill.billing.catalog.api.Currency; import org.killbill.billing.catalog.api.Currency;
import org.killbill.billing.catalog.api.Listing; import org.killbill.billing.catalog.api.Listing;
import org.killbill.billing.catalog.api.Plan; import org.killbill.billing.catalog.api.Plan;
import org.killbill.billing.catalog.api.PlanAlignmentChange;
import org.killbill.billing.catalog.api.PlanAlignmentCreate; import org.killbill.billing.catalog.api.PlanAlignmentCreate;
import org.killbill.billing.catalog.api.PlanChangeResult; import org.killbill.billing.catalog.api.PlanChangeResult;
import org.killbill.billing.catalog.api.PlanPhase; import org.killbill.billing.catalog.api.PlanPhase;
Expand All @@ -61,6 +59,7 @@
import org.killbill.billing.catalog.api.Product; import org.killbill.billing.catalog.api.Product;
import org.killbill.billing.catalog.api.StaticCatalog; import org.killbill.billing.catalog.api.StaticCatalog;
import org.killbill.billing.catalog.api.Unit; import org.killbill.billing.catalog.api.Unit;
import org.killbill.billing.catalog.api.VersionedCatalog;
import org.killbill.billing.util.cache.ExternalizableInput; import org.killbill.billing.util.cache.ExternalizableInput;
import org.killbill.billing.util.cache.ExternalizableOutput; import org.killbill.billing.util.cache.ExternalizableOutput;
import org.killbill.billing.util.cache.MapperHolder; import org.killbill.billing.util.cache.MapperHolder;
Expand All @@ -71,7 +70,7 @@


@XmlRootElement(name = "catalogs") @XmlRootElement(name = "catalogs")
@XmlAccessorType(XmlAccessType.NONE) @XmlAccessorType(XmlAccessType.NONE)
public class VersionedCatalog extends ValidatingConfig<VersionedCatalog> implements Catalog, StaticCatalog, Externalizable { public class DefaultVersionedCatalog extends ValidatingConfig<DefaultVersionedCatalog> implements VersionedCatalog<StandaloneCatalog>, Externalizable {


private static final long serialVersionUID = 3181874902672322725L; private static final long serialVersionUID = 3181874902672322725L;


Expand All @@ -85,12 +84,12 @@ public class VersionedCatalog extends ValidatingConfig<VersionedCatalog> impleme
private String catalogName; private String catalogName;


// Required for JAXB deserialization // Required for JAXB deserialization
public VersionedCatalog() { public DefaultVersionedCatalog() {
this.clock = null; this.clock = null;
this.versions = new ArrayList<StandaloneCatalog>(); this.versions = new ArrayList<StandaloneCatalog>();
} }


public VersionedCatalog(final Clock clock) { public DefaultVersionedCatalog(final Clock clock) {
this.clock = clock; this.clock = clock;
this.versions = new ArrayList<StandaloneCatalog>(); this.versions = new ArrayList<StandaloneCatalog>();
} }
Expand Down Expand Up @@ -188,19 +187,12 @@ public Clock getClock() {
return clock; return clock;
} }


@Override
public List<StandaloneCatalog> getVersions() { public List<StandaloneCatalog> getVersions() {
return versions; return versions;
} }


// @Override
// Public methods not exposed in interface
//
public void addAll(final Iterable<StandaloneCatalog> inputVersions) {
for (final StandaloneCatalog cur : inputVersions) {
add(cur);
}
}

public void add(final StandaloneCatalog e) { public void add(final StandaloneCatalog e) {
if (catalogName == null && e.getCatalogName() != null) { if (catalogName == null && e.getCatalogName() != null) {
catalogName = e.getCatalogName(); catalogName = e.getCatalogName();
Expand All @@ -214,14 +206,6 @@ public int compare(final StandaloneCatalog c1, final StandaloneCatalog c2) {
}); });
} }


public Iterator<StandaloneCatalog> iterator() {
return versions.iterator();
}

public int size() {
return versions.size();
}

@Override @Override
public String getCatalogName() { public String getCatalogName() {
return catalogName; return catalogName;
Expand Down Expand Up @@ -352,7 +336,7 @@ private StaticCatalog getStaticCatalog(final PlanSpecifier spec, final DateTime
} }


@Override @Override
public void initialize(final VersionedCatalog catalog, final URI sourceURI) { public void initialize(final DefaultVersionedCatalog catalog, final URI sourceURI) {
// //
// Initialization is performed first on each StandaloneCatalog (XMLLoader#initializeAndValidate) // Initialization is performed first on each StandaloneCatalog (XMLLoader#initializeAndValidate)
// and then later on the VersionedCatalog, so we only initialize and validate VersionedCatalog // and then later on the VersionedCatalog, so we only initialize and validate VersionedCatalog
Expand All @@ -363,7 +347,7 @@ public void initialize(final VersionedCatalog catalog, final URI sourceURI) {
} }


@Override @Override
public ValidationErrors validate(final VersionedCatalog catalog, final ValidationErrors errors) { public ValidationErrors validate(final DefaultVersionedCatalog catalog, final ValidationErrors errors) {
final Set<Date> effectiveDates = new TreeSet<Date>(); final Set<Date> effectiveDates = new TreeSet<Date>();


for (final StandaloneCatalog c : versions) { for (final StandaloneCatalog c : versions) {
Expand Down
@@ -1,6 +1,6 @@
/* /*
* Copyright 2014-2017 Groupon, Inc * Copyright 2014-2018 Groupon, Inc
* Copyright 2014-2017 The Billing Project, LLC * Copyright 2014-2018 The Billing Project, LLC
* *
* The Billing Project licenses this file to you under the Apache License, version 2.0 * The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the * (the "License"); you may not use this file except in compliance with the
Expand All @@ -18,18 +18,19 @@
package org.killbill.billing.catalog.api; package org.killbill.billing.catalog.api;


import org.killbill.billing.callcontext.InternalTenantContext; import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.catalog.DefaultVersionedCatalog;
import org.killbill.billing.platform.api.KillbillService; import org.killbill.billing.platform.api.KillbillService;


/** /**
* The interface {@code CatalogService} is a {@code KillbillService} required to handle catalog operations. * The interface {@code CatalogService} is a {@code KillbillService} required to handle catalog operations.
*/ */
public interface CatalogService extends KillbillService { public interface CatalogService extends KillbillService {


public Catalog getFullCatalog(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException; public DefaultVersionedCatalog getFullCatalog(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException;


public Catalog getFullCatalogForInternalUse(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException; public DefaultVersionedCatalog getFullCatalogForInternalUse(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException;


public StaticCatalog getCurrentCatalog(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException; public DefaultVersionedCatalog getCurrentCatalog(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException;


public StaticCatalog getCurrentCatalogForInternalUse(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException; public DefaultVersionedCatalog getCurrentCatalogForInternalUse(boolean useDefaultCatalog, final boolean filterTemplateCatalog, InternalTenantContext context) throws CatalogApiException;
} }
@@ -1,6 +1,6 @@
/* /*
* Copyright 2014-2017 Groupon, Inc * Copyright 2014-2018 Groupon, Inc
* Copyright 2014-2017 The Billing Project, LLC * Copyright 2014-2018 The Billing Project, LLC
* *
* The Billing Project licenses this file to you under the Apache License, version 2.0 * The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the * (the "License"); you may not use this file except in compliance with the
Expand Down

0 comments on commit 13094ab

Please sign in to comment.