From 0518f63aad863d8694413471691eb4c677671357 Mon Sep 17 00:00:00 2001 From: cgoldfeder Date: Mon, 19 Sep 2016 10:05:42 -0700 Subject: [PATCH] [] ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133597433 --- .../registry/flows/ResourceFlowUtils.java | 54 +++++++++++++++++++ .../contact/ContactTransferApproveFlow.java | 14 ++--- .../contact/ContactTransferCancelFlow.java | 14 ++--- .../contact/ContactTransferRejectFlow.java | 12 +++-- java/google/registry/model/EppResource.java | 22 -------- 5 files changed, 76 insertions(+), 40 deletions(-) diff --git a/java/google/registry/flows/ResourceFlowUtils.java b/java/google/registry/flows/ResourceFlowUtils.java index 6450779d5..946c18a28 100644 --- a/java/google/registry/flows/ResourceFlowUtils.java +++ b/java/google/registry/flows/ResourceFlowUtils.java @@ -217,6 +217,60 @@ public class ResourceFlowUtils { } } + /** + * Turn a resource into a builder with its pending transfer resolved. + * + *

This removes the {@link StatusValue#PENDING_TRANSFER} status, sets the + * {@link TransferStatus}, clears all the server-approve fields on the {@link TransferData} + * including the extended registration years field, and sets the expiration time of the last + * pending transfer to now. + */ + @SuppressWarnings("unchecked") + private static EppResource.Builder resolvePendingTransfer( + R resource, TransferStatus transferStatus, DateTime now) { + return (EppResource.Builder) resource.asBuilder() + .removeStatusValue(StatusValue.PENDING_TRANSFER) + .setTransferData(resource.getTransferData().asBuilder() + .setExtendedRegistrationYears(null) + .setServerApproveEntities(null) + .setServerApproveBillingEvent(null) + .setServerApproveAutorenewEvent(null) + .setServerApproveAutorenewPollMessage(null) + .setTransferStatus(transferStatus) + .setPendingTransferExpirationTime(now) + .build()); + } + + /** + * Resolve a pending transfer by awarding it to the gaining client. + * + *

This removes the {@link StatusValue#PENDING_TRANSFER} status, sets the + * {@link TransferStatus}, clears all the server-approve fields on the {@link TransferData} + * including the extended registration years field, and sets the expiration time of the last + * pending transfer to now. + */ + public static R approvePendingTransfer( + R resource, TransferStatus transferStatus, DateTime now) { + Builder builder = resolvePendingTransfer(resource, transferStatus, now); + builder + .setLastTransferTime(now) + .setCurrentSponsorClientId(resource.getTransferData().getGainingClientId()); + return builder.build(); + } + + /** + * Resolve a pending transfer by denying it. + * + *

This removes the {@link StatusValue#PENDING_TRANSFER} status, sets the + * {@link TransferStatus}, clears all the server-approve fields on the {@link TransferData} + * including the extended registration years field, sets the new client id, and sets the last + * transfer time and the expiration time of the last pending transfer to now. + */ + public static R denyPendingTransfer( + R resource, TransferStatus transferStatus, DateTime now) { + return resolvePendingTransfer(resource, transferStatus, now).build(); + } + /** The specified resource belongs to another client. */ public static class ResourceNotOwnedException extends AuthorizationErrorException { public ResourceNotOwnedException() { diff --git a/java/google/registry/flows/contact/ContactTransferApproveFlow.java b/java/google/registry/flows/contact/ContactTransferApproveFlow.java index 406cce245..66aa588d5 100644 --- a/java/google/registry/flows/contact/ContactTransferApproveFlow.java +++ b/java/google/registry/flows/contact/ContactTransferApproveFlow.java @@ -14,6 +14,7 @@ package google.registry.flows.contact; +import static google.registry.flows.ResourceFlowUtils.approvePendingTransfer; import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfoForResource; import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership; import static google.registry.flows.contact.ContactFlowUtils.createGainingTransferPollMessage; @@ -38,6 +39,7 @@ import google.registry.model.eppinput.ResourceCommand; import google.registry.model.eppoutput.EppOutput; import google.registry.model.poll.PollMessage; import google.registry.model.reporting.HistoryEntry; +import google.registry.model.transfer.TransferData; import google.registry.model.transfer.TransferStatus; import javax.inject.Inject; @@ -70,15 +72,13 @@ public class ContactTransferApproveFlow extends LoggedInFlow implements Transact throw new ResourceToMutateDoesNotExistException(ContactResource.class, targetId); } verifyOptionalAuthInfoForResource(authInfo, existingResource); - if (existingResource.getTransferData().getTransferStatus() != TransferStatus.PENDING) { + TransferData transferData = existingResource.getTransferData(); + if (transferData.getTransferStatus() != TransferStatus.PENDING) { throw new NotPendingTransferException(targetId); } verifyResourceOwnership(clientId, existingResource); - ContactResource newResource = existingResource.asBuilder() - .clearPendingTransfer(TransferStatus.CLIENT_APPROVED, now) - .setLastTransferTime(now) - .setCurrentSponsorClientId(existingResource.getTransferData().getGainingClientId()) - .build(); + ContactResource newResource = + approvePendingTransfer(existingResource, TransferStatus.CLIENT_APPROVED, now); HistoryEntry historyEntry = historyBuilder .setType(HistoryEntry.Type.CONTACT_TRANSFER_APPROVE) .setModificationTime(now) @@ -90,7 +90,7 @@ public class ContactTransferApproveFlow extends LoggedInFlow implements Transact ofy().save().entities(newResource, historyEntry, gainingPollMessage); // Delete the billing event and poll messages that were written in case the transfer would have // been implicitly server approved. - ofy().delete().keys(existingResource.getTransferData().getServerApproveEntities()); + ofy().delete().keys(transferData.getServerApproveEntities()); return createOutput(SUCCESS, createTransferResponse(targetId, newResource.getTransferData())); } } diff --git a/java/google/registry/flows/contact/ContactTransferCancelFlow.java b/java/google/registry/flows/contact/ContactTransferCancelFlow.java index 2073f1408..c66362e79 100644 --- a/java/google/registry/flows/contact/ContactTransferCancelFlow.java +++ b/java/google/registry/flows/contact/ContactTransferCancelFlow.java @@ -14,6 +14,7 @@ package google.registry.flows.contact; +import static google.registry.flows.ResourceFlowUtils.denyPendingTransfer; import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfoForResource; import static google.registry.flows.contact.ContactFlowUtils.createLosingTransferPollMessage; import static google.registry.flows.contact.ContactFlowUtils.createTransferResponse; @@ -38,6 +39,7 @@ import google.registry.model.eppinput.ResourceCommand; import google.registry.model.eppoutput.EppOutput; import google.registry.model.poll.PollMessage; import google.registry.model.reporting.HistoryEntry; +import google.registry.model.transfer.TransferData; import google.registry.model.transfer.TransferStatus; import javax.inject.Inject; @@ -71,15 +73,15 @@ public class ContactTransferCancelFlow extends LoggedInFlow implements Transacti throw new ResourceToMutateDoesNotExistException(ContactResource.class, targetId); } verifyOptionalAuthInfoForResource(authInfo, existingResource); - if (existingResource.getTransferData().getTransferStatus() != TransferStatus.PENDING) { + TransferData transferData = existingResource.getTransferData(); + if (transferData.getTransferStatus() != TransferStatus.PENDING) { throw new NotPendingTransferException(targetId); } - if (!clientId.equals(existingResource.getTransferData().getGainingClientId())) { + if (!clientId.equals(transferData.getGainingClientId())) { throw new NotTransferInitiatorException(); } - ContactResource newResource = existingResource.asBuilder() - .clearPendingTransfer(TransferStatus.CLIENT_CANCELLED, now) - .build(); + ContactResource newResource = + denyPendingTransfer(existingResource, TransferStatus.CLIENT_CANCELLED, now); HistoryEntry historyEntry = historyBuilder .setType(HistoryEntry.Type.CONTACT_TRANSFER_CANCEL) .setModificationTime(now) @@ -91,7 +93,7 @@ public class ContactTransferCancelFlow extends LoggedInFlow implements Transacti ofy().save().entities(newResource, historyEntry, losingPollMessage); // Delete the billing event and poll messages that were written in case the transfer would have // been implicitly server approved. - ofy().delete().keys(existingResource.getTransferData().getServerApproveEntities()); + ofy().delete().keys(transferData.getServerApproveEntities()); return createOutput(SUCCESS, createTransferResponse(targetId, newResource.getTransferData())); } } diff --git a/java/google/registry/flows/contact/ContactTransferRejectFlow.java b/java/google/registry/flows/contact/ContactTransferRejectFlow.java index 02d88050f..a62e28a82 100644 --- a/java/google/registry/flows/contact/ContactTransferRejectFlow.java +++ b/java/google/registry/flows/contact/ContactTransferRejectFlow.java @@ -14,6 +14,7 @@ package google.registry.flows.contact; +import static google.registry.flows.ResourceFlowUtils.denyPendingTransfer; import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfoForResource; import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership; import static google.registry.flows.contact.ContactFlowUtils.createGainingTransferPollMessage; @@ -37,6 +38,7 @@ import google.registry.model.eppcommon.AuthInfo; import google.registry.model.eppoutput.EppOutput; import google.registry.model.poll.PollMessage; import google.registry.model.reporting.HistoryEntry; +import google.registry.model.transfer.TransferData; import google.registry.model.transfer.TransferStatus; import javax.inject.Inject; @@ -68,13 +70,13 @@ public class ContactTransferRejectFlow extends LoggedInFlow implements Transacti throw new ResourceToMutateDoesNotExistException(ContactResource.class, targetId); } verifyOptionalAuthInfoForResource(authInfo, existingResource); - if (existingResource.getTransferData().getTransferStatus() != TransferStatus.PENDING) { + TransferData transferData = existingResource.getTransferData(); + if (transferData.getTransferStatus() != TransferStatus.PENDING) { throw new NotPendingTransferException(targetId); } verifyResourceOwnership(clientId, existingResource); - ContactResource newResource = existingResource.asBuilder() - .clearPendingTransfer(TransferStatus.CLIENT_REJECTED, now) - .build(); + ContactResource newResource = + denyPendingTransfer(existingResource, TransferStatus.CLIENT_REJECTED, now); HistoryEntry historyEntry = historyBuilder .setType(HistoryEntry.Type.CONTACT_TRANSFER_REJECT) .setModificationTime(now) @@ -85,7 +87,7 @@ public class ContactTransferRejectFlow extends LoggedInFlow implements Transacti ofy().save().entities(newResource, historyEntry, gainingPollMessage); // Delete the billing event and poll messages that were written in case the transfer would have // been implicitly server approved. - ofy().delete().keys(existingResource.getTransferData().getServerApproveEntities()); + ofy().delete().keys(transferData.getServerApproveEntities()); return createOutput(SUCCESS, createTransferResponse(targetId, newResource.getTransferData())); } } diff --git a/java/google/registry/model/EppResource.java b/java/google/registry/model/EppResource.java index 2d09f2cb9..741653ae6 100644 --- a/java/google/registry/model/EppResource.java +++ b/java/google/registry/model/EppResource.java @@ -32,7 +32,6 @@ import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppoutput.EppResponse.ResponseData; import google.registry.model.ofy.CommitLogManifest; import google.registry.model.transfer.TransferData; -import google.registry.model.transfer.TransferStatus; import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlTransient; @@ -304,27 +303,6 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable, return thisCastToDerived(); } - /** - * Remove a pending transfer. - * - *

This removes the {@link StatusValue#PENDING_TRANSFER} status, clears all the - * server-approve fields on the {@link TransferData} including the extended registration years - * field, and sets the expiration time of the last pending transfer (i.e. the one being cleared) - * to now. - */ - public B clearPendingTransfer(TransferStatus transferStatus, DateTime now) { - removeStatusValue(StatusValue.PENDING_TRANSFER); - return setTransferData(getInstance().getTransferData().asBuilder() - .setExtendedRegistrationYears(null) - .setServerApproveEntities(null) - .setServerApproveBillingEvent(null) - .setServerApproveAutorenewEvent(null) - .setServerApproveAutorenewPollMessage(null) - .setTransferStatus(transferStatus) - .setPendingTransferExpirationTime(now) - .build()); - } - /** Wipe out any personal information in the resource. */ public B wipeOut() { return thisCastToDerived();