mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Add create timestamp as field on AllocationToken entity
This definitely seems like a useful thing to have around. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=181401799
This commit is contained in:
parent
5f62947691
commit
ccbe958063
5 changed files with 56 additions and 3 deletions
|
@ -15,6 +15,7 @@
|
|||
package google.registry.model;
|
||||
|
||||
import google.registry.model.translators.CreateAutoTimestampTranslatorFactory;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
|
@ -27,11 +28,12 @@ public class CreateAutoTimestamp extends ImmutableObject {
|
|||
DateTime timestamp;
|
||||
|
||||
/** Returns the timestamp. */
|
||||
@Nullable
|
||||
public DateTime getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public static CreateAutoTimestamp create(DateTime timestamp) {
|
||||
public static CreateAutoTimestamp create(@Nullable DateTime timestamp) {
|
||||
CreateAutoTimestamp instance = new CreateAutoTimestamp();
|
||||
instance.timestamp = timestamp;
|
||||
return instance;
|
||||
|
|
|
@ -202,7 +202,8 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
|
|||
* normal EPP flows.
|
||||
*/
|
||||
public B setCreationTime(DateTime creationTime) {
|
||||
checkState(getInstance().creationTime.timestamp == null,
|
||||
checkState(
|
||||
getInstance().creationTime.getTimestamp() == null,
|
||||
"creationTime can only be set once for EppResource.");
|
||||
getInstance().creationTime = CreateAutoTimestamp.create(creationTime);
|
||||
return thisCastToDerived();
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.model.domain;
|
||||
|
||||
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;
|
||||
|
@ -22,8 +23,11 @@ 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
|
||||
|
@ -36,6 +40,9 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
|
|||
/** 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;
|
||||
}
|
||||
|
@ -48,6 +55,10 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
|
|||
return redemptionHistoryEntry != null;
|
||||
}
|
||||
|
||||
public Optional<DateTime> getCreationTime() {
|
||||
return Optional.ofNullable(creationTime.getTimestamp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder asBuilder() {
|
||||
return new Builder(clone(this));
|
||||
|
@ -73,5 +84,12 @@ public class AllocationToken extends BackupGroupRoot implements Buildable {
|
|||
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