diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/CatalogJsonSimple.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/CatalogJsonSimple.java
new file mode 100644
index 0000000..3a8e86f
--- /dev/null
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/CatalogJsonSimple.java
@@ -0,0 +1,193 @@
+/*
+ * 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.jaxrs.json;
+
+import java.math.BigDecimal;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
+import com.ning.billing.catalog.api.CatalogApiException;
+import com.ning.billing.catalog.api.Plan;
+import com.ning.billing.catalog.api.PlanPhase;
+import com.ning.billing.catalog.api.Price;
+import com.ning.billing.catalog.api.Product;
+import com.ning.billing.catalog.api.StaticCatalog;
+
+@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
+public class CatalogJsonSimple {
+
+ private final ProductJson [] products;
+
+ public CatalogJsonSimple(StaticCatalog catalog) throws CatalogApiException {
+
+ Map<String, ProductJson> productMap = new HashMap<String, CatalogJsonSimple.ProductJson>();
+
+ Plan [] plans = catalog.getCurrentPlans();
+ for (Plan plan : plans) {
+
+ Product product = plan.getProduct();
+ ProductJson jProduct = productMap.get(product.getName());
+ if (jProduct == null) {
+ jProduct = new ProductJson(product.getCategory().toString(),
+ product.getName(),
+ toProductNames(product.getIncluded()), toProductNames(product.getAvailable()));
+ productMap.put(product.getName(), jProduct);
+ }
+
+ int i = 0 ;
+ PhaseJson [] phases = new PhaseJson[plan.getAllPhases().length];
+ for (PlanPhase phase : plan.getAllPhases()) {
+
+ Map<String, BigDecimal> prices = new HashMap<String, BigDecimal>();
+ if (phase.getRecurringPrice() != null) {
+ for (Price cur : phase.getRecurringPrice().getPrices()) {
+ prices.put(cur.getCurrency().toString(), cur.getValue());
+ }
+ }
+ PhaseJson jPhase = new PhaseJson(phase.getPhaseType().toString(), prices);
+ phases[i++] = jPhase;
+ }
+ PlanJson jPlan = new PlanJson(plan.getName(), phases);
+ jProduct.addPlan(jPlan);
+ }
+ products = productMap.values().toArray(new ProductJson[productMap.values().size()]);
+ }
+
+ private Collection<String> toProductNames(Product [] in) {
+ return Collections2.transform(Lists.newArrayList(in), new Function<Product, String>() {
+ public String apply(Product input) {
+ return input.getName();
+ }
+ });
+ }
+
+ @JsonCreator
+ public CatalogJsonSimple(@JsonProperty("products") ProductJson[] products) {
+ super();
+ this.products = products;
+ }
+
+
+
+ public ProductJson[] getProducts() {
+ return products;
+ }
+
+
+ @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
+ public static class ProductJson {
+
+ private final String type;
+ private final String name;
+ private final String [] included;
+ private final String [] available;
+ private final List<PlanJson> plans;
+
+
+ @JsonCreator
+ public ProductJson(@JsonProperty("type") String type,
+ @JsonProperty("name") String name,
+ @JsonProperty("plans") List<PlanJson> plans,
+ @JsonProperty("included") Collection<String> included,
+ @JsonProperty("available") Collection<String> available) {
+ super();
+ this.type = type;
+ this.name = name;
+ this.included = included.toArray(new String[included.size()]);
+ this.available = available.toArray(new String[available.size()]);
+ this.plans = plans;
+ }
+
+ public ProductJson(String type, String name, Collection<String> included, Collection<String> available) {
+ this(type, name, new LinkedList<CatalogJsonSimple.PlanJson>(), included, available);
+ }
+
+ public void addPlan(PlanJson plan) {
+ plans.add(plan);
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<PlanJson> getPlans() {
+ return plans;
+ }
+
+ public String[] getIncluded() {
+ return included;
+ }
+
+ public String[] getAvailable() {
+ return available;
+ }
+ }
+
+ @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
+ public static class PlanJson {
+
+ private final String name;
+ private final PhaseJson [] phases;
+
+ @JsonCreator
+ public PlanJson(@JsonProperty("name") String name,
+ @JsonProperty("phases") PhaseJson[] phases) {
+ super();
+ this.name = name;
+ this.phases = phases;
+ }
+ public String getName() {
+ return name;
+ }
+ public PhaseJson[] getPhases() {
+ return phases;
+ }
+ }
+
+ @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
+ public static class PhaseJson {
+
+ private final String type;
+ private final Map<String, BigDecimal> prices;
+
+ @JsonCreator
+ public PhaseJson(@JsonProperty("type") String type,
+ @JsonProperty("prices") Map<String, BigDecimal> prices) {
+ super();
+ this.type = type;
+ this.prices = prices;
+ }
+ public String getType() {
+ return type;
+ }
+ public Map<String, BigDecimal> getPrices() {
+ return prices;
+ }
+ }
+}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/SubscriptionResource.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/SubscriptionResource.java
index 8f3c93e..fe79b2a 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/SubscriptionResource.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/SubscriptionResource.java
@@ -83,8 +83,8 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Inject
public SubscriptionResource(final JaxrsUriBuilder uriBuilder, final EntitlementUserApi entitlementApi,
- final Context context, final KillbillEventHandler killbillHandler,
- final TagUserApi tagUserApi, final TagHelper tagHelper, final CustomFieldUserApi customFieldUserApi) {
+ final Context context, final KillbillEventHandler killbillHandler,
+ final TagUserApi tagUserApi, final TagHelper tagHelper, final CustomFieldUserApi customFieldUserApi) {
super(uriBuilder, tagUserApi, tagHelper, customFieldUserApi);
this.uriBuilder = uriBuilder;
this.entitlementApi = entitlementApi;
@@ -116,12 +116,12 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Response createSubscription(final SubscriptionJsonNoEvents subscription,
- @QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
- @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
- @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
- @HeaderParam(HDR_CREATED_BY) final String createdBy,
- @HeaderParam(HDR_REASON) final String reason,
- @HeaderParam(HDR_COMMENT) final String comment) {
+ @QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
+ @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
+ @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
+ @HeaderParam(HDR_CREATED_BY) final String createdBy,
+ @HeaderParam(HDR_REASON) final String reason,
+ @HeaderParam(HDR_COMMENT) final String comment) {
final SubscriptionCallCompletionCallback<Subscription> callback = new SubscriptionCallCompletionCallback<Subscription>() {
@@ -132,8 +132,8 @@ public class SubscriptionResource extends JaxRsResourceBase {
final UUID uuid = UUID.fromString(subscription.getBundleId());
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(subscription.getProductName(),
- ProductCategory.valueOf(subscription.getProductCategory()),
- BillingPeriod.valueOf(subscription.getBillingPeriod()), subscription.getPriceList(), null);
+ ProductCategory.valueOf(subscription.getProductCategory()),
+ BillingPeriod.valueOf(subscription.getBillingPeriod()), subscription.getPriceList(), null);
return entitlementApi.createSubscription(uuid, spec, inputDate, ctx);
}
@@ -156,13 +156,13 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Consumes(APPLICATION_JSON)
@Path("/{subscriptionId:" + UUID_PATTERN + "}")
public Response changeSubscriptionPlan(final SubscriptionJsonNoEvents subscription,
- @PathParam("subscriptionId") final String subscriptionId,
- @QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
- @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
- @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
- @HeaderParam(HDR_CREATED_BY) final String createdBy,
- @HeaderParam(HDR_REASON) final String reason,
- @HeaderParam(HDR_COMMENT) final String comment) {
+ @PathParam("subscriptionId") final String subscriptionId,
+ @QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
+ @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
+ @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec,
+ @HeaderParam(HDR_CREATED_BY) final String createdBy,
+ @HeaderParam(HDR_REASON) final String reason,
+ @HeaderParam(HDR_COMMENT) final String comment) {
final SubscriptionCallCompletionCallback<Response> callback = new SubscriptionCallCompletionCallback<Response>() {
@@ -170,8 +170,8 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Override
public Response doOperation(final CallContext ctx)
- throws EntitlementUserApiException, InterruptedException,
- TimeoutException {
+ throws EntitlementUserApiException, InterruptedException,
+ TimeoutException {
try {
final UUID uuid = UUID.fromString(subscriptionId);
final Subscription current = entitlementApi.getSubscriptionFromId(uuid);
@@ -213,9 +213,9 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Path("/{subscriptionId:" + UUID_PATTERN + "}/uncancel")
@Produces(APPLICATION_JSON)
public Response uncancelSubscriptionPlan(@PathParam("subscriptionId") final String subscriptionId,
- @HeaderParam(HDR_CREATED_BY) final String createdBy,
- @HeaderParam(HDR_REASON) final String reason,
- @HeaderParam(HDR_COMMENT) final String comment) {
+ @HeaderParam(HDR_CREATED_BY) final String createdBy,
+ @HeaderParam(HDR_REASON) final String reason,
+ @HeaderParam(HDR_COMMENT) final String comment) {
try {
final UUID uuid = UUID.fromString(subscriptionId);
final Subscription current = entitlementApi.getSubscriptionFromId(uuid);
@@ -236,12 +236,12 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Path("/{subscriptionId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
public Response cancelSubscriptionPlan(@PathParam("subscriptionId") final String subscriptionId,
- @QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
- @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
- @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("5") final long timeoutSec,
- @HeaderParam(HDR_CREATED_BY) final String createdBy,
- @HeaderParam(HDR_REASON) final String reason,
- @HeaderParam(HDR_COMMENT) final String comment) {
+ @QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
+ @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion,
+ @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("5") final long timeoutSec,
+ @HeaderParam(HDR_CREATED_BY) final String createdBy,
+ @HeaderParam(HDR_REASON) final String reason,
+ @HeaderParam(HDR_COMMENT) final String comment) {
final SubscriptionCallCompletionCallback<Response> callback = new SubscriptionCallCompletionCallback<Response>() {
@@ -249,8 +249,8 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Override
public Response doOperation(final CallContext ctx)
- throws EntitlementUserApiException, InterruptedException,
- TimeoutException {
+ throws EntitlementUserApiException, InterruptedException,
+ TimeoutException {
try {
final UUID uuid = UUID.fromString(subscriptionId);
@@ -289,34 +289,34 @@ public class SubscriptionResource extends JaxRsResourceBase {
}
@Override
- public void onSubscriptionTransition(final SubscriptionEvent curEvent) {
- log.debug(String.format("Got event SubscriptionTransition token = %s, type = %s, remaining = %d ",
- curEvent.getUserToken(), curEvent.getTransitionType(), curEvent.getRemainingEventsForUserOperation()));
+ public void onSubscriptionTransition(SubscriptionEvent curEvent) {
+ log.info(String.format("Got event SubscriptionTransition token = %s, type = %s, remaining = %d ",
+ curEvent.getUserToken(), curEvent.getTransitionType(), curEvent.getRemainingEventsForUserOperation()));
}
@Override
public void onEmptyInvoice(final EmptyInvoiceEvent curEvent) {
- log.debug(String.format("Got event EmptyInvoiceNotification token = %s ", curEvent.getUserToken()));
+ log.info(String.format("Got event EmptyInvoiceNotification token = %s ", curEvent.getUserToken()));
notifyForCompletion();
}
@Override
- public void onInvoiceCreation(final InvoiceCreationEvent curEvent) {
- log.debug(String.format("Got event InvoiceCreationNotification token = %s ", curEvent.getUserToken()));
+ public void onInvoiceCreation(InvoiceCreationEvent curEvent) {
+ log.info(String.format("Got event InvoiceCreationNotification token = %s ", curEvent.getUserToken()));
if (curEvent.getAmountOwed().compareTo(BigDecimal.ZERO) <= 0) {
notifyForCompletion();
}
}
@Override
- public void onPaymentInfo(final PaymentInfoEvent curEvent) {
- log.debug(String.format("Got event PaymentInfo token = %s ", curEvent.getUserToken()));
+ public void onPaymentInfo(PaymentInfoEvent curEvent) {
+ log.info(String.format("Got event PaymentInfo token = %s ", curEvent.getUserToken()));
notifyForCompletion();
}
@Override
- public void onPaymentError(final PaymentErrorEvent curEvent) {
- log.debug(String.format("Got event PaymentError token = %s ", curEvent.getUserToken()));
+ public void onPaymentError(PaymentErrorEvent curEvent) {
+ log.info(String.format("Got event PaymentError token = %s ", curEvent.getUserToken()));
notifyForCompletion();
}
}
@@ -332,11 +332,11 @@ public class SubscriptionResource extends JaxRsResourceBase {
private class SubscriptionCallCompletion<T> {
public Response withSynchronization(final SubscriptionCallCompletionCallback<T> callback,
- final long timeoutSec,
- final boolean callCompletion,
- final String createdBy,
- final String reason,
- final String comment) {
+ final long timeoutSec,
+ final boolean callCompletion,
+ final String createdBy,
+ final String reason,
+ final String comment) {
final CallContext ctx = context.createContext(createdBy, reason, comment);
final CompletionUserRequestSubscription waiter = callCompletion ? new CompletionUserRequestSubscription(ctx.getUserToken()) : null;
@@ -376,12 +376,12 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Response createCustomFields(@PathParam(ID_PARAM_NAME) final String id,
- final List<CustomFieldJson> customFields,
- @HeaderParam(HDR_CREATED_BY) final String createdBy,
- @HeaderParam(HDR_REASON) final String reason,
- @HeaderParam(HDR_COMMENT) final String comment) {
+ final List<CustomFieldJson> customFields,
+ @HeaderParam(HDR_CREATED_BY) final String createdBy,
+ @HeaderParam(HDR_REASON) final String reason,
+ @HeaderParam(HDR_COMMENT) final String comment) {
return super.createCustomFields(UUID.fromString(id), customFields,
- context.createContext(createdBy, reason, comment));
+ context.createContext(createdBy, reason, comment));
}
@DELETE
@@ -389,12 +389,12 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Response deleteCustomFields(@PathParam(ID_PARAM_NAME) final String id,
- @QueryParam(QUERY_CUSTOM_FIELDS) final String customFieldList,
- @HeaderParam(HDR_CREATED_BY) final String createdBy,
- @HeaderParam(HDR_REASON) final String reason,
- @HeaderParam(HDR_COMMENT) final String comment) {
+ @QueryParam(QUERY_CUSTOM_FIELDS) final String customFieldList,
+ @HeaderParam(HDR_CREATED_BY) final String createdBy,
+ @HeaderParam(HDR_REASON) final String reason,
+ @HeaderParam(HDR_COMMENT) final String comment) {
return super.deleteCustomFields(UUID.fromString(id), customFieldList,
- context.createContext(createdBy, reason, comment));
+ context.createContext(createdBy, reason, comment));
}
@GET
@@ -409,12 +409,12 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Response createTags(@PathParam(ID_PARAM_NAME) final String id,
- @QueryParam(QUERY_TAGS) final String tagList,
- @HeaderParam(HDR_CREATED_BY) final String createdBy,
- @HeaderParam(HDR_REASON) final String reason,
- @HeaderParam(HDR_COMMENT) final String comment) {
+ @QueryParam(QUERY_TAGS) final String tagList,
+ @HeaderParam(HDR_CREATED_BY) final String createdBy,
+ @HeaderParam(HDR_REASON) final String reason,
+ @HeaderParam(HDR_COMMENT) final String comment) {
return super.createTags(UUID.fromString(id), tagList,
- context.createContext(createdBy, reason, comment));
+ context.createContext(createdBy, reason, comment));
}
@DELETE
@@ -422,13 +422,13 @@ public class SubscriptionResource extends JaxRsResourceBase {
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Response deleteTags(@PathParam(ID_PARAM_NAME) final String id,
- @QueryParam(QUERY_TAGS) final String tagList,
- @HeaderParam(HDR_CREATED_BY) final String createdBy,
- @HeaderParam(HDR_REASON) final String reason,
- @HeaderParam(HDR_COMMENT) final String comment) {
+ @QueryParam(QUERY_TAGS) final String tagList,
+ @HeaderParam(HDR_CREATED_BY) final String createdBy,
+ @HeaderParam(HDR_REASON) final String reason,
+ @HeaderParam(HDR_COMMENT) final String comment) {
return super.deleteTags(UUID.fromString(id), tagList,
- context.createContext(createdBy, reason, comment));
+ context.createContext(createdBy, reason, comment));
}
@Override