killbill-memoizeit

Details

diff --git a/analytics/src/test/java/com/ning/billing/analytics/MockPhase.java b/analytics/src/test/java/com/ning/billing/analytics/MockPhase.java
index 03c8cf5..6a1604c 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/MockPhase.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/MockPhase.java
@@ -22,6 +22,7 @@ import com.ning.billing.catalog.api.BillingPeriod;
 import com.ning.billing.catalog.api.Currency;
 import com.ning.billing.catalog.api.Duration;
 import com.ning.billing.catalog.api.InternationalPrice;
+import com.ning.billing.catalog.api.Limit;
 import com.ning.billing.catalog.api.PhaseType;
 import com.ning.billing.catalog.api.Plan;
 import com.ning.billing.catalog.api.PlanPhase;
@@ -110,4 +111,9 @@ public class MockPhase implements PlanPhase {
     public PhaseType getPhaseType() {
         return cohort;
     }
+
+    @Override
+    public Limit[] getLimits() {
+         return new Limit[0];
+    }
 }
diff --git a/api/src/main/java/com/ning/billing/catalog/api/Limit.java b/api/src/main/java/com/ning/billing/catalog/api/Limit.java
new file mode 100644
index 0000000..70a0d62
--- /dev/null
+++ b/api/src/main/java/com/ning/billing/catalog/api/Limit.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning 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
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.catalog.api;
+
+
+public interface Limit {
+
+    public abstract Unit getUnit();
+
+    public abstract Double getMax();
+
+    public abstract Double getMin();
+
+}
\ No newline at end of file
diff --git a/api/src/main/java/com/ning/billing/catalog/api/PlanPhase.java b/api/src/main/java/com/ning/billing/catalog/api/PlanPhase.java
index 5059ce2..e9803b8 100644
--- a/api/src/main/java/com/ning/billing/catalog/api/PlanPhase.java
+++ b/api/src/main/java/com/ning/billing/catalog/api/PlanPhase.java
@@ -17,6 +17,7 @@
 package com.ning.billing.catalog.api;
 
 
+
 /**
  * The interface {@code PlanPhase} is used to express the various phases available on a given {@code Plan}
  * 
@@ -65,4 +66,10 @@ public interface PlanPhase {
      * @return  the {@code PhaseType}
      */
     public PhaseType getPhaseType();
+
+    /**
+    *
+    * @return  the {@code Limit}
+    */
+    public Limit[] getLimits();
 }
