mirror of
https://github.com/google/nomulus.git
synced 2025-05-31 09:44:03 +02:00
This also deletes the associated commands and domain application specific entities. We haven't used any of these TLD phases since early 2015 and have no intent to do so in the future, so it makes sense to delete them now so we don't have to carry them through the Registry 3.0 migration. Note that, while there are data model changes, there should be no required data migrations. The fields and entities being removed will simply remain as orphans. I confirmed that the removed types (such as the SUNRUSH_ADD GracePeriodType) are no longer used in production data, and left types that are still used, e.g. BillingEvent.Flag.LANDRUSH or HistoryEntry.Type.ALLOCATE. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=228752843
297 lines
11 KiB
Java
297 lines
11 KiB
Java
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.model.domain;
|
|
|
|
import static com.google.common.base.Preconditions.checkArgument;
|
|
import static com.google.common.base.Strings.emptyToNull;
|
|
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
|
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
|
|
import static com.google.common.collect.Sets.difference;
|
|
import static com.google.common.collect.Sets.union;
|
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
|
import static google.registry.util.CollectionUtils.forceEmptyToNull;
|
|
import static google.registry.util.CollectionUtils.nullToEmpty;
|
|
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
|
import static google.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy;
|
|
import static google.registry.util.CollectionUtils.union;
|
|
import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
|
|
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
|
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
import com.google.common.collect.ImmutableSortedSet;
|
|
import com.google.common.collect.Ordering;
|
|
import com.google.common.collect.Streams;
|
|
import com.googlecode.objectify.Key;
|
|
import com.googlecode.objectify.annotation.Entity;
|
|
import com.googlecode.objectify.annotation.IgnoreSave;
|
|
import com.googlecode.objectify.annotation.Index;
|
|
import com.googlecode.objectify.condition.IfNull;
|
|
import google.registry.model.EppResource;
|
|
import google.registry.model.annotations.ReportedOn;
|
|
import google.registry.model.contact.ContactResource;
|
|
import google.registry.model.domain.DesignatedContact.Type;
|
|
import google.registry.model.domain.launch.LaunchNotice;
|
|
import google.registry.model.domain.secdns.DelegationSignerData;
|
|
import google.registry.model.host.HostResource;
|
|
import java.util.Objects;
|
|
import java.util.Set;
|
|
import java.util.function.Predicate;
|
|
|
|
/** Base class for {@link DomainResource}. */
|
|
// TODO(b/121028829): Squash DomainResource into this.
|
|
@ReportedOn
|
|
@Entity
|
|
public abstract class DomainBase extends EppResource {
|
|
|
|
/**
|
|
* Fully qualified domain name (puny-coded), which serves as the foreign key for this domain.
|
|
*
|
|
* <p>This is only unique in the sense that for any given lifetime specified as the time range
|
|
* from (creationTime, deletionTime) there can only be one domain in Datastore with this name.
|
|
* However, there can be many domains with the same name and non-overlapping lifetimes.
|
|
*
|
|
* @invariant fullyQualifiedDomainName == fullyQualifiedDomainName.toLowerCase()
|
|
*/
|
|
@Index
|
|
String fullyQualifiedDomainName;
|
|
|
|
/** The top level domain this is under, dernormalized from {@link #fullyQualifiedDomainName}. */
|
|
@Index
|
|
String tld;
|
|
|
|
/** References to hosts that are the nameservers for the domain. */
|
|
@Index
|
|
Set<Key<HostResource>> nsHosts;
|
|
|
|
/**
|
|
* The union of the contacts visible via {@link #getContacts} and {@link #getRegistrant}.
|
|
*
|
|
* <p>These are stored in one field so that we can query across all contacts at once.
|
|
*/
|
|
Set<DesignatedContact> allContacts;
|
|
|
|
/** Authorization info (aka transfer secret) of the domain. */
|
|
DomainAuthInfo authInfo;
|
|
|
|
/**
|
|
* Data used to construct DS records for this domain.
|
|
*
|
|
* <p>This is {@literal @}XmlTransient because it needs to be returned under the "extension" tag
|
|
* of an info response rather than inside the "infData" tag.
|
|
*/
|
|
Set<DelegationSignerData> dsData;
|
|
|
|
/**
|
|
* The claims notice supplied when this application or domain was created, if there was one. It's
|
|
* {@literal @}XmlTransient because it's not returned in an info response.
|
|
*/
|
|
@IgnoreSave(IfNull.class)
|
|
LaunchNotice launchNotice;
|
|
|
|
/**
|
|
* Name of first IDN table associated with TLD that matched the characters in this domain label.
|
|
*
|
|
* @see google.registry.tldconfig.idn.IdnLabelValidator#findValidIdnTableForTld
|
|
*/
|
|
@IgnoreSave(IfNull.class)
|
|
String idnTableName;
|
|
|
|
public String getFullyQualifiedDomainName() {
|
|
return fullyQualifiedDomainName;
|
|
}
|
|
|
|
public ImmutableSortedSet<DelegationSignerData> getDsData() {
|
|
return nullToEmptyImmutableSortedCopy(dsData);
|
|
}
|
|
|
|
public LaunchNotice getLaunchNotice() {
|
|
return launchNotice;
|
|
}
|
|
|
|
public String getIdnTableName() {
|
|
return idnTableName;
|
|
}
|
|
|
|
public ImmutableSet<Key<HostResource>> getNameservers() {
|
|
return nullToEmptyImmutableCopy(nsHosts);
|
|
}
|
|
|
|
public final String getCurrentSponsorClientId() {
|
|
return getPersistedCurrentSponsorClientId();
|
|
}
|
|
|
|
/** Loads and returns the fully qualified host names of all linked nameservers. */
|
|
public ImmutableSortedSet<String> loadNameserverFullyQualifiedHostNames() {
|
|
return ofy()
|
|
.load()
|
|
.keys(getNameservers())
|
|
.values()
|
|
.stream()
|
|
.map(HostResource::getFullyQualifiedHostName)
|
|
.collect(toImmutableSortedSet(Ordering.natural()));
|
|
}
|
|
|
|
/** A key to the registrant who registered this domain. */
|
|
public Key<ContactResource> getRegistrant() {
|
|
return nullToEmpty(allContacts)
|
|
.stream()
|
|
.filter(IS_REGISTRANT)
|
|
.findFirst()
|
|
.get()
|
|
.getContactKey();
|
|
}
|
|
|
|
/** Associated contacts for the domain (other than registrant). */
|
|
public ImmutableSet<DesignatedContact> getContacts() {
|
|
return nullToEmpty(allContacts)
|
|
.stream()
|
|
.filter(IS_REGISTRANT.negate())
|
|
.collect(toImmutableSet());
|
|
}
|
|
|
|
public DomainAuthInfo getAuthInfo() {
|
|
return authInfo;
|
|
}
|
|
|
|
/** Returns all referenced contacts from this domain or application. */
|
|
public ImmutableSet<Key<ContactResource>> getReferencedContacts() {
|
|
return nullToEmptyImmutableCopy(allContacts)
|
|
.stream()
|
|
.map(DesignatedContact::getContactKey)
|
|
.filter(Objects::nonNull)
|
|
.collect(toImmutableSet());
|
|
}
|
|
|
|
public String getTld() {
|
|
return tld;
|
|
}
|
|
|
|
/** Predicate to determine if a given {@link DesignatedContact} is the registrant. */
|
|
private static final Predicate<DesignatedContact> IS_REGISTRANT =
|
|
(DesignatedContact contact) -> DesignatedContact.Type.REGISTRANT.equals(contact.type);
|
|
|
|
/** An override of {@link EppResource#asBuilder} with tighter typing. */
|
|
@Override
|
|
public abstract Builder<?, ?> asBuilder();
|
|
|
|
/** A builder for constructing {@link DomainBase}, since it is immutable. */
|
|
public abstract static class Builder<T extends DomainBase, B extends Builder<?, ?>>
|
|
extends EppResource.Builder<T, B> {
|
|
|
|
protected Builder() {}
|
|
|
|
protected Builder(T instance) {
|
|
super(instance);
|
|
}
|
|
|
|
@Override
|
|
public T build() {
|
|
T instance = getInstance();
|
|
checkArgumentNotNull(
|
|
emptyToNull(instance.fullyQualifiedDomainName), "Missing fullyQualifiedDomainName");
|
|
checkArgument(instance.allContacts.stream().anyMatch(IS_REGISTRANT), "Missing registrant");
|
|
instance.tld = getTldFromDomainName(instance.fullyQualifiedDomainName);
|
|
return super.build();
|
|
}
|
|
|
|
public B setFullyQualifiedDomainName(String fullyQualifiedDomainName) {
|
|
checkArgument(
|
|
fullyQualifiedDomainName.equals(canonicalizeDomainName(fullyQualifiedDomainName)),
|
|
"Domain name must be in puny-coded, lower-case form");
|
|
getInstance().fullyQualifiedDomainName = fullyQualifiedDomainName;
|
|
return thisCastToDerived();
|
|
}
|
|
|
|
public B setDsData(ImmutableSet<DelegationSignerData> dsData) {
|
|
getInstance().dsData = dsData;
|
|
return thisCastToDerived();
|
|
}
|
|
|
|
public B setRegistrant(Key<ContactResource> registrant) {
|
|
// Replace the registrant contact inside allContacts.
|
|
getInstance().allContacts = union(
|
|
getInstance().getContacts(),
|
|
DesignatedContact.create(Type.REGISTRANT, checkArgumentNotNull(registrant)));
|
|
return thisCastToDerived();
|
|
}
|
|
|
|
public B setAuthInfo(DomainAuthInfo authInfo) {
|
|
getInstance().authInfo = authInfo;
|
|
return thisCastToDerived();
|
|
}
|
|
|
|
public B setNameservers(Key<HostResource> nameserver) {
|
|
getInstance().nsHosts = ImmutableSet.of(nameserver);
|
|
return thisCastToDerived();
|
|
}
|
|
|
|
public B setNameservers(ImmutableSet<Key<HostResource>> nameservers) {
|
|
getInstance().nsHosts = forceEmptyToNull(nameservers);
|
|
return thisCastToDerived();
|
|
}
|
|
|
|
public B addNameserver(Key<HostResource> nameserver) {
|
|
return addNameservers(ImmutableSet.of(nameserver));
|
|
}
|
|
|
|
public B addNameservers(ImmutableSet<Key<HostResource>> nameservers) {
|
|
return setNameservers(
|
|
ImmutableSet.copyOf(union(getInstance().getNameservers(), nameservers)));
|
|
}
|
|
|
|
public B removeNameserver(Key<HostResource> nameserver) {
|
|
return removeNameservers(ImmutableSet.of(nameserver));
|
|
}
|
|
|
|
public B removeNameservers(ImmutableSet<Key<HostResource>> nameservers) {
|
|
return setNameservers(
|
|
ImmutableSet.copyOf(difference(getInstance().getNameservers(), nameservers)));
|
|
}
|
|
|
|
public B setContacts(DesignatedContact contact) {
|
|
return setContacts(ImmutableSet.of(contact));
|
|
}
|
|
|
|
public B setContacts(ImmutableSet<DesignatedContact> contacts) {
|
|
checkArgument(contacts.stream().noneMatch(IS_REGISTRANT), "Registrant cannot be a contact");
|
|
// Replace the non-registrant contacts inside allContacts.
|
|
getInstance().allContacts =
|
|
Streams.concat(
|
|
nullToEmpty(getInstance().allContacts).stream().filter(IS_REGISTRANT),
|
|
contacts.stream())
|
|
.collect(toImmutableSet());
|
|
return thisCastToDerived();
|
|
}
|
|
|
|
public B addContacts(ImmutableSet<DesignatedContact> contacts) {
|
|
return setContacts(ImmutableSet.copyOf(union(getInstance().getContacts(), contacts)));
|
|
}
|
|
|
|
public B removeContacts(ImmutableSet<DesignatedContact> contacts) {
|
|
return setContacts(ImmutableSet.copyOf(difference(getInstance().getContacts(), contacts)));
|
|
}
|
|
|
|
public B setLaunchNotice(LaunchNotice launchNotice) {
|
|
getInstance().launchNotice = launchNotice;
|
|
return thisCastToDerived();
|
|
}
|
|
|
|
public B setIdnTableName(String idnTableName) {
|
|
getInstance().idnTableName = idnTableName;
|
|
return thisCastToDerived();
|
|
}
|
|
}
|
|
}
|