killbill-aplcache

jaxrs: populate missing fields in AccountJson Signed-off-by:

8/8/2012 9:04:17 PM

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 05f405f..a83e8b7 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
@@ -29,33 +29,25 @@ import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
 public class AccountJson extends AccountJsonSimple {
-    // STEPH Missing city, locale, postalCode from https://home.ninginc.com:8443/display/REVINFRA/Killbill+1.0+APIs
 
     private final String name;
-
     private final Integer length;
-
     private final String email;
-
     private final BillCycleDayJson billCycleDayJson;
-
     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) {
         super(account.getId().toString(), account.getExternalKey());
@@ -68,10 +60,15 @@ public class AccountJson extends AccountJsonSimple {
         this.timeZone = account.getTimeZone().toString();
         this.address1 = account.getAddress1();
         this.address2 = account.getAddress2();
+        this.postalCode = account.getPostalCode();
         this.company = account.getCompanyName();
+        this.city = account.getCity();
         this.state = account.getStateOrProvince();
         this.country = account.getCountry();
+        this.locale = account.getLocale();
         this.phone = account.getPhone();
+        this.isMigrated = account.isMigrated();
+        this.isNotifiedForInvoices = account.isNotifiedForInvoices();
     }
 
     public AccountData toAccountData() {
@@ -88,7 +85,7 @@ public class AccountJson extends AccountJsonSimple {
 
             @Override
             public String getPostalCode() {
-                return null;
+                return postalCode;
             }
 
             @Override
@@ -98,12 +95,12 @@ public class AccountJson extends AccountJsonSimple {
 
             @Override
             public Boolean isMigrated() {
-                return false;
+                return isMigrated;
             }
 
             @Override
             public Boolean isNotifiedForInvoices() {
-                return false;
+                return isNotifiedForInvoices;
             }
 
             @Override
@@ -118,8 +115,7 @@ public class AccountJson extends AccountJsonSimple {
 
             @Override
             public String getLocale() {
-                // TODO
-                return "en";
+                return locale;
             }
 
             @Override
@@ -154,7 +150,7 @@ public class AccountJson extends AccountJsonSimple {
 
             @Override
             public String getCity() {
-                return null;
+                return city;
             }
 
             @Override
@@ -200,10 +196,15 @@ public class AccountJson extends AccountJsonSimple {
                        @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("phone") final String phone) {
+                       @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.length = length;
@@ -214,10 +215,15 @@ public class AccountJson extends AccountJsonSimple {
         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 getName() {
@@ -256,10 +262,18 @@ public class AccountJson extends AccountJsonSimple {
         return address2;
     }
 
+    public String getPostalCode() {
+        return postalCode;
+    }
+
     public String getCompany() {
         return company;
     }
 
+    public String getCity() {
+        return city;
+    }
+
     public String getState() {
         return state;
     }
@@ -268,167 +282,152 @@ public class AccountJson extends AccountJsonSimple {
         return country;
     }
 
+    public String getLocale() {
+        return locale;
+    }
+
     public String getPhone() {
         return phone;
     }
 
+    @JsonProperty("isMigrated")
+    public Boolean isMigrated() {
+        return isMigrated;
+    }
+
+    @JsonProperty("isNotifiedForInvoices")
+    public Boolean isNotifiedForInvoices() {
+        return isNotifiedForInvoices;
+    }
+
     @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result
-                 + ((accountId == null) ? 0 : accountId.hashCode());
-        result = prime * result
-                 + ((address1 == null) ? 0 : address1.hashCode());
-        result = prime * result
-                 + ((address2 == null) ? 0 : address2.hashCode());
-        result = prime * result
-                 + ((billCycleDayJson == null) ? 0 : billCycleDayJson.hashCode());
-        result = prime * result + ((company == null) ? 0 : company.hashCode());
-        result = prime * result + ((country == null) ? 0 : country.hashCode());
-        result = prime * result
-                 + ((currency == null) ? 0 : currency.hashCode());
-        result = prime * result + ((email == null) ? 0 : email.hashCode());
-        result = prime * result
-                 + ((externalKey == null) ? 0 : externalKey.hashCode());
-        result = prime * result + ((length == null) ? 0 : length.hashCode());
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result
-                 + ((paymentMethodId == null) ? 0 : paymentMethodId.hashCode());
-        result = prime * result + ((phone == null) ? 0 : phone.hashCode());
-        result = prime * result + ((state == null) ? 0 : state.hashCode());
-        result = prime * result
-                 + ((timeZone == null) ? 0 : timeZone.hashCode());
-        return result;
+    public String toString() {
+        final StringBuilder sb = new StringBuilder();
+        sb.append("AccountJson");
+        sb.append("{name='").append(name).append('\'');
+        sb.append(", length=").append(length);
+        sb.append(", email='").append(email).append('\'');
+        sb.append(", billCycleDayJson=").append(billCycleDayJson);
+        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();
     }
 
-    // Used to check POST versus GET
-    public boolean equalsNoId(final Object obj) {
-        if (this == obj) {
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) {
             return true;
         }
-        if (obj == null) {
+        if (o == null || getClass() != o.getClass()) {
             return false;
         }
-        if (getClass() != obj.getClass()) {
+
+        final AccountJson that = (AccountJson) o;
+
+        if (accountId != null ? !accountId.equals(that.accountId) : that.accountId != null) {
             return false;
+        } else {
+            return equalsNoId(that);
         }
-        final AccountJson other = (AccountJson) obj;
-        if (address1 == null) {
-            if (other.address1 != null) {
-                return false;
-            }
-        } else if (!address1.equals(other.address1)) {
+    }
+
+    // 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) {
-            if (other.address2 != null) {
-                return false;
-            }
-        } else if (!address2.equals(other.address2)) {
+        if (address2 != null ? !address2.equals(that.address2) : that.address2 != null) {
             return false;
         }
-        if (billCycleDayJson == null) {
-            if (other.billCycleDayJson != null) {
-                return false;
-            }
-        } else if (!billCycleDayJson.equals(other.billCycleDayJson)) {
+        if (billCycleDayJson != null ? !billCycleDayJson.equals(that.billCycleDayJson) : that.billCycleDayJson != null) {
             return false;
         }
-        if (company == null) {
-            if (other.company != null) {
-                return false;
-            }
-        } else if (!company.equals(other.company)) {
+        if (city != null ? !city.equals(that.city) : that.city != null) {
             return false;
         }
-        if (country == null) {
-            if (other.country != null) {
-                return false;
-            }
-        } else if (!country.equals(other.country)) {
+        if (company != null ? !company.equals(that.company) : that.company != null) {
             return false;
         }
-        if (currency == null) {
-            if (other.currency != null) {
-                return false;
-            }
-        } else if (!currency.equals(other.currency)) {
+        if (country != null ? !country.equals(that.country) : that.country != null) {
             return false;
         }
-        if (email == null) {
-            if (other.email != null) {
-                return false;
-            }
-        } else if (!email.equals(other.email)) {
+        if (currency != null ? !currency.equals(that.currency) : that.currency != null) {
             return false;
         }
-        if (externalKey == null) {
-            if (other.externalKey != null) {
-                return false;
-            }
-        } else if (!externalKey.equals(other.externalKey)) {
+        if (email != null ? !email.equals(that.email) : that.email != null) {
             return false;
         }
-        if (length == null) {
-            if (other.length != null) {
-                return false;
-            }
-        } else if (!length.equals(other.length)) {
+        if (externalKey != null ? !externalKey.equals(that.externalKey) : that.externalKey != null) {
             return false;
         }
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
+        if (isMigrated != null ? !isMigrated.equals(that.isMigrated) : that.isMigrated != null) {
             return false;
         }
-        if (paymentMethodId == null) {
-            if (other.paymentMethodId != null) {
-                return false;
-            }
-        } else if (!paymentMethodId.equals(other.paymentMethodId)) {
+        if (isNotifiedForInvoices != null ? !isNotifiedForInvoices.equals(that.isNotifiedForInvoices) : that.isNotifiedForInvoices != null) {
             return false;
         }
-        if (phone == null) {
-            if (other.phone != null) {
-                return false;
-            }
-        } else if (!phone.equals(other.phone)) {
+        if (length != null ? !length.equals(that.length) : that.length != null) {
             return false;
         }
-        if (state == null) {
-            if (other.state != null) {
-                return false;
-            }
-        } else if (!state.equals(other.state)) {
+        if (locale != null ? !locale.equals(that.locale) : that.locale != null) {
             return false;
         }
-        if (timeZone == null) {
-            if (other.timeZone != null) {
-                return false;
-            }
-        } else if (!timeZone.equals(other.timeZone)) {
+        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 boolean equals(final Object obj) {
-        if (!equalsNoId(obj)) {
-            return false;
-        } else {
-            final AccountJson other = (AccountJson) obj;
-            if (accountId == null) {
-                if (other.accountId != null) {
-                    return false;
-                }
-            } else if (!accountId.equals(other.accountId)) {
-                return false;
-            }
-        }
-        return true;
+    public int hashCode() {
+        int result = super.hashCode();
+        result = 31 * result + (name != null ? name.hashCode() : 0);
+        result = 31 * result + (length != null ? length.hashCode() : 0);
+        result = 31 * result + (email != null ? email.hashCode() : 0);
+        result = 31 * result + (billCycleDayJson != null ? billCycleDayJson.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/test/java/com/ning/billing/jaxrs/json/TestAccountJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJson.java
index d787fc8..3c70a20 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
@@ -28,12 +28,8 @@ import com.ning.billing.jaxrs.JaxrsTestSuite;
 import com.ning.billing.mock.MockAccountBuilder;
 import com.ning.billing.mock.api.MockBillCycleDay;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-
 public class TestAccountJson extends JaxrsTestSuite {
 
-    private static final ObjectMapper mapper = new ObjectMapper();
-
     @Test(groups = "fast")
     public void testJson() throws Exception {
         final String accountId = UUID.randomUUID().toString();
@@ -47,15 +43,20 @@ public class TestAccountJson extends JaxrsTestSuite {
         final String timeZone = UUID.randomUUID().toString();
         final String address1 = UUID.randomUUID().toString();
         final String address2 = UUID.randomUUID().toString();
+        final String postalCode = UUID.randomUUID().toString();
         final String company = UUID.randomUUID().toString();
+        final String city = UUID.randomUUID().toString();
         final String state = UUID.randomUUID().toString();
         final String country = UUID.randomUUID().toString();
+        final String locale = UUID.randomUUID().toString();
         final String phone = UUID.randomUUID().toString();
+        final Boolean isMigrated = true;
+        final Boolean isNotifiedForInvoice = false;
 
         final AccountJson accountJson = new AccountJson(accountId, name, length, externalKey,
                                                         email, billCycleDay, currency, paymentMethodId,
-                                                        timeZone, address1, address2, company, state,
-                                                        country, phone);
+                                                        timeZone, address1, address2, postalCode, company, city, state,
+                                                        country, locale, phone, isMigrated, isNotifiedForInvoice);
         Assert.assertEquals(accountJson.getAccountId(), accountId);
         Assert.assertEquals(accountJson.getName(), name);
         Assert.assertEquals(accountJson.getLength(), length);
@@ -67,21 +68,17 @@ public class TestAccountJson extends JaxrsTestSuite {
         Assert.assertEquals(accountJson.getTimeZone(), timeZone);
         Assert.assertEquals(accountJson.getAddress1(), address1);
         Assert.assertEquals(accountJson.getAddress2(), address2);
+        Assert.assertEquals(accountJson.getPostalCode(), postalCode);
         Assert.assertEquals(accountJson.getCompany(), company);
+        Assert.assertEquals(accountJson.getCity(), city);
         Assert.assertEquals(accountJson.getState(), state);
         Assert.assertEquals(accountJson.getCountry(), country);
+        Assert.assertEquals(accountJson.getLocale(), locale);
         Assert.assertEquals(accountJson.getPhone(), phone);
+        Assert.assertEquals(accountJson.isMigrated(), isMigrated);
+        Assert.assertEquals(accountJson.isNotifiedForInvoices(), isNotifiedForInvoice);
 
         final String asJson = mapper.writeValueAsString(accountJson);
-        Assert.assertEquals(asJson, "{\"accountId\":\"" + accountJson.getAccountId() + "\",\"name\":\"" + accountJson.getName() + "\"," +
-                                    "\"externalKey\":\"" + accountJson.getExternalKey() + "\",\"email\":\"" + accountJson.getEmail() + "\"," +
-                                    "\"billCycleDay\":" + accountJson.getBillCycleDay() + "," +
-                                    "\"currency\":\"" + accountJson.getCurrency() + "\",\"paymentMethodId\":\"" + accountJson.getPaymentMethodId() + "\"," +
-                                    "\"address1\":\"" + accountJson.getAddress1() + "\",\"address2\":\"" + accountJson.getAddress2() + "\"," +
-                                    "\"company\":\"" + accountJson.getCompany() + "\",\"state\":\"" + accountJson.getState() + "\"," +
-                                    "\"country\":\"" + accountJson.getCountry() + "\",\"phone\":\"" + accountJson.getPhone() + "\"," +
-                                    "\"length\":" + accountJson.getLength() + ",\"timeZone\":\"" + accountJson.getTimeZone() + "\"}");
-
         final AccountJson fromJson = mapper.readValue(asJson, AccountJson.class);
         Assert.assertEquals(fromJson, accountJson);
     }
@@ -116,13 +113,17 @@ public class TestAccountJson extends JaxrsTestSuite {
         Assert.assertEquals(accountJson.getAddress2(), account.getAddress2());
         Assert.assertEquals(accountJson.getBillCycleDay().toString(), "{\"dayOfMonthLocal\":" + bcd + ",\"dayOfMonthUTC\":" + bcd + "}");
         Assert.assertEquals(accountJson.getCountry(), account.getCountry());
+        Assert.assertEquals(accountJson.getLocale(), account.getLocale());
         Assert.assertEquals(accountJson.getCompany(), account.getCompanyName());
+        Assert.assertEquals(accountJson.getCity(), account.getCity());
         Assert.assertEquals(accountJson.getCurrency(), account.getCurrency().toString());
         Assert.assertEquals(accountJson.getEmail(), account.getEmail());
         Assert.assertEquals(accountJson.getExternalKey(), account.getExternalKey());
         Assert.assertEquals(accountJson.getName(), account.getName());
         Assert.assertEquals(accountJson.getPaymentMethodId(), account.getPaymentMethodId().toString());
         Assert.assertEquals(accountJson.getPhone(), account.getPhone());
+        Assert.assertEquals(accountJson.isMigrated(), account.isMigrated());
+        Assert.assertEquals(accountJson.isNotifiedForInvoices(), account.isNotifiedForInvoices());
         Assert.assertEquals(accountJson.getState(), account.getStateOrProvince());
         Assert.assertEquals(accountJson.getTimeZone(), account.getTimeZone().toString());
     }
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 eebdc82..9d88abb 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
@@ -73,7 +73,8 @@ public class TestAccount extends TestJaxrsBase {
         // Update Account
         final AccountJson newInput = new AccountJson(objFromJson.getAccountId(),
                                                      "zozo", 4, objFromJson.getExternalKey(), "rr@google.com", new BillCycleDayJson(18, 18),
-                                                     "USD", null, "UTC", "bl1", "bh2", "", "ca", "usa", "415-255-2991");
+                                                     "USD", null, "UTC", "bl1", "bh2", "", "", "ca", "San Francisco", "usa", "en", "415-255-2991",
+                                                     false, false);
         baseJson = mapper.writeValueAsString(newInput);
         final String uri = JaxrsResource.ACCOUNTS_PATH + "/" + objFromJson.getAccountId();
         response = doPut(uri, baseJson, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java b/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
index dca664d..b682877 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
@@ -858,13 +858,17 @@ public class TestJaxrsBase extends ServerTestSuiteWithEmbeddedDB {
         final String timeZone = "UTC";
         final String address1 = "12 rue des ecoles";
         final String address2 = "Poitier";
+        final String postalCode = "44 567";
         final String company = "Renault";
+        final String city = "Quelque part";
         final String state = "Poitou";
         final String country = "France";
+        final String locale = "fr";
         final String phone = "81 53 26 56";
 
         // Note: the accountId payload is ignored on account creation
-        return new AccountJson(accountId, name, length, externalKey, email, billCycleDay, currency, null, timeZone, address1, address2, company, state, country, phone);
+        return new AccountJson(accountId, name, length, externalKey, email, billCycleDay, currency, null, timeZone,
+                               address1, address2, postalCode, company, city, state, country, locale, phone, false, false);
     }
 
     /**