Details
diff --git a/api/src/main/java/com/ning/billing/catalog/api/ICatalog.java b/api/src/main/java/com/ning/billing/catalog/api/ICatalog.java
index e67c154..c2c0c43 100644
--- a/api/src/main/java/com/ning/billing/catalog/api/ICatalog.java
+++ b/api/src/main/java/com/ning/billing/catalog/api/ICatalog.java
@@ -17,46 +17,44 @@
package com.ning.billing.catalog.api;
import java.util.Date;
-import java.util.List;
public interface ICatalog {
public abstract IProduct[] getProducts();
- public abstract IPlan getPlan(String productName, BillingPeriod term, String priceList);
+ public abstract IPlan findPlan(String productName, BillingPeriod term, String priceList) throws CatalogApiException;
- public abstract Currency[] getSupportedCurrencies();
+ public abstract IPlan findPlan(String name) throws CatalogApiException;
- public abstract IPlan[] getPlans();
+ public abstract IProduct findProduct(String name) throws CatalogApiException;
- public abstract ActionPolicy getPlanChangePolicy(PlanPhaseSpecifier from,
- PlanSpecifier to);
+ public abstract IPlanPhase findPhase(String name) throws CatalogApiException;
- public abstract PlanChangeResult planChange(PlanPhaseSpecifier from,
- PlanSpecifier to) throws IllegalPlanChange;
- public abstract IPlan getPlanFromName(String name);
+ public abstract Currency[] getSupportedCurrencies();
- public abstract IPlanPhase getPhaseFromName(String name);
+ public abstract IPlan[] getPlans();
- public abstract Date getEffectiveDate();
+ public abstract ActionPolicy planChangePolicy(PlanPhaseSpecifier from,
+ PlanSpecifier to) throws CatalogApiException;
- public abstract IPlanPhase getPhaseFor(String name, Date date);
+ public abstract PlanChangeResult planChange(PlanPhaseSpecifier from,
+ PlanSpecifier to) throws IllegalPlanChange, CatalogApiException;
- public abstract IProduct getProductFromName(String name);
+ public abstract Date getEffectiveDate();
- public abstract ActionPolicy getPlanCancelPolicy(PlanPhaseSpecifier planPhase);
+ public abstract ActionPolicy planCancelPolicy(PlanPhaseSpecifier planPhase) throws CatalogApiException;
public abstract void configureEffectiveDate(Date date);
public abstract String getCalalogName();
- public abstract PlanAlignmentCreate getPlanCreateAlignment(PlanSpecifier specifier);
+ public abstract PlanAlignmentCreate planCreateAlignment(PlanSpecifier specifier) throws CatalogApiException;
- public abstract BillingAlignment getBillingAlignment(PlanPhaseSpecifier planPhase);
+ public abstract BillingAlignment billingAlignment(PlanPhaseSpecifier planPhase) throws CatalogApiException;
- public abstract PlanAlignmentChange getPlanChangeAlignment(PlanPhaseSpecifier from,
- PlanSpecifier to);
+ public abstract PlanAlignmentChange planChangeAlignment(PlanPhaseSpecifier from,
+ PlanSpecifier to) throws CatalogApiException;
}
\ No newline at end of file
diff --git a/api/src/main/java/com/ning/billing/catalog/api/IPrice.java b/api/src/main/java/com/ning/billing/catalog/api/IPrice.java
index dce29cc..52a9c54 100644
--- a/api/src/main/java/com/ning/billing/catalog/api/IPrice.java
+++ b/api/src/main/java/com/ning/billing/catalog/api/IPrice.java
@@ -23,6 +23,6 @@ public interface IPrice {
public abstract Currency getCurrency();
- public abstract BigDecimal getValue();
+ public abstract BigDecimal getValue() throws CurrencyValueNull;
}
\ No newline at end of file
diff --git a/catalog/src/main/java/com/ning/billing/catalog/Catalog.java b/catalog/src/main/java/com/ning/billing/catalog/Catalog.java
index bbc9485..61a4604 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/Catalog.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/Catalog.java
@@ -26,22 +26,24 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
+import com.ning.billing.ErrorCode;
import com.ning.billing.catalog.api.ActionPolicy;
import com.ning.billing.catalog.api.BillingAlignment;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.catalog.api.ICatalog;
import com.ning.billing.catalog.api.IProduct;
import com.ning.billing.catalog.api.IllegalPlanChange;
import com.ning.billing.catalog.api.PlanAlignmentChange;
import com.ning.billing.catalog.api.PlanAlignmentCreate;
+import com.ning.billing.catalog.api.PlanChangeResult;
import com.ning.billing.catalog.api.PlanPhaseSpecifier;
import com.ning.billing.catalog.api.PlanSpecifier;
import com.ning.billing.catalog.rules.PlanRules;
import com.ning.billing.util.config.ValidatingConfig;
import com.ning.billing.util.config.ValidationError;
import com.ning.billing.util.config.ValidationErrors;
-import com.ning.billing.catalog.api.PlanChangeResult;
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@@ -86,6 +88,11 @@ public class Catalog extends ValidatingConfig<Catalog> implements ICatalog {
return catalogName;
}
+ @Override
+ public Date getEffectiveDate() {
+ return effectiveDate;
+ }
+
/* (non-Javadoc)
* @see com.ning.billing.catalog.ICatalog#getProducts()
*/
@@ -94,14 +101,6 @@ public class Catalog extends ValidatingConfig<Catalog> implements ICatalog {
return products;
}
- /* (non-Javadoc)
- * @see com.ning.billing.catalog.ICatalog#getPlan(java.lang.String, java.lang.String)
- */
- @Override
- public Plan getPlan(String productName, BillingPeriod period, String priceListName) {
- IProduct product = getProductFromName(productName);
- return priceLists.getPlanListFrom(priceListName, product, period);
- }
@Override
public Currency[] getSupportedCurrencies() {
@@ -112,34 +111,44 @@ public class Catalog extends ValidatingConfig<Catalog> implements ICatalog {
public Plan[] getPlans() {
return plans;
}
- @Override
- public ActionPolicy getPlanChangePolicy(PlanPhaseSpecifier from, PlanSpecifier to) {
- return planRules.getPlanChangePolicy(from, to, this);
- }
- @Override
- public PlanAlignmentChange getPlanChangeAlignment(PlanPhaseSpecifier from, PlanSpecifier to) {
- return planRules.getPlanChangeAlignment(from, to, this);
+ public URI getCatalogURI() {
+ return catalogURI;
}
- @Override
- public ActionPolicy getPlanCancelPolicy(PlanPhaseSpecifier planPhase) {
- return planRules.getPlanCancelPolicy(planPhase, this);
+ public PlanRules getPlanRules() {
+ return planRules;
}
-
- @Override
- public PlanAlignmentCreate getPlanCreateAlignment(PlanSpecifier specifier) {
- return planRules.getPlanCreateAlignment(specifier, this);
+
+ public PriceList getPriceListFromName(String priceListName) {
+ return priceLists.findPriceListFrom(priceListName);
+ }
+
+ public PriceListSet getPriceLists() {
+ return this.priceLists;
}
@Override
- public BillingAlignment getBillingAlignment(PlanPhaseSpecifier planPhase) {
- return planRules.getBillingAlignment(planPhase, this);
+ public void configureEffectiveDate(Date date) {
+ // Nothing to do here this is a method that is only implemented on VersionedCatalog
}
+ /* (non-Javadoc)
+ * @see com.ning.billing.catalog.ICatalog#getPlan(java.lang.String, java.lang.String)
+ */
@Override
- public Plan getPlanFromName(String name) {
+ public Plan findPlan(String productName, BillingPeriod period, String priceListName) throws CatalogApiException {
+ IProduct product = findProduct(productName);
+ Plan result = priceLists.getPlanListFrom(priceListName, product, period);
+ if ( result == null) {
+ throw new CatalogApiException(ErrorCode.CAT_PLAN_NOT_FOUND, productName, period.toString(), priceListName);
+ }
+ return result;
+ }
+
+ @Override
+ public Plan findPlan(String name) throws CatalogApiException {
if (name == null) {
return null;
}
@@ -148,26 +157,21 @@ public class Catalog extends ValidatingConfig<Catalog> implements ICatalog {
return p;
}
}
- return null;
+ throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PLAN, name);
}
-
+
@Override
- public IProduct getProductFromName(String name) {
+ public IProduct findProduct(String name) throws CatalogApiException {
for(Product p : products) {
if (p.getName().equals(name)) {
return p;
}
}
- return null;
+ throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PRODUCT, name);
}
-
@Override
- public PlanPhase getPhaseFromName(String name) {
-
- if (name == null) {
- return null;
- }
+ public PlanPhase findPhase(String name) throws CatalogApiException {
for(Plan p : plans) {
if(p.getFinalPhase().getName().equals(name)) {
@@ -182,59 +186,42 @@ public class Catalog extends ValidatingConfig<Catalog> implements ICatalog {
}
}
- return null;
+ throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PHASE, name);
}
+ //////////////////////////////////////////////////////////////////////////////
+ //
+ // RULES
+ //
+ //////////////////////////////////////////////////////////////////////////////
@Override
- public Date getEffectiveDate() {
- return effectiveDate;
- }
-
- public void setEffectiveDate(Date effectiveDate) {
- this.effectiveDate = effectiveDate;
- }
-
- public URI getCatalogURI() {
- return catalogURI;
- }
-
- public PlanRules getPlanRules() {
- return planRules;
- }
-
- public void setPlanRules(PlanRules planRules) {
- this.planRules = planRules;
+ public ActionPolicy planChangePolicy(PlanPhaseSpecifier from, PlanSpecifier to) throws CatalogApiException {
+ return planRules.getPlanChangePolicy(from, to, this);
}
@Override
- public PlanPhase getPhaseFor(String name, Date date) {
- if(getEffectiveDate().getTime() >= date.getTime()){
- return getPhaseFromName(name);
- }
- return null;
- }
-
- public void setPriceLists(PriceListSet priceLists) {
- this.priceLists = priceLists;
+ public PlanAlignmentChange planChangeAlignment(PlanPhaseSpecifier from, PlanSpecifier to) throws CatalogApiException {
+ return planRules.getPlanChangeAlignment(from, to, this);
}
- public PriceListSet getPriceLists() {
- return this.priceLists;
+ @Override
+ public ActionPolicy planCancelPolicy(PlanPhaseSpecifier planPhase) throws CatalogApiException {
+ return planRules.getPlanCancelPolicy(planPhase, this);
}
@Override
- public void configureEffectiveDate(Date date) {
- // Nothing to do here this is a method that is only inplemented on VersionedCatalog
-
+ public PlanAlignmentCreate planCreateAlignment(PlanSpecifier specifier) throws CatalogApiException {
+ return planRules.getPlanCreateAlignment(specifier, this);
}
- public PriceList getPriceListFromName(String priceListName) {
- return priceLists.findPriceListFrom(priceListName);
+ @Override
+ public BillingAlignment billingAlignment(PlanPhaseSpecifier planPhase) throws CatalogApiException {
+ return planRules.getBillingAlignment(planPhase, this);
}
@Override
public PlanChangeResult planChange(PlanPhaseSpecifier from, PlanSpecifier to)
- throws IllegalPlanChange {
+ throws CatalogApiException {
return planRules.planChange(from, to, this);
}
@@ -290,5 +277,21 @@ public class Catalog extends ValidatingConfig<Catalog> implements ICatalog {
return this;
}
+ protected Catalog setEffectiveDate(Date effectiveDate) {
+ this.effectiveDate = effectiveDate;
+ return this;
+ }
+
+ protected Catalog setPlanRules(PlanRules planRules) {
+ this.planRules = planRules;
+ return this;
+ }
+
+ protected Catalog setPriceLists(PriceListSet priceLists) {
+ this.priceLists = priceLists;
+ return this;
+ }
+
+
}
diff --git a/catalog/src/main/java/com/ning/billing/catalog/PlanPhase.java b/catalog/src/main/java/com/ning/billing/catalog/PlanPhase.java
index 61dab1e..2656804 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/PlanPhase.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/PlanPhase.java
@@ -134,6 +134,12 @@ public class PlanPhase extends ValidatingConfig<Catalog> implements IPlanPhase {
catalog.getCatalogURI(), PlanPhase.class, type.toString()));
}
+ //Validation: there must be at least one of reccuringPrice or fixedPrice
+ if(recurringPrice == null && fixedPrice == null) {
+ errors.add(new ValidationError(String.format("Phase %s of plan %s has neither a reccurring price or a fixed price.",
+ type.toString(), plan.getName()),
+ catalog.getCatalogURI(), PlanPhase.class, type.toString()));
+ }
return errors;
}
diff --git a/catalog/src/main/java/com/ning/billing/catalog/Price.java b/catalog/src/main/java/com/ning/billing/catalog/Price.java
index cdbf464..3e81f64 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/Price.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/Price.java
@@ -23,6 +23,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.catalog.api.CurrencyValueNull;
import com.ning.billing.catalog.api.IPrice;
import com.ning.billing.util.config.ValidatingConfig;
import com.ning.billing.util.config.ValidationErrors;
@@ -32,7 +33,7 @@ public class Price extends ValidatingConfig<Catalog> implements IPrice {
@XmlElement(required=true)
private Currency currency;
- @XmlElement(required=true)
+ @XmlElement(required=true,nillable=true)
private BigDecimal value;
/* (non-Javadoc)
@@ -47,7 +48,10 @@ public class Price extends ValidatingConfig<Catalog> implements IPrice {
* @see com.ning.billing.catalog.IPrice#getValue()
*/
@Override
- public BigDecimal getValue() {
+ public BigDecimal getValue() throws CurrencyValueNull {
+ if (value == null) {
+ throw new CurrencyValueNull(currency);
+ }
return value;
}
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/Case.java b/catalog/src/main/java/com/ning/billing/catalog/rules/Case.java
index 67f7bae..39b267d 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/Case.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/Case.java
@@ -20,6 +20,7 @@ import com.ning.billing.catalog.Catalog;
import com.ning.billing.catalog.PriceList;
import com.ning.billing.catalog.Product;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.PlanSpecifier;
import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.util.config.ValidatingConfig;
@@ -34,21 +35,21 @@ public abstract class Case<T> extends ValidatingConfig<Catalog> {
protected abstract T getResult();
- public T getResult(PlanSpecifier planPhase, Catalog c) {
+ public T getResult(PlanSpecifier planPhase, Catalog c) throws CatalogApiException {
if (satisfiesCase(planPhase, c) ) {
return getResult();
}
return null;
}
- protected boolean satisfiesCase(PlanSpecifier planPhase, Catalog c) {
- return (product == null || product.equals(c.getProductFromName(planPhase.getProductName()))) &&
+ protected boolean satisfiesCase(PlanSpecifier planPhase, Catalog c) throws CatalogApiException {
+ return (product == null || product.equals(c.findProduct(planPhase.getProductName()))) &&
(productCategory == null || productCategory.equals(planPhase.getProductCategory())) &&
(billingPeriod == null || billingPeriod.equals(planPhase.getBillingPeriod())) &&
(priceList == null || priceList.equals(c.getPriceListFromName(planPhase.getPriceListName())));
}
- public static <K> K getResult(Case<K>[] cases, PlanSpecifier planSpec, Catalog catalog) {
+ public static <K> K getResult(Case<K>[] cases, PlanSpecifier planSpec, Catalog catalog) throws CatalogApiException {
if(cases != null) {
for(Case<K> c : cases) {
K result = c.getResult(planSpec, catalog);
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChange.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChange.java
index e0095f8..b5e6f8d 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChange.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CaseChange.java
@@ -25,6 +25,7 @@ import com.ning.billing.catalog.Catalog;
import com.ning.billing.catalog.PriceList;
import com.ning.billing.catalog.Product;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.PlanPhaseSpecifier;
import com.ning.billing.catalog.api.PlanSpecifier;
@@ -69,13 +70,13 @@ public abstract class CaseChange<T> extends ValidatingConfig<Catalog> {
protected abstract T getResult();
public T getResult(PlanPhaseSpecifier from,
- PlanSpecifier to, Catalog catalog) {
+ PlanSpecifier to, Catalog catalog) throws CatalogApiException {
if(
(phaseType == null || from.getPhaseType() == phaseType) &&
- (fromProduct == null || fromProduct.equals(catalog.getProductFromName(from.getProductName()))) &&
+ (fromProduct == null || fromProduct.equals(catalog.findProduct(from.getProductName()))) &&
(fromProductCategory == null || fromProductCategory.equals(from.getProductCategory())) &&
(fromBillingPeriod == null || fromBillingPeriod.equals(from.getBillingPeriod())) &&
- (toProduct == null || toProduct.equals(catalog.getProductFromName(to.getProductName()))) &&
+ (toProduct == null || toProduct.equals(catalog.findProduct(to.getProductName()))) &&
(toProductCategory == null || toProductCategory.equals(to.getProductCategory())) &&
(toBillingPeriod == null || toBillingPeriod.equals(to.getBillingPeriod())) &&
(fromPriceList == null || fromPriceList.equals(catalog.getPriceListFromName(from.getPriceListName()))) &&
@@ -87,7 +88,7 @@ public abstract class CaseChange<T> extends ValidatingConfig<Catalog> {
}
static public <K> K getResult(CaseChange<K>[] cases, PlanPhaseSpecifier from,
- PlanSpecifier to, Catalog catalog) {
+ PlanSpecifier to, Catalog catalog) throws CatalogApiException {
if(cases != null) {
for(CaseChange<K> cc : cases) {
K result = cc.getResult(from, to, catalog);
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/CasePhase.java b/catalog/src/main/java/com/ning/billing/catalog/rules/CasePhase.java
index afd6d4b..a098a77 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/CasePhase.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/CasePhase.java
@@ -22,6 +22,7 @@ import com.ning.billing.catalog.Catalog;
import com.ning.billing.catalog.PriceList;
import com.ning.billing.catalog.Product;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.PlanPhaseSpecifier;
import com.ning.billing.catalog.api.PlanSpecifier;
@@ -33,7 +34,7 @@ public abstract class CasePhase<T> extends CaseStandardNaming<T> {
@XmlElement(required=false)
private PhaseType phaseType;
- public T getResult(PlanPhaseSpecifier specifier, Catalog c) {
+ public T getResult(PlanPhaseSpecifier specifier, Catalog c) throws CatalogApiException {
if (
(phaseType == null || specifier.getPhaseType() == null || specifier.getPhaseType() == phaseType) &&
satisfiesCase(new PlanSpecifier(specifier), c)
@@ -43,7 +44,7 @@ public abstract class CasePhase<T> extends CaseStandardNaming<T> {
return null;
}
- public static <K> K getResult(CasePhase<K>[] cases, PlanPhaseSpecifier planSpec, Catalog catalog) {
+ public static <K> K getResult(CasePhase<K>[] cases, PlanPhaseSpecifier planSpec, Catalog catalog) throws CatalogApiException {
if(cases != null) {
for(CasePhase<K> cp : cases) {
K result = cp.getResult(planSpec, catalog);
diff --git a/catalog/src/main/java/com/ning/billing/catalog/rules/PlanRules.java b/catalog/src/main/java/com/ning/billing/catalog/rules/PlanRules.java
index 787dbaf..d688815 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/rules/PlanRules.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/rules/PlanRules.java
@@ -25,13 +25,13 @@ import com.ning.billing.catalog.Catalog;
import com.ning.billing.catalog.PriceList;
import com.ning.billing.catalog.api.ActionPolicy;
import com.ning.billing.catalog.api.BillingAlignment;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.IllegalPlanChange;
import com.ning.billing.catalog.api.PlanAlignmentChange;
import com.ning.billing.catalog.api.PlanAlignmentCreate;
import com.ning.billing.catalog.api.PlanChangeResult;
import com.ning.billing.catalog.api.PlanPhaseSpecifier;
import com.ning.billing.catalog.api.PlanSpecifier;
-import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.util.config.ValidatingConfig;
import com.ning.billing.util.config.ValidationErrors;
@@ -62,19 +62,19 @@ public class PlanRules extends ValidatingConfig<Catalog> {
@XmlElement(name="priceListCase", required=false)
private CasePriceList[] priceListCase;
- public PlanAlignmentCreate getPlanCreateAlignment(PlanSpecifier specifier, Catalog catalog) {
+ public PlanAlignmentCreate getPlanCreateAlignment(PlanSpecifier specifier, Catalog catalog) throws CatalogApiException {
return Case.getResult(createAlignmentCase, specifier, catalog);
}
- public ActionPolicy getPlanCancelPolicy(PlanPhaseSpecifier planPhase, Catalog catalog) {
+ public ActionPolicy getPlanCancelPolicy(PlanPhaseSpecifier planPhase, Catalog catalog) throws CatalogApiException {
return CasePhase.getResult(cancelCase, planPhase, catalog);
}
- public BillingAlignment getBillingAlignment(PlanPhaseSpecifier planPhase, Catalog catalog) {
+ public BillingAlignment getBillingAlignment(PlanPhaseSpecifier planPhase, Catalog catalog) throws CatalogApiException {
return CasePhase.getResult(billingAlignmentCase, planPhase, catalog);
}
- public PlanChangeResult planChange(PlanPhaseSpecifier from, PlanSpecifier to, Catalog catalog) throws IllegalPlanChange {
+ public PlanChangeResult planChange(PlanPhaseSpecifier from, PlanSpecifier to, Catalog catalog) throws CatalogApiException {
PriceList priceList = catalog.getPriceListFromName(to.getPriceListName());
if( priceList== null ) {
priceList = findPriceList(from.toPlanSpecifier(), catalog);
@@ -92,12 +92,12 @@ public class PlanRules extends ValidatingConfig<Catalog> {
}
public PlanAlignmentChange getPlanChangeAlignment(PlanPhaseSpecifier from,
- PlanSpecifier to, Catalog catalog) {
+ PlanSpecifier to, Catalog catalog) throws CatalogApiException {
return CaseChange.getResult(changeAlignmentCase, from, to, catalog);
}
public ActionPolicy getPlanChangePolicy(PlanPhaseSpecifier from,
- PlanSpecifier to, Catalog catalog) {
+ PlanSpecifier to, Catalog catalog) throws CatalogApiException {
if(from.getProductName().equals(to.getProductName()) &&
from.getBillingPeriod() == to.getBillingPeriod() &&
from.getPriceListName().equals(to.getPriceListName())) {
@@ -107,7 +107,7 @@ public class PlanRules extends ValidatingConfig<Catalog> {
return CaseChange.getResult(changeCase, from, to, catalog);
}
- private PriceList findPriceList(PlanSpecifier specifier, Catalog catalog) {
+ private PriceList findPriceList(PlanSpecifier specifier, Catalog catalog) throws CatalogApiException {
PriceList result = Case.getResult(priceListCase, specifier, catalog);
if (result == null) {
result = catalog.getPriceListFromName(specifier.getPriceListName());
diff --git a/catalog/src/main/java/com/ning/billing/catalog/VersionedCatalog.java b/catalog/src/main/java/com/ning/billing/catalog/VersionedCatalog.java
index 73d6560..7bf76f5 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/VersionedCatalog.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/VersionedCatalog.java
@@ -27,18 +27,17 @@ import com.google.inject.Inject;
import com.ning.billing.catalog.api.ActionPolicy;
import com.ning.billing.catalog.api.BillingAlignment;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.catalog.api.ICatalog;
import com.ning.billing.catalog.api.IPlan;
import com.ning.billing.catalog.api.IPlanPhase;
import com.ning.billing.catalog.api.IProduct;
-import com.ning.billing.catalog.api.IllegalPlanChange;
import com.ning.billing.catalog.api.PlanAlignmentChange;
import com.ning.billing.catalog.api.PlanAlignmentCreate;
import com.ning.billing.catalog.api.PlanChangeResult;
import com.ning.billing.catalog.api.PlanPhaseSpecifier;
import com.ning.billing.catalog.api.PlanSpecifier;
-import com.ning.billing.util.clock.IClock;
import com.ning.billing.util.config.ValidatingConfig;
import com.ning.billing.util.config.ValidationErrors;
@@ -98,12 +97,6 @@ public class VersionedCatalog extends ValidatingConfig<Catalog> implements ICata
}
@Override
- public IPlan getPlan(String productName, BillingPeriod term,
- String planSetName) {
- return currentCatalog.getPlan(productName, term, planSetName);
- }
-
- @Override
public Currency[] getSupportedCurrencies() {
return currentCatalog.getSupportedCurrencies();
}
@@ -114,19 +107,29 @@ public class VersionedCatalog extends ValidatingConfig<Catalog> implements ICata
}
@Override
- public Plan getPlanFromName(String name) {
- return currentCatalog.getPlanFromName(name);
+ public Date getEffectiveDate() {
+ return currentCatalog.getEffectiveDate();
}
+ @Override
+ public IPlan findPlan(String productName, BillingPeriod term,
+ String planSetName) throws CatalogApiException {
+ return currentCatalog.findPlan(productName, term, planSetName);
+ }
@Override
- public IPlanPhase getPhaseFromName(String name) {
- return currentCatalog.getPhaseFromName(name);
+ public Plan findPlan(String name) throws CatalogApiException {
+ return currentCatalog.findPlan(name);
}
@Override
- public Date getEffectiveDate() {
- return currentCatalog.getEffectiveDate();
+ public IPlanPhase findPhase(String name) throws CatalogApiException {
+ return currentCatalog.findPhase(name);
+ }
+
+ @Override
+ public IProduct findProduct(String name) throws CatalogApiException {
+ return currentCatalog.findProduct(name);
}
@Override
@@ -145,36 +148,25 @@ public class VersionedCatalog extends ValidatingConfig<Catalog> implements ICata
}
@Override
- public PlanPhase getPhaseFor(String name, Date date) {
- Catalog c = versionForDate(date);
- return c.getPhaseFromName(name);
- }
-
- @Override
- public ActionPolicy getPlanChangePolicy(PlanPhaseSpecifier from,
- PlanSpecifier to) {
- return currentCatalog.getPlanChangePolicy(from, to);
- }
-
- @Override
- public IProduct getProductFromName(String name) {
- return currentCatalog.getProductFromName(name);
+ public ActionPolicy planChangePolicy(PlanPhaseSpecifier from,
+ PlanSpecifier to) throws CatalogApiException {
+ return currentCatalog.planChangePolicy(from, to);
}
@Override
- public ActionPolicy getPlanCancelPolicy(PlanPhaseSpecifier planPhase) {
- return currentCatalog.getPlanCancelPolicy(planPhase);
+ public ActionPolicy planCancelPolicy(PlanPhaseSpecifier planPhase) throws CatalogApiException {
+ return currentCatalog.planCancelPolicy(planPhase);
}
@Override
- public PlanAlignmentChange getPlanChangeAlignment(PlanPhaseSpecifier from,
- PlanSpecifier to) {
- return currentCatalog.getPlanChangeAlignment(from, to);
+ public PlanAlignmentChange planChangeAlignment(PlanPhaseSpecifier from,
+ PlanSpecifier to) throws CatalogApiException {
+ return currentCatalog.planChangeAlignment(from, to);
}
@Override
- public PlanAlignmentCreate getPlanCreateAlignment(PlanSpecifier specifier) {
- return currentCatalog.getPlanCreateAlignment(specifier);
+ public PlanAlignmentCreate planCreateAlignment(PlanSpecifier specifier) throws CatalogApiException {
+ return currentCatalog.planCreateAlignment(specifier);
}
@Override
@@ -183,13 +175,13 @@ public class VersionedCatalog extends ValidatingConfig<Catalog> implements ICata
}
@Override
- public BillingAlignment getBillingAlignment(PlanPhaseSpecifier planPhase) {
- return currentCatalog.getBillingAlignment(planPhase);
+ public BillingAlignment billingAlignment(PlanPhaseSpecifier planPhase) throws CatalogApiException {
+ return currentCatalog.billingAlignment(planPhase);
}
@Override
public PlanChangeResult planChange(PlanPhaseSpecifier from, PlanSpecifier to)
- throws IllegalPlanChange {
+ throws CatalogApiException {
return currentCatalog.planChange(from, to);
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/MockCatalog.java b/catalog/src/test/java/com/ning/billing/catalog/MockCatalog.java
index c561457..31d9e51 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/MockCatalog.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/MockCatalog.java
@@ -16,6 +16,10 @@
package com.ning.billing.catalog;
+import java.util.Date;
+
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.catalog.rules.CaseCancelPolicy;
import com.ning.billing.catalog.rules.CaseChangePlanAlignment;
@@ -27,6 +31,7 @@ public class MockCatalog extends Catalog {
private static final String[] PRODUCT_NAMES = new String[]{ "TestProduct1", "TestProduct2", "TestProduct3"};
public MockCatalog() {
+ setEffectiveDate(new Date());
populateProducts();
populateRules();
populatePlans();
@@ -59,7 +64,8 @@ public class MockCatalog extends Catalog {
Product[] products = getProducts();
Plan[] plans = new Plan[products.length];
for(int i = 0; i < products.length; i++) {
- plans[i] = new MockPlan().setName(products[i].getName().toLowerCase() + "-plan").setProduct(products[i]);
+ PlanPhase phase = new PlanPhase().setPhaseType(PhaseType.EVERGREEN).setBillingPeriod(BillingPeriod.MONTHLY).setReccuringPrice(new InternationalPrice());
+ plans[i] = new MockPlan().setName(products[i].getName().toLowerCase() + "-plan").setProduct(products[i]).setFinalPhase(phase);
}
setPlans(plans);
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java
index 3cd031b..f8ed9f8 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java
@@ -28,6 +28,7 @@ import com.ning.billing.catalog.MockCatalog;
import com.ning.billing.catalog.PriceList;
import com.ning.billing.catalog.Product;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.IPriceListSet;
import com.ning.billing.catalog.api.PlanSpecifier;
import com.ning.billing.catalog.api.ProductCategory;
@@ -56,7 +57,7 @@ public class TestCase {
}
@Test(enabled=true)
- public void testBasic(){
+ public void testBasic() throws CatalogApiException{
MockCatalog cat = new MockCatalog();
Product product = cat.getProducts()[0];
@@ -78,7 +79,7 @@ public class TestCase {
}
@Test(enabled=true)
- public void testWildCardProduct(){
+ public void testWildCardProduct() throws CatalogApiException{
MockCatalog cat = new MockCatalog();
Product product = cat.getProducts()[0];
@@ -101,7 +102,7 @@ public class TestCase {
}
@Test(enabled=true)
- public void testWildCardProductCategory(){
+ public void testWildCardProductCategory() throws CatalogApiException{
MockCatalog cat = new MockCatalog();
Product product = cat.getProducts()[0];
@@ -124,7 +125,7 @@ public class TestCase {
}
@Test(enabled=true)
- public void testWildCardBillingPeriod(){
+ public void testWildCardBillingPeriod() throws CatalogApiException{
MockCatalog cat = new MockCatalog();
Product product = cat.getProducts()[0];
@@ -147,7 +148,7 @@ public class TestCase {
}
@Test(enabled=true)
- public void testWildCardPriceList(){
+ public void testWildCardPriceList() throws CatalogApiException{
MockCatalog cat = new MockCatalog();
Product product = cat.getProducts()[0];
@@ -170,7 +171,7 @@ public class TestCase {
}
@Test
- public void testCaseOrder() {
+ public void testCaseOrder() throws CatalogApiException {
MockCatalog cat = new MockCatalog();
Product product = cat.getProducts()[0];
@@ -217,11 +218,11 @@ public class TestCase {
- protected void assertionNull(CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName, Catalog cat){
+ protected void assertionNull(CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName, Catalog cat) throws CatalogApiException{
assertNull(cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
}
- protected void assertion(Result result, CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName,Catalog cat){
+ protected void assertion(Result result, CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName,Catalog cat) throws CatalogApiException{
assertEquals(result, cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java
index 34f055d..baa3d8c 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java
@@ -21,6 +21,7 @@ import static org.testng.AssertJUnit.assertNull;
import javax.xml.bind.annotation.XmlElement;
+import org.testng.Assert;
import org.testng.annotations.Test;
import com.ning.billing.catalog.Catalog;
@@ -28,6 +29,7 @@ import com.ning.billing.catalog.MockCatalog;
import com.ning.billing.catalog.PriceList;
import com.ning.billing.catalog.Product;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.IPriceListSet;
import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.PlanPhaseSpecifier;
@@ -960,7 +962,7 @@ public class TestCaseChange {
@Test(enabled=true)
- public void testOrder(){
+ public void testOrder() throws CatalogApiException{
MockCatalog cat = new MockCatalog();
Product product1 = cat.getProducts()[0];
@@ -1031,8 +1033,12 @@ public class TestCaseChange {
BillingPeriod fromBp, BillingPeriod toBp,
String fromPriceListName, String toPriceListName,
PhaseType phaseType, Catalog cat){
- assertNull(cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory, fromBp, fromPriceListName, phaseType),
- new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName),cat));
+ try {
+ assertNull(cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory, fromBp, fromPriceListName, phaseType),
+ new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName),cat));
+ } catch (CatalogApiException e) {
+ Assert.fail("", e);
+ }
}
protected void assertion(Result result, CaseChangeResult cr,
@@ -1041,8 +1047,12 @@ public class TestCaseChange {
BillingPeriod fromBp, BillingPeriod toBp,
String fromPriceListName, String toPriceListName,
PhaseType phaseType, Catalog cat){
- assertEquals(result, cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory,fromBp, fromPriceListName, phaseType),
- new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName),cat));
+ try {
+ assertEquals(result, cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory,fromBp, fromPriceListName, phaseType),
+ new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName),cat));
+ } catch (CatalogApiException e) {
+ Assert.fail("", e);
+ }
}
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java
index 32c8354..998099c 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java
@@ -16,11 +16,9 @@
package com.ning.billing.catalog.rules;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-
import javax.xml.bind.annotation.XmlElement;
+import org.testng.Assert;
import org.testng.annotations.Test;
import com.ning.billing.catalog.Catalog;
@@ -28,6 +26,7 @@ import com.ning.billing.catalog.MockCatalog;
import com.ning.billing.catalog.PriceList;
import com.ning.billing.catalog.Product;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.PlanPhaseSpecifier;
import com.ning.billing.catalog.api.ProductCategory;
@@ -201,7 +200,7 @@ public class TestCasePhase {
}
@Test(enabled=true)
- public void testOrder(){
+ public void testOrder() throws CatalogApiException{
MockCatalog cat = new MockCatalog();
Product product = cat.getProducts()[0];
@@ -251,22 +250,30 @@ public class TestCasePhase {
Result r1 = CasePhase.getResult(new CaseResult[]{cr0, cr1, cr2,cr3,cr4},
new PlanPhaseSpecifier(product.getName(), product.getCategory(), BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN), cat);
- assertEquals(Result.FOO, r1);
+ Assert.assertEquals(Result.FOO, r1);
Result r2 = CasePhase.getResult(new CaseResult[]{cr0, cr1, cr2,cr3,cr4},
new PlanPhaseSpecifier(product.getName(), product.getCategory(), BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN), cat);
- assertEquals(Result.DIPSY, r2);
+ Assert.assertEquals(Result.DIPSY, r2);
}
protected void assertionNull(CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName, PhaseType phaseType, Catalog cat){
- assertNull(cr.getResult(new PlanPhaseSpecifier(productName, productCategory, bp, priceListName, phaseType), cat));
+ try {
+ Assert.assertNull(cr.getResult(new PlanPhaseSpecifier(productName, productCategory, bp, priceListName, phaseType), cat));
+ } catch (CatalogApiException e) {
+ Assert.fail("", e);
+ }
}
protected void assertion(Result result, CaseResult cr, String productName, ProductCategory productCategory, BillingPeriod bp, String priceListName, PhaseType phaseType, Catalog cat){
- assertEquals(result, cr.getResult(new PlanPhaseSpecifier(productName, productCategory, bp, priceListName, phaseType), cat));
+ try {
+ Assert.assertEquals(result, cr.getResult(new PlanPhaseSpecifier(productName, productCategory, bp, priceListName, phaseType), cat));
+ } catch (CatalogApiException e) {
+ Assert.fail("", e);
+ }
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java
index fac41a2..38f0f60 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java
@@ -16,10 +16,9 @@
package com.ning.billing.catalog.rules;
-import junit.framework.Assert;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@@ -28,6 +27,7 @@ import com.ning.billing.catalog.PriceList;
import com.ning.billing.catalog.Product;
import com.ning.billing.catalog.api.ActionPolicy;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.IPriceListSet;
import com.ning.billing.catalog.api.IllegalPlanChange;
import com.ning.billing.catalog.api.PhaseType;
@@ -70,6 +70,8 @@ public class TestPlanRules {
Assert.fail("We did not see an exception when trying to change plan to the same plan");
} catch (IllegalPlanChange e) {
log.info("Correct - cannot change to the same plan:", e);
+ } catch (CatalogApiException e) {
+ Assert.fail("", e);
}
}
@@ -88,6 +90,8 @@ public class TestPlanRules {
} catch (IllegalPlanChange e) {
log.info("Correct - cannot change to the same plan:", e);
Assert.fail("We should not have triggered this error");
+ } catch (CatalogApiException e) {
+ Assert.fail("", e);
}
Assert.assertEquals(result.getPolicy(), ActionPolicy.END_OF_TERM);
@@ -113,6 +117,8 @@ public class TestPlanRules {
} catch (IllegalPlanChange e) {
log.info("Correct - cannot change to the same plan:", e);
Assert.fail("We should not have triggered this error");
+ } catch (CatalogApiException e) {
+ Assert.fail("", e);
}
Assert.assertEquals(result.getPolicy(), ActionPolicy.END_OF_TERM);
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/alignment/PlanAligner.java b/entitlement/src/main/java/com/ning/billing/entitlement/alignment/PlanAligner.java
index 01ec2c0..2cc492f 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/alignment/PlanAligner.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/alignment/PlanAligner.java
@@ -22,6 +22,7 @@ import java.util.List;
import org.joda.time.DateTime;
import com.google.inject.Inject;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.ICatalog;
import com.ning.billing.catalog.api.ICatalogService;
import com.ning.billing.catalog.api.IDuration;
@@ -94,7 +95,16 @@ public class PlanAligner implements IPlanAligner {
priceList);
DateTime planStartDate = null;
- PlanAlignmentCreate alignement = catalog.getPlanCreateAlignment(planSpecifier);
+
+ //TODO fix exception handling
+ PlanAlignmentCreate alignement = null;
+ try {
+ alignement = catalog.planCreateAlignment(planSpecifier);
+ } catch (CatalogApiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
switch(alignement) {
case START_OF_SUBSCRIPTION:
planStartDate = subscription.getStartDate();
@@ -130,7 +140,15 @@ public class PlanAligner implements IPlanAligner {
priceList);
DateTime planStartDate = null;
- PlanAlignmentChange alignment = catalog.getPlanChangeAlignment(fromPlanPhaseSpecifier, toPlanSpecifier);
+
+ //TODO Correctly handle exception
+ PlanAlignmentChange alignment = null;
+ try {
+ alignment = catalog.planChangeAlignment(fromPlanPhaseSpecifier, toPlanSpecifier);
+ } catch (CatalogApiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
switch(alignment) {
case START_OF_SUBSCRIPTION:
planStartDate = subscription.getStartDate();
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/EntitlementUserApi.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/EntitlementUserApi.java
index 93fe561..a795cf1 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/EntitlementUserApi.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/EntitlementUserApi.java
@@ -26,6 +26,7 @@ import com.google.inject.Inject;
import com.ning.billing.ErrorCode;
import com.ning.billing.account.api.IAccount;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.ICatalogService;
import com.ning.billing.catalog.api.IPlan;
import com.ning.billing.catalog.api.IPlanPhase;
@@ -100,7 +101,15 @@ public class EntitlementUserApi implements IEntitlementUserApi {
requestedDate = (requestedDate == null) ? now : requestedDate;
- IPlan plan = catalogService.getCatalog().getPlan(productName, term, realPriceList);
+ //TODO: Correctly handle exception
+ IPlan plan = null;
+ try {
+ plan = catalogService.getCatalog().findPlan(productName, term, realPriceList);
+ } catch (CatalogApiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
if (plan == null) {
throw new EntitlementUserApiException(ErrorCode.ENT_CREATE_BAD_CATALOG, productName, term, realPriceList);
}
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/Subscription.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/Subscription.java
index 05f6e9d..396838e 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/Subscription.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/Subscription.java
@@ -229,7 +229,15 @@ public class Subscription extends PrivateFields implements ISubscription {
getCurrentPriceList(),
getCurrentPhase().getPhaseType());
- ActionPolicy policy = catalog.getPlanCancelPolicy(planPhase);
+ //TODO: Correctly handle exception
+ ActionPolicy policy = null;
+ try {
+ policy = catalog.planCancelPolicy(planPhase);
+ } catch (CatalogApiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
DateTime effectiveDate = getPlanChangeEffectiveDate(policy, now);
IEvent cancelEvent = new ApiEventCancel(id, bundleStartDate, now, now, effectiveDate, activeVersion);
dao.cancelSubscription(id, cancelEvent);
@@ -275,7 +283,7 @@ public class Subscription extends PrivateFields implements ISubscription {
PlanChangeResult planChangeResult = null;
try {
- IProduct destProduct = catalog.getProductFromName(productName);
+ IProduct destProduct = catalog.findProduct(productName);
// STEPH really catalog exception
if (destProduct == null) {
throw new EntitlementUserApiException(ErrorCode.ENT_CREATE_BAD_CATALOG,
@@ -300,8 +308,16 @@ public class Subscription extends PrivateFields implements ISubscription {
ActionPolicy policy = planChangeResult.getPolicy();
IPriceList newPriceList = planChangeResult.getNewPriceList();
- IPlan newPlan = catalog.getPlan(productName, term, newPriceList.getName());
- if (newPlan == null) {
+ //TODO: Correctly handle exception
+ IPlan newPlan = null;
+ try {
+ newPlan = catalog.findPlan(productName, term, newPriceList.getName());
+ } catch (CatalogApiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ if (newPlan == null) {
throw new EntitlementUserApiException(ErrorCode.ENT_CREATE_BAD_CATALOG,
productName, term.toString(), newPriceList.getName());
}
@@ -536,12 +552,22 @@ public class Subscription extends PrivateFields implements ISubscription {
throw new EntitlementError(String.format("Unexpected Event type = %s",
cur.getType()));
}
-
- IPlan previousPlan = catalog.getPlanFromName(previousPlanName);
- IPlanPhase previousPhase = catalog.getPhaseFromName(previousPhaseName);
- IPlan nextPlan = catalog.getPlanFromName(nextPlanName);
- IPlanPhase nextPhase = catalog.getPhaseFromName(nextPhaseName);
-
+
+ //TODO: Correctly handle exception
+ IPlan previousPlan = null;
+ IPlanPhase previousPhase = null;
+ IPlan nextPlan = null;
+ IPlanPhase nextPhase = null;
+ try {
+ previousPlan = catalog.findPlan(previousPlanName);
+ previousPhase = catalog.findPhase(previousPhaseName);
+ nextPlan = catalog.findPlan(nextPlanName);
+ nextPhase = catalog.findPhase(nextPhaseName);
+ } catch (CatalogApiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
SubscriptionTransition transition =
new SubscriptionTransition(id, bundleId, cur.getType(), apiEventType,
cur.getRequestedDate(), cur.getEffectiveDate(),
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/TestEntitlementDao.java b/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/TestEntitlementDao.java
index b2dee60..ec44978 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/TestEntitlementDao.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/TestEntitlementDao.java
@@ -29,6 +29,7 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.IPlan;
import com.ning.billing.catalog.api.IPriceListSet;
import com.ning.billing.catalog.api.ProductCategory;
@@ -61,7 +62,15 @@ public class TestEntitlementDao extends TestUserApiBase {
String planSetName = "standard";
DateTime now = new DateTime();
- IPlan plan = catalog.getPlan(productName, term, planSetName);
+
+ //TODO: Correctly handle exception
+ IPlan plan = null;
+ try {
+ plan = catalog.findPlan(productName, term, planSetName);
+ } catch (CatalogApiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
IEvent event = new ApiEventCreate(UUID.randomUUID(), now, now, plan.getName(), "evergreen", planSetName, now, now, 1);
dao.insertEvent(event);
@@ -105,7 +114,15 @@ public class TestEntitlementDao extends TestUserApiBase {
BillingPeriod term = BillingPeriod.MONTHLY;
String planSetName = IPriceListSet.DEFAULT_PRICELIST_NAME;
- IPlan plan = catalog.getPlan(productName, term, planSetName);
+ //TODO: Correctly handle exception
+ IPlan plan = null;
+ try {
+ plan = catalog.findPlan(productName, term, planSetName);
+ } catch (CatalogApiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
final IEvent event = new ApiEventCreate(UUID.randomUUID(), now, now, plan.getName(), "evergreen", planSetName, now, now, 1);
dao.inTransaction(new Transaction<Void, ISubscriptionSqlDao>() {