diff --git a/api/src/main/java/com/ning/billing/catalog/api/StaticCatalog.java b/api/src/main/java/com/ning/billing/catalog/api/StaticCatalog.java
index 698718f..1e5632a 100644
--- a/api/src/main/java/com/ning/billing/catalog/api/StaticCatalog.java
+++ b/api/src/main/java/com/ning/billing/catalog/api/StaticCatalog.java
@@ -57,6 +57,13 @@ public interface StaticCatalog {
     public Product[] getCurrentProducts() throws CatalogApiException;
 
     /**
+     * @return an array of supported {@code Unit}
+     * 
+     * @throws CatalogApiException
+     */
+    public Unit[] getCurrentUnits() throws CatalogApiException;
+
+    /**
      *
      * @return an array of supported {@code Plan}
      *
@@ -138,4 +145,5 @@ public interface StaticCatalog {
     public List<Listing> getAvailableBasePlanListings() throws CatalogApiException;
     public List<Listing> getAvailableAddonListings(String baseProductName) throws CatalogApiException;
 
+
 }
diff --git a/api/src/main/java/com/ning/billing/catalog/api/Unit.java b/api/src/main/java/com/ning/billing/catalog/api/Unit.java
new file mode 100644
index 0000000..5f2956c
--- /dev/null
+++ b/api/src/main/java/com/ning/billing/catalog/api/Unit.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning 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
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.catalog.api;
+
+public interface Unit {
+
+    public abstract String getName();
+
+}
\ No newline at end of file
diff --git a/catalog/src/main/java/com/ning/billing/catalog/DefaultLimit.java b/catalog/src/main/java/com/ning/billing/catalog/DefaultLimit.java
new file mode 100644
index 0000000..c583679
--- /dev/null
+++ b/catalog/src/main/java/com/ning/billing/catalog/DefaultLimit.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning 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
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.catalog;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlIDREF;
+
+import com.ning.billing.catalog.api.Limit;
+import com.ning.billing.util.config.catalog.ValidatingConfig;
+import com.ning.billing.util.config.catalog.ValidationError;
+import com.ning.billing.util.config.catalog.ValidationErrors;
+
+@XmlAccessorType(XmlAccessType.NONE)
+public class DefaultLimit extends ValidatingConfig<StandaloneCatalog> implements Limit {
+    @XmlElement(required = true)
+    @XmlIDREF
+    private DefaultUnit unit;
+
+    @XmlElement(required = false)
+    private Double max;
+    
+    @XmlElement(required = false)
+    private Double min;
+    
+    
+    /* (non-Javadoc)
+     * @see com.ning.billing.catalog.Limit#getUnit()
+     */
+    @Override
+    public DefaultUnit getUnit() {
+        return unit;
+    }
+
+    /* (non-Javadoc)
+     * @see com.ning.billing.catalog.Limit#getMax()
+     */
+    @Override
+    public Double getMax() {
+        return max;
+    }
+
+    /* (non-Javadoc)
+     * @see com.ning.billing.catalog.Limit#getMin()
+     */
+    @Override
+    public Double getMin() {
+        return min;
+    }
+
+    @Override
+    public ValidationErrors validate(StandaloneCatalog root, ValidationErrors errors) {
+        if(max == null && min == null) {
+            errors.add(new ValidationError("max and min cannot both be ommitted",root.getCatalogURI(), Limit.class, ""));
+        } else if (max != null && min != null && max.doubleValue() < min.doubleValue()) {
+            errors.add(new ValidationError("max must be greater than min",root.getCatalogURI(), Limit.class, ""));
+        }
+
+        return errors;
+    }
+}
diff --git a/catalog/src/main/java/com/ning/billing/catalog/DefaultPlanPhase.java b/catalog/src/main/java/com/ning/billing/catalog/DefaultPlanPhase.java
index 9c04e64..85ee0ee 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/DefaultPlanPhase.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/DefaultPlanPhase.java
@@ -20,6 +20,8 @@ import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+
 import java.net.URI;
 
 import com.ning.billing.ErrorCode;
@@ -27,6 +29,7 @@ import com.ning.billing.catalog.api.BillingPeriod;
 import com.ning.billing.catalog.api.CatalogApiException;
 import com.ning.billing.catalog.api.Duration;
 import com.ning.billing.catalog.api.InternationalPrice;
+import com.ning.billing.catalog.api.Limit;
 import com.ning.billing.catalog.api.PhaseType;
 import com.ning.billing.catalog.api.Plan;
 import com.ning.billing.catalog.api.PlanPhase;
@@ -52,6 +55,10 @@ public class DefaultPlanPhase extends ValidatingConfig<StandaloneCatalog> implem
     @XmlElement(required = false)
     private DefaultInternationalPrice fixedPrice;
 
+    @XmlElementWrapper(name = "limits", required = false)
+    @XmlElement(name = "limit", required = true)
+    private DefaultLimit[] limits = new DefaultLimit[0];
+
 //  Not supported: variable pricing
 //	@XmlElement(required=false)
 //	private InternationalPrice unitPrice;
@@ -121,14 +128,26 @@ public class DefaultPlanPhase extends ValidatingConfig<StandaloneCatalog> implem
         return plan;
     }
 
