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:
cgoldfeder 2016-11-15 08:03:25 -08:00 committed by Ben McIlwain
parent 0234795240
commit 84009eaccb
24 changed files with 309 additions and 240 deletions

View file

@ -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;
/** Contacts voice number. Personal info; cleared by wipeOut(). */
/** Contacts voice number. Personal info; cleared by {@link Builder#wipeOut}. */
@IgnoreSave(IfNull.class)
ContactPhoneNumber voice;
/** Contacts fax number. Personal info; cleared by wipeOut(). */
/** Contacts fax number. Personal info; cleared by {@link Builder#wipeOut}. */
@IgnoreSave(IfNull.class)
ContactPhoneNumber fax;
/** Contacts email address. Personal info; cleared by wipeOut(). */
/** Contacts 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();
}