mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
RDAP: Factor out a utility method
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=134700128
This commit is contained in:
parent
bf75c4ca48
commit
e5c0854ae6
2 changed files with 38 additions and 40 deletions
|
@ -168,7 +168,9 @@ public abstract class RdapActionBase implements Runnable {
|
||||||
*
|
*
|
||||||
* @param clazz the type of resource to be queried
|
* @param clazz the type of resource to be queried
|
||||||
* @param filterField the database field of interest
|
* @param filterField the database field of interest
|
||||||
* @param partialStringQuery the details of the search string
|
* @param partialStringQuery the details of the search string; if there is no wildcard, an
|
||||||
|
* equality query is used; if there is a wildcard, a range query is used instead; there
|
||||||
|
* should not be a search suffix
|
||||||
* @param resultSetMaxSize the maximum number of results to return
|
* @param resultSetMaxSize the maximum number of results to return
|
||||||
* @return the results of the query
|
* @return the results of the query
|
||||||
*/
|
*/
|
||||||
|
@ -177,7 +179,14 @@ public abstract class RdapActionBase implements Runnable {
|
||||||
String filterField,
|
String filterField,
|
||||||
RdapSearchPattern partialStringQuery,
|
RdapSearchPattern partialStringQuery,
|
||||||
int resultSetMaxSize) {
|
int resultSetMaxSize) {
|
||||||
checkArgument(partialStringQuery.getHasWildcard(), "search string doesn't have wildcard");
|
if (!partialStringQuery.getHasWildcard()) {
|
||||||
|
return ofy().load()
|
||||||
|
.type(clazz)
|
||||||
|
.filter(filterField, partialStringQuery.getInitialString())
|
||||||
|
.filter("deletionTime", END_OF_TIME)
|
||||||
|
.limit(resultSetMaxSize);
|
||||||
|
} else {
|
||||||
|
checkArgument(partialStringQuery.getSuffix() == null, "Unexpected search string suffix");
|
||||||
return ofy().load()
|
return ofy().load()
|
||||||
.type(clazz)
|
.type(clazz)
|
||||||
.filter(filterField + " >=", partialStringQuery.getInitialString())
|
.filter(filterField + " >=", partialStringQuery.getInitialString())
|
||||||
|
@ -186,3 +195,4 @@ public abstract class RdapActionBase implements Runnable {
|
||||||
.limit(resultSetMaxSize);
|
.limit(resultSetMaxSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -125,41 +125,29 @@ public class RdapEntitySearchAction extends RdapActionBase {
|
||||||
*/
|
*/
|
||||||
private ImmutableList<ImmutableMap<String, Object>>
|
private ImmutableList<ImmutableMap<String, Object>>
|
||||||
searchByName(final RdapSearchPattern partialStringQuery, DateTime now) {
|
searchByName(final RdapSearchPattern partialStringQuery, DateTime now) {
|
||||||
// Handle queries without a wildcard -- load by name, which may not be unique.
|
|
||||||
if (!partialStringQuery.getHasWildcard()) {
|
|
||||||
Registrar registrar = Registrar.loadByName(partialStringQuery.getInitialString());
|
|
||||||
return makeSearchResults(
|
|
||||||
ofy().load()
|
|
||||||
.type(ContactResource.class)
|
|
||||||
.filter("searchName", partialStringQuery.getInitialString())
|
|
||||||
.filter("deletionTime", END_OF_TIME)
|
|
||||||
.limit(rdapResultSetMaxSize)
|
|
||||||
.list(),
|
|
||||||
(registrar == null)
|
|
||||||
? ImmutableList.<Registrar>of() : ImmutableList.of(registrar),
|
|
||||||
now);
|
|
||||||
// Handle queries with a wildcard, but no suffix. For contact resources, the deletion time will
|
|
||||||
// always be END_OF_TIME for non-deleted records; unlike domain resources, we don't need to
|
|
||||||
// worry about deletion times in the future. That allows us to use an equality query for the
|
|
||||||
// deletion time.
|
|
||||||
} else if (partialStringQuery.getSuffix() == null) {
|
|
||||||
return makeSearchResults(
|
|
||||||
ofy().load()
|
|
||||||
.type(ContactResource.class)
|
|
||||||
.filter("searchName >=", partialStringQuery.getInitialString())
|
|
||||||
.filter("searchName <", partialStringQuery.getNextInitialString())
|
|
||||||
.filter("deletionTime", END_OF_TIME)
|
|
||||||
.limit(rdapResultSetMaxSize)
|
|
||||||
.list(),
|
|
||||||
ImmutableList.copyOf(Registrar.loadByNameRange(
|
|
||||||
partialStringQuery.getInitialString(),
|
|
||||||
partialStringQuery.getNextInitialString(),
|
|
||||||
rdapResultSetMaxSize)),
|
|
||||||
now);
|
|
||||||
// Don't allow suffixes in entity name search queries.
|
// Don't allow suffixes in entity name search queries.
|
||||||
} else {
|
if (!partialStringQuery.getHasWildcard() && (partialStringQuery.getSuffix() != null)) {
|
||||||
throw new UnprocessableEntityException("Suffixes not allowed in entity name searches");
|
throw new UnprocessableEntityException("Suffixes not allowed in entity name searches");
|
||||||
}
|
}
|
||||||
|
// Get the registrar matches, depending on whether there's a wildcard.
|
||||||
|
ImmutableList<Registrar> registrarMatches;
|
||||||
|
if (!partialStringQuery.getHasWildcard()) {
|
||||||
|
Registrar registrar = Registrar.loadByName(partialStringQuery.getInitialString());
|
||||||
|
registrarMatches = (registrar == null)
|
||||||
|
? ImmutableList.<Registrar>of()
|
||||||
|
: ImmutableList.of(registrar);
|
||||||
|
} else {
|
||||||
|
registrarMatches = ImmutableList.copyOf(Registrar.loadByNameRange(
|
||||||
|
partialStringQuery.getInitialString(),
|
||||||
|
partialStringQuery.getNextInitialString(),
|
||||||
|
rdapResultSetMaxSize));
|
||||||
|
}
|
||||||
|
// Get the contact matches and return the results.
|
||||||
|
return makeSearchResults(
|
||||||
|
queryUndeleted(
|
||||||
|
ContactResource.class, "searchName", partialStringQuery, rdapResultSetMaxSize).list(),
|
||||||
|
registrarMatches,
|
||||||
|
now);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Searches for entities by handle, returning a JSON array of entity info maps. */
|
/** Searches for entities by handle, returning a JSON array of entity info maps. */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue