mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
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:
parent
2bb61b82f4
commit
d5160213e5
3 changed files with 24 additions and 17 deletions
|
@ -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())
|
||||
|
|
|
@ -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<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(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())
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue