Make LINKED into a virtual status value

* Remove LINKED when loading an EppResource
* Enforce that you can't add it to a resource
* Ignore LINKED on xjc import of contacts and hosts

After running ResaveAllEppResourcesAction we will no
longer have persisted LINKED statuses in datastore.

In the process of writing this I discovered that RDAP
treats LINKED like any other status value and returns
the persisted value rather than the derived one. Since
this is an existing bug and is orthogonal to the changes
in this CL, I am addressing it in a separate CL.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=145585227
This commit is contained in:
cgoldfeder 2017-01-25 12:59:26 -08:00 committed by Ben McIlwain
parent 4a730e0c9e
commit 0b1781b110
10 changed files with 68 additions and 73 deletions

View file

@ -14,10 +14,12 @@
package google.registry.model;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.union;
import static google.registry.util.CollectionUtils.difference;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
@ -28,6 +30,7 @@ import com.google.common.collect.ImmutableSortedMap;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;
import com.googlecode.objectify.annotation.OnLoad;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.ofy.CommitLogManifest;
import google.registry.model.transfer.TransferData;
@ -240,6 +243,9 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
/** Set this resource's status values. */
public B setStatusValues(ImmutableSet<StatusValue> statusValues) {
checkArgument(
!nullToEmpty(statusValues).contains(StatusValue.LINKED),
"LINKED is a virtual status value that should never be set on an EppResource");
getInstance().status = statusValues;
return thisCastToDerived();
}
@ -275,10 +281,9 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
/** Build the resource, nullifying empty strings and sets and setting defaults. */
@Override
public T build() {
// An EPP object has an implicit status of OK if no pending operations or prohibitions exist
// (i.e. no other status value besides LINKED is present).
// An EPP object has an implicit status of OK if no pending operations or prohibitions exist.
removeStatusValue(StatusValue.OK);
if (difference(getInstance().getStatusValues(), StatusValue.LINKED).isEmpty()) {
if (getInstance().getStatusValues().isEmpty()) {
addStatusValue(StatusValue.OK);
}
// If there is no deletion time, set it to END_OF_TIME.
@ -286,4 +291,12 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
return ImmutableObject.cloneEmptyToNull(super.build());
}
}
// TODO(b/34664935): remove this once LINKED has been removed from all persisted resources.
@OnLoad
void onLoadRemoveLinked() {
if (status != null) {
status = difference(status, StatusValue.LINKED);
}
}
}

View file

@ -44,7 +44,16 @@ public enum StatusValue implements EppEnum {
CLIENT_TRANSFER_PROHIBITED,
CLIENT_UPDATE_PROHIBITED,
INACTIVE,
/**
* A status that means a resource has an incoming reference from an active domain.
*
* <p>LINKED is a "virtual" status value that should never be persisted to Datastore on any
* resource. It must be computed on the fly when we need it, as the set of domains using a
* resource can change at any time.
*/
LINKED,
OK,
PENDING_CREATE,
PENDING_DELETE,