Add metadata map to LrpToken

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135382828
This commit is contained in:
ctingue 2016-10-06 11:27:21 -07:00 committed by Ben McIlwain
parent 2cdd252919
commit 0ae5d10632
2 changed files with 25 additions and 4 deletions

View file

@ -18,13 +18,15 @@ import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.EmbedMap;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;
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.Map;
import java.util.Set;
/**
@ -52,11 +54,18 @@ public class LrpToken extends BackupGroupRoot implements Buildable {
Set<String> validTlds;
/**
* The key of the history entry for which the token was used. Given LRP is a domain application
* phase, this should always be a {@link Type#DOMAIN_APPLICATION_CREATE}.
* The key of the history entry for which the token was used.
*/
Key<HistoryEntry> redemptionHistoryEntry;
/**
* A set of key-value properties associated with the LRP token. This map can be used to store
* additional metadata about the assignee or space of domain names for which this token can be
* valid.
*/
@EmbedMap
Map<String, String> metadata;
public String getToken() {
return token;
}
@ -77,6 +86,10 @@ public class LrpToken extends BackupGroupRoot implements Buildable {
return nullToEmptyImmutableCopy(validTlds);
}
public Map<String, String> getMetadata() {
return nullToEmptyImmutableCopy(metadata);
}
@Override
public Builder asBuilder() {
return new Builder(clone(this));
@ -109,5 +122,10 @@ public class LrpToken extends BackupGroupRoot implements Buildable {
getInstance().validTlds = validTlds;
return this;
}
public Builder setMetadata(Map<String, String> metadata) {
getInstance().metadata = metadata;
return this;
}
}
}

View file

@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.model.EntityTestCase;
@ -51,6 +52,7 @@ public class LrpTokenTest extends EntityTestCase {
.setAssignee("1:1020304")
.setToken("a0b1c2d3e4f5g6")
.setValidTlds(ImmutableSet.of("tld"))
.setMetadata(ImmutableMap.of("foo", "bar"))
.build());
redeemedToken = persistResource(
new LrpToken.Builder()
@ -59,6 +61,7 @@ public class LrpTokenTest extends EntityTestCase {
.setRedemptionHistoryEntry(
Key.create(applicationCreateHistoryEntry))
.setValidTlds(ImmutableSet.of("tld"))
.setMetadata(ImmutableMap.of("bar", "foo"))
.build());
}