From d18ef9529fee74b47210a41ff761c42f9c3332d7 Mon Sep 17 00:00:00 2001 From: Pavlo Tkach <3469726+ptkach@users.noreply.github.com> Date: Wed, 10 May 2023 16:05:03 -0400 Subject: [PATCH] Expand nomulus get_domain command to load up deleted domain data too (#2018) --- .../registry/tools/GetDomainCommand.java | 28 ++++++++++++++++--- .../registry/tools/GetDomainCommandTest.java | 21 ++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/google/registry/tools/GetDomainCommand.java b/core/src/main/java/google/registry/tools/GetDomainCommand.java index 21827d708..1c63d1810 100644 --- a/core/src/main/java/google/registry/tools/GetDomainCommand.java +++ b/core/src/main/java/google/registry/tools/GetDomainCommand.java @@ -15,17 +15,23 @@ package google.registry.tools; import static google.registry.model.EppResourceUtils.loadByForeignKey; +import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import google.registry.model.domain.Domain; +import google.registry.persistence.transaction.QueryComposer.Comparator; import google.registry.util.DomainNameUtils; import java.util.List; +import java.util.Optional; /** Command to show a domain resource. */ @Parameters(separators = " =", commandDescription = "Show domain resource(s)") final class GetDomainCommand extends GetEppResourceCommand { + @Parameter(names = "--show_deleted", description = "Include deleted domains in the print out") + private boolean showDeleted = false; + @Parameter( description = "Fully qualified domain name(s)", required = true) @@ -35,10 +41,24 @@ final class GetDomainCommand extends GetEppResourceCommand { public void runAndPrint() { for (String domainName : mainParameters) { String canonicalDomain = DomainNameUtils.canonicalizeHostname(domainName); - printResource( - "Domain", - canonicalDomain, - loadByForeignKey(Domain.class, canonicalDomain, readTimestamp)); + if (showDeleted) { + tm().transact( + () -> + tm() + .createQueryComposer(Domain.class) + .where("domainName", Comparator.EQ, canonicalDomain) + .orderBy("creationTime") + .stream() + .forEach( + d -> { + printResource("Domain", canonicalDomain, Optional.of(d)); + })); + } else { + printResource( + "Domain", + canonicalDomain, + loadByForeignKey(Domain.class, canonicalDomain, readTimestamp)); + } } } } diff --git a/core/src/test/java/google/registry/tools/GetDomainCommandTest.java b/core/src/test/java/google/registry/tools/GetDomainCommandTest.java index 353c60fbd..2e729c635 100644 --- a/core/src/test/java/google/registry/tools/GetDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetDomainCommandTest.java @@ -116,4 +116,25 @@ class GetDomainCommandTest extends CommandTestCase { assertInStdout("domainName=example.tld"); assertInStdout("Domain 'example.com' does not exist or is deleted"); } + + @Test + void testSuccess_printDeletedDomain() throws Exception { + persistDeletedDomain("example.tld", fakeClock.nowUtc().minusDays(1)); + runCommand("--show_deleted", "example.tld"); + assertInStdout("domainName=example.tld"); + assertInStdout("Websafe key: kind:Domain@sql:rO0ABXQABTItVExE"); + } + + @Test + void testSuccess_printsEntireDomainHistory() throws Exception { + persistActiveDomain("example.tld"); + persistDeletedDomain("example.tld", fakeClock.nowUtc().minusDays(1)); + runCommand("--show_deleted", "example.tld"); + assertInStdout("domainName=example.tld"); + // Active + assertInStdout("Websafe key: kind:Domain@sql:rO0ABXQABTItVExE"); + // Deleted + assertInStdout("Websafe key: kind:Domain@sql:rO0ABXQABTQtVExE"); + } } +