mirror of
https://github.com/google/nomulus.git
synced 2025-05-28 15:11:26 +02:00
Scope down TransferData to only ContactResource and DomainResource
HostResource and DomainApplication are not transferable, (or at least, not directly in the case of hosts) and have no need for the TransferData field. In a flat-flow world, we can push it down to where it's actually used. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=139201423
This commit is contained in:
parent
0234795240
commit
84009eaccb
24 changed files with 309 additions and 240 deletions
|
@ -117,10 +117,6 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable,
|
|||
/** Status values associated with this resource. */
|
||||
Set<StatusValue> status;
|
||||
|
||||
/** Data about any pending or past transfers on this contact. */
|
||||
@XmlTransient
|
||||
TransferData transferData;
|
||||
|
||||
/**
|
||||
* Sorted map of {@link DateTime} keys (modified time) to {@link CommitLogManifest} entries.
|
||||
*
|
||||
|
@ -161,15 +157,6 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable,
|
|||
return nullToEmptyImmutableCopy(status);
|
||||
}
|
||||
|
||||
public final TransferData getTransferData() {
|
||||
return Optional.fromNullable(transferData).or(TransferData.EMPTY);
|
||||
}
|
||||
|
||||
/** Returns whether there is any transferData. */
|
||||
public final boolean hasTransferData() {
|
||||
return transferData != null;
|
||||
}
|
||||
|
||||
@XmlElement(name = "trDate")
|
||||
public DateTime getLastTransferTime() {
|
||||
return lastTransferTime;
|
||||
|
@ -196,6 +183,16 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable,
|
|||
/** EppResources that are loaded via foreign keys should implement this marker interface. */
|
||||
public interface ForeignKeyedEppResource {}
|
||||
|
||||
/** An interface for resources that have transfer data. */
|
||||
public interface ResourceWithTransferData {
|
||||
public TransferData getTransferData();
|
||||
}
|
||||
|
||||
/** An interface for builders of resources that have transfer data. */
|
||||
public interface BuilderWithTransferData<B extends BuilderWithTransferData<B>> {
|
||||
public B setTransferData(TransferData transferData);
|
||||
}
|
||||
|
||||
/** Abstract builder for {@link EppResource} types. */
|
||||
public abstract static class Builder<T extends EppResource, B extends Builder<?, ?>>
|
||||
extends GenericBuilder<T, B> {
|
||||
|
@ -292,23 +289,12 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable,
|
|||
difference(getInstance().getStatusValues(), statusValues)));
|
||||
}
|
||||
|
||||
/** Set this resource's transfer data. */
|
||||
public B setTransferData(TransferData transferData) {
|
||||
getInstance().transferData = transferData;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
/** Set this resource's repoId. */
|
||||
public B setRepoId(String repoId) {
|
||||
getInstance().repoId = repoId;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
/** Wipe out any personal information in the resource. */
|
||||
public B wipeOut() {
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
/** Build the resource, nullifying empty strings and sets and setting defaults. */
|
||||
@Override
|
||||
public T build() {
|
||||
|
@ -323,10 +309,6 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable,
|
|||
|
||||
/** Build the resource, nullifying empty strings and sets and setting defaults. */
|
||||
public T buildWithoutImplicitStatusValues() {
|
||||
// If TransferData is totally empty, set it to null.
|
||||
if (TransferData.EMPTY.equals(getInstance().transferData)) {
|
||||
setTransferData(null);
|
||||
}
|
||||
// If there is no deletion time, set it to END_OF_TIME.
|
||||
setDeletionTime(Optional.fromNullable(getInstance().deletionTime).or(END_OF_TIME));
|
||||
return ImmutableObject.cloneEmptyToNull(super.build());
|
||||
|
|
|
@ -29,7 +29,9 @@ import com.googlecode.objectify.Result;
|
|||
import com.googlecode.objectify.util.ResultNow;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.model.EppResource.Builder;
|
||||
import google.registry.model.EppResource.BuilderWithTransferData;
|
||||
import google.registry.model.EppResource.ForeignKeyedEppResource;
|
||||
import google.registry.model.EppResource.ResourceWithTransferData;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.domain.DomainApplication;
|
||||
import google.registry.model.domain.DomainBase;
|
||||
|
@ -201,8 +203,8 @@ public final class EppResourceUtils {
|
|||
}
|
||||
|
||||
/** Process an automatic transfer on a resource. */
|
||||
public static void setAutomaticTransferSuccessProperties(
|
||||
Builder<?, ?> builder, TransferData transferData) {
|
||||
public static <B extends Builder<?, B> & BuilderWithTransferData<B>>
|
||||
void setAutomaticTransferSuccessProperties(B builder, TransferData transferData) {
|
||||
checkArgument(TransferStatus.PENDING.equals(transferData.getTransferStatus()));
|
||||
builder.removeStatusValue(StatusValue.PENDING_TRANSFER)
|
||||
.setTransferData(transferData.asBuilder()
|
||||
|
@ -222,8 +224,10 @@ public final class EppResourceUtils {
|
|||
* <li>Process an automatic transfer.
|
||||
* </ul>
|
||||
*/
|
||||
public static <T extends EppResource> void projectResourceOntoBuilderAtTime(
|
||||
T resource, Builder<?, ?> builder, DateTime now) {
|
||||
public static <
|
||||
T extends EppResource & ResourceWithTransferData,
|
||||
B extends Builder<?, B> & BuilderWithTransferData<B>>
|
||||
void projectResourceOntoBuilderAtTime(T resource, B builder, DateTime now) {
|
||||
TransferData transferData = resource.getTransferData();
|
||||
// If there's a pending transfer that has expired, process it.
|
||||
DateTime expirationTime = transferData.getPendingTransferExpirationTime();
|
||||
|
|
|
@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||
import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
|
||||
import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Lists;
|
||||
|
@ -28,8 +29,10 @@ import com.googlecode.objectify.annotation.Index;
|
|||
import com.googlecode.objectify.condition.IfNull;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.EppResource.ForeignKeyedEppResource;
|
||||
import google.registry.model.EppResource.ResourceWithTransferData;
|
||||
import google.registry.model.annotations.ExternalMessagingName;
|
||||
import google.registry.model.contact.PostalInfo.Type;
|
||||
import google.registry.model.transfer.TransferData;
|
||||
import java.util.List;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
@ -64,7 +67,8 @@ import org.joda.time.DateTime;
|
|||
@Cache(expirationSeconds = RECOMMENDED_MEMCACHE_EXPIRATION)
|
||||
@Entity
|
||||
@ExternalMessagingName("contact")
|
||||
public class ContactResource extends EppResource implements ForeignKeyedEppResource {
|
||||
public class ContactResource extends EppResource
|
||||
implements ForeignKeyedEppResource, ResourceWithTransferData {
|
||||
|
||||
/**
|
||||
* Unique identifier for this contact.
|
||||
|
@ -78,13 +82,16 @@ public class ContactResource extends EppResource implements ForeignKeyedEppResou
|
|||
|
||||
/**
|
||||
* Localized postal info for the contact. All contained values must be representable in the 7-bit
|
||||
* US-ASCII character set. Personal info; cleared by wipeOut().
|
||||
* US-ASCII character set. Personal info; cleared by {@link Builder#wipeOut}.
|
||||
*/
|
||||
@IgnoreSave(IfNull.class)
|
||||
@XmlTransient
|
||||
PostalInfo localizedPostalInfo;
|
||||
|
||||
/** Internationalized postal info for the contact. Personal info; cleared by wipeOut(). */
|
||||
/**
|
||||
* Internationalized postal info for the contact. Personal info; cleared by
|
||||
* {@link Builder#wipeOut}.
|
||||
*/
|
||||
@IgnoreSave(IfNull.class)
|
||||
@XmlTransient
|
||||
PostalInfo internationalizedPostalInfo;
|
||||
|
@ -92,21 +99,21 @@ public class ContactResource extends EppResource implements ForeignKeyedEppResou
|
|||
/**
|
||||
* Contact name used for name searches. This is set automatically to be the internationalized
|
||||
* postal name, or if null, the localized postal name, or if that is null as well, null. Personal
|
||||
* info; cleared by wipeOut().
|
||||
* info; cleared by {@link Builder#wipeOut}.
|
||||
*/
|
||||
@Index
|
||||
@XmlTransient
|
||||
String searchName;
|
||||
|
||||
/** Contact’s voice number. Personal info; cleared by wipeOut(). */
|
||||
/** Contact’s voice number. Personal info; cleared by {@link Builder#wipeOut}. */
|
||||
@IgnoreSave(IfNull.class)
|
||||
ContactPhoneNumber voice;
|
||||
|
||||
/** Contact’s fax number. Personal info; cleared by wipeOut(). */
|
||||
/** Contact’s fax number. Personal info; cleared by {@link Builder#wipeOut}. */
|
||||
@IgnoreSave(IfNull.class)
|
||||
ContactPhoneNumber fax;
|
||||
|
||||
/** Contact’s email address. Personal info; cleared by wipeOut(). */
|
||||
/** Contact’s email address. Personal info; cleared by {@link Builder#wipeOut}. */
|
||||
@IgnoreSave(IfNull.class)
|
||||
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
|
||||
String email;
|
||||
|
@ -114,6 +121,10 @@ public class ContactResource extends EppResource implements ForeignKeyedEppResou
|
|||
/** Authorization info (aka transfer secret) of the contact. */
|
||||
ContactAuthInfo authInfo;
|
||||
|
||||
/** Data about any pending or past transfers on this contact. */
|
||||
@XmlTransient
|
||||
TransferData transferData;
|
||||
|
||||
// If any new fields are added which contain personal information, make sure they are cleared by
|
||||
// the wipeOut() function, so that data is not kept around for deleted contacts.
|
||||
|
||||
|
@ -154,6 +165,11 @@ public class ContactResource extends EppResource implements ForeignKeyedEppResou
|
|||
return disclose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TransferData getTransferData() {
|
||||
return Optional.fromNullable(transferData).or(TransferData.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForeignKey() {
|
||||
return contactId;
|
||||
|
@ -188,7 +204,9 @@ public class ContactResource extends EppResource implements ForeignKeyedEppResou
|
|||
}
|
||||
|
||||
/** A builder for constructing {@link ContactResource}, since it is immutable. */
|
||||
public static class Builder extends EppResource.Builder<ContactResource, Builder> {
|
||||
public static class Builder extends EppResource.Builder<ContactResource, Builder>
|
||||
implements BuilderWithTransferData<Builder>{
|
||||
|
||||
public Builder() {}
|
||||
|
||||
private Builder(ContactResource instance) {
|
||||
|
@ -252,26 +270,42 @@ public class ContactResource extends EppResource implements ForeignKeyedEppResou
|
|||
}
|
||||
|
||||
@Override
|
||||
public Builder setTransferData(TransferData transferData) {
|
||||
getInstance().transferData = transferData;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all personally identifying information about a contact.
|
||||
*
|
||||
* <p>This should be used when deleting a contact so that the soft-deleted entity doesn't
|
||||
* contain information that the registrant requested to be deleted.
|
||||
*/
|
||||
public Builder wipeOut() {
|
||||
this.setEmailAddress(null);
|
||||
this.setFaxNumber(null);
|
||||
this.setInternationalizedPostalInfo(null);
|
||||
this.setLocalizedPostalInfo(null);
|
||||
this.setVoiceNumber(null);
|
||||
return super.wipeOut();
|
||||
setEmailAddress(null);
|
||||
setFaxNumber(null);
|
||||
setInternationalizedPostalInfo(null);
|
||||
setLocalizedPostalInfo(null);
|
||||
setVoiceNumber(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContactResource build() {
|
||||
ContactResource instance = getInstance();
|
||||
// If TransferData is totally empty, set it to null.
|
||||
if (TransferData.EMPTY.equals(instance.transferData)) {
|
||||
setTransferData(null);
|
||||
}
|
||||
// Set the searchName using the internationalized and localized postal info names.
|
||||
if ((getInstance().internationalizedPostalInfo != null)
|
||||
&& (getInstance().internationalizedPostalInfo.getName() != null)) {
|
||||
getInstance().searchName = getInstance().internationalizedPostalInfo.getName();
|
||||
} else if ((getInstance().localizedPostalInfo != null)
|
||||
&& (getInstance().localizedPostalInfo.getName() != null)) {
|
||||
getInstance().searchName = getInstance().localizedPostalInfo.getName();
|
||||
if ((instance.internationalizedPostalInfo != null)
|
||||
&& (instance.internationalizedPostalInfo.getName() != null)) {
|
||||
instance.searchName = instance.internationalizedPostalInfo.getName();
|
||||
} else if ((instance.localizedPostalInfo != null)
|
||||
&& (instance.localizedPostalInfo.getName() != null)) {
|
||||
instance.searchName = instance.localizedPostalInfo.getName();
|
||||
} else {
|
||||
getInstance().searchName = null;
|
||||
instance.searchName = null;
|
||||
}
|
||||
return super.build();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.domain;
|
||||
package google.registry.model.domain;
|
||||
|
||||
import static com.google.common.collect.Sets.intersection;
|
||||
import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
|
||||
|
@ -33,6 +33,7 @@ import com.googlecode.objectify.annotation.EntitySubclass;
|
|||
import com.googlecode.objectify.annotation.IgnoreSave;
|
||||
import com.googlecode.objectify.condition.IfNull;
|
||||
import google.registry.model.EppResource.ForeignKeyedEppResource;
|
||||
import google.registry.model.EppResource.ResourceWithTransferData;
|
||||
import google.registry.model.annotations.ExternalMessagingName;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
|
@ -75,7 +76,8 @@ import org.joda.time.Interval;
|
|||
@Cache(expirationSeconds = RECOMMENDED_MEMCACHE_EXPIRATION)
|
||||
@EntitySubclass(index = true)
|
||||
@ExternalMessagingName("domain")
|
||||
public class DomainResource extends DomainBase implements ForeignKeyedEppResource {
|
||||
public class DomainResource extends DomainBase
|
||||
implements ForeignKeyedEppResource, ResourceWithTransferData {
|
||||
|
||||
/** The max number of years that a domain can be registered for, as set by ICANN policy. */
|
||||
public static final int MAX_REGISTRATION_YEARS = 10;
|
||||
|
@ -156,6 +158,10 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc
|
|||
@XmlTransient
|
||||
Key<DomainApplication> application;
|
||||
|
||||
/** Data about any pending or past transfers on this domain. */
|
||||
@XmlTransient
|
||||
TransferData transferData;
|
||||
|
||||
public ImmutableSet<String> getSubordinateHosts() {
|
||||
return nullToEmptyImmutableCopy(subordinateHosts);
|
||||
}
|
||||
|
@ -192,6 +198,11 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc
|
|||
return application;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TransferData getTransferData() {
|
||||
return Optional.fromNullable(transferData).or(TransferData.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForeignKey() {
|
||||
return fullyQualifiedDomainName;
|
||||
|
@ -356,7 +367,8 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc
|
|||
}
|
||||
|
||||
/** A builder for constructing {@link DomainResource}, since it is immutable. */
|
||||
public static class Builder extends DomainBase.Builder<DomainResource, Builder> {
|
||||
public static class Builder extends DomainBase.Builder<DomainResource, Builder>
|
||||
implements BuilderWithTransferData<Builder> {
|
||||
|
||||
public Builder() {}
|
||||
|
||||
|
@ -366,6 +378,10 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc
|
|||
|
||||
@Override
|
||||
public DomainResource build() {
|
||||
// If TransferData is totally empty, set it to null.
|
||||
if (TransferData.EMPTY.equals(getInstance().transferData)) {
|
||||
setTransferData(null);
|
||||
}
|
||||
// A DomainResource has status INACTIVE if there are no nameservers.
|
||||
if (getInstance().getNameservers().isEmpty()) {
|
||||
addStatusValue(StatusValue.INACTIVE);
|
||||
|
@ -440,5 +456,11 @@ public class DomainResource extends DomainBase implements ForeignKeyedEppResourc
|
|||
getInstance().gracePeriods = difference(getInstance().getGracePeriods(), gracePeriod);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setTransferData(TransferData transferData) {
|
||||
getInstance().transferData = transferData;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package google.registry.model.host;
|
|||
|
||||
import static com.google.common.collect.Sets.difference;
|
||||
import static com.google.common.collect.Sets.union;
|
||||
import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
|
||||
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
||||
|
@ -126,15 +125,14 @@ public class HostResource extends EppResource implements ForeignKeyedEppResource
|
|||
@Override
|
||||
public HostResource cloneProjectedAtTime(DateTime now) {
|
||||
Builder builder = this.asBuilder();
|
||||
projectResourceOntoBuilderAtTime(this, builder, now);
|
||||
|
||||
if (superordinateDomain == null) {
|
||||
// If this was a subordinate host to a domain that was being transferred, there might be a
|
||||
// pending transfer still extant, so remove it.
|
||||
builder.setTransferData(null).removeStatusValue(StatusValue.PENDING_TRANSFER);
|
||||
builder.removeStatusValue(StatusValue.PENDING_TRANSFER);
|
||||
} else {
|
||||
// For hosts with superordinate domains, the client id, last transfer time, and transfer data
|
||||
// need to be read off the domain projected to the correct time.
|
||||
// For hosts with superordinate domains, the client id, last transfer time, and transfer
|
||||
// status value need to be read off the domain projected to the correct time.
|
||||
DomainResource domainAtTime = ofy().load().key(superordinateDomain).now()
|
||||
.cloneProjectedAtTime(now);
|
||||
builder.setCurrentSponsorClientId(domainAtTime.getCurrentSponsorClientId());
|
||||
|
@ -145,15 +143,14 @@ public class HostResource extends EppResource implements ForeignKeyedEppResource
|
|||
.isBefore(Optional.fromNullable(domainAtTime.getLastTransferTime()).or(START_OF_TIME))) {
|
||||
builder.setLastTransferTime(domainAtTime.getLastTransferTime());
|
||||
}
|
||||
// Copy the transfer status and data from the superordinate domain onto the host, because the
|
||||
// host's doesn't matter and the superordinate domain always has the canonical data.
|
||||
TransferData domainTransferData = domainAtTime.getTransferData();
|
||||
if (TransferStatus.PENDING.equals(domainTransferData.getTransferStatus())) {
|
||||
// Copy the transfer status from the superordinate domain onto the host, because the host's
|
||||
// doesn't matter and the superordinate domain always has the canonical data.
|
||||
TransferStatus domainTransferStatus = domainAtTime.getTransferData().getTransferStatus();
|
||||
if (TransferStatus.PENDING.equals(domainTransferStatus)) {
|
||||
builder.addStatusValue(StatusValue.PENDING_TRANSFER);
|
||||
} else {
|
||||
builder.removeStatusValue(StatusValue.PENDING_TRANSFER);
|
||||
}
|
||||
builder.setTransferData(domainTransferData);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue