mirror of
https://github.com/google/nomulus.git
synced 2025-04-29 19:47:51 +02:00
Expand nomulus get_domain command to load up deleted domain data too (#2018)
This commit is contained in:
parent
a90ef39a40
commit
d18ef9529f
2 changed files with 45 additions and 4 deletions
|
@ -15,17 +15,23 @@
|
||||||
package google.registry.tools;
|
package google.registry.tools;
|
||||||
|
|
||||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||||
|
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||||
|
|
||||||
import com.beust.jcommander.Parameter;
|
import com.beust.jcommander.Parameter;
|
||||||
import com.beust.jcommander.Parameters;
|
import com.beust.jcommander.Parameters;
|
||||||
import google.registry.model.domain.Domain;
|
import google.registry.model.domain.Domain;
|
||||||
|
import google.registry.persistence.transaction.QueryComposer.Comparator;
|
||||||
import google.registry.util.DomainNameUtils;
|
import google.registry.util.DomainNameUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/** Command to show a domain resource. */
|
/** Command to show a domain resource. */
|
||||||
@Parameters(separators = " =", commandDescription = "Show domain resource(s)")
|
@Parameters(separators = " =", commandDescription = "Show domain resource(s)")
|
||||||
final class GetDomainCommand extends GetEppResourceCommand {
|
final class GetDomainCommand extends GetEppResourceCommand {
|
||||||
|
|
||||||
|
@Parameter(names = "--show_deleted", description = "Include deleted domains in the print out")
|
||||||
|
private boolean showDeleted = false;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "Fully qualified domain name(s)",
|
description = "Fully qualified domain name(s)",
|
||||||
required = true)
|
required = true)
|
||||||
|
@ -35,10 +41,24 @@ final class GetDomainCommand extends GetEppResourceCommand {
|
||||||
public void runAndPrint() {
|
public void runAndPrint() {
|
||||||
for (String domainName : mainParameters) {
|
for (String domainName : mainParameters) {
|
||||||
String canonicalDomain = DomainNameUtils.canonicalizeHostname(domainName);
|
String canonicalDomain = DomainNameUtils.canonicalizeHostname(domainName);
|
||||||
printResource(
|
if (showDeleted) {
|
||||||
"Domain",
|
tm().transact(
|
||||||
canonicalDomain,
|
() ->
|
||||||
loadByForeignKey(Domain.class, canonicalDomain, readTimestamp));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,4 +116,25 @@ class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
|
||||||
assertInStdout("domainName=example.tld");
|
assertInStdout("domainName=example.tld");
|
||||||
assertInStdout("Domain 'example.com' does not exist or is deleted");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue