mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Move the AllocationToken entity to the token subpackage
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=204485366
This commit is contained in:
parent
35110927d6
commit
df5d9957f7
12 changed files with 19 additions and 19 deletions
96
java/google/registry/model/domain/token/AllocationToken.java
Normal file
96
java/google/registry/model/domain/token/AllocationToken.java
Normal file
|
@ -0,0 +1,96 @@
|
|||
// Copyright 2018 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.token;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
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.CreateAutoTimestamp;
|
||||
import google.registry.model.annotations.ReportedOn;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** When this token was created. */
|
||||
CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public Key<HistoryEntry> getRedemptionHistoryEntry() {
|
||||
return redemptionHistoryEntry;
|
||||
}
|
||||
|
||||
public boolean isRedeemed() {
|
||||
return redemptionHistoryEntry != null;
|
||||
}
|
||||
|
||||
public Optional<DateTime> getCreationTime() {
|
||||
return Optional.ofNullable(creationTime.getTimestamp());
|
||||
}
|
||||
|
||||
@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) {
|
||||
checkState(getInstance().token == null, "token can only be set once");
|
||||
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;
|
||||
}
|
||||
|
||||
public Builder setCreationTime(DateTime creationTime) {
|
||||
checkState(
|
||||
getInstance().creationTime.getTimestamp() == null, "creationTime can only be set once");
|
||||
getInstance().creationTime = CreateAutoTimestamp.create(creationTime);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue