diff --git a/java/google/registry/rdap/RdapJsonFormatter.java b/java/google/registry/rdap/RdapJsonFormatter.java index 5350980db..7eec9ca60 100644 --- a/java/google/registry/rdap/RdapJsonFormatter.java +++ b/java/google/registry/rdap/RdapJsonFormatter.java @@ -543,6 +543,14 @@ public class RdapJsonFormatter { outputDataType, authorization)) .collect(toImmutableList()); + entities = + addRegistrarEntity( + entities, + domainResource.getCurrentSponsorClientId(), + linkBase, + whoisServer, + now, + outputDataType); if (!entities.isEmpty()) { jsonBuilder.put("entities", entities); } @@ -574,6 +582,38 @@ public class RdapJsonFormatter { return jsonBuilder.build(); } + /** + * Adds a JSON object for the desired registrar to an existing array of JSON objects. + * + * @param clientId the registrar client ID + * @param linkBase the URL base to be used when creating links + * @param whoisServer the fully-qualified domain name of the WHOIS server to be listed in the + * port43 field; if null, port43 is not added to the object + * @param now the as-date + * @param outputDataType whether to generate full or summary data + */ + ImmutableList> addRegistrarEntity( + ImmutableList> entities, + @Nullable String clientId, + @Nullable String linkBase, + @Nullable String whoisServer, + DateTime now, + OutputDataType outputDataType) { + if (clientId == null) { + return entities; + } + Optional registrar = Registrar.loadByClientIdCached(clientId); + if (!registrar.isPresent()) { + return entities; + } + ImmutableList.Builder> builder = new ImmutableList.Builder<>(); + builder.addAll(entities); + builder.add( + makeRdapJsonForRegistrar( + registrar.get(), false /* isTopLevel */, linkBase, whoisServer, now, outputDataType)); + return builder.build(); + } + /** * Creates a JSON object for a {@link HostResource}. * diff --git a/javatests/google/registry/rdap/RdapDomainActionTest.java b/javatests/google/registry/rdap/RdapDomainActionTest.java index ecfa9a640..f55a70799 100644 --- a/javatests/google/registry/rdap/RdapDomainActionTest.java +++ b/javatests/google/registry/rdap/RdapDomainActionTest.java @@ -298,7 +298,8 @@ public class RdapDomainActionTest { String punycodeName, String handle, String expectedOutputFile) { - return generateExpectedJson(name, punycodeName, handle, null, null, null, expectedOutputFile); + return generateExpectedJson( + name, punycodeName, handle, null, null, null, null, expectedOutputFile); } private Object generateExpectedJson( @@ -308,6 +309,7 @@ public class RdapDomainActionTest { @Nullable List contactRoids, @Nullable List nameserverRoids, @Nullable List nameserverNames, + @Nullable String registrarName, String expectedOutputFile) { ImmutableMap.Builder substitutionsBuilder = new ImmutableMap.Builder<>(); substitutionsBuilder.put("NAME", name); @@ -316,6 +318,9 @@ public class RdapDomainActionTest { substitutionsBuilder.put("TYPE", "domain name"); substitutionsBuilder.put("NAMESERVER1ADDRESS", "1.2.3.4"); substitutionsBuilder.put("NAMESERVER2ADDRESS", "bad:f00d:cafe::15:beef"); + if (registrarName != null) { + substitutionsBuilder.put("REGISTRARNAME", registrarName); + } if (contactRoids != null) { for (int i = 0; i < contactRoids.size(); i++) { substitutionsBuilder.put("CONTACT" + (i + 1) + "ROID", contactRoids.get(i)); @@ -350,9 +355,17 @@ public class RdapDomainActionTest { String handle, @Nullable List contactRoids, @Nullable List nameserverRoids, + @Nullable String registrarName, String expectedOutputFile) { return generateExpectedJsonWithTopLevelEntries( - name, punycodeName, handle, contactRoids, nameserverRoids, null, expectedOutputFile); + name, + punycodeName, + handle, + contactRoids, + nameserverRoids, + null, + registrarName, + expectedOutputFile); } private Object generateExpectedJsonWithTopLevelEntries( String name, @@ -361,6 +374,7 @@ public class RdapDomainActionTest { @Nullable List contactRoids, @Nullable List nameserverRoids, @Nullable List nameserverNames, + @Nullable String registrarName, String expectedOutputFile) { Object obj = generateExpectedJson( @@ -370,6 +384,7 @@ public class RdapDomainActionTest { contactRoids, nameserverRoids, nameserverNames, + registrarName, expectedOutputFile); if (obj instanceof Map) { @SuppressWarnings("unchecked") @@ -412,6 +427,7 @@ public class RdapDomainActionTest { ? ImmutableList.of("4-ROID", "6-ROID", "2-ROID") : null, ImmutableList.of("8-ROID", "A-ROID"), + "Yes Virginia