Fix RDE import pending transfer handling

Mostly based on the original PR, but with some tweaking by nfelt@, in particular to add some support for autorenew grace period subsumption.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=169922894
This commit is contained in:
nickfelt 2017-09-25 10:10:20 -07:00 committed by Ben McIlwain
parent 2814561e92
commit 3ad21e3834
7 changed files with 495 additions and 89 deletions

View file

@ -16,12 +16,12 @@ package google.registry.rde.imports;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC;
import com.google.appengine.tools.cloudstorage.GcsFilename;
import com.google.common.collect.ImmutableSet;
@ -61,7 +61,6 @@ import java.util.UUID;
import javax.inject.Inject;
import javax.xml.bind.JAXBException;
import javax.xml.stream.XMLStreamException;
import org.joda.time.DateTime;
/**
* Utility functions for escrow file import.
@ -89,14 +88,9 @@ public class RdeImportUtils {
public <T extends EppResource & ForeignKeyedEppResource> ImmutableSet<Object>
createIndexesForEppResource(T resource) {
@SuppressWarnings("unchecked")
Class<T> resourceClass = (Class<T>) resource.getClass();
Object existing = ofy.load().key(Key.create(resource)).now();
if (existing != null) {
// This will roll back the transaction and prevent duplicate history entries from being saved.
throw new ResourceExistsException();
}
ForeignKeyIndex<T> existingForeignKeyIndex =
ForeignKeyIndex.load(resourceClass, resource.getForeignKey(), START_OF_TIME);
ForeignKeyIndex.load(
(Class<T>) resource.getClass(), resource.getForeignKey(), START_OF_TIME);
// ForeignKeyIndex should never have existed, since existing resource was not found.
checkState(
existingForeignKeyIndex == null,
@ -111,20 +105,27 @@ public class RdeImportUtils {
/**
* Imports a resource from an escrow file.
*
* <p>The host will only be imported if it has not been previously imported.
* <p>The resource will only be imported if it has not been previously imported.
*
* <p>If the host is imported, {@link ForeignKeyIndex} and {@link EppResourceIndex} are also
* <p>If the resource is imported, {@link ForeignKeyIndex} and {@link EppResourceIndex} are also
* created.
*/
public <T extends EppResource & ForeignKeyedEppResource> void
importEppResource(final T resource) {
Object existing = ofy.load().key(Key.create(resource)).now();
if (existing != null) {
// This will roll back the transaction and prevent duplicate history entries from being saved.
throw new ResourceExistsException();
}
ofy.save().entities(new ImmutableSet.Builder<>()
.add(resource)
.addAll(createIndexesForEppResource(resource))
.build());
logger.infofmt(
"Imported %s resource - ROID=%s, id=%s",
resource.getClass().getCanonicalName(), resource.getRepoId(), resource.getForeignKey());
resource.getClass().getSimpleName(),
resource.getRepoId(),
resource.getForeignKey());
}
/**
@ -221,7 +222,7 @@ public class RdeImportUtils {
.setType(HistoryEntry.Type.RDE_IMPORT)
.setClientId(domain.getClID())
.setTrid(generateTridForImport())
.setModificationTime(DateTime.now(UTC))
.setModificationTime(ofy().getTransactionTime())
.setXmlBytes(getObjectXml(element))
.setBySuperuser(true)
.setReason("RDE Import")