Add basic AllocationToken entity and tests

Logic actually using this entity to follow in subsequent CLs introducing
the command to generate/save these entities as well as the flow logic for
considering them during domain EPP operations.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181342600
This commit is contained in:
mcilwain 2018-01-09 10:56:27 -08:00 committed by Ben McIlwain
parent d2d7fdeb90
commit f6f43badd4
6 changed files with 130 additions and 0 deletions

View file

@ -23,6 +23,7 @@ import google.registry.model.common.Cursor;
import google.registry.model.common.EntityGroupRoot;
import google.registry.model.common.GaeUserIdConverter;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.AllocationToken;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainResource;
@ -62,6 +63,7 @@ public final class EntityClasses {
@SuppressWarnings("unchecked") // varargs
public static final ImmutableSet<Class<? extends ImmutableObject>> ALL_CLASSES =
ImmutableSet.of(
AllocationToken.class,
BillingEvent.Cancellation.class,
BillingEvent.Modification.class,
BillingEvent.OneTime.class,

View file

@ -0,0 +1,77 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.model.domain;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import google.registry.model.BackupGroupRoot;
import google.registry.model.Buildable;
import google.registry.model.annotations.ReportedOn;
import google.registry.model.reporting.HistoryEntry;
/** An entity representing an allocation token. */
@ReportedOn
@Entity
public class AllocationToken extends BackupGroupRoot implements Buildable {
/** The allocation token string. */
@Id String token;
/** The key of the history entry for which the token was used. Null if not yet used. */
Key<HistoryEntry> redemptionHistoryEntry;
public String getToken() {
return token;
}
public Key<HistoryEntry> getRedemptionHistoryEntry() {
return redemptionHistoryEntry;
}
public boolean isRedeemed() {
return redemptionHistoryEntry != null;
}
@Override
public Builder asBuilder() {
return new Builder(clone(this));
}
/** A builder for constructing {@link AllocationToken} objects, since they are immutable. */
public static class Builder extends Buildable.Builder<AllocationToken> {
public Builder() {}
private Builder(AllocationToken instance) {
super(instance);
}
public Builder setToken(String token) {
checkArgumentNotNull(token, "token must not be null");
checkArgument(!token.isEmpty(), "token must not be blank");
getInstance().token = token;
return this;
}
public Builder setRedemptionHistoryEntry(Key<HistoryEntry> redemptionHistoryEntry) {
getInstance().redemptionHistoryEntry =
checkArgumentNotNull(redemptionHistoryEntry, "redemptionHistoryEntry must not be null");
return this;
}
}
}