From d5160213e5e7f849bf6421b11bc673fb979608b0 Mon Sep 17 00:00:00 2001 From: cgoldfeder Date: Tue, 24 Jan 2017 09:16:22 -0800 Subject: [PATCH] Get rid of cloneWithLinkedStatus Now that we return an Info object rather than the resource itself, there's no reason for the cloning pattern. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=145426484 --- .../registry/flows/contact/ContactInfoFlow.java | 15 ++++++++++++--- java/google/registry/flows/host/HostInfoFlow.java | 15 ++++++++++++--- java/google/registry/model/EppResourceUtils.java | 11 ----------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/java/google/registry/flows/contact/ContactInfoFlow.java b/java/google/registry/flows/contact/ContactInfoFlow.java index 20ccc0777..0d3af47ef 100644 --- a/java/google/registry/flows/contact/ContactInfoFlow.java +++ b/java/google/registry/flows/contact/ContactInfoFlow.java @@ -17,9 +17,12 @@ package google.registry.flows.contact; import static google.registry.flows.FlowUtils.validateClientIsLoggedIn; import static google.registry.flows.ResourceFlowUtils.loadAndVerifyExistence; import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfo; -import static google.registry.model.EppResourceUtils.cloneResourceWithLinkedStatus; +import static google.registry.model.EppResourceUtils.isLinked; +import static google.registry.util.CollectionUtils.difference; import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import com.googlecode.objectify.Key; import google.registry.flows.EppException; import google.registry.flows.ExtensionManager; import google.registry.flows.Flow; @@ -28,6 +31,7 @@ import google.registry.flows.FlowModule.TargetId; import google.registry.model.contact.ContactInfoData; import google.registry.model.contact.ContactResource; import google.registry.model.eppcommon.AuthInfo; +import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppoutput.EppResponse; import google.registry.util.Clock; import javax.inject.Inject; @@ -60,14 +64,19 @@ public final class ContactInfoFlow implements Flow { validateClientIsLoggedIn(clientId); ContactResource contact = loadAndVerifyExistence(ContactResource.class, targetId, now); verifyOptionalAuthInfo(authInfo, contact); - contact = (ContactResource) cloneResourceWithLinkedStatus(contact, now); boolean includeAuthInfo = clientId.equals(contact.getCurrentSponsorClientId()) || authInfo.isPresent(); + ImmutableSet.Builder statusValues = new ImmutableSet.Builder<>(); + // TODO(b/34664935): When LINKED is no longer persisted we won't need to filter it out. + statusValues.addAll(difference(contact.getStatusValues(), StatusValue.LINKED)); + if (isLinked(Key.create(contact), now)) { + statusValues.add(StatusValue.LINKED); + } return responseBuilder .setResData(ContactInfoData.newBuilder() .setContactId(contact.getContactId()) .setRepoId(contact.getRepoId()) - .setStatusValues(contact.getStatusValues()) + .setStatusValues(statusValues.build()) .setPostalInfos(contact.getPostalInfosAsList()) .setVoiceNumber(contact.getVoiceNumber()) .setFaxNumber(contact.getFaxNumber()) diff --git a/java/google/registry/flows/host/HostInfoFlow.java b/java/google/registry/flows/host/HostInfoFlow.java index b730acd81..f92b52525 100644 --- a/java/google/registry/flows/host/HostInfoFlow.java +++ b/java/google/registry/flows/host/HostInfoFlow.java @@ -17,13 +17,17 @@ package google.registry.flows.host; import static google.registry.flows.FlowUtils.validateClientIsLoggedIn; import static google.registry.flows.ResourceFlowUtils.loadAndVerifyExistence; import static google.registry.flows.host.HostFlowUtils.validateHostName; -import static google.registry.model.EppResourceUtils.cloneResourceWithLinkedStatus; +import static google.registry.model.EppResourceUtils.isLinked; +import static google.registry.util.CollectionUtils.difference; +import com.google.common.collect.ImmutableSet; +import com.googlecode.objectify.Key; import google.registry.flows.EppException; import google.registry.flows.ExtensionManager; import google.registry.flows.Flow; import google.registry.flows.FlowModule.ClientId; import google.registry.flows.FlowModule.TargetId; +import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppoutput.EppResponse; import google.registry.model.host.HostInfoData; import google.registry.model.host.HostResource; @@ -58,12 +62,17 @@ public final class HostInfoFlow implements Flow { validateHostName(targetId); DateTime now = clock.nowUtc(); HostResource host = loadAndVerifyExistence(HostResource.class, targetId, now); - host = (HostResource) cloneResourceWithLinkedStatus(host, now); + ImmutableSet.Builder statusValues = new ImmutableSet.Builder<>(); + // TODO(b/34664935): When LINKED is no longer persisted we won't need to filter it out. + statusValues.addAll(difference(host.getStatusValues(), StatusValue.LINKED)); + if (isLinked(Key.create(host), now)) { + statusValues.add(StatusValue.LINKED); + } return responseBuilder .setResData(HostInfoData.newBuilder() .setFullyQualifiedHostName(host.getFullyQualifiedHostName()) .setRepoId(host.getRepoId()) - .setStatusValues(host.getStatusValues()) + .setStatusValues(statusValues.build()) .setInetAddresses(host.getInetAddresses()) .setCurrentSponsorClientId(host.getCurrentSponsorClientId()) .setCreationClientId(host.getCreationClientId()) diff --git a/java/google/registry/model/EppResourceUtils.java b/java/google/registry/model/EppResourceUtils.java index 45ebb5749..e7fe229bb 100644 --- a/java/google/registry/model/EppResourceUtils.java +++ b/java/google/registry/model/EppResourceUtils.java @@ -360,17 +360,6 @@ public final class EppResourceUtils { return queryForLinkedDomains(key, now).limit(1).count() > 0; } - /** Clone a contact or host with an eventually-consistent notion of LINKED. */ - public static EppResource cloneResourceWithLinkedStatus(EppResource resource, DateTime now) { - Builder builder = resource.asBuilder(); - if (isLinked(Key.create(resource), now)) { - builder.addStatusValue(StatusValue.LINKED); - } else { - builder.removeStatusValue(StatusValue.LINKED); - } - return builder.build(); - } - /** Exception to throw when failing to parse a repo id. */ public static class InvalidRepoIdException extends Exception {