-    /* (non-Javadoc)
-      * @see com.ning.billing.catalog.IPlanPhase#getDuration()
-      */
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.ning.billing.catalog.IPlanPhase#getDuration()
+     */
     @Override
     public Duration getDuration() {
         return duration;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.ning.billing.catalog.PlanPhase#getLimit()
+     */
+    @Override
+    public DefaultLimit[] getLimits() {
+        return limits;
+    }
+
     @Override
     public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) {
         //Validation: check for nulls
diff --git a/catalog/src/main/java/com/ning/billing/catalog/DefaultUnit.java b/catalog/src/main/java/com/ning/billing/catalog/DefaultUnit.java
new file mode 100644
index 0000000..95f897e
--- /dev/null
+++ b/catalog/src/main/java/com/ning/billing/catalog/DefaultUnit.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning 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
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.catalog;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlID;
+
+import com.ning.billing.catalog.api.Unit;
+import com.ning.billing.util.config.catalog.ValidatingConfig;
+import com.ning.billing.util.config.catalog.ValidationErrors;
+
+@XmlAccessorType(XmlAccessType.NONE)
+public class DefaultUnit extends ValidatingConfig<StandaloneCatalog> implements Unit {
+    
+    @XmlAttribute(required = true)
+    @XmlID
+    private String name;
+
+    /* (non-Javadoc)
+     * @see com.ning.billing.catalog.Unit#getName()
+     */
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public ValidationErrors validate(StandaloneCatalog root, ValidationErrors errors) {
+        return errors;
+    }
+
+}
diff --git a/catalog/src/main/java/com/ning/billing/catalog/StandaloneCatalog.java b/catalog/src/main/java/com/ning/billing/catalog/StandaloneCatalog.java
index f299a1a..864e33b 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/StandaloneCatalog.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/StandaloneCatalog.java
@@ -66,6 +66,10 @@ public class StandaloneCatalog extends ValidatingConfig<StandaloneCatalog> imple
     @XmlElement(name = "currency", required = true)
     private Currency[] supportedCurrencies;
 
+    @XmlElementWrapper(name = "units", required = false)
+    @XmlElement(name = "unit", required = true)
+    private DefaultUnit[] units;
+
     @XmlElementWrapper(name = "products", required = true)
     @XmlElement(name = "product", required = true)
     private DefaultProduct[] products;
@@ -101,14 +105,21 @@ public class StandaloneCatalog extends ValidatingConfig<StandaloneCatalog> imple
     }
 
     /* (non-Javadoc)
-      * @see com.ning.billing.catalog.ICatalog#getProducts()
-      */
+     * @see com.ning.billing.catalog.ICatalog#getProducts()
+     */
+   @Override
+   public DefaultProduct[] getCurrentProducts() {
+       return products;
+   }
+
+   /* (non-Javadoc)
+    * @see com.ning.billing.catalog.ICatalog#getProducts()
+    */
     @Override
-    public DefaultProduct[] getCurrentProducts() {
-        return products;
+    public DefaultUnit[] getCurrentUnits() {
+        return units;
     }
 
-
     @Override
     public Currency[] getCurrentSupportedCurrencies() {
         return supportedCurrencies;
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 fc1559e..fc58c52 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/VersionedCatalog.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/VersionedCatalog.java
@@ -29,8 +29,6 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.joda.time.DateTime;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.ning.billing.ErrorCode;
 import com.ning.billing.catalog.api.ActionPolicy;
@@ -50,6 +48,7 @@ import com.ning.billing.catalog.api.PlanSpecifier;
 import com.ning.billing.catalog.api.PriceList;
 import com.ning.billing.catalog.api.Product;
 import com.ning.billing.catalog.api.StaticCatalog;
+import com.ning.billing.catalog.api.Unit;
 import com.ning.billing.util.clock.Clock;
 import com.ning.billing.util.config.catalog.ValidatingConfig;
 import com.ning.billing.util.config.catalog.ValidationErrors;
@@ -58,7 +57,6 @@ import com.ning.billing.util.config.catalog.ValidationErrors;
 @XmlRootElement(name = "catalog")
 @XmlAccessorType(XmlAccessType.NONE)
 public class VersionedCatalog extends ValidatingConfig<StandaloneCatalog> implements Catalog, StaticCatalog {
-    private static final Logger log = LoggerFactory.getLogger(VersionedCatalog.class);
 
     private final Clock clock;
     private String catalogName;
@@ -370,6 +368,11 @@ public class VersionedCatalog extends ValidatingConfig<StandaloneCatalog> implem
     }
 
     @Override
+    public Unit[] getCurrentUnits() throws CatalogApiException {
+        return versionForDate(clock.getUTCNow()).getCurrentUnits();
+    }
+
+    @Override
     public Plan[] getCurrentPlans() throws CatalogApiException {
         return versionForDate(clock.getUTCNow()).getCurrentPlans();
     }