killbill-uncached

Cleanup for account json in jaxrs

9/13/2013 11:23:22 PM

Changes

jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJsonSimple.java 70(+0 -70)

jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJsonWithBalance.java 65(+0 -65)

jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJsonWithBalanceAndCBA.java 66(+0 -66)

jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJsonSimple.java 43(+0 -43)

Details

diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJson.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJson.java
index f1be173..42fc843 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJson.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJson.java
@@ -16,6 +16,7 @@
 
 package com.ning.billing.jaxrs.json;
 
+import java.math.BigDecimal;
 import java.util.UUID;
 
 import org.joda.time.DateTimeZone;
@@ -28,29 +29,37 @@ import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.google.common.base.Objects;
 
-public class AccountJson extends AccountJsonSimple {
-
-    protected final String name;
-    protected final Integer firstNameLength;
-    protected final String email;
-    protected final Integer billCycleDayLocal;
-    protected final String currency;
-    protected final String paymentMethodId;
-    protected final String timeZone;
-    protected final String address1;
-    protected final String address2;
-    protected final String postalCode;
-    protected final String company;
-    protected final String city;
-    protected final String state;
-    protected final String country;
-    protected final String locale;
-    protected final String phone;
-    protected final Boolean isMigrated;
-    protected final Boolean isNotifiedForInvoices;
-
-    public AccountJson(final Account account) {
-        super(account.getId().toString(), account.getExternalKey());
+public class AccountJson extends JsonBase {
+
+    private final String accountId;
+    private final String externalKey;
+    private final BigDecimal accountCBA;
+    private final BigDecimal accountBalance;
+    private final String name;
+    private final Integer firstNameLength;
+    private final String email;
+    private final Integer billCycleDayLocal;
+    private final String currency;
+    private final String paymentMethodId;
+    private final String timeZone;
+    private final String address1;
+    private final String address2;
+    private final String postalCode;
+    private final String company;
+    private final String city;
+    private final String state;
+    private final String country;
+    private final String locale;
+    private final String phone;
+    private final Boolean isMigrated;
+    private final Boolean isNotifiedForInvoices;
+
+    public AccountJson(final Account account, final BigDecimal accountBalance, final BigDecimal accountCBA) {
+        super(null);
+        this.accountCBA = accountCBA;
+        this.accountBalance = accountBalance;
+        this.accountId = account.getId().toString();
+        this.externalKey = account.getExternalKey();
         this.name = account.getName();
         this.firstNameLength = account.getFirstNameLength();
         this.email = account.getEmail();
@@ -71,6 +80,54 @@ public class AccountJson extends AccountJsonSimple {
         this.isNotifiedForInvoices = account.isNotifiedForInvoices();
     }
 
+    @JsonCreator
+    public AccountJson(@JsonProperty("accountId") final String accountId,
+                       @JsonProperty("name") final String name,
+                       @JsonProperty("firstNameLength") final Integer firstNameLength,
+                       @JsonProperty("externalKey") final String externalKey,
+                       @JsonProperty("email") final String email,
+                       @JsonProperty("billCycleDayLocal") final Integer billCycleDayLocal,
+                       @JsonProperty("currency") final String currency,
+                       @JsonProperty("paymentMethodId") final String paymentMethodId,
+                       @JsonProperty("timeZone") final String timeZone,
+                       @JsonProperty("address1") final String address1,
+                       @JsonProperty("address2") final String address2,
+                       @JsonProperty("postalCode") final String postalCode,
+                       @JsonProperty("company") final String company,
+                       @JsonProperty("city") final String city,
+                       @JsonProperty("state") final String state,
+                       @JsonProperty("country") final String country,
+                       @JsonProperty("locale") final String locale,
+                       @JsonProperty("phone") final String phone,
+                       @JsonProperty("isMigrated") final Boolean isMigrated,
+                       @JsonProperty("isNotifiedForInvoices") final Boolean isNotifiedForInvoices,
+                       @JsonProperty("accountBalance") final BigDecimal accountBalance,
+                       @JsonProperty("accountCBA") final BigDecimal accountCBA) {
+        super(null);
+        this.accountBalance = accountBalance;
+        this.externalKey = externalKey;
+        this.accountId = accountId;
+        this.name = name;
+        this.firstNameLength = firstNameLength;
+        this.email = email;
+        this.billCycleDayLocal = billCycleDayLocal;
+        this.currency = currency;
+        this.paymentMethodId = paymentMethodId;
+        this.timeZone = timeZone;
+        this.address1 = address1;
+        this.address2 = address2;
+        this.postalCode = postalCode;
+        this.company = company;
+        this.city = city;
+        this.state = state;
+        this.country = country;
+        this.locale = locale;
+        this.phone = phone;
+        this.isMigrated = isMigrated;
+        this.isNotifiedForInvoices = isNotifiedForInvoices;
+        this.accountCBA = accountCBA;
+    }
+
     public AccountData toAccountData() {
         return new AccountData() {
             @Override
@@ -179,47 +236,21 @@ public class AccountJson extends AccountJsonSimple {
             }
         };
     }
+    
+    public BigDecimal getAccountBalance() {
+        return accountBalance;
+    }
 
-    @JsonCreator
-    public AccountJson(@JsonProperty("accountId") final String accountId,
-                       @JsonProperty("name") final String name,
-                       @JsonProperty("firstNameLength") final Integer firstNameLength,
-                       @JsonProperty("externalKey") final String externalKey,
-                       @JsonProperty("email") final String email,
-                       @JsonProperty("billCycleDayLocal") final Integer billCycleDayLocal,
-                       @JsonProperty("currency") final String currency,
-                       @JsonProperty("paymentMethodId") final String paymentMethodId,
-                       @JsonProperty("timeZone") final String timeZone,
-                       @JsonProperty("address1") final String address1,
-                       @JsonProperty("address2") final String address2,
-                       @JsonProperty("postalCode") final String postalCode,
-                       @JsonProperty("company") final String company,
-                       @JsonProperty("city") final String city,
-                       @JsonProperty("state") final String state,
-                       @JsonProperty("country") final String country,
-                       @JsonProperty("locale") final String locale,
-                       @JsonProperty("phone") final String phone,
-                       @JsonProperty("isMigrated") final Boolean isMigrated,
-                       @JsonProperty("isNotifiedForInvoices") final Boolean isNotifiedForInvoices) {
-        super(accountId, externalKey);
-        this.name = name;
-        this.firstNameLength = firstNameLength;
-        this.email = email;
-        this.billCycleDayLocal = billCycleDayLocal;
-        this.currency = currency;
-        this.paymentMethodId = paymentMethodId;
-        this.timeZone = timeZone;
-        this.address1 = address1;
-        this.address2 = address2;
-        this.postalCode = postalCode;
-        this.company = company;
-        this.city = city;
-        this.state = state;
-        this.country = country;
-        this.locale = locale;
-        this.phone = phone;
-        this.isMigrated = isMigrated;
-        this.isNotifiedForInvoices = isNotifiedForInvoices;
+    public String getAccountId() {
+        return accountId;
+    }
+
+    public String getExternalKey() {
+        return externalKey;
+    }
+
+    public BigDecimal getAccountCBA() {
+        return accountCBA;
     }
 
     public String getName() {
@@ -286,144 +317,11 @@ public class AccountJson extends AccountJsonSimple {
         return phone;
     }
 
-    @JsonProperty("isMigrated")
     public Boolean isMigrated() {
         return isMigrated;
     }
 
-    @JsonProperty("isNotifiedForInvoices")
     public Boolean isNotifiedForInvoices() {
         return isNotifiedForInvoices;
     }
-
-    @Override
-    public String toString() {
-        final StringBuilder sb = new StringBuilder();
-        sb.append("AccountJson");
-        sb.append("{name='").append(name).append('\'');
-        sb.append(", firstNameLength=").append(firstNameLength);
-        sb.append(", email='").append(email).append('\'');
-        sb.append(", billCycleDayJson=").append(billCycleDayLocal);
-        sb.append(", currency='").append(currency).append('\'');
-        sb.append(", paymentMethodId='").append(paymentMethodId).append('\'');
-        sb.append(", timeZone='").append(timeZone).append('\'');
-        sb.append(", address1='").append(address1).append('\'');
-        sb.append(", address2='").append(address2).append('\'');
-        sb.append(", postalCode='").append(postalCode).append('\'');
-        sb.append(", company='").append(company).append('\'');
-        sb.append(", city='").append(city).append('\'');
-        sb.append(", state='").append(state).append('\'');
-        sb.append(", country='").append(country).append('\'');
-        sb.append(", locale='").append(locale).append('\'');
-        sb.append(", phone='").append(phone).append('\'');
-        sb.append(", isMigrated=").append(isMigrated);
-        sb.append(", isNotifiedForInvoices=").append(isNotifiedForInvoices);
-        sb.append('}');
-        return sb.toString();
-    }
-
-    @Override
-    public boolean equals(final Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-
-        final AccountJson that = (AccountJson) o;
-
-        if (accountId != null ? !accountId.equals(that.accountId) : that.accountId != null) {
-            return false;
-        } else {
-            return equalsNoId(that);
-        }
-    }
-
-    // Used to check POST versus GET
-    public boolean equalsNoId(final AccountJson that) {
-        if (address1 != null ? !address1.equals(that.address1) : that.address1 != null) {
-            return false;
-        }
-        if (address2 != null ? !address2.equals(that.address2) : that.address2 != null) {
-            return false;
-        }
-        if (billCycleDayLocal != null ? !billCycleDayLocal.equals(that.billCycleDayLocal) : that.billCycleDayLocal != null) {
-            return false;
-        }
-        if (city != null ? !city.equals(that.city) : that.city != null) {
-            return false;
-        }
-        if (company != null ? !company.equals(that.company) : that.company != null) {
-            return false;
-        }
-        if (country != null ? !country.equals(that.country) : that.country != null) {
-            return false;
-        }
-        if (currency != null ? !currency.equals(that.currency) : that.currency != null) {
-            return false;
-        }
-        if (email != null ? !email.equals(that.email) : that.email != null) {
-            return false;
-        }
-        if (externalKey != null ? !externalKey.equals(that.externalKey) : that.externalKey != null) {
-            return false;
-        }
-        if (isMigrated != null ? !isMigrated.equals(that.isMigrated) : that.isMigrated != null) {
-            return false;
-        }
-        if (isNotifiedForInvoices != null ? !isNotifiedForInvoices.equals(that.isNotifiedForInvoices) : that.isNotifiedForInvoices != null) {
-            return false;
-        }
-        if (firstNameLength != null ? !firstNameLength.equals(that.firstNameLength) : that.firstNameLength != null) {
-            return false;
-        }
-        if (locale != null ? !locale.equals(that.locale) : that.locale != null) {
-            return false;
-        }
-        if (name != null ? !name.equals(that.name) : that.name != null) {
-            return false;
-        }
-        if (paymentMethodId != null ? !paymentMethodId.equals(that.paymentMethodId) : that.paymentMethodId != null) {
-            return false;
-        }
-        if (phone != null ? !phone.equals(that.phone) : that.phone != null) {
-            return false;
-        }
-        if (postalCode != null ? !postalCode.equals(that.postalCode) : that.postalCode != null) {
-            return false;
-        }
-        if (state != null ? !state.equals(that.state) : that.state != null) {
-            return false;
-        }
-        if (timeZone != null ? !timeZone.equals(that.timeZone) : that.timeZone != null) {
-            return false;
-        }
-
-        return true;
-    }
-
-    @Override
-    public int hashCode() {
-        int result = super.hashCode();
-        result = 31 * result + (name != null ? name.hashCode() : 0);
-        result = 31 * result + (firstNameLength != null ? firstNameLength.hashCode() : 0);
-        result = 31 * result + (email != null ? email.hashCode() : 0);
-        result = 31 * result + (billCycleDayLocal != null ? billCycleDayLocal.hashCode() : 0);
-        result = 31 * result + (currency != null ? currency.hashCode() : 0);
-        result = 31 * result + (paymentMethodId != null ? paymentMethodId.hashCode() : 0);
-        result = 31 * result + (timeZone != null ? timeZone.hashCode() : 0);
-        result = 31 * result + (address1 != null ? address1.hashCode() : 0);
-        result = 31 * result + (address2 != null ? address2.hashCode() : 0);
-        result = 31 * result + (postalCode != null ? postalCode.hashCode() : 0);
-        result = 31 * result + (company != null ? company.hashCode() : 0);
-        result = 31 * result + (city != null ? city.hashCode() : 0);
-        result = 31 * result + (state != null ? state.hashCode() : 0);
-        result = 31 * result + (country != null ? country.hashCode() : 0);
-        result = 31 * result + (locale != null ? locale.hashCode() : 0);
-        result = 31 * result + (phone != null ? phone.hashCode() : 0);
-        result = 31 * result + (isMigrated != null ? isMigrated.hashCode() : 0);
-        result = 31 * result + (isNotifiedForInvoices != null ? isNotifiedForInvoices.hashCode() : 0);
-        return result;
-    }
 }
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
index e05d73f..5c87754 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
@@ -48,13 +48,13 @@ import com.google.common.collect.Multimap;
 
 public class AccountTimelineJson {
 
-    private final AccountJsonSimple account;
+    private final AccountJson account;
     private final List<BundleJson> bundles;
     private final List<InvoiceJsonWithBundleKeys> invoices;
     private final List<PaymentJsonWithBundleKeys> payments;
 
     @JsonCreator
-    public AccountTimelineJson(@JsonProperty("account") final AccountJsonSimple account,
+    public AccountTimelineJson(@JsonProperty("account") final AccountJson account,
                                @JsonProperty("bundles") final List<BundleJson> bundles,
                                @JsonProperty("invoices") final List<InvoiceJsonWithBundleKeys> invoices,
                                @JsonProperty("payments") final List<PaymentJsonWithBundleKeys> payments) {
@@ -118,7 +118,7 @@ public class AccountTimelineJson {
                                final Map<UUID, List<AuditLog>> paymentsAuditLogs, final Map<UUID, List<AuditLog>> refundsAuditLogs,
                                final Map<UUID, List<AuditLog>> chargebacksAuditLogs, final Map<UUID, List<AuditLog>> bundlesAuditLogs,
                                final Map<UUID, List<AuditLog>> subscriptionsAuditLogs, final Map<UUID, List<AuditLog>> subscriptionEventsAuditLogs) {
-        this.account = new AccountJsonSimple(account.getId().toString(), account.getExternalKey());
+        this.account = new AccountJson(account, null, null);
         this.bundles = new LinkedList<BundleJson>();
         for (final SubscriptionBundle bundle : bundles) {
             final List<AuditLog> bundleAuditLogs = bundlesAuditLogs.get(bundle.getId());
@@ -176,7 +176,7 @@ public class AccountTimelineJson {
         }
     }
 
-    public AccountJsonSimple getAccount() {
+    public AccountJson getAccount() {
         return account;
     }
 
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java
index 618886b..c9faa12 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java
@@ -56,8 +56,6 @@ import com.ning.billing.invoice.api.InvoicePaymentApi;
 import com.ning.billing.invoice.api.InvoiceUserApi;
 import com.ning.billing.jaxrs.json.AccountEmailJson;
 import com.ning.billing.jaxrs.json.AccountJson;
-import com.ning.billing.jaxrs.json.AccountJsonWithBalance;
-import com.ning.billing.jaxrs.json.AccountJsonWithBalanceAndCBA;
 import com.ning.billing.jaxrs.json.AccountTimelineJson;
 import com.ning.billing.jaxrs.json.BundleJson;
 import com.ning.billing.jaxrs.json.ChargebackCollectionJson;
@@ -208,16 +206,15 @@ public class AccountResource extends JaxRsResourceBase {
     }
 
     private AccountJson getAccount(final Account account, final Boolean accountWithBalance, final Boolean accountWithBalanceAndCBA, final TenantContext tenantContext) {
-        final AccountJson json;
         if (accountWithBalanceAndCBA) {
             final BigDecimal accountBalance = invoiceApi.getAccountBalance(account.getId(), tenantContext);
             final BigDecimal accountCBA = invoiceApi.getAccountCBA(account.getId(), tenantContext);
-            return new AccountJsonWithBalanceAndCBA(account, accountBalance, accountCBA);
+            return new AccountJson(account, accountBalance, accountCBA);
         } else if (accountWithBalance) {
             final BigDecimal accountBalance = invoiceApi.getAccountBalance(account.getId(), tenantContext);
-            return new AccountJsonWithBalance(account, accountBalance);
+            return new AccountJson(account, accountBalance, null);
         } else {
-            return new AccountJson(account);
+            return new AccountJson(account, null, null);
         }
     }
 
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJson.java
index 81f3c1d..9ab3e24 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJson.java
@@ -55,7 +55,7 @@ public class TestAccountJson extends JaxrsTestSuiteNoDB {
         final AccountJson accountJson = new AccountJson(accountId, name, length, externalKey,
                                                         email, billCycleDayLocal, currency, paymentMethodId,
                                                         timeZone, address1, address2, postalCode, company, city, state,
-                                                        country, locale, phone, isMigrated, isNotifiedForInvoice);
+                                                        country, locale, phone, isMigrated, isNotifiedForInvoice, null, null);
         Assert.assertEquals(accountJson.getAccountId(), accountId);
         Assert.assertEquals(accountJson.getName(), name);
         Assert.assertEquals(accountJson.getFirstNameLength(), length);
@@ -107,7 +107,7 @@ public class TestAccountJson extends JaxrsTestSuiteNoDB {
         accountBuilder.timeZone(DateTimeZone.UTC);
         final Account account = accountBuilder.build();
 
-        final AccountJson accountJson = new AccountJson(account);
+        final AccountJson accountJson = new AccountJson(account, null, null);
         Assert.assertEquals(accountJson.getAddress1(), account.getAddress1());
         Assert.assertEquals(accountJson.getAddress2(), account.getAddress2());
         Assert.assertEquals(accountJson.getBillCycleDayLocal(), (Integer) bcd);
diff --git a/server/src/test/java/com/ning/billing/jaxrs/KillbillClient.java b/server/src/test/java/com/ning/billing/jaxrs/KillbillClient.java
index 654157f..227d2d9 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/KillbillClient.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/KillbillClient.java
@@ -1105,7 +1105,7 @@ public abstract class KillbillClient extends GuicyKillbillTestSuiteWithEmbeddedD
 
         // Note: the accountId payload is ignored on account creation
         return new AccountJson(accountId, name, length, externalKey, email, null, currency, null, timeZone,
-                               address1, address2, postalCode, company, city, state, country, locale, phone, false, false);
+                               address1, address2, postalCode, company, city, state, country, locale, phone, false, false, null, null);
     }
 
     /**
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
index af1e2c4..bb61ac3 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
@@ -30,7 +30,6 @@ import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import com.ning.billing.jaxrs.json.AccountJson;
-import com.ning.billing.jaxrs.json.AccountJsonWithBalance;
 import com.ning.billing.jaxrs.json.AuditLogJson;
 import com.ning.billing.jaxrs.json.CustomFieldJson;
 import com.ning.billing.jaxrs.json.PaymentJsonSimple;
@@ -66,7 +65,7 @@ public class TestAccount extends TestJaxrsBase {
         final AccountJson newInput = new AccountJson(input.getAccountId(),
                                                      "zozo", 4, input.getExternalKey(), "rr@google.com", 18,
                                                      "USD", null, "UTC", "bl1", "bh2", "", "", "ca", "San Francisco", "usa", "en", "415-255-2991",
-                                                     false, false);
+                                                     false, false, null, null);
         final AccountJson updatedAccount = updateAccount(input.getAccountId(), newInput);
         Assert.assertTrue(updatedAccount.equals(newInput));
 
@@ -83,7 +82,7 @@ public class TestAccount extends TestJaxrsBase {
         final Response response = doGet(uri, queryParams, DEFAULT_HTTP_TIMEOUT_SEC);
         Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
         final String baseJson = response.getResponseBody();
-        final AccountJsonWithBalance accountWithBalance = mapper.readValue(baseJson, AccountJsonWithBalance.class);
+        final AccountJson accountWithBalance = mapper.readValue(baseJson, AccountJson.class);
         final BigDecimal accountBalance = accountWithBalance.getAccountBalance();
         Assert.assertTrue(accountBalance.compareTo(BigDecimal.ZERO) > 0);
     }
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestAccountEmailNotifications.java b/server/src/test/java/com/ning/billing/jaxrs/TestAccountEmailNotifications.java
index 412d452..112891e 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestAccountEmailNotifications.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestAccountEmailNotifications.java
@@ -22,6 +22,7 @@ import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import com.fasterxml.jackson.core.type.TypeReference;
+
 import com.ning.billing.jaxrs.json.AccountJson;
 import com.ning.billing.jaxrs.json.InvoiceEmailJson;
 import com.ning.billing.jaxrs.resources.JaxrsResource;
diff --git a/server/src/test/java/com/ning/billing/server/security/TestTenantFilter.java b/server/src/test/java/com/ning/billing/server/security/TestTenantFilter.java
index ef60130..e4c54b4 100644
--- a/server/src/test/java/com/ning/billing/server/security/TestTenantFilter.java
+++ b/server/src/test/java/com/ning/billing/server/security/TestTenantFilter.java
@@ -20,12 +20,10 @@ import javax.ws.rs.core.Response.Status;
 
 import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import com.ning.billing.jaxrs.TestJaxrsBase;
 import com.ning.billing.jaxrs.json.AccountJson;
-import com.ning.billing.server.listeners.KillbillGuiceListener;
 
 // Pure Multi-Tenancy test (no RBAC)
 public class TestTenantFilter extends TestJaxrsBase {