diff --git a/java/google/registry/model/domain/LrpToken.java b/java/google/registry/model/domain/LrpToken.java index 89218c40f..7f6e0f9b2 100644 --- a/java/google/registry/model/domain/LrpToken.java +++ b/java/google/registry/model/domain/LrpToken.java @@ -25,7 +25,6 @@ import google.registry.model.BackupGroupRoot; import google.registry.model.Buildable; import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry.Type; - import java.util.Set; /** @@ -34,18 +33,19 @@ import java.util.Set; @Entity public class LrpToken extends BackupGroupRoot implements Buildable { - /** - * The token's assignee (a unique identifier). - */ - @Id - String assignee; - /** * The secret token assigned to a registrant for the purposes of LRP registration. */ - @Index + @Id String token; + /** + * The token's assignee (additional metadata for identifying the owner of the token, which may + * vary from TLD to TLD). + */ + @Index + String assignee; + /** * A list of TLDs for which this LRP token is valid. */ @@ -89,7 +89,7 @@ public class LrpToken extends BackupGroupRoot implements Buildable { private Builder(LrpToken instance) { super(instance); } - + public Builder setAssignee(String assignee) { getInstance().assignee = assignee; return this; diff --git a/java/google/registry/tools/GetLrpTokenCommand.java b/java/google/registry/tools/GetLrpTokenCommand.java index 2c8ef1177..4e8037f28 100644 --- a/java/google/registry/tools/GetLrpTokenCommand.java +++ b/java/google/registry/tools/GetLrpTokenCommand.java @@ -19,6 +19,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; import google.registry.model.domain.LrpToken; import google.registry.tools.Command.GtechCommand; @@ -51,22 +52,25 @@ public final class GetLrpTokenCommand implements RemoteApiCommand, GtechCommand checkArgument( (tokenString == null) == (assignee != null), "Exactly one of either token or assignee must be specified."); - LrpToken token = null; - if (assignee != null) { - token = ofy().load().key(Key.create(LrpToken.class, assignee)).now(); - } else if (tokenString != null) { - token = ofy().load() - .type(LrpToken.class) - .filter("token", tokenString) - .first() - .now(); - } - if (token != null) { - System.out.println(token); - if (includeHistory && token.getRedemptionHistoryEntry() != null) { - System.out.println( - ofy().load().key(token.getRedemptionHistoryEntry()).now().toHydratedString()); + ImmutableSet.Builder tokensBuilder = ImmutableSet.builder(); + if (tokenString != null) { + LrpToken token = ofy().load().key(Key.create(LrpToken.class, tokenString)).now(); + if (token != null) { + tokensBuilder.add(token); } + } else { + tokensBuilder.addAll(ofy().load().type(LrpToken.class).filter("assignee", assignee)); + } + + ImmutableSet tokens = tokensBuilder.build(); + if (!tokens.isEmpty()) { + for (LrpToken token : tokens) { + System.out.println(token); + if (includeHistory && token.getRedemptionHistoryEntry() != null) { + System.out.println( + ofy().load().key(token.getRedemptionHistoryEntry()).now().toHydratedString()); + } + } } else { System.out.println("Token not found."); } diff --git a/javatests/google/registry/model/schema.txt b/javatests/google/registry/model/schema.txt index 7953f01f5..ffc39ec02 100644 --- a/javatests/google/registry/model/schema.txt +++ b/javatests/google/registry/model/schema.txt @@ -285,10 +285,10 @@ class google.registry.model.domain.GracePeriod { org.joda.time.DateTime expirationTime; } class google.registry.model.domain.LrpToken { - @Id java.lang.String assignee; + @Id java.lang.String token; com.googlecode.objectify.Key redemptionHistoryEntry; google.registry.model.UpdateAutoTimestamp updateTimestamp; - java.lang.String token; + java.lang.String assignee; java.util.Set validTlds; } class google.registry.model.domain.Period {