mirror of
https://github.com/google/nomulus
synced 2026-09-06 08:07:03 +00:00
Add a new method to load all Registry entities of a given type (#373)
* Add a new method to load all Registry entities of a given type This is useful for things that need to know more than just the TLD strings themselves, which is all Registries currently provides.
This commit is contained in:
@@ -33,6 +33,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.registry.Registry.TldType;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -80,6 +81,15 @@ public final class Registries {
|
||||
return ImmutableSet.copyOf(filterValues(cache.get(), equalTo(type)).keySet());
|
||||
}
|
||||
|
||||
/** Returns the Registry entities themselves of the given type loaded fresh from Datastore. */
|
||||
public static ImmutableSet<Registry> getTldEntitiesOfType(TldType type) {
|
||||
ImmutableSet<Key<Registry>> keys =
|
||||
filterValues(cache.get(), equalTo(type)).keySet().stream()
|
||||
.map(tld -> Key.create(getCrossTldKey(), Registry.class, tld))
|
||||
.collect(toImmutableSet());
|
||||
return ImmutableSet.copyOf(tm().doTransactionless(() -> ofy().load().keys(keys).values()));
|
||||
}
|
||||
|
||||
/** Pass-through check that the specified TLD exists, otherwise throw an IAE. */
|
||||
public static String assertTldExists(String tld) {
|
||||
checkArgument(
|
||||
|
||||
Reference in New Issue
Block a user