mirror of
https://github.com/google/nomulus.git
synced 2025-05-21 03:39:36 +02:00
Handle pending transfers on domain imports from RDE deposits
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=148496597
This commit is contained in:
parent
3ca9bb6aeb
commit
9f90597691
14 changed files with 752 additions and 125 deletions
|
@ -16,34 +16,47 @@ 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.util.DateTimeUtils.END_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.appengine.tools.cloudstorage.GcsFilename;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.gcs.GcsUtils;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.EppResource.ForeignKeyedEppResource;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.billing.BillingEvent.Flag;
|
||||
import google.registry.model.billing.BillingEvent.Reason;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.host.HostResource;
|
||||
import google.registry.model.index.EppResourceIndex;
|
||||
import google.registry.model.index.ForeignKeyIndex;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.Registry.RegistryNotFoundException;
|
||||
import google.registry.model.registry.Registry.TldState;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.util.Clock;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import google.registry.xjc.XjcXmlTransformer;
|
||||
import google.registry.xjc.rdedomain.XjcRdeDomain;
|
||||
import google.registry.xjc.rdedomain.XjcRdeDomainElement;
|
||||
import google.registry.xjc.rderegistrar.XjcRdeRegistrar;
|
||||
import google.registry.xml.XmlException;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
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.
|
||||
|
@ -66,10 +79,11 @@ public class RdeImportUtils {
|
|||
this.escrowBucketName = escrowBucketName;
|
||||
}
|
||||
|
||||
private <T extends EppResource> void importEppResource(final T resource, final String type) {
|
||||
public <T extends EppResource & ForeignKeyedEppResource> ImmutableSet<Object>
|
||||
createIndexesForEppResource(T resource) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<T> resourceClass = (Class<T>) resource.getClass();
|
||||
EppResource existing = ofy.load().key(Key.create(resource)).now();
|
||||
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();
|
||||
|
@ -80,51 +94,30 @@ public class RdeImportUtils {
|
|||
checkState(
|
||||
existingForeignKeyIndex == null,
|
||||
"New %s resource has existing foreign key index; foreignKey=%s, repoId=%s",
|
||||
type,
|
||||
resource.getClass().getCanonicalName(),
|
||||
resource.getForeignKey(),
|
||||
resource.getRepoId());
|
||||
ofy.save().entity(resource);
|
||||
ofy.save().entity(ForeignKeyIndex.create(resource, resource.getDeletionTime()));
|
||||
ofy.save().entity(EppResourceIndex.create(Key.create(resource)));
|
||||
logger.infofmt(
|
||||
"Imported %s resource - ROID=%s, id=%s",
|
||||
type, resource.getRepoId(), resource.getForeignKey());
|
||||
return ImmutableSet.<Object>of(ForeignKeyIndex.create(resource, resource.getDeletionTime()),
|
||||
EppResourceIndex.create(Key.create(resource)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a host from an escrow file.
|
||||
* Imports a resource from an escrow file.
|
||||
*
|
||||
* <p>The host will only be imported if it has not been previously imported.
|
||||
*
|
||||
* <p>If the host is imported, {@link ForeignKeyIndex} and {@link EppResourceIndex} are also
|
||||
* created.
|
||||
*/
|
||||
public void importHost(final HostResource resource) {
|
||||
importEppResource(resource, "host");
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a contact from an escrow file.
|
||||
*
|
||||
* <p>The contact will only be imported if it has not been previously imported.
|
||||
*
|
||||
* <p>If the contact is imported, {@link ForeignKeyIndex} and {@link EppResourceIndex} are also
|
||||
* created.
|
||||
*/
|
||||
public void importContact(final ContactResource resource) {
|
||||
importEppResource(resource, "contact");
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a domain from an escrow file.
|
||||
*
|
||||
* <p>The domain will only be imported if it has not been previously imported.
|
||||
*
|
||||
* <p>If the domain is imported, {@link ForeignKeyIndex} and {@link EppResourceIndex} are also
|
||||
* created.
|
||||
*/
|
||||
public void importDomain(final DomainResource resource) {
|
||||
importEppResource(resource, "domain");
|
||||
public <T extends EppResource & ForeignKeyedEppResource> void
|
||||
importEppResource(final T resource) {
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,4 +177,59 @@ public class RdeImportUtils {
|
|||
return Trid.create(
|
||||
"Import_" + BaseEncoding.base64().encode(UUID.randomUUID().toString().getBytes()));
|
||||
}
|
||||
|
||||
public static BillingEvent.Recurring createAutoRenewBillingEventForDomainImport(
|
||||
XjcRdeDomain domain, HistoryEntry historyEntry) {
|
||||
final BillingEvent.Recurring billingEvent =
|
||||
new BillingEvent.Recurring.Builder()
|
||||
.setReason(Reason.RENEW)
|
||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||
.setTargetId(domain.getRoid())
|
||||
.setClientId(domain.getClID())
|
||||
.setEventTime(domain.getExDate())
|
||||
.setRecurrenceEndTime(END_OF_TIME)
|
||||
.setParent(historyEntry)
|
||||
.build();
|
||||
return billingEvent;
|
||||
}
|
||||
|
||||
public static PollMessage.Autorenew createAutoRenewPollMessageForDomainImport(
|
||||
XjcRdeDomain domain, HistoryEntry historyEntry) {
|
||||
final PollMessage.Autorenew pollMessage =
|
||||
new PollMessage.Autorenew.Builder()
|
||||
.setTargetId(domain.getRoid())
|
||||
.setClientId(domain.getClID())
|
||||
.setEventTime(domain.getExDate())
|
||||
.setMsg("Domain was auto-renewed.")
|
||||
.setParent(historyEntry)
|
||||
.build();
|
||||
return pollMessage;
|
||||
}
|
||||
|
||||
public static HistoryEntry createHistoryEntryForDomainImport(XjcRdeDomain domain) {
|
||||
XjcRdeDomainElement element = new XjcRdeDomainElement(domain);
|
||||
final HistoryEntry historyEntry =
|
||||
new HistoryEntry.Builder()
|
||||
.setType(HistoryEntry.Type.RDE_IMPORT)
|
||||
.setClientId(domain.getClID())
|
||||
.setTrid(generateTridForImport())
|
||||
.setModificationTime(DateTime.now())
|
||||
.setXmlBytes(getObjectXml(element))
|
||||
.setBySuperuser(true)
|
||||
.setReason("RDE Import")
|
||||
.setRequestedByRegistrar(false)
|
||||
.setParent(Key.create(null, DomainResource.class, domain.getRoid()))
|
||||
.build();
|
||||
return historyEntry;
|
||||
}
|
||||
|
||||
public static byte[] getObjectXml(Object jaxbElement) {
|
||||
try {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
XjcXmlTransformer.marshalLenient(jaxbElement, bout, UTF_8);
|
||||
return bout.toByteArray();
|
||||
} catch (XmlException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue