diff --git a/java/google/registry/flows/domain/DomainApplicationInfoFlow.java b/java/google/registry/flows/domain/DomainApplicationInfoFlow.java index d540f2d5f..12dfca012 100644 --- a/java/google/registry/flows/domain/DomainApplicationInfoFlow.java +++ b/java/google/registry/flows/domain/DomainApplicationInfoFlow.java @@ -97,7 +97,7 @@ public final class DomainApplicationInfoFlow implements Flow { } // We don't support authInfo for applications, so if it's another registrar always fail. verifyResourceOwnership(clientId, application); - application = getResourceInfo(application); + boolean showDelegatedHosts = ((Info) resourceCommand).getHostsRequest().requestDelegated(); prefetchReferencedResources(application); return responseBuilder .setResData(DomainInfoData.newBuilder() @@ -106,7 +106,9 @@ public final class DomainApplicationInfoFlow implements Flow { .setStatusValues(application.getStatusValues()) .setRegistrant(ofy().load().key(application.getRegistrant()).now().getContactId()) .setContacts(loadForeignKeyedDesignatedContacts(application.getContacts())) - .setNameservers(application.loadNameserverFullyQualifiedHostNames()) + .setNameservers(showDelegatedHosts + ? application.loadNameserverFullyQualifiedHostNames() + : null) .setCurrentSponsorClientId(application.getCurrentSponsorClientId()) .setCreationClientId(application.getCreationClientId()) .setCreationTime(application.getCreationTime()) @@ -118,18 +120,6 @@ public final class DomainApplicationInfoFlow implements Flow { .build(); } - DomainApplication getResourceInfo(DomainApplication application) { - if (!((Info) resourceCommand).getHostsRequest().requestDelegated()) { - // Delegated hosts are present by default, so clear them out if they aren't wanted. - // This requires overriding the implicit status values so that we don't get INACTIVE added due - // to the missing nameservers. - return application.asBuilder() - .setNameservers(null) - .buildWithoutImplicitStatusValues(); - } - return application; - } - ImmutableList getDomainResponseExtensions( DomainApplication application, LaunchInfoExtension launchInfo) { ImmutableList.Builder marksBuilder = new ImmutableList.Builder<>(); diff --git a/java/google/registry/flows/domain/DomainInfoFlow.java b/java/google/registry/flows/domain/DomainInfoFlow.java index dc9e5f079..08d70ecb2 100644 --- a/java/google/registry/flows/domain/DomainInfoFlow.java +++ b/java/google/registry/flows/domain/DomainInfoFlow.java @@ -40,7 +40,6 @@ import google.registry.model.domain.DomainCommand.Info; import google.registry.model.domain.DomainCommand.Info.HostsRequest; import google.registry.model.domain.DomainInfoData; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.DomainResource.Builder; import google.registry.model.domain.fee06.FeeInfoCommandExtensionV06; import google.registry.model.domain.fee06.FeeInfoResponseExtensionV06; import google.registry.model.domain.rgp.GracePeriodStatus; @@ -98,59 +97,43 @@ public final class DomainInfoFlow implements Flow { customLogic.beforeResponse( BeforeResponseParameters.newBuilder() .setDomain(domain) - .setResData(getResourceInfo(domain)) + .setResData(domain) .setResponseExtensions(getDomainResponseExtensions(domain, now)) .build()); domain = responseData.resData(); prefetchReferencedResources(domain); - return responseBuilder - .setResData(DomainInfoData.newBuilder() - .setFullyQualifiedDomainName(domain.getFullyQualifiedDomainName()) - .setRepoId(domain.getRepoId()) - .setStatusValues(domain.getStatusValues()) - .setRegistrant(ofy().load().key(domain.getRegistrant()).now().getContactId()) - .setContacts(loadForeignKeyedDesignatedContacts(domain.getContacts())) - .setNameservers(domain.loadNameserverFullyQualifiedHostNames()) - .setSubordinateHosts(domain.getSubordinateHosts()) - .setCurrentSponsorClientId(domain.getCurrentSponsorClientId()) - .setCreationClientId(domain.getCreationClientId()) - .setCreationTime(domain.getCreationTime()) - .setLastEppUpdateClientId(domain.getLastEppUpdateClientId()) - .setLastEppUpdateTime(domain.getLastEppUpdateTime()) - .setRegistrationExpirationTime(domain.getRegistrationExpirationTime()) - .setLastTransferTime(domain.getLastTransferTime()) - .setAuthInfo(domain.getAuthInfo()) - .build()) - .setExtensions(responseData.responseExtensions()) - .build(); - } - - private DomainResource getResourceInfo(DomainResource domain) { + // Registrars can only see a few fields on unauthorized domains. + // This is a policy decision that is left up to us by the rfcs. + DomainInfoData.Builder infoBuilder = DomainInfoData.newBuilder() + .setFullyQualifiedDomainName(domain.getFullyQualifiedDomainName()) + .setRepoId(domain.getRepoId()) + .setCurrentSponsorClientId(domain.getCurrentSponsorClientId()) + .setRegistrant(ofy().load().key(domain.getRegistrant()).now().getContactId()); // If authInfo is non-null, then the caller is authorized to see the full information since we // will have already verified the authInfo is valid. - if (!(clientId.equals(domain.getCurrentSponsorClientId()) || authInfo.isPresent())) { - // Registrars can only see a few fields on unauthorized domains. - // This is a policy decision that is left up to us by the rfcs. - return new DomainResource.Builder() - .setFullyQualifiedDomainName(domain.getFullyQualifiedDomainName()) - .setRepoId(domain.getRepoId()) - .setCurrentSponsorClientId(domain.getCurrentSponsorClientId()) - .setRegistrant(domain.getRegistrant()) - // If we didn't do this, we'd get implicit status values. - .buildWithoutImplicitStatusValues(); + if (clientId.equals(domain.getCurrentSponsorClientId()) || authInfo.isPresent()) { + HostsRequest hostsRequest = ((Info) resourceCommand).getHostsRequest(); + infoBuilder + .setStatusValues(domain.getStatusValues()) + .setContacts(loadForeignKeyedDesignatedContacts(domain.getContacts())) + .setNameservers(hostsRequest.requestDelegated() + ? domain.loadNameserverFullyQualifiedHostNames() + : null) + .setSubordinateHosts(hostsRequest.requestSubordinate() + ? domain.getSubordinateHosts() + : null) + .setCreationClientId(domain.getCreationClientId()) + .setCreationTime(domain.getCreationTime()) + .setLastEppUpdateClientId(domain.getLastEppUpdateClientId()) + .setLastEppUpdateTime(domain.getLastEppUpdateTime()) + .setRegistrationExpirationTime(domain.getRegistrationExpirationTime()) + .setLastTransferTime(domain.getLastTransferTime()) + .setAuthInfo(domain.getAuthInfo()); } - HostsRequest hostsRequest = ((Info) resourceCommand).getHostsRequest(); - Builder info = domain.asBuilder(); - if (!hostsRequest.requestSubordinate()) { - info.setSubordinateHosts(null); - } - if (!hostsRequest.requestDelegated()) { - // Delegated hosts are present by default, so clear them out if they aren't wanted. - // This requires overriding the implicit status values so that we don't get INACTIVE added due - // to the missing nameservers. - return info.setNameservers(null).buildWithoutImplicitStatusValues(); - } - return info.build(); + return responseBuilder + .setResData(infoBuilder.build()) + .setExtensions(responseData.responseExtensions()) + .build(); } private ImmutableList getDomainResponseExtensions( diff --git a/java/google/registry/model/EppResource.java b/java/google/registry/model/EppResource.java index 54dba26d3..741e69c19 100644 --- a/java/google/registry/model/EppResource.java +++ b/java/google/registry/model/EppResource.java @@ -281,11 +281,6 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable { if (difference(getInstance().getStatusValues(), StatusValue.LINKED).isEmpty()) { addStatusValue(StatusValue.OK); } - return buildWithoutImplicitStatusValues(); - } - - /** Build the resource, nullifying empty strings and sets and setting defaults. */ - public T buildWithoutImplicitStatusValues() { // 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()); diff --git a/java/google/registry/model/domain/DomainInfoData.java b/java/google/registry/model/domain/DomainInfoData.java index 42c7bf9a5..1033188d3 100644 --- a/java/google/registry/model/domain/DomainInfoData.java +++ b/java/google/registry/model/domain/DomainInfoData.java @@ -57,12 +57,14 @@ public abstract class DomainInfoData implements ResponseData { abstract String getRepoId(); @XmlElement(name = "status") + @Nullable abstract ImmutableSet getStatusValues(); @XmlElement(name = "registrant") abstract String getRegistrant(); @XmlElement(name = "contact") + @Nullable abstract ImmutableSet getContacts(); @XmlElementWrapper(name = "ns") @@ -110,9 +112,10 @@ public abstract class DomainInfoData implements ResponseData { public abstract static class Builder { public abstract Builder setFullyQualifiedDomainName(String fullyQualifiedDomainName); public abstract Builder setRepoId(String repoId); - public abstract Builder setStatusValues(ImmutableSet statusValues); + public abstract Builder setStatusValues(@Nullable ImmutableSet statusValues); public abstract Builder setRegistrant(String registrant); - public abstract Builder setContacts(ImmutableSet contacts); + public abstract Builder setContacts( + @Nullable ImmutableSet contacts); public abstract Builder setNameservers(@Nullable ImmutableSet nameservers); public abstract Builder setSubordinateHosts(@Nullable ImmutableSet subordinateHosts); public abstract Builder setCurrentSponsorClientId(String currentSponsorClientId);