1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.search
.checkers
;
5 import com
.google
.appengine
.api
.NamespaceManager
;
6 import com
.google
.appengine
.api
.search
.SearchServicePb
.ListIndexesParams
;
7 import com
.google
.apphosting
.api
.AppEngineInternal
;
8 import com
.google
.common
.base
.Strings
;
11 * Checks values of {@link com.google.appengine.api.search.GetIndexesRequest}.
15 public class GetIndexesRequestChecker
{
18 * The maximum offset of the first index returned in list indexes results.
19 * @deprecated From 1.7.4, use {@link SearchApiLimits#GET_INDEXES_MAXIMUM_OFFSET}
21 @Deprecated public static final int MAXIMUM_OFFSET
= 1000;
24 * The maximum number of indexes that can be requested to be returned in
25 * list indexes results.
26 * @deprecated From 1.7.4, use {@link SearchApiLimits#GET_INDEXES_MAXIMUM_LIMIT}
28 @Deprecated public static final int MAXIMUM_LIMIT
= 1000;
31 * The default number of indexes we will try to return.
32 * @deprecated From 1.7.4, use {@link SearchApiLimits#GET_INDEXES_DEFAULT_LIMIT}
34 @Deprecated public static final int DEFAULT_LIMIT
= 20;
37 * Checks whether the number of indexes to return is between 1 and the
40 * @param limit the maximum number of indexes to return in list results
41 * @return the checked number of indexes to return
42 * @throws IllegalArgumentException if the number of indexes to return
45 public static int checkLimit(int limit
) {
46 Preconditions
.checkArgument(limit
>= 1 && limit
<= SearchApiLimits
.GET_INDEXES_MAXIMUM_LIMIT
,
47 String
.format("The limit %d must be between 1 and %d",
48 limit
, SearchApiLimits
.GET_INDEXES_MAXIMUM_LIMIT
));
53 * Checks whether the offset of the first indexes to return is between 0 and the
56 * @param offset the offset of the first index to return in list results
57 * @return the checked offset of the first index to return
58 * @throws IllegalArgumentException if the offset of the first index to return
61 public static int checkOffset(int offset
) {
62 Preconditions
.checkArgument(offset
>= 0 && offset
<= SearchApiLimits
.GET_INDEXES_MAXIMUM_OFFSET
,
63 String
.format("The limit %d must be between 1 and %d",
64 offset
, SearchApiLimits
.GET_INDEXES_MAXIMUM_OFFSET
));
69 * Checks whether the given index name prefix is legal. This method uses the same
70 * checks as {@link IndexChecker#checkName(String)}.
72 * @param indexNamePrefix the index name prefix to be checked
73 * @return the checked index name prefix
74 * @throws IllegalArgumentException if the index name prefix is illegal.
76 public static String
checkIndexNamePrefix(String indexNamePrefix
) {
77 if (Strings
.isNullOrEmpty(indexNamePrefix
)) {
78 return indexNamePrefix
;
80 return IndexChecker
.checkName(indexNamePrefix
);
84 * Checks whether the given start index name is legal. This method uses the same
85 * checks as {@link IndexChecker#checkName(String)}.
87 * @param startIndexName the name of the first index to be returned
88 * @return the checked start index name
89 * @throws IllegalArgumentException if the start index name is illegal.
91 public static String
checkStartIndexName(String startIndexName
) {
92 if (Strings
.isNullOrEmpty(startIndexName
)) {
93 return startIndexName
;
95 return IndexChecker
.checkName(startIndexName
);
99 * Ensures the given protocol buffer parameters are valid. If any of the parameters
100 * fail to pass the checks, this method throws {@link IllegalArgumentException}. If
101 * everything is valid the original parameters are returned.
103 * @param params the parameters to be checked for validity
104 * @return the checked parameters for listing indexes
105 * @throws IllegalArgumentException if any of the values are incorrect
107 public static ListIndexesParams
checkListIndexesParams(ListIndexesParams params
) {
108 if (params
.hasLimit()) {
109 checkLimit(params
.getLimit());
111 if (params
.hasNamespace()) {
112 NamespaceManager
.validateNamespace(params
.getNamespace());
114 if (params
.hasStartIndexName()) {
115 checkStartIndexName(params
.getStartIndexName());
117 if (params
.hasIndexNamePrefix()) {
118 checkIndexNamePrefix(params
.getIndexNamePrefix());
120 if (params
.hasOffset()) {
121 checkOffset(params
.getOffset());