RDAP: Implement entity name search

Adds the ability to search for entities (contacts and registrars) by name.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130305930
This commit is contained in:
mountford 2016-08-15 11:48:40 -07:00 committed by Ben McIlwain
parent 64abebec82
commit 160266f37a
8 changed files with 368 additions and 66 deletions

View file

@ -24,6 +24,7 @@ import com.google.common.collect.Lists;
import com.googlecode.objectify.annotation.Cache;
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.EppResource.ForeignKeyedEppResource;
@ -85,6 +86,15 @@ public class ContactResource extends EppResource implements ForeignKeyedEppResou
@XmlTransient
PostalInfo internationalizedPostalInfo;
/**
* Contact name used for name searches. This is set automatically to be the internationalized
* postal name, or if null, the localized postal name, or if that is null as well, null. Personal
* info; cleared by wipeOut().
*/
@Index
@XmlTransient
String searchName;
/** Contacts voice number. Personal info; cleared by wipeOut(). */
@IgnoreSave(IfNull.class)
ContactPhoneNumber voice;
@ -250,6 +260,16 @@ public class ContactResource extends EppResource implements ForeignKeyedEppResou
@Override
public ContactResource build() {
// Set the searchName using the internationalized and localized postal info names.
if ((getInstance().internationalizedPostalInfo != null)
&& (getInstance().internationalizedPostalInfo.getName() != null)) {
getInstance().searchName = getInstance().internationalizedPostalInfo.getName();
} else if ((getInstance().localizedPostalInfo != null)
&& (getInstance().localizedPostalInfo.getName() != null)) {
getInstance().searchName = getInstance().localizedPostalInfo.getName();
} else {
getInstance().searchName = null;
}
return super.build();
}
}

View file

@ -786,7 +786,7 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
}
}
/** Load a registrar entity by its client id. */
/** Load a registrar entity by its client id outside of a transaction. */
@Nullable
public static Registrar loadByClientId(final String clientId) {
return ofy().doTransactionless(new Work<Registrar>() {
@ -801,7 +801,7 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
}
/**
* Load registrar entities by client id range.
* Load registrar entities by client id range outside of a transaction.
*
* @param clientIdStart returned registrars will have a client id greater than or equal to this
* @param clientIdAfterEnd returned registrars will have a client id less than this
@ -820,6 +820,41 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
}});
}
/** Load a registrar entity by its name outside of a transaction. */
@Nullable
public static Registrar loadByName(final String name) {
return ofy().doTransactionless(new Work<Registrar>() {
@Override
public Registrar run() {
return ofy().load()
.type(Registrar.class)
.filter("registrarName", name)
.first()
.now();
}});
}
/**
* Load registrar entities by registrar name range, inclusive of the start but not the end,
* outside of a transaction.
*
* @param nameStart returned registrars will have a name greater than or equal to this
* @param nameAfterEnd returned registrars will have a name less than this
* @param resultSetMaxSize the maximum number of registrar entities to be returned
*/
public static Iterable<Registrar> loadByNameRange(
final String nameStart, final String nameAfterEnd, final int resultSetMaxSize) {
return ofy().doTransactionless(new Work<Iterable<Registrar>>() {
@Override
public Iterable<Registrar> run() {
return ofy().load()
.type(Registrar.class)
.filter("registrarName >=", nameStart)
.filter("registrarName <", nameAfterEnd)
.limit(resultSetMaxSize);
}});
}
/** Loads all registrar entities. */
public static Iterable<Registrar> loadAll() {
return ofy().load().type(Registrar.class).ancestor(getCrossTldKey());