mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 01:47:14 +02:00
Replace command.applyTo() with inlined builder operations
These are much easier to understand. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=137446273
This commit is contained in:
parent
b84d7f1fb5
commit
1dbc5f6bb0
28 changed files with 489 additions and 426 deletions
|
@ -20,7 +20,6 @@ import static google.registry.util.CollectionUtils.nullToEmpty;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Maps;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.contact.ContactResource.Builder;
|
||||
import google.registry.model.contact.PostalInfo.Type;
|
||||
import google.registry.model.eppinput.ResourceCommand.AbstractSingleResourceCommand;
|
||||
import google.registry.model.eppinput.ResourceCommand.ResourceCheck;
|
||||
|
@ -75,23 +74,32 @@ public class ContactCommand {
|
|||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(Builder builder) {
|
||||
if (authInfo != null) {
|
||||
builder.setAuthInfo(authInfo);
|
||||
}
|
||||
if (disclose != null) {
|
||||
builder.setDisclose(disclose);
|
||||
}
|
||||
if (email != null) {
|
||||
builder.setEmailAddress(email);
|
||||
}
|
||||
if (fax != null) {
|
||||
builder.setFaxNumber(fax);
|
||||
}
|
||||
if (voice != null) {
|
||||
builder.setVoiceNumber(voice);
|
||||
}
|
||||
public ContactPhoneNumber getVoice() {
|
||||
return voice;
|
||||
}
|
||||
|
||||
public ContactPhoneNumber getFax() {
|
||||
return fax;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public ContactAuthInfo getAuthInfo() {
|
||||
return authInfo;
|
||||
}
|
||||
|
||||
public Disclose getDisclose() {
|
||||
return disclose;
|
||||
}
|
||||
|
||||
public PostalInfo getInternationalizedPostalInfo() {
|
||||
return getPostalInfosAsMap().get(Type.INTERNATIONALIZED);
|
||||
}
|
||||
|
||||
public PostalInfo getLocalizedPostalInfo() {
|
||||
return getPostalInfosAsMap().get(Type.LOCALIZED);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,21 +142,6 @@ public class ContactCommand {
|
|||
public ContactAuthInfo getAuthInfo() {
|
||||
return authInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(ContactResource.Builder builder) {
|
||||
super.applyTo(builder);
|
||||
if (contactId != null) {
|
||||
builder.setContactId(contactId);
|
||||
}
|
||||
Map<Type, PostalInfo> postalInfosAsMap = getPostalInfosAsMap();
|
||||
if (postalInfosAsMap.containsKey(Type.INTERNATIONALIZED)) {
|
||||
builder.setInternationalizedPostalInfo(postalInfosAsMap.get(Type.INTERNATIONALIZED));
|
||||
}
|
||||
if (postalInfosAsMap.containsKey(Type.LOCALIZED)) {
|
||||
builder.setLocalizedPostalInfo(postalInfosAsMap.get(Type.LOCALIZED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A delete command for a {@link ContactResource}. */
|
||||
|
@ -204,34 +197,6 @@ public class ContactCommand {
|
|||
|
||||
/** The inner change type on a contact update command. */
|
||||
@XmlType(propOrder = {"postalInfo", "voice", "fax", "email", "authInfo", "disclose"})
|
||||
public static class Change extends ContactCreateOrChange {
|
||||
/**
|
||||
* The spec requires the following behaviors:
|
||||
* <ul>
|
||||
* <li>If you update part of a postal info, the fields that you didn't update are unchanged.
|
||||
* <li>If you update one postal info but not the other, the other is deleted.
|
||||
* </ul>
|
||||
* Therefore, if you want to preserve one postal info and update another you need to send the
|
||||
* update and also something that technically updates the preserved one, even if it only
|
||||
* "updates" it by setting just one field to the same value.
|
||||
*/
|
||||
@Override
|
||||
public void applyTo(ContactResource.Builder builder) {
|
||||
super.applyTo(builder);
|
||||
Map<Type, PostalInfo> postalInfosAsMap = getPostalInfosAsMap();
|
||||
if (postalInfosAsMap.containsKey(Type.INTERNATIONALIZED)) {
|
||||
builder.overlayInternationalizedPostalInfo(postalInfosAsMap.get(Type.INTERNATIONALIZED));
|
||||
if (postalInfosAsMap.size() == 1) {
|
||||
builder.setLocalizedPostalInfo(null);
|
||||
}
|
||||
}
|
||||
if (postalInfosAsMap.containsKey(Type.LOCALIZED)) {
|
||||
builder.overlayLocalizedPostalInfo(postalInfosAsMap.get(Type.LOCALIZED));
|
||||
if (postalInfosAsMap.size() == 1) {
|
||||
builder.setInternationalizedPostalInfo(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static class Change extends ContactCreateOrChange {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import google.registry.model.EppResource;
|
|||
import google.registry.model.EppResource.ForeignKeyedEppResource;
|
||||
import google.registry.model.annotations.ExternalMessagingName;
|
||||
import google.registry.model.contact.PostalInfo.Type;
|
||||
import google.registry.model.eppcommon.AuthInfo;
|
||||
import java.util.List;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
@ -147,7 +146,7 @@ public class ContactResource extends EppResource implements ForeignKeyedEppResou
|
|||
return email;
|
||||
}
|
||||
|
||||
public AuthInfo getAuthInfo() {
|
||||
public ContactAuthInfo getAuthInfo() {
|
||||
return authInfo;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ import google.registry.model.contact.ContactResource;
|
|||
import google.registry.model.domain.DesignatedContact.Type;
|
||||
import google.registry.model.domain.launch.LaunchNotice;
|
||||
import google.registry.model.domain.secdns.DelegationSignerData;
|
||||
import google.registry.model.eppcommon.AuthInfo;
|
||||
import google.registry.model.host.HostResource;
|
||||
import java.util.Set;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
@ -221,7 +220,7 @@ public abstract class DomainBase extends EppResource {
|
|||
.toSet();
|
||||
}
|
||||
|
||||
public AuthInfo getAuthInfo() {
|
||||
public DomainAuthInfo getAuthInfo() {
|
||||
return authInfo;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.collect.Maps.transformValues;
|
||||
import static com.google.common.collect.Sets.difference;
|
||||
import static com.google.common.collect.Sets.intersection;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.util.CollectionUtils.difference;
|
||||
import static google.registry.util.CollectionUtils.forceEmptyToNull;
|
||||
|
@ -37,7 +36,6 @@ import com.googlecode.objectify.Work;
|
|||
import google.registry.model.EppResource;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.eppcommon.AuthInfo;
|
||||
import google.registry.model.eppinput.ResourceCommand.AbstractSingleResourceCommand;
|
||||
import google.registry.model.eppinput.ResourceCommand.ResourceCheck;
|
||||
import google.registry.model.eppinput.ResourceCommand.ResourceCreateOrChange;
|
||||
|
@ -98,14 +96,8 @@ public class DomainCommand {
|
|||
return registrant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(B builder) {
|
||||
if (registrant != null) {
|
||||
builder.setRegistrant(registrant);
|
||||
}
|
||||
if (authInfo != null) {
|
||||
builder.setAuthInfo(authInfo);
|
||||
}
|
||||
public DomainAuthInfo getAuthInfo() {
|
||||
return authInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,24 +167,10 @@ public class DomainCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AuthInfo getAuthInfo() {
|
||||
public DomainAuthInfo getAuthInfo() {
|
||||
return authInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(DomainBase.Builder<?, ?> builder) {
|
||||
super.applyTo(builder);
|
||||
if (fullyQualifiedDomainName != null) {
|
||||
builder.setFullyQualifiedDomainName(fullyQualifiedDomainName);
|
||||
}
|
||||
if (nameservers != null) {
|
||||
builder.setNameservers(getNameservers());
|
||||
}
|
||||
if (contacts != null) {
|
||||
builder.setContacts(getContacts());
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a copy of this {@link Create} with hard links to hosts and contacts. */
|
||||
@Override
|
||||
public Create cloneAndLinkReferences(DateTime now) throws InvalidReferencesException {
|
||||
|
@ -422,24 +400,6 @@ public class DomainCommand {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(DomainBase.Builder<?, ?> builder) throws AddRemoveSameValueException {
|
||||
super.applyTo(builder);
|
||||
getInnerChange().applyTo(builder);
|
||||
AddRemove add = getInnerAdd();
|
||||
AddRemove remove = getInnerRemove();
|
||||
if (!intersection(add.getNameservers(), remove.getNameservers()).isEmpty()) {
|
||||
throw new AddRemoveSameValueException();
|
||||
}
|
||||
builder.addNameservers(add.getNameservers());
|
||||
builder.removeNameservers(remove.getNameservers());
|
||||
if (!intersection(add.getContacts(), remove.getContacts()).isEmpty()) {
|
||||
throw new AddRemoveSameValueException();
|
||||
}
|
||||
builder.addContacts(add.getContacts());
|
||||
builder.removeContacts(remove.getContacts());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a copy of this {@link Update} with hard links to hosts and contacts.
|
||||
*
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
package google.registry.model.eppinput;
|
||||
|
||||
import static com.google.common.collect.Sets.intersection;
|
||||
import static google.registry.util.CollectionUtils.nullSafeImmutableCopy;
|
||||
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
||||
|
||||
|
@ -83,9 +82,7 @@ public interface ResourceCommand {
|
|||
}
|
||||
|
||||
/** A create command, or the inner change (as opposed to add or remove) part of an update. */
|
||||
public interface ResourceCreateOrChange<B extends Builder<?>> {
|
||||
public abstract void applyTo(B builder);
|
||||
}
|
||||
public interface ResourceCreateOrChange<B extends Builder<?>> {}
|
||||
|
||||
/**
|
||||
* An update command for an {@link EppResource}.
|
||||
|
@ -133,18 +130,5 @@ public interface ResourceCommand {
|
|||
A remove = getNullableInnerRemove();
|
||||
return remove == null ? new TypeInstantiator<A>(getClass()){}.instantiate() : remove;
|
||||
}
|
||||
|
||||
public void applyTo(B builder) throws AddRemoveSameValueException {
|
||||
getInnerChange().applyTo(builder);
|
||||
if (!intersection(getInnerAdd().getStatusValues(), getInnerRemove().getStatusValues())
|
||||
.isEmpty()) {
|
||||
throw new AddRemoveSameValueException();
|
||||
}
|
||||
builder.addStatusValues(getInnerAdd().getStatusValues());
|
||||
builder.removeStatusValues(getInnerRemove().getStatusValues());
|
||||
}
|
||||
}
|
||||
|
||||
/** Exception for adding and removing the same value in {@link ResourceUpdate#applyTo}. */
|
||||
public static class AddRemoveSameValueException extends Exception {}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
package google.registry.model.host;
|
||||
|
||||
import static com.google.common.collect.Sets.intersection;
|
||||
import static google.registry.util.CollectionUtils.nullSafeImmutableCopy;
|
||||
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
||||
|
||||
|
@ -37,27 +36,9 @@ public class HostCommand {
|
|||
@XmlTransient
|
||||
abstract static class HostCreateOrChange extends AbstractSingleResourceCommand
|
||||
implements ResourceCreateOrChange<HostResource.Builder> {
|
||||
/** IP Addresses for this host. Can be null if this is an external host. */
|
||||
@XmlElement(name = "addr")
|
||||
Set<InetAddress> inetAddresses;
|
||||
|
||||
public ImmutableSet<InetAddress> getInetAddresses() {
|
||||
return nullSafeImmutableCopy(inetAddresses);
|
||||
}
|
||||
|
||||
public String getFullyQualifiedHostName() {
|
||||
return getTargetId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(HostResource.Builder builder) {
|
||||
if (getFullyQualifiedHostName() != null) {
|
||||
builder.setFullyQualifiedHostName(getFullyQualifiedHostName());
|
||||
}
|
||||
if (getInetAddresses() != null) {
|
||||
builder.setInetAddresses(getInetAddresses());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,7 +48,15 @@ public class HostCommand {
|
|||
@XmlType(propOrder = {"targetId", "inetAddresses" })
|
||||
@XmlRootElement
|
||||
public static class Create
|
||||
extends HostCreateOrChange implements ResourceCreateOrChange<HostResource.Builder> {}
|
||||
extends HostCreateOrChange implements ResourceCreateOrChange<HostResource.Builder> {
|
||||
/** IP Addresses for this host. Can be null if this is an external host. */
|
||||
@XmlElement(name = "addr")
|
||||
Set<InetAddress> inetAddresses;
|
||||
|
||||
public ImmutableSet<InetAddress> getInetAddresses() {
|
||||
return nullSafeImmutableCopy(inetAddresses);
|
||||
}
|
||||
}
|
||||
|
||||
/** A delete command for a {@link HostResource}. */
|
||||
@XmlRootElement
|
||||
|
@ -124,18 +113,6 @@ public class HostCommand {
|
|||
}
|
||||
|
||||
/** The inner change type on a host update command. */
|
||||
@XmlType(propOrder = {"targetId", "inetAddresses" })
|
||||
public static class Change extends HostCreateOrChange {}
|
||||
|
||||
@Override
|
||||
public void applyTo(HostResource.Builder builder) throws AddRemoveSameValueException {
|
||||
super.applyTo(builder);
|
||||
if (!intersection(getInnerAdd().getInetAddresses(), getInnerRemove().getInetAddresses())
|
||||
.isEmpty()) {
|
||||
throw new AddRemoveSameValueException();
|
||||
}
|
||||
builder.addInetAddresses(getInnerAdd().getInetAddresses());
|
||||
builder.removeInetAddresses(getInnerRemove().getInetAddresses());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue