killbill-aplcache

Details

diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/InvoiceItemJson.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/InvoiceItemJson.java
index a363c25..0d9c15c 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/InvoiceItemJson.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/InvoiceItemJson.java
@@ -339,8 +339,7 @@ public class InvoiceItemJson extends JsonBase {
         if (childAccountId != null ? !childAccountId.equals(that.childAccountId) : that.childAccountId != null) {
             return false;
         }
-        if (!((amount == null && that.amount == null) ||
-              (amount != null && that.amount != null && amount.compareTo(that.amount) == 0))) {
+        if (amount != null ? amount.compareTo(that.amount) != 0 : that.amount != null) {
             return false;
         }
         if (bundleId != null ? !bundleId.equals(that.bundleId) : that.bundleId != null) {
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/SimplePlanJson.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/SimplePlanJson.java
new file mode 100644
index 0000000..12913cd
--- /dev/null
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/SimplePlanJson.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2014-2016 Groupon, Inc
+ * Copyright 2014-2016 The Billing Project, LLC
+ *
+ * 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
+ * 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 org.killbill.billing.jaxrs.json;
+
+import java.math.BigDecimal;
+
+import org.killbill.billing.catalog.api.BillingPeriod;
+import org.killbill.billing.catalog.api.Currency;
+import org.killbill.billing.catalog.api.TimeUnit;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class SimplePlanJson {
+
+    private final String planId;
+    private final String productName;
+    private final Currency currency;
+    private final BigDecimal amount;
+    private final BillingPeriod billingPeriod;
+    private final Integer trialLength;
+    private final TimeUnit trialTimeUnit;
+
+    @JsonCreator
+    public SimplePlanJson(@JsonProperty("planId")  final String planId,
+                          @JsonProperty("productName")  final String productName,
+                          @JsonProperty("currency")  final Currency currency,
+                          @JsonProperty("amount")  final BigDecimal amount,
+                          @JsonProperty("billingPeriod")  final BillingPeriod billingPeriod,
+                          @JsonProperty("trialLength")  final Integer trialLength,
+                          @JsonProperty("trialTimeUnit")  final TimeUnit trialTimeUnit) {
+        this.planId = planId;
+        this.productName = productName;
+        this.currency = currency;
+        this.amount = amount;
+        this.billingPeriod = billingPeriod;
+        this.trialLength = trialLength;
+        this.trialTimeUnit = trialTimeUnit;
+    }
+
+    public String getPlanId() {
+        return planId;
+    }
+
+    public String getProductName() {
+        return productName;
+    }
+
+    public Currency getCurrency() {
+        return currency;
+    }
+
+    public BigDecimal getAmount() {
+        return amount;
+    }
+
+    public BillingPeriod getBillingPeriod() {
+        return billingPeriod;
+    }
+
+    public Integer getTrialLength() {
+        return trialLength;
+    }
+
+    public TimeUnit getTrialTimeUnit() {
+        return trialTimeUnit;
+    }
+
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof SimplePlanJson)) {
+            return false;
+        }
+
+        final SimplePlanJson that = (SimplePlanJson) o;
+
+        if (planId != null ? !planId.equals(that.planId) : that.planId != null) {
+            return false;
+        }
+        if (productName != null ? !productName.equals(that.productName) : that.productName != null) {
+            return false;
+        }
+        if (currency != that.currency) {
+            return false;
+        }
+        if (amount != null ? amount.compareTo(that.amount) != 0 : that.amount != null) {
+            return false;
+        }
+        if (billingPeriod != that.billingPeriod) {
+            return false;
+        }
+        if (trialLength != null ? !trialLength.equals(that.trialLength) : that.trialLength != null) {
+            return false;
+        }
+        return trialTimeUnit == that.trialTimeUnit;
+
+    }
+
+    @Override
+    public int hashCode() {
+        int result = planId != null ? planId.hashCode() : 0;
+        result = 31 * result + (productName != null ? productName.hashCode() : 0);
+        result = 31 * result + (currency != null ? currency.hashCode() : 0);
+        result = 31 * result + (amount != null ? amount.hashCode() : 0);
+        result = 31 * result + (billingPeriod != null ? billingPeriod.hashCode() : 0);
+        result = 31 * result + (trialLength != null ? trialLength.hashCode() : 0);
+        result = 31 * result + (trialTimeUnit != null ? trialTimeUnit.hashCode() : 0);
+        return result;
+    }
+}
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/CatalogResource.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/CatalogResource.java
index 6aaae90..f8ab371 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/CatalogResource.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/CatalogResource.java
@@ -40,9 +40,12 @@ import org.killbill.billing.catalog.api.Catalog;
 import org.killbill.billing.catalog.api.CatalogApiException;
 import org.killbill.billing.catalog.api.CatalogUserApi;
 import org.killbill.billing.catalog.api.Listing;
+import org.killbill.billing.catalog.api.SimplePlanDescriptor;
 import org.killbill.billing.catalog.api.StaticCatalog;
+import org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor;
 import org.killbill.billing.jaxrs.json.CatalogJson;
 import org.killbill.billing.jaxrs.json.PlanDetailJson;
+import org.killbill.billing.jaxrs.json.SimplePlanJson;
 import org.killbill.billing.jaxrs.util.Context;
 import org.killbill.billing.jaxrs.util.JaxrsUriBuilder;
 import org.killbill.billing.payment.api.PaymentApi;
@@ -179,4 +182,31 @@ public class CatalogResource extends JaxRsResourceBase {
         return Response.status(Status.OK).entity(details).build();
     }
 
+
+    @TimedResource
+    @POST
+    @Path("/simplePlan")
+    @Consumes(APPLICATION_JSON)
+    @Produces(APPLICATION_JSON)
+    @ApiOperation(value = "Upload the full catalog as XML")
+    @ApiResponses(value = {})
+    public Response addSimplePlan(final SimplePlanJson simplePlan,
+                                     @HeaderParam(HDR_CREATED_BY) final String createdBy,
+                                     @HeaderParam(HDR_REASON) final String reason,
+                                     @HeaderParam(HDR_COMMENT) final String comment,
+                                     @javax.ws.rs.core.Context final HttpServletRequest request,
+                                     @javax.ws.rs.core.Context final UriInfo uriInfo) throws Exception {
+        final CallContext callContext = context.createContext(createdBy, reason, comment, request);
+
+        final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor(simplePlan.getPlanId(),
+                                                                          simplePlan.getProductName(),
+                                                                          simplePlan.getCurrency(),
+                                                                          simplePlan.getAmount(),
+                                                                          simplePlan.getBillingPeriod(),
+                                                                          simplePlan.getTrialLength(),
+                                                                          simplePlan.getTrialTimeUnit());
+        catalogUserApi.addSimplePlan(desc, clock.getUTCNow(), callContext);
+        return uriBuilder.buildResponse(uriInfo, CatalogResource.class, null, null);
+    }
+
 }