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
This commit is contained in:
cgoldfeder 2017-01-24 09:16:22 -08:00 committed by Ben McIlwain
parent 2bb61b82f4
commit d5160213e5
3 changed files with 24 additions and 17 deletions

View file

@ -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<StatusValue> 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())