diff --git a/java/google/registry/export/sheet/SyncRegistrarsSheet.java b/java/google/registry/export/sheet/SyncRegistrarsSheet.java index f6e8eb4f7..3f1fedd99 100644 --- a/java/google/registry/export/sheet/SyncRegistrarsSheet.java +++ b/java/google/registry/export/sheet/SyncRegistrarsSheet.java @@ -78,8 +78,7 @@ class SyncRegistrarsSheet { final DateTime executionTime = clock.nowUtc(); sheetSynchronizer.synchronize( spreadsheetId, - FluentIterable - .from( + FluentIterable.from( new Ordering() { @Override public int compare(Registrar left, Registrar right) { @@ -128,6 +127,7 @@ class SyncRegistrarsSheet { builder.put("state", convert(registrar.getState())); builder.put("ianaIdentifier", convert(registrar.getIanaIdentifier())); builder.put("billingIdentifier", convert(registrar.getBillingIdentifier())); + builder.put("billingAccountMap", convert(registrar.getBillingAccountMap())); builder.put("primaryContacts", convertContacts(contacts, byType(ADMIN))); builder.put("techContacts", convertContacts(contacts, byType(TECH))); builder.put("marketingContacts", convertContacts(contacts, byType(MARKETING))); diff --git a/java/google/registry/export/sheet/SyncRegistrarsSheetAction.java b/java/google/registry/export/sheet/SyncRegistrarsSheetAction.java index adbf43e5d..c0da8e083 100644 --- a/java/google/registry/export/sheet/SyncRegistrarsSheetAction.java +++ b/java/google/registry/export/sheet/SyncRegistrarsSheetAction.java @@ -81,7 +81,7 @@ public class SyncRegistrarsSheetAction implements Runnable { private final int statusCode; protected final String message; - private Result(int statusCode, String message) { + Result(int statusCode, String message) { this.statusCode = statusCode; this.message = message; } diff --git a/java/google/registry/model/registrar/Registrar.java b/java/google/registry/model/registrar/Registrar.java index 7dc4f3677..e1b8aff44 100644 --- a/java/google/registry/model/registrar/Registrar.java +++ b/java/google/registry/model/registrar/Registrar.java @@ -43,7 +43,9 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Ordering; import com.google.common.collect.Range; import com.google.common.collect.Sets; import com.google.re2j.Pattern; @@ -336,7 +338,9 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable * Map of currency-to-billing account for the registrar. * *

A registrar can have different billing accounts that are denoted in different currencies. - * This provides flexibility for billing systems that require such distinction. + * This provides flexibility for billing systems that require such distinction. When this field is + * accessed by {@link #getBillingAccountMap}, a sorted map is returned to guarantee deterministic + * behavior when serializing the map, for display purpose for instance. */ @Nullable @Mapify(CurrencyMapper.class) @@ -448,8 +452,8 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable if (billingAccountMap == null) { return ImmutableMap.of(); } - ImmutableMap.Builder billingAccountMapBuilder = - new ImmutableMap.Builder<>(); + ImmutableSortedMap.Builder billingAccountMapBuilder = + new ImmutableSortedMap.Builder<>(Ordering.natural()); for (Map.Entry entry : billingAccountMap.entrySet()) { billingAccountMapBuilder.put(entry.getKey(), entry.getValue().accountId); } diff --git a/javatests/google/registry/export/sheet/BUILD b/javatests/google/registry/export/sheet/BUILD index c060cdfac..5c42cc68c 100644 --- a/javatests/google/registry/export/sheet/BUILD +++ b/javatests/google/registry/export/sheet/BUILD @@ -22,6 +22,7 @@ java_library( "@javax_servlet_api", "@joda_time", "@junit", + "@org_joda_money", "@org_mockito_all", ], ) diff --git a/javatests/google/registry/export/sheet/SyncRegistrarsSheetTest.java b/javatests/google/registry/export/sheet/SyncRegistrarsSheetTest.java index 1b9a8b089..9c12f66b1 100644 --- a/javatests/google/registry/export/sheet/SyncRegistrarsSheetTest.java +++ b/javatests/google/registry/export/sheet/SyncRegistrarsSheetTest.java @@ -25,6 +25,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.persistNewRegistrar; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistSimpleResources; +import static org.joda.money.CurrencyUnit.JPY; +import static org.joda.money.CurrencyUnit.USD; import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.Duration.standardMinutes; import static org.mockito.Matchers.eq; @@ -135,25 +137,29 @@ public class SyncRegistrarsSheetTest { .setIcannReferralEmail("jim@example.net") .build()); - Registrar registrar = new Registrar.Builder() - .setClientId("aaaregistrar") - .setRegistrarName("AAA Registrar Inc.") - .setType(Registrar.Type.REAL) - .setIanaIdentifier(8L) - .setState(Registrar.State.SUSPENDED) - .setPassword("pa$$word") - .setEmailAddress("nowhere@example.org") - .setInternationalizedAddress(new RegistrarAddress.Builder() - .setStreet(ImmutableList.of("I get fallen back upon since there's no l10n addr")) - .setCity("Williamsburg") - .setState("NY") - .setZip("11211") - .setCountryCode("US") - .build()) - .setAllowedTlds(ImmutableSet.of("example")) - .setPhoneNumber("+1.2223334444") - .setUrl("http://www.example.org/aaa_registrar") - .build(); + Registrar registrar = + new Registrar.Builder() + .setClientId("aaaregistrar") + .setRegistrarName("AAA Registrar Inc.") + .setType(Registrar.Type.REAL) + .setIanaIdentifier(8L) + .setState(Registrar.State.SUSPENDED) + .setPassword("pa$$word") + .setEmailAddress("nowhere@example.org") + .setInternationalizedAddress( + new RegistrarAddress.Builder() + .setStreet( + ImmutableList.of("I get fallen back upon since there's no l10n addr")) + .setCity("Williamsburg") + .setState("NY") + .setZip("11211") + .setCountryCode("US") + .build()) + .setAllowedTlds(ImmutableSet.of("example")) + .setPhoneNumber("+1.2223334444") + .setUrl("http://www.example.org/aaa_registrar") + .setBillingAccountMap(ImmutableMap.of(USD, "USD1234", JPY, "JPY7890")) + .build(); ImmutableList contacts = ImmutableList.of( new RegistrarContact.Builder() .setParent(registrar) @@ -281,6 +287,7 @@ public class SyncRegistrarsSheetTest { assertThat(row).containsEntry("icannReferralEmail", ""); assertThat(row).containsEntry("whoisServer", getDefaultRegistrarWhoisServer()); assertThat(row).containsEntry("referralUrl", getDefaultRegistrarReferralUrl()); + assertThat(row).containsEntry("billingAccountMap", "{JPY=JPY7890, USD=USD1234}"); row = rows.get(1); assertThat(row).containsEntry("clientIdentifier", "anotherregistrar"); @@ -314,6 +321,7 @@ public class SyncRegistrarsSheetTest { assertThat(row).containsEntry("url", "http://www.example.org/another_registrar"); assertThat(row).containsEntry("referralUrl", getDefaultRegistrarReferralUrl()); assertThat(row).containsEntry("icannReferralEmail", "jim@example.net"); + assertThat(row).containsEntry("billingAccountMap", "{}"); Cursor cursor = ofy().load().key(Cursor.createGlobalKey(SYNC_REGISTRAR_SHEET)).now(); assertThat(cursor).isNotNull(); @@ -357,5 +365,6 @@ public class SyncRegistrarsSheetTest { assertThat(row).containsEntry("url", ""); assertThat(row).containsEntry("referralUrl", getDefaultRegistrarReferralUrl()); assertThat(row).containsEntry("icannReferralEmail", ""); + assertThat(row).containsEntry("billingAccountMap", "{}"); } }