killbill-uncached
Changes
entitlement/src/main/java/org/killbill/billing/entitlement/engine/core/EventsStreamBuilder.java 2(+1 -1)
pom.xml 2(+1 -1)
Details
diff --git a/catalog/src/main/java/org/killbill/billing/catalog/DefaultPlan.java b/catalog/src/main/java/org/killbill/billing/catalog/DefaultPlan.java
index 29cbeb2..79503ad 100644
--- a/catalog/src/main/java/org/killbill/billing/catalog/DefaultPlan.java
+++ b/catalog/src/main/java/org/killbill/billing/catalog/DefaultPlan.java
@@ -78,7 +78,7 @@ public class DefaultPlan extends ValidatingConfig<StandaloneCatalog> implements
@XmlElement(required = false)
private Integer plansAllowedInBundle = 1;
- private PriceList priceList;
+ private String priceListName;
public DefaultPlan() {
initialPhases = new DefaultPlanPhase[0];
@@ -94,7 +94,7 @@ public class DefaultPlan extends ValidatingConfig<StandaloneCatalog> implements
initialPhases[i] = newPhase;
}
this.finalPhase = new DefaultPlanPhase(this, in.getFinalPhase(), overrides[overrides.length - 1]);
- this.priceList = in.getPriceList();
+ this.priceListName = in.getPriceListName();
}
@Override
@@ -113,8 +113,8 @@ public class DefaultPlan extends ValidatingConfig<StandaloneCatalog> implements
}
@Override
- public PriceList getPriceList() {
- return priceList;
+ public String getPriceListName() {
+ return priceListName;
}
@Override
@@ -185,7 +185,7 @@ public class DefaultPlan extends ValidatingConfig<StandaloneCatalog> implements
p.initialize(catalog, sourceURI);
}
}
- this.priceList = findPriceListForPlan(catalog);
+ this.priceListName = findPriceListForPlan(catalog);
}
@Override
@@ -223,8 +223,8 @@ public class DefaultPlan extends ValidatingConfig<StandaloneCatalog> implements
return this;
}
- public DefaultPlan setPriceList(final DefaultPriceList priceList) {
- this.priceList = priceList;
+ public DefaultPlan setPriceListName(final String priceListName) {
+ this.priceListName = priceListName;
return this;
}
@@ -313,11 +313,11 @@ public class DefaultPlan extends ValidatingConfig<StandaloneCatalog> implements
+ plansAllowedInBundle + "]";
}
- private DefaultPriceList findPriceListForPlan(final StandaloneCatalog catalog) {
+ private String findPriceListForPlan(final StandaloneCatalog catalog) {
for (PriceList cur : catalog.getPriceLists().getAllPriceLists()) {
for (Plan p : cur.getPlans()) {
if (p.getName().equals(name)) {
- return (DefaultPriceList) cur;
+ return ((DefaultPriceList) cur).getName();
}
}
}
diff --git a/catalog/src/main/java/org/killbill/billing/catalog/VersionedCatalog.java b/catalog/src/main/java/org/killbill/billing/catalog/VersionedCatalog.java
index de4e38a..d70a831 100644
--- a/catalog/src/main/java/org/killbill/billing/catalog/VersionedCatalog.java
+++ b/catalog/src/main/java/org/killbill/billing/catalog/VersionedCatalog.java
@@ -23,10 +23,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
import javax.annotation.Nullable;
import javax.xml.bind.annotation.XmlAccessType;
@@ -149,9 +147,9 @@ public class VersionedCatalog extends ValidatingConfig<StandaloneCatalogWithPric
}
}
- private Plan findPlan(final PlanRequestWrapper wrapper,
- final DateTime requestedDate,
- final DateTime subscriptionStartDate)
+ private CatalogPlanEntry findCatalogPlanEntry(final PlanRequestWrapper wrapper,
+ final DateTime requestedDate,
+ final DateTime subscriptionStartDate)
throws CatalogApiException {
final List<StandaloneCatalogWithPriceOverride> catalogs = versionsBeforeDate(requestedDate.toDate());
if (catalogs.isEmpty()) {
@@ -174,12 +172,12 @@ public class VersionedCatalog extends ValidatingConfig<StandaloneCatalogWithPric
final DateTime catalogEffectiveDate = CatalogDateHelper.toUTCDateTime(c.getEffectiveDate());
if (!subscriptionStartDate.isBefore(catalogEffectiveDate)) { // Its a new subscription this plan always applies
- return plan;
+ return new CatalogPlanEntry(c, plan);
} else { //Its an existing subscription
if (plan.getEffectiveDateForExistingSubscriptions() != null) { //if it is null any change to this does not apply to existing subscriptions
final DateTime existingSubscriptionDate = CatalogDateHelper.toUTCDateTime(plan.getEffectiveDateForExistingSubscriptions());
if (requestedDate.isAfter(existingSubscriptionDate)) { // this plan is now applicable to existing subs
- return plan;
+ return new CatalogPlanEntry(c, plan);
}
}
}
@@ -188,6 +186,26 @@ public class VersionedCatalog extends ValidatingConfig<StandaloneCatalogWithPric
throw new CatalogApiException(ErrorCode.CAT_NO_CATALOG_FOR_GIVEN_DATE, requestedDate.toDate().toString());
}
+ private static class CatalogPlanEntry {
+
+ private final StaticCatalog staticCatalog;
+ private final Plan plan;
+
+ public CatalogPlanEntry(final StaticCatalog staticCatalog, final Plan plan) {
+ this.staticCatalog = staticCatalog;
+ this.plan = plan;
+ }
+
+ public StaticCatalog getStaticCatalog() {
+ return staticCatalog;
+ }
+
+ public Plan getPlan() {
+ return plan;
+ }
+ }
+
+
public Clock getClock() {
return clock;
}
@@ -284,7 +302,8 @@ public class VersionedCatalog extends ValidatingConfig<StandaloneCatalogWithPric
final DateTime requestedDate,
final DateTime subscriptionStartDate)
throws CatalogApiException {
- return findPlan(new PlanRequestWrapper(name), requestedDate, subscriptionStartDate);
+ final CatalogPlanEntry entry = findCatalogPlanEntry(new PlanRequestWrapper(name), requestedDate, subscriptionStartDate);
+ return entry.getPlan();
}
@Override
@@ -295,7 +314,8 @@ public class VersionedCatalog extends ValidatingConfig<StandaloneCatalogWithPric
final DateTime requestedDate,
final DateTime subscriptionStartDate)
throws CatalogApiException {
- return findPlan(new PlanRequestWrapper(productName, term, priceListName, overrides), requestedDate, subscriptionStartDate);
+ final CatalogPlanEntry entry = findCatalogPlanEntry(new PlanRequestWrapper(productName, term, priceListName, overrides), requestedDate, subscriptionStartDate);
+ return entry.getPlan();
}
//
@@ -320,14 +340,24 @@ public class VersionedCatalog extends ValidatingConfig<StandaloneCatalogWithPric
}
//
- // Find a price list
+ // Find a price list associated to a given subscription
//
@Override
+ public PriceList findPriceListForPlan(final String planName,
+ final DateTime requestedDate,
+ final DateTime subscriptionStartDate)
+ throws CatalogApiException {
+ final CatalogPlanEntry entry = findCatalogPlanEntry(new PlanRequestWrapper(planName), requestedDate, subscriptionStartDate);
+ return entry.getStaticCatalog().findCurrentPricelist(entry.getPlan().getPriceListName());
+ }
+
+
public PriceList findPriceList(final String name, final DateTime requestedDate)
throws CatalogApiException {
return versionForDate(requestedDate).findCurrentPriceList(name);
}
+
//
// Rules
//
diff --git a/catalog/src/test/java/org/killbill/billing/catalog/MockCatalog.java b/catalog/src/test/java/org/killbill/billing/catalog/MockCatalog.java
index 2bea796..5e6c579 100644
--- a/catalog/src/test/java/org/killbill/billing/catalog/MockCatalog.java
+++ b/catalog/src/test/java/org/killbill/billing/catalog/MockCatalog.java
@@ -154,6 +154,11 @@ public class MockCatalog extends StandaloneCatalog implements Catalog {
}
@Override
+ public PriceList findPriceListForPlan(final String name, final DateTime requestedDate, final DateTime subscriptionStartDate) throws CatalogApiException {
+ return findCurrentPricelist(name);
+ }
+
+ @Override
public BillingActionPolicy planChangePolicy(final PlanPhaseSpecifier from, final PlanSpecifier to, final DateTime requestedDate)
throws CatalogApiException {
return planChangePolicy(from, to);
diff --git a/entitlement/src/main/java/org/killbill/billing/entitlement/engine/core/EventsStreamBuilder.java b/entitlement/src/main/java/org/killbill/billing/entitlement/engine/core/EventsStreamBuilder.java
index 6cee88b..ba5f169 100644
--- a/entitlement/src/main/java/org/killbill/billing/entitlement/engine/core/EventsStreamBuilder.java
+++ b/entitlement/src/main/java/org/killbill/billing/entitlement/engine/core/EventsStreamBuilder.java
@@ -374,7 +374,7 @@ public class EventsStreamBuilder {
productCategory = lastActiveProduct.getCategory();
final PlanPhase lastActivePlanPhase = subscription.getLastActivePhase();
billingPeriod = lastActivePlanPhase.getRecurring() != null ? lastActivePlanPhase.getRecurring().getBillingPeriod() : BillingPeriod.NO_BILLING_PERIOD;
- priceListName = subscription.getLastActivePlan().getPriceList().getName();
+ priceListName = subscription.getLastActivePlan().getPriceListName();
phaseType = subscription.getLastActivePhase().getPhaseType();
}
return new PlanPhaseSpecifier(lastActiveProductName,
pom.xml 2(+1 -1)
diff --git a/pom.xml b/pom.xml
index d1cf442..e661f87 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
<parent>
<artifactId>killbill-oss-parent</artifactId>
<groupId>org.kill-bill.billing</groupId>
- <version>0.111</version>
+ <version>0.112</version>
</parent>
<artifactId>killbill</artifactId>
<version>0.17.1-SNAPSHOT</version>
diff --git a/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBase.java b/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBase.java
index f6c0e8a..b3f06f2 100644
--- a/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBase.java
+++ b/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBase.java
@@ -664,7 +664,7 @@ public class DefaultSubscriptionBase extends EntityBase implements SubscriptionB
nextPlan = (nextPlanName != null) ? catalog.findPlan(nextPlanName, cur.getEffectiveDate(), getAlignStartDate()) : null;
nextPhase = (nextPhaseName != null) ? catalog.findPhase(nextPhaseName, cur.getEffectiveDate(), getAlignStartDate()) : null;
- nextPriceList = (nextPlan != null) ? nextPlan.getPriceList() : null;
+ nextPriceList = (nextPlan != null) ? catalog.findPriceListForPlan(nextPlanName, cur.getEffectiveDate(), getAlignStartDate()) : null;
final SubscriptionBaseTransitionData transition = new SubscriptionBaseTransitionData(
cur.getId(), id, bundleId, cur.getType(), apiEventType,
diff --git a/util/src/test/java/org/killbill/billing/mock/MockPlan.java b/util/src/test/java/org/killbill/billing/mock/MockPlan.java
index ab6ae03..09b4e88 100644
--- a/util/src/test/java/org/killbill/billing/mock/MockPlan.java
+++ b/util/src/test/java/org/killbill/billing/mock/MockPlan.java
@@ -53,7 +53,7 @@ public class MockPlan implements Plan {
}
@Override
- public PriceList getPriceList() {
+ public String getPriceListName() {
throw new UnsupportedOperationException();
}