diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index 28ff64310c..5936f42cd5 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -384,13 +384,118 @@ runs: key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-java-2/search/**', + 'clients/algoliasearch-client-java-2/api/SearchApi.java', 'clients/algoliasearch-client-java-2/model/search/**', 'specs/bundled/search.yml', 'templates/java/**', 'generators/src/**' )}} + - name: Restore built Java recommend client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/RecommendApi.java', + 'clients/algoliasearch-client-java-2/model/recommend/**', + 'specs/bundled/recommend.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java personalization client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/PersonalizationApi.java', + 'clients/algoliasearch-client-java-2/model/personalization/**', + 'specs/bundled/personalization.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java analytics client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/AnalyticsApi.java', + 'clients/algoliasearch-client-java-2/model/analytics/**', + 'specs/bundled/analytics.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java insights client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/Insights.java', + 'clients/algoliasearch-client-java-2/model/insights/**', + 'specs/bundled/insights.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java abtesting client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/AbtestingApi.java', + 'clients/algoliasearch-client-java-2/model/abtesting/**', + 'specs/bundled/abtesting.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java query-suggestions client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/QuerySuggestionsApi.java', + 'clients/algoliasearch-client-java-2/model/querySuggestions/**', + 'specs/bundled/query-suggestions.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java predict client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/PredictApi.java', + 'clients/algoliasearch-client-java-2/model/predict/**', + 'specs/bundled/predict.yml', + 'templates/java/**', + 'generators/src/**' + )}} + # Restore PHP clients: used during 'cts' or 'codegen' - name: Restore built PHP search client if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/search/SearchApi.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/search/SearchApi.java deleted file mode 100644 index c0cedca1f7..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/search/SearchApi.java +++ /dev/null @@ -1,6710 +0,0 @@ -package com.algolia.search; - -import com.algolia.ApiCallback; -import com.algolia.ApiClient; -import com.algolia.ApiResponse; -import com.algolia.Pair; -import com.algolia.exceptions.*; -import com.algolia.model.search.*; -import com.algolia.utils.*; -import com.algolia.utils.echo.*; -import com.algolia.utils.retry.CallType; -import com.algolia.utils.retry.StatefulHost; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import okhttp3.Call; - -public class SearchApi extends ApiClient { - - public SearchApi(String appId, String apiKey) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(appId)), null); - } - - public SearchApi( - String appId, - String apiKey, - UserAgent.Segment[] userAgentSegments - ) { - this( - appId, - apiKey, - new HttpRequester(getDefaultHosts(appId)), - userAgentSegments - ); - } - - public SearchApi(String appId, String apiKey, Requester requester) { - this(appId, apiKey, requester, null); - } - - public SearchApi( - String appId, - String apiKey, - Requester requester, - UserAgent.Segment[] userAgentSegments - ) { - super(appId, apiKey, requester, "Search", userAgentSegments); - } - - private static List getDefaultHosts(String appId) { - List hosts = new ArrayList(); - hosts.add( - new StatefulHost( - appId + "-dsn.algolia.net", - "https", - EnumSet.of(CallType.READ) - ) - ); - hosts.add( - new StatefulHost( - appId + ".algolia.net", - "https", - EnumSet.of(CallType.WRITE) - ) - ); - - List commonHosts = new ArrayList(); - hosts.add( - new StatefulHost( - appId + "-1.algolianet.net", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - hosts.add( - new StatefulHost( - appId + "-2.algolianet.net", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - hosts.add( - new StatefulHost( - appId + "-3.algolianet.net", - "https", - EnumSet.of(CallType.READ, CallType.WRITE) - ) - ); - - Collections.shuffle(commonHosts, new Random()); - - return Stream - .concat(hosts.stream(), commonHosts.stream()) - .collect(Collectors.toList()); - } - - /** - * Build call for addApiKey - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call addApiKeyCall( - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = apiKey; - - // create path and map variables - String requestPath = "/1/keys"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call addApiKeyValidateBeforeCall( - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'apiKey' is set - if (apiKey == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'apiKey' when calling addApiKey(Async)" - ); - } - - return addApiKeyCall(apiKey, callback); - } - - /** - * Add a new API Key with specific permissions/restrictions. - * - * @param apiKey (required) - * @return AddApiKeyResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public AddApiKeyResponse addApiKey(ApiKey apiKey) - throws AlgoliaRuntimeException { - Call req = addApiKeyValidateBeforeCall(apiKey, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.AddApiKey(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Add a new API Key with specific permissions/restrictions. - * - * @param apiKey (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call addApiKeyAsync( - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = addApiKeyValidateBeforeCall(apiKey, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for addOrUpdateObject - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call addOrUpdateObjectCall( - String indexName, - String objectID, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call addOrUpdateObjectValidateBeforeCall( - String indexName, - String objectID, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling addOrUpdateObject(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling addOrUpdateObject(Async)" - ); - } - - // verify the required parameter 'body' is set - if (body == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'body' when calling addOrUpdateObject(Async)" - ); - } - - return addOrUpdateObjectCall(indexName, objectID, body, callback); - } - - /** - * Add or replace an object with a given object ID. If the object does not exist, it will be - * created. If it already exists, it will be replaced. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param body The Algolia object. (required) - * @return UpdatedAtWithObjectIdResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtWithObjectIdResponse addOrUpdateObject( - String indexName, - String objectID, - Object body - ) throws AlgoliaRuntimeException { - Call req = addOrUpdateObjectValidateBeforeCall( - indexName, - objectID, - body, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.AddOrUpdateObject( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Add or replace an object with a given object ID. If the object does not exist, - * it will be created. If it already exists, it will be replaced. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param body The Algolia object. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call addOrUpdateObjectAsync( - String indexName, - String objectID, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = addOrUpdateObjectValidateBeforeCall( - indexName, - objectID, - body, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for appendSource - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call appendSourceCall( - Source source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = source; - - // create path and map variables - String requestPath = "/1/security/sources/append"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call appendSourceValidateBeforeCall( - Source source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'source' is set - if (source == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'source' when calling appendSource(Async)" - ); - } - - return appendSourceCall(source, callback); - } - - /** - * Add a single source to the list of allowed sources. - * - * @param source The source to add. (required) - * @return CreatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public CreatedAtResponse appendSource(Source source) - throws AlgoliaRuntimeException { - Call req = appendSourceValidateBeforeCall(source, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.AppendSource( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Add a single source to the list of allowed sources. - * - * @param source The source to add. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call appendSourceAsync( - Source source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = appendSourceValidateBeforeCall(source, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for assignUserId - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call assignUserIdCall( - String xAlgoliaUserID, - AssignUserIdParams assignUserIdParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = assignUserIdParams; - - // create path and map variables - String requestPath = "/1/clusters/mapping"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (xAlgoliaUserID != null) { - queryParams.addAll( - this.parameterToPair("X-Algolia-User-ID", xAlgoliaUserID) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call assignUserIdValidateBeforeCall( - String xAlgoliaUserID, - AssignUserIdParams assignUserIdParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'xAlgoliaUserID' is set - if (xAlgoliaUserID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'xAlgoliaUserID' when calling assignUserId(Async)" - ); - } - - // verify the required parameter 'assignUserIdParams' is set - if (assignUserIdParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'assignUserIdParams' when calling assignUserId(Async)" - ); - } - - return assignUserIdCall(xAlgoliaUserID, assignUserIdParams, callback); - } - - /** - * Assign or Move a userID to a cluster. The time it takes to migrate (move) a user is - * proportional to the amount of data linked to the userID. Upon success, the response is 200 OK. - * A successful response indicates that the operation has been taken into account, and the userID - * is directly usable. - * - * @param xAlgoliaUserID userID to assign. (required) - * @param assignUserIdParams (required) - * @return CreatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public CreatedAtResponse assignUserId( - String xAlgoliaUserID, - AssignUserIdParams assignUserIdParams - ) throws AlgoliaRuntimeException { - Call req = assignUserIdValidateBeforeCall( - xAlgoliaUserID, - assignUserIdParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.AssignUserId( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Assign or Move a userID to a cluster. The time it takes to migrate (move) a - * user is proportional to the amount of data linked to the userID. Upon success, the response is - * 200 OK. A successful response indicates that the operation has been taken into account, and the - * userID is directly usable. - * - * @param xAlgoliaUserID userID to assign. (required) - * @param assignUserIdParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call assignUserIdAsync( - String xAlgoliaUserID, - AssignUserIdParams assignUserIdParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = assignUserIdValidateBeforeCall( - xAlgoliaUserID, - assignUserIdParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for batch - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call batchCall( - String indexName, - BatchWriteParams batchWriteParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = batchWriteParams; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/batch".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call batchValidateBeforeCall( - String indexName, - BatchWriteParams batchWriteParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling batch(Async)" - ); - } - - // verify the required parameter 'batchWriteParams' is set - if (batchWriteParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'batchWriteParams' when calling batch(Async)" - ); - } - - return batchCall(indexName, batchWriteParams, callback); - } - - /** - * Performs multiple write operations in a single API call. - * - * @param indexName The index in which to perform the request. (required) - * @param batchWriteParams (required) - * @return BatchResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public BatchResponse batch( - String indexName, - BatchWriteParams batchWriteParams - ) throws AlgoliaRuntimeException { - Call req = batchValidateBeforeCall(indexName, batchWriteParams, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.Batch(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Performs multiple write operations in a single API call. - * - * @param indexName The index in which to perform the request. (required) - * @param batchWriteParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call batchAsync( - String indexName, - BatchWriteParams batchWriteParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = batchValidateBeforeCall(indexName, batchWriteParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for batchAssignUserIds - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call batchAssignUserIdsCall( - String xAlgoliaUserID, - BatchAssignUserIdsParams batchAssignUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = batchAssignUserIdsParams; - - // create path and map variables - String requestPath = "/1/clusters/mapping/batch"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (xAlgoliaUserID != null) { - queryParams.addAll( - this.parameterToPair("X-Algolia-User-ID", xAlgoliaUserID) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call batchAssignUserIdsValidateBeforeCall( - String xAlgoliaUserID, - BatchAssignUserIdsParams batchAssignUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'xAlgoliaUserID' is set - if (xAlgoliaUserID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'xAlgoliaUserID' when calling batchAssignUserIds(Async)" - ); - } - - // verify the required parameter 'batchAssignUserIdsParams' is set - if (batchAssignUserIdsParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'batchAssignUserIdsParams' when calling" + - " batchAssignUserIds(Async)" - ); - } - - return batchAssignUserIdsCall( - xAlgoliaUserID, - batchAssignUserIdsParams, - callback - ); - } - - /** - * Assign multiple userIDs to a cluster. Upon success, the response is 200 OK. A successful - * response indicates that the operation has been taken into account, and the userIDs are directly - * usable. - * - * @param xAlgoliaUserID userID to assign. (required) - * @param batchAssignUserIdsParams (required) - * @return CreatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public CreatedAtResponse batchAssignUserIds( - String xAlgoliaUserID, - BatchAssignUserIdsParams batchAssignUserIdsParams - ) throws AlgoliaRuntimeException { - Call req = batchAssignUserIdsValidateBeforeCall( - xAlgoliaUserID, - batchAssignUserIdsParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.BatchAssignUserIds( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Assign multiple userIDs to a cluster. Upon success, the response is 200 OK. A - * successful response indicates that the operation has been taken into account, and the userIDs - * are directly usable. - * - * @param xAlgoliaUserID userID to assign. (required) - * @param batchAssignUserIdsParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call batchAssignUserIdsAsync( - String xAlgoliaUserID, - BatchAssignUserIdsParams batchAssignUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = batchAssignUserIdsValidateBeforeCall( - xAlgoliaUserID, - batchAssignUserIdsParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for batchDictionaryEntries - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call batchDictionaryEntriesCall( - DictionaryType dictionaryName, - BatchDictionaryEntriesParams batchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = batchDictionaryEntriesParams; - - // create path and map variables - String requestPath = - "/1/dictionaries/{dictionaryName}/batch".replaceAll( - "\\{dictionaryName\\}", - this.escapeString(dictionaryName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call batchDictionaryEntriesValidateBeforeCall( - DictionaryType dictionaryName, - BatchDictionaryEntriesParams batchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'dictionaryName' is set - if (dictionaryName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'dictionaryName' when calling" + - " batchDictionaryEntries(Async)" - ); - } - - // verify the required parameter 'batchDictionaryEntriesParams' is set - if (batchDictionaryEntriesParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'batchDictionaryEntriesParams' when calling" + - " batchDictionaryEntries(Async)" - ); - } - - return batchDictionaryEntriesCall( - dictionaryName, - batchDictionaryEntriesParams, - callback - ); - } - - /** - * Send a batch of dictionary entries. - * - * @param dictionaryName The dictionary to search in. (required) - * @param batchDictionaryEntriesParams (required) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse batchDictionaryEntries( - DictionaryType dictionaryName, - BatchDictionaryEntriesParams batchDictionaryEntriesParams - ) throws AlgoliaRuntimeException { - Call req = batchDictionaryEntriesValidateBeforeCall( - dictionaryName, - batchDictionaryEntriesParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.BatchDictionaryEntries( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Send a batch of dictionary entries. - * - * @param dictionaryName The dictionary to search in. (required) - * @param batchDictionaryEntriesParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call batchDictionaryEntriesAsync( - DictionaryType dictionaryName, - BatchDictionaryEntriesParams batchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = batchDictionaryEntriesValidateBeforeCall( - dictionaryName, - batchDictionaryEntriesParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for batchRules - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call batchRulesCall( - String indexName, - List rule, - Boolean forwardToReplicas, - Boolean clearExistingRules, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = rule; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/batch".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - if (clearExistingRules != null) { - queryParams.addAll( - this.parameterToPair("clearExistingRules", clearExistingRules) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call batchRulesValidateBeforeCall( - String indexName, - List rule, - Boolean forwardToReplicas, - Boolean clearExistingRules, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling batchRules(Async)" - ); - } - - // verify the required parameter 'rule' is set - if (rule == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'rule' when calling batchRules(Async)" - ); - } - - return batchRulesCall( - indexName, - rule, - forwardToReplicas, - clearExistingRules, - callback - ); - } - - /** - * Create or update a batch of Rules. - * - * @param indexName The index in which to perform the request. (required) - * @param rule (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param clearExistingRules When true, existing Rules are cleared before adding this batch. When - * false, existing Rules are kept. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse batchRules( - String indexName, - List rule, - Boolean forwardToReplicas, - Boolean clearExistingRules - ) throws AlgoliaRuntimeException { - Call req = batchRulesValidateBeforeCall( - indexName, - rule, - forwardToReplicas, - clearExistingRules, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.BatchRules(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse batchRules(String indexName, List rule) - throws AlgoliaRuntimeException { - return this.batchRules(indexName, rule, null, null); - } - - /** - * (asynchronously) Create or update a batch of Rules. - * - * @param indexName The index in which to perform the request. (required) - * @param rule (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param clearExistingRules When true, existing Rules are cleared before adding this batch. When - * false, existing Rules are kept. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call batchRulesAsync( - String indexName, - List rule, - Boolean forwardToReplicas, - Boolean clearExistingRules, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = batchRulesValidateBeforeCall( - indexName, - rule, - forwardToReplicas, - clearExistingRules, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for browse - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call browseCall( - String indexName, - BrowseRequest browseRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = browseRequest; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/browse".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call browseValidateBeforeCall( - String indexName, - BrowseRequest browseRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling browse(Async)" - ); - } - - return browseCall(indexName, browseRequest, callback); - } - - /** - * This method allows you to retrieve all index content. It can retrieve up to 1,000 records per - * call and supports full text search and filters. For performance reasons, some features are not - * supported, including `distinct`, sorting by `typos`, `words` or `geo distance`. When there is - * more content to be browsed, the response contains a cursor field. This cursor has to be passed - * to the subsequent call to browse in order to get the next page of results. When the end of the - * index has been reached, the cursor field is absent from the response. - * - * @param indexName The index in which to perform the request. (required) - * @param browseRequest (optional) - * @return BrowseResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public BrowseResponse browse(String indexName, BrowseRequest browseRequest) - throws AlgoliaRuntimeException { - Call req = browseValidateBeforeCall(indexName, browseRequest, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.Browse(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public BrowseResponse browse(String indexName) - throws AlgoliaRuntimeException { - return this.browse(indexName, null); - } - - /** - * (asynchronously) This method allows you to retrieve all index content. It can retrieve up to - * 1,000 records per call and supports full text search and filters. For performance reasons, some - * features are not supported, including `distinct`, sorting by `typos`, - * `words` or `geo distance`. When there is more content to be browsed, the - * response contains a cursor field. This cursor has to be passed to the subsequent call to browse - * in order to get the next page of results. When the end of the index has been reached, the - * cursor field is absent from the response. - * - * @param indexName The index in which to perform the request. (required) - * @param browseRequest (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call browseAsync( - String indexName, - BrowseRequest browseRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = browseValidateBeforeCall(indexName, browseRequest, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for clearAllSynonyms - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call clearAllSynonymsCall( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/clear".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call clearAllSynonymsValidateBeforeCall( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling clearAllSynonyms(Async)" - ); - } - - return clearAllSynonymsCall(indexName, forwardToReplicas, callback); - } - - /** - * Remove all synonyms from an index. - * - * @param indexName The index in which to perform the request. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse clearAllSynonyms( - String indexName, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = clearAllSynonymsValidateBeforeCall( - indexName, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.ClearAllSynonyms( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse clearAllSynonyms(String indexName) - throws AlgoliaRuntimeException { - return this.clearAllSynonyms(indexName, null); - } - - /** - * (asynchronously) Remove all synonyms from an index. - * - * @param indexName The index in which to perform the request. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call clearAllSynonymsAsync( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = clearAllSynonymsValidateBeforeCall( - indexName, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for clearObjects - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call clearObjectsCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/clear".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call clearObjectsValidateBeforeCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling clearObjects(Async)" - ); - } - - return clearObjectsCall(indexName, callback); - } - - /** - * Delete an index's content, but leave settings and index-specific API keys untouched. - * - * @param indexName The index in which to perform the request. (required) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse clearObjects(String indexName) - throws AlgoliaRuntimeException { - Call req = clearObjectsValidateBeforeCall(indexName, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.ClearObjects( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Delete an index's content, but leave settings and index-specific API keys - * untouched. - * - * @param indexName The index in which to perform the request. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call clearObjectsAsync( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = clearObjectsValidateBeforeCall(indexName, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for clearRules - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call clearRulesCall( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/clear".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call clearRulesValidateBeforeCall( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling clearRules(Async)" - ); - } - - return clearRulesCall(indexName, forwardToReplicas, callback); - } - - /** - * Delete all Rules in the index. - * - * @param indexName The index in which to perform the request. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse clearRules( - String indexName, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = clearRulesValidateBeforeCall(indexName, forwardToReplicas, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.ClearRules(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse clearRules(String indexName) - throws AlgoliaRuntimeException { - return this.clearRules(indexName, null); - } - - /** - * (asynchronously) Delete all Rules in the index. - * - * @param indexName The index in which to perform the request. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call clearRulesAsync( - String indexName, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = clearRulesValidateBeforeCall( - indexName, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for del - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call delCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair( - parameter.getKey(), - parameter.getValue().toString() - ) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call delValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling del(Async)" - ); - } - - return delCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object del(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = delValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.Del(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object del(String path) throws AlgoliaRuntimeException { - return this.del(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call delAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = delValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteApiKey - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteApiKeyCall( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/keys/{key}".replaceAll( - "\\{key\\}", - this.escapeString(key.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteApiKeyValidateBeforeCall( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'key' is set - if (key == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'key' when calling deleteApiKey(Async)" - ); - } - - return deleteApiKeyCall(key, callback); - } - - /** - * Delete an existing API Key. - * - * @param key API Key string. (required) - * @return DeleteApiKeyResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeleteApiKeyResponse deleteApiKey(String key) - throws AlgoliaRuntimeException { - Call req = deleteApiKeyValidateBeforeCall(key, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.DeleteApiKey( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Delete an existing API Key. - * - * @param key API Key string. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteApiKeyAsync( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteApiKeyValidateBeforeCall(key, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteBy - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteByCall( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchParams; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/deleteByQuery".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteByValidateBeforeCall( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteBy(Async)" - ); - } - - // verify the required parameter 'searchParams' is set - if (searchParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'searchParams' when calling deleteBy(Async)" - ); - } - - return deleteByCall(indexName, searchParams, callback); - } - - /** - * Remove all objects matching a filter (including geo filters). This method enables you to delete - * one or more objects based on filters (numeric, facet, tag or geo queries). It doesn't accept - * empty filters or a query. - * - * @param indexName The index in which to perform the request. (required) - * @param searchParams (required) - * @return DeletedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeletedAtResponse deleteBy( - String indexName, - SearchParams searchParams - ) throws AlgoliaRuntimeException { - Call req = deleteByValidateBeforeCall(indexName, searchParams, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.DeleteBy(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Remove all objects matching a filter (including geo filters). This method - * enables you to delete one or more objects based on filters (numeric, facet, tag or geo - * queries). It doesn't accept empty filters or a query. - * - * @param indexName The index in which to perform the request. (required) - * @param searchParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteByAsync( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteByValidateBeforeCall(indexName, searchParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteIndex - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteIndexCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteIndexValidateBeforeCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteIndex(Async)" - ); - } - - return deleteIndexCall(indexName, callback); - } - - /** - * Delete an existing index. - * - * @param indexName The index in which to perform the request. (required) - * @return DeletedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeletedAtResponse deleteIndex(String indexName) - throws AlgoliaRuntimeException { - Call req = deleteIndexValidateBeforeCall(indexName, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.DeleteIndex( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Delete an existing index. - * - * @param indexName The index in which to perform the request. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteIndexAsync( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteIndexValidateBeforeCall(indexName, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteObject - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteObjectCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteObjectValidateBeforeCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteObject(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling deleteObject(Async)" - ); - } - - return deleteObjectCall(indexName, objectID, callback); - } - - /** - * Delete an existing object. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @return DeletedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeletedAtResponse deleteObject(String indexName, String objectID) - throws AlgoliaRuntimeException { - Call req = deleteObjectValidateBeforeCall(indexName, objectID, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.DeleteObject( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Delete an existing object. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteObjectAsync( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteObjectValidateBeforeCall(indexName, objectID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteRule - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteRuleCall( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteRuleValidateBeforeCall( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteRule(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling deleteRule(Async)" - ); - } - - return deleteRuleCall(indexName, objectID, forwardToReplicas, callback); - } - - /** - * Delete the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse deleteRule( - String indexName, - String objectID, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = deleteRuleValidateBeforeCall( - indexName, - objectID, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.DeleteRule(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse deleteRule(String indexName, String objectID) - throws AlgoliaRuntimeException { - return this.deleteRule(indexName, objectID, null); - } - - /** - * (asynchronously) Delete the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteRuleAsync( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteRuleValidateBeforeCall( - indexName, - objectID, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteSource - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteSourceCall( - String source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/security/sources/{source}".replaceAll( - "\\{source\\}", - this.escapeString(source.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteSourceValidateBeforeCall( - String source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'source' is set - if (source == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'source' when calling deleteSource(Async)" - ); - } - - return deleteSourceCall(source, callback); - } - - /** - * Remove a single source from the list of allowed sources. - * - * @param source The IP range of the source. (required) - * @return DeleteSourceResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeleteSourceResponse deleteSource(String source) - throws AlgoliaRuntimeException { - Call req = deleteSourceValidateBeforeCall(source, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.DeleteSource( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Remove a single source from the list of allowed sources. - * - * @param source The IP range of the source. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteSourceAsync( - String source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteSourceValidateBeforeCall(source, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for deleteSynonym - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call deleteSynonymCall( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call deleteSynonymValidateBeforeCall( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling deleteSynonym(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling deleteSynonym(Async)" - ); - } - - return deleteSynonymCall(indexName, objectID, forwardToReplicas, callback); - } - - /** - * Delete a single synonyms set, identified by the given objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return DeletedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public DeletedAtResponse deleteSynonym( - String indexName, - String objectID, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = deleteSynonymValidateBeforeCall( - indexName, - objectID, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.DeleteSynonym( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public DeletedAtResponse deleteSynonym(String indexName, String objectID) - throws AlgoliaRuntimeException { - return this.deleteSynonym(indexName, objectID, null); - } - - /** - * (asynchronously) Delete a single synonyms set, identified by the given objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call deleteSynonymAsync( - String indexName, - String objectID, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = deleteSynonymValidateBeforeCall( - indexName, - objectID, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for get - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair( - parameter.getKey(), - parameter.getValue().toString() - ) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getValidateBeforeCall( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling get(Async)" - ); - } - - return getCall(path, parameters, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object get(String path, Map parameters) - throws AlgoliaRuntimeException { - Call req = getValidateBeforeCall(path, parameters, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.Get(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object get(String path) throws AlgoliaRuntimeException { - return this.get(path, new HashMap<>()); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getAsync( - String path, - Map parameters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getValidateBeforeCall(path, parameters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getApiKey - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getApiKeyCall(String key, final ApiCallback callback) - throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/keys/{key}".replaceAll( - "\\{key\\}", - this.escapeString(key.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getApiKeyValidateBeforeCall( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'key' is set - if (key == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'key' when calling getApiKey(Async)" - ); - } - - return getApiKeyCall(key, callback); - } - - /** - * Get the permissions of an API key. - * - * @param key API Key string. (required) - * @return Key - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Key getApiKey(String key) throws AlgoliaRuntimeException { - Call req = getApiKeyValidateBeforeCall(key, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetApiKey(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get the permissions of an API key. - * - * @param key API Key string. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getApiKeyAsync(String key, final ApiCallback callback) - throws AlgoliaRuntimeException { - Call call = getApiKeyValidateBeforeCall(key, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getDictionaryLanguages - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getDictionaryLanguagesCall( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/dictionaries/*/languages"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getDictionaryLanguagesValidateBeforeCall( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - return getDictionaryLanguagesCall(callback); - } - - /** - * List dictionaries supported per language. - * - * @return Map<String, Languages> - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Map getDictionaryLanguages() - throws AlgoliaRuntimeException { - Call req = getDictionaryLanguagesValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetDictionaryLanguages( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken>() {}.getType(); - ApiResponse> res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) List dictionaries supported per language. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getDictionaryLanguagesAsync( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Call call = getDictionaryLanguagesValidateBeforeCall(callback); - Type returnType = new TypeToken>() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getDictionarySettings - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getDictionarySettingsCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/dictionaries/*/settings"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getDictionarySettingsValidateBeforeCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return getDictionarySettingsCall(callback); - } - - /** - * Retrieve dictionaries settings. - * - * @return GetDictionarySettingsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetDictionarySettingsResponse getDictionarySettings() - throws AlgoliaRuntimeException { - Call req = getDictionarySettingsValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetDictionarySettings( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Retrieve dictionaries settings. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getDictionarySettingsAsync( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getDictionarySettingsValidateBeforeCall(callback); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getLogs - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getLogsCall( - Integer offset, - Integer length, - String indexName, - LogType type, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/logs"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (offset != null) { - queryParams.addAll(this.parameterToPair("offset", offset)); - } - - if (length != null) { - queryParams.addAll(this.parameterToPair("length", length)); - } - - if (indexName != null) { - queryParams.addAll(this.parameterToPair("indexName", indexName)); - } - - if (type != null) { - queryParams.addAll(this.parameterToPair("type", type)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getLogsValidateBeforeCall( - Integer offset, - Integer length, - String indexName, - LogType type, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return getLogsCall(offset, length, indexName, type, callback); - } - - /** - * Return the lastest log entries. - * - * @param offset First entry to retrieve (zero-based). Log entries are sorted by decreasing date, - * therefore 0 designates the most recent log entry. (optional, default to 0) - * @param length Maximum number of entries to retrieve. The maximum allowed value is 1000. - * (optional, default to 10) - * @param indexName Index for which log entries should be retrieved. When omitted, log entries are - * retrieved across all indices. (optional) - * @param type Type of log entries to retrieve. When omitted, all log entries are retrieved. - * (optional, default to all) - * @return GetLogsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetLogsResponse getLogs( - Integer offset, - Integer length, - String indexName, - LogType type - ) throws AlgoliaRuntimeException { - Call req = getLogsValidateBeforeCall(offset, length, indexName, type, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetLogs(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public GetLogsResponse getLogs() throws AlgoliaRuntimeException { - return this.getLogs(0, 10, null, LogType.ALL); - } - - /** - * (asynchronously) Return the lastest log entries. - * - * @param offset First entry to retrieve (zero-based). Log entries are sorted by decreasing date, - * therefore 0 designates the most recent log entry. (optional, default to 0) - * @param length Maximum number of entries to retrieve. The maximum allowed value is 1000. - * (optional, default to 10) - * @param indexName Index for which log entries should be retrieved. When omitted, log entries are - * retrieved across all indices. (optional) - * @param type Type of log entries to retrieve. When omitted, all log entries are retrieved. - * (optional, default to all) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getLogsAsync( - Integer offset, - Integer length, - String indexName, - LogType type, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getLogsValidateBeforeCall( - offset, - length, - indexName, - type, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getObject - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getObjectCall( - String indexName, - String objectID, - List attributesToRetrieve, - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (attributesToRetrieve != null) { - queryParams.addAll( - this.parameterToPair("attributesToRetrieve", attributesToRetrieve) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getObjectValidateBeforeCall( - String indexName, - String objectID, - List attributesToRetrieve, - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getObject(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling getObject(Async)" - ); - } - - return getObjectCall(indexName, objectID, attributesToRetrieve, callback); - } - - /** - * Retrieve one object from the index. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param attributesToRetrieve List of attributes to retrieve. If not specified, all retrievable - * attributes are returned. (optional) - * @return Map<String, String> - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Map getObject( - String indexName, - String objectID, - List attributesToRetrieve - ) throws AlgoliaRuntimeException { - Call req = getObjectValidateBeforeCall( - indexName, - objectID, - attributesToRetrieve, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetObject(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken>() {}.getType(); - ApiResponse> res = this.execute(call, returnType); - return res.getData(); - } - - public Map getObject(String indexName, String objectID) - throws AlgoliaRuntimeException { - return this.getObject(indexName, objectID, new ArrayList<>()); - } - - /** - * (asynchronously) Retrieve one object from the index. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param attributesToRetrieve List of attributes to retrieve. If not specified, all retrievable - * attributes are returned. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getObjectAsync( - String indexName, - String objectID, - List attributesToRetrieve, - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - Call call = getObjectValidateBeforeCall( - indexName, - objectID, - attributesToRetrieve, - callback - ); - Type returnType = new TypeToken>() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getObjects - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getObjectsCall( - GetObjectsParams getObjectsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = getObjectsParams; - - // create path and map variables - String requestPath = "/1/indexes/*/objects"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getObjectsValidateBeforeCall( - GetObjectsParams getObjectsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'getObjectsParams' is set - if (getObjectsParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'getObjectsParams' when calling getObjects(Async)" - ); - } - - return getObjectsCall(getObjectsParams, callback); - } - - /** - * Retrieve one or more objects, potentially from different indices, in a single API call. - * - * @param getObjectsParams (required) - * @return GetObjectsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetObjectsResponse getObjects(GetObjectsParams getObjectsParams) - throws AlgoliaRuntimeException { - Call req = getObjectsValidateBeforeCall(getObjectsParams, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetObjects(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Retrieve one or more objects, potentially from different indices, in a single - * API call. - * - * @param getObjectsParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getObjectsAsync( - GetObjectsParams getObjectsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getObjectsValidateBeforeCall(getObjectsParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getRule - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getRuleCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getRuleValidateBeforeCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getRule(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling getRule(Async)" - ); - } - - return getRuleCall(indexName, objectID, callback); - } - - /** - * Retrieve the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @return Rule - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Rule getRule(String indexName, String objectID) - throws AlgoliaRuntimeException { - Call req = getRuleValidateBeforeCall(indexName, objectID, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetRule(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Retrieve the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getRuleAsync( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getRuleValidateBeforeCall(indexName, objectID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getSettings - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getSettingsCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/settings".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getSettingsValidateBeforeCall( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getSettings(Async)" - ); - } - - return getSettingsCall(indexName, callback); - } - - /** - * Retrieve settings of a given indexName. - * - * @param indexName The index in which to perform the request. (required) - * @return IndexSettings - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public IndexSettings getSettings(String indexName) - throws AlgoliaRuntimeException { - Call req = getSettingsValidateBeforeCall(indexName, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetSettings( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Retrieve settings of a given indexName. - * - * @param indexName The index in which to perform the request. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getSettingsAsync( - String indexName, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getSettingsValidateBeforeCall(indexName, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getSources - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getSourcesCall(final ApiCallback> callback) - throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/security/sources"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getSourcesValidateBeforeCall( - final ApiCallback> callback - ) throws AlgoliaRuntimeException { - return getSourcesCall(callback); - } - - /** - * List all allowed sources. - * - * @return List<Source> - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public List getSources() throws AlgoliaRuntimeException { - Call req = getSourcesValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetSources(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken>() {}.getType(); - ApiResponse> res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) List all allowed sources. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getSourcesAsync(final ApiCallback> callback) - throws AlgoliaRuntimeException { - Call call = getSourcesValidateBeforeCall(callback); - Type returnType = new TypeToken>() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getSynonym - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getSynonymCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getSynonymValidateBeforeCall( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getSynonym(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling getSynonym(Async)" - ); - } - - return getSynonymCall(indexName, objectID, callback); - } - - /** - * Fetch a synonym object identified by its objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @return SynonymHit - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SynonymHit getSynonym(String indexName, String objectID) - throws AlgoliaRuntimeException { - Call req = getSynonymValidateBeforeCall(indexName, objectID, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetSynonym(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Fetch a synonym object identified by its objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getSynonymAsync( - String indexName, - String objectID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getSynonymValidateBeforeCall(indexName, objectID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getTask - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getTaskCall( - String indexName, - Integer taskID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/task/{taskID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{taskID\\}", this.escapeString(taskID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getTaskValidateBeforeCall( - String indexName, - Integer taskID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling getTask(Async)" - ); - } - - // verify the required parameter 'taskID' is set - if (taskID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'taskID' when calling getTask(Async)" - ); - } - - return getTaskCall(indexName, taskID, callback); - } - - /** - * Check the current status of a given task. - * - * @param indexName The index in which to perform the request. (required) - * @param taskID Unique identifier of an task. Numeric value (up to 64bits). (required) - * @return GetTaskResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetTaskResponse getTask(String indexName, Integer taskID) - throws AlgoliaRuntimeException { - Call req = getTaskValidateBeforeCall(indexName, taskID, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetTask(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Check the current status of a given task. - * - * @param indexName The index in which to perform the request. (required) - * @param taskID Unique identifier of an task. Numeric value (up to 64bits). (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getTaskAsync( - String indexName, - Integer taskID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getTaskValidateBeforeCall(indexName, taskID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getTopUserIds - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getTopUserIdsCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/clusters/mapping/top"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getTopUserIdsValidateBeforeCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return getTopUserIdsCall(callback); - } - - /** - * Get the top 10 userIDs with the highest number of records per cluster. The data returned will - * usually be a few seconds behind real time, because userID usage may take up to a few seconds to - * propagate to the different clusters. Upon success, the response is 200 OK and contains the - * following array of userIDs and clusters. - * - * @return GetTopUserIdsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public GetTopUserIdsResponse getTopUserIds() throws AlgoliaRuntimeException { - Call req = getTopUserIdsValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetTopUserIds( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get the top 10 userIDs with the highest number of records per cluster. The - * data returned will usually be a few seconds behind real time, because userID usage may take up - * to a few seconds to propagate to the different clusters. Upon success, the response is 200 OK - * and contains the following array of userIDs and clusters. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getTopUserIdsAsync( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = getTopUserIdsValidateBeforeCall(callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for getUserId - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call getUserIdCall(String userID, final ApiCallback callback) - throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/clusters/mapping/{userID}".replaceAll( - "\\{userID\\}", - this.escapeString(userID.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call getUserIdValidateBeforeCall( - String userID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'userID' is set - if (userID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'userID' when calling getUserId(Async)" - ); - } - - return getUserIdCall(userID, callback); - } - - /** - * Returns the userID data stored in the mapping. The data returned will usually be a few seconds - * behind real time, because userID usage may take up to a few seconds to propagate to the - * different clusters. Upon success, the response is 200 OK and contains the following userID - * data. - * - * @param userID userID to assign. (required) - * @return UserId - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UserId getUserId(String userID) throws AlgoliaRuntimeException { - Call req = getUserIdValidateBeforeCall(userID, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.GetUserId(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Returns the userID data stored in the mapping. The data returned will usually - * be a few seconds behind real time, because userID usage may take up to a few seconds to - * propagate to the different clusters. Upon success, the response is 200 OK and contains the - * following userID data. - * - * @param userID userID to assign. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call getUserIdAsync(String userID, final ApiCallback callback) - throws AlgoliaRuntimeException { - Call call = getUserIdValidateBeforeCall(userID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for hasPendingMappings - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call hasPendingMappingsCall( - Boolean getClusters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/clusters/mapping/pending"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (getClusters != null) { - queryParams.addAll(this.parameterToPair("getClusters", getClusters)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call hasPendingMappingsValidateBeforeCall( - Boolean getClusters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return hasPendingMappingsCall(getClusters, callback); - } - - /** - * Get the status of your clusters' migrations or user creations. Creating a large batch of users - * or migrating your multi-cluster may take quite some time. This method lets you retrieve the - * status of the migration, so you can know when it's done. Upon success, the response is 200 OK. - * A successful response indicates that the operation has been taken into account, and the userIDs - * are directly usable. - * - * @param getClusters Whether to get clusters or not. (optional) - * @return CreatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public CreatedAtResponse hasPendingMappings(Boolean getClusters) - throws AlgoliaRuntimeException { - Call req = hasPendingMappingsValidateBeforeCall(getClusters, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.HasPendingMappings( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public CreatedAtResponse hasPendingMappings() throws AlgoliaRuntimeException { - return this.hasPendingMappings(null); - } - - /** - * (asynchronously) Get the status of your clusters' migrations or user creations. Creating a - * large batch of users or migrating your multi-cluster may take quite some time. This method lets - * you retrieve the status of the migration, so you can know when it's done. Upon success, the - * response is 200 OK. A successful response indicates that the operation has been taken into - * account, and the userIDs are directly usable. - * - * @param getClusters Whether to get clusters or not. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call hasPendingMappingsAsync( - Boolean getClusters, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = hasPendingMappingsValidateBeforeCall(getClusters, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for listApiKeys - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call listApiKeysCall(final ApiCallback callback) - throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/keys"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call listApiKeysValidateBeforeCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return listApiKeysCall(callback); - } - - /** - * List API keys, along with their associated rights. - * - * @return ListApiKeysResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ListApiKeysResponse listApiKeys() throws AlgoliaRuntimeException { - Call req = listApiKeysValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.ListApiKeys( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) List API keys, along with their associated rights. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call listApiKeysAsync(final ApiCallback callback) - throws AlgoliaRuntimeException { - Call call = listApiKeysValidateBeforeCall(callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for listClusters - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call listClustersCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/clusters"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call listClustersValidateBeforeCall( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return listClustersCall(callback); - } - - /** - * List the clusters available in a multi-clusters setup for a single appID. Upon success, the - * response is 200 OK and contains the following clusters. - * - * @return ListClustersResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ListClustersResponse listClusters() throws AlgoliaRuntimeException { - Call req = listClustersValidateBeforeCall(null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.ListClusters( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) List the clusters available in a multi-clusters setup for a single appID. Upon - * success, the response is 200 OK and contains the following clusters. - * - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call listClustersAsync( - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = listClustersValidateBeforeCall(callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for listIndices - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call listIndicesCall( - Integer page, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/indexes"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (page != null) { - queryParams.addAll(this.parameterToPair("page", page)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call listIndicesValidateBeforeCall( - Integer page, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return listIndicesCall(page, callback); - } - - /** - * List existing indexes from an application. - * - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional) - * @return ListIndicesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ListIndicesResponse listIndices(Integer page) - throws AlgoliaRuntimeException { - Call req = listIndicesValidateBeforeCall(page, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.ListIndices( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public ListIndicesResponse listIndices() throws AlgoliaRuntimeException { - return this.listIndices(null); - } - - /** - * (asynchronously) List existing indexes from an application. - * - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call listIndicesAsync( - Integer page, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = listIndicesValidateBeforeCall(page, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for listUserIds - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call listUserIdsCall( - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = "/1/clusters/mapping"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (page != null) { - queryParams.addAll(this.parameterToPair("page", page)); - } - - if (hitsPerPage != null) { - queryParams.addAll(this.parameterToPair("hitsPerPage", hitsPerPage)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "GET", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call listUserIdsValidateBeforeCall( - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - return listUserIdsCall(page, hitsPerPage, callback); - } - - /** - * List the userIDs assigned to a multi-clusters appID. The data returned will usually be a few - * seconds behind real time, because userID usage may take up to a few seconds to propagate to the - * different clusters. Upon success, the response is 200 OK and contains the following userIDs - * data. - * - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional) - * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) - * @return ListUserIdsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ListUserIdsResponse listUserIds(Integer page, Integer hitsPerPage) - throws AlgoliaRuntimeException { - Call req = listUserIdsValidateBeforeCall(page, hitsPerPage, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.ListUserIds( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public ListUserIdsResponse listUserIds() throws AlgoliaRuntimeException { - return this.listUserIds(null, 100); - } - - /** - * (asynchronously) List the userIDs assigned to a multi-clusters appID. The data returned will - * usually be a few seconds behind real time, because userID usage may take up to a few seconds to - * propagate to the different clusters. Upon success, the response is 200 OK and contains the - * following userIDs data. - * - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional) - * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call listUserIdsAsync( - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = listUserIdsValidateBeforeCall(page, hitsPerPage, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for multipleBatch - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call multipleBatchCall( - BatchParams batchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = batchParams; - - // create path and map variables - String requestPath = "/1/indexes/*/batch"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call multipleBatchValidateBeforeCall( - BatchParams batchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'batchParams' is set - if (batchParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'batchParams' when calling multipleBatch(Async)" - ); - } - - return multipleBatchCall(batchParams, callback); - } - - /** - * Perform multiple write operations, potentially targeting multiple indices, in a single API - * call. - * - * @param batchParams (required) - * @return MultipleBatchResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public MultipleBatchResponse multipleBatch(BatchParams batchParams) - throws AlgoliaRuntimeException { - Call req = multipleBatchValidateBeforeCall(batchParams, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.MultipleBatch( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Perform multiple write operations, potentially targeting multiple indices, in - * a single API call. - * - * @param batchParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call multipleBatchAsync( - BatchParams batchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = multipleBatchValidateBeforeCall(batchParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for multipleQueries - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call multipleQueriesCall( - MultipleQueriesParams multipleQueriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = multipleQueriesParams; - - // create path and map variables - String requestPath = "/1/indexes/*/queries"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call multipleQueriesValidateBeforeCall( - MultipleQueriesParams multipleQueriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'multipleQueriesParams' is set - if (multipleQueriesParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'multipleQueriesParams' when calling" + - " multipleQueries(Async)" - ); - } - - return multipleQueriesCall(multipleQueriesParams, callback); - } - - /** - * Get search results for the given requests. - * - * @param multipleQueriesParams (required) - * @return MultipleQueriesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public MultipleQueriesResponse multipleQueries( - MultipleQueriesParams multipleQueriesParams - ) throws AlgoliaRuntimeException { - Call req = multipleQueriesValidateBeforeCall(multipleQueriesParams, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.MultipleQueries( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get search results for the given requests. - * - * @param multipleQueriesParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call multipleQueriesAsync( - MultipleQueriesParams multipleQueriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = multipleQueriesValidateBeforeCall( - multipleQueriesParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for operationIndex - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call operationIndexCall( - String indexName, - OperationIndexParams operationIndexParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = operationIndexParams; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/operation".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call operationIndexValidateBeforeCall( - String indexName, - OperationIndexParams operationIndexParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling operationIndex(Async)" - ); - } - - // verify the required parameter 'operationIndexParams' is set - if (operationIndexParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'operationIndexParams' when calling" + - " operationIndex(Async)" - ); - } - - return operationIndexCall(indexName, operationIndexParams, callback); - } - - /** - * Peforms a copy or a move operation on a index. - * - * @param indexName The index in which to perform the request. (required) - * @param operationIndexParams (required) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse operationIndex( - String indexName, - OperationIndexParams operationIndexParams - ) throws AlgoliaRuntimeException { - Call req = operationIndexValidateBeforeCall( - indexName, - operationIndexParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.OperationIndex( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Peforms a copy or a move operation on a index. - * - * @param indexName The index in which to perform the request. (required) - * @param operationIndexParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call operationIndexAsync( - String indexName, - OperationIndexParams operationIndexParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = operationIndexValidateBeforeCall( - indexName, - operationIndexParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for partialUpdateObject - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call partialUpdateObjectCall( - String indexName, - String objectID, - List> attributeOrBuiltInOperation, - Boolean createIfNotExists, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = attributeOrBuiltInOperation; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/{objectID}/partial".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (createIfNotExists != null) { - queryParams.addAll( - this.parameterToPair("createIfNotExists", createIfNotExists) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call partialUpdateObjectValidateBeforeCall( - String indexName, - String objectID, - List> attributeOrBuiltInOperation, - Boolean createIfNotExists, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling partialUpdateObject(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling partialUpdateObject(Async)" - ); - } - - // verify the required parameter 'attributeOrBuiltInOperation' is set - if (attributeOrBuiltInOperation == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'attributeOrBuiltInOperation' when calling" + - " partialUpdateObject(Async)" - ); - } - - return partialUpdateObjectCall( - indexName, - objectID, - attributeOrBuiltInOperation, - createIfNotExists, - callback - ); - } - - /** - * Update one or more attributes of an existing object. This method lets you update only a part of - * an existing object, either by adding new attributes or updating existing ones. You can - * partially update several objects in a single method call. If the index targeted by this - * operation doesn't exist yet, it's automatically created. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param attributeOrBuiltInOperation List of attributes to update. (required) - * @param createIfNotExists Creates the record if it does not exist yet. (optional, default to - * true) - * @return UpdatedAtWithObjectIdResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtWithObjectIdResponse partialUpdateObject( - String indexName, - String objectID, - List> attributeOrBuiltInOperation, - Boolean createIfNotExists - ) throws AlgoliaRuntimeException { - Call req = partialUpdateObjectValidateBeforeCall( - indexName, - objectID, - attributeOrBuiltInOperation, - createIfNotExists, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.PartialUpdateObject( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtWithObjectIdResponse partialUpdateObject( - String indexName, - String objectID, - List> attributeOrBuiltInOperation - ) throws AlgoliaRuntimeException { - return this.partialUpdateObject( - indexName, - objectID, - attributeOrBuiltInOperation, - true - ); - } - - /** - * (asynchronously) Update one or more attributes of an existing object. This method lets you - * update only a part of an existing object, either by adding new attributes or updating existing - * ones. You can partially update several objects in a single method call. If the index targeted - * by this operation doesn't exist yet, it's automatically created. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param attributeOrBuiltInOperation List of attributes to update. (required) - * @param createIfNotExists Creates the record if it does not exist yet. (optional, default to - * true) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call partialUpdateObjectAsync( - String indexName, - String objectID, - List> attributeOrBuiltInOperation, - Boolean createIfNotExists, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = partialUpdateObjectValidateBeforeCall( - indexName, - objectID, - attributeOrBuiltInOperation, - createIfNotExists, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for post - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call postCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair( - parameter.getKey(), - parameter.getValue().toString() - ) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call postValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling post(Async)" - ); - } - - return postCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object post(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = postValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.Post(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object post(String path) throws AlgoliaRuntimeException { - return this.post(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call postAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = postValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for put - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call putCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = "/1{path}".replaceAll("\\{path\\}", path.toString()); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (parameters != null) { - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll( - this.parameterToPair( - parameter.getKey(), - parameter.getValue().toString() - ) - ); - } - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call putValidateBeforeCall( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'path' is set - if (path == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'path' when calling put(Async)" - ); - } - - return putCall(path, parameters, body, callback); - } - - /** - * This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @return Object - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public Object put(String path, Map parameters, Object body) - throws AlgoliaRuntimeException { - Call req = putValidateBeforeCall(path, parameters, body, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.Put(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public Object put(String path) throws AlgoliaRuntimeException { - return this.put(path, new HashMap<>(), null); - } - - /** - * (asynchronously) This method allow you to send requests to the Algolia REST API. - * - * @param path The path of the API endpoint to target, anything after the /1 needs to be - * specified. (required) - * @param parameters Query parameters to be applied to the current query. (optional) - * @param body The parameters to send with the custom request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call putAsync( - String path, - Map parameters, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = putValidateBeforeCall(path, parameters, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for removeUserId - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call removeUserIdCall( - String userID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/clusters/mapping/{userID}".replaceAll( - "\\{userID\\}", - this.escapeString(userID.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "DELETE", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call removeUserIdValidateBeforeCall( - String userID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'userID' is set - if (userID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'userID' when calling removeUserId(Async)" - ); - } - - return removeUserIdCall(userID, callback); - } - - /** - * Remove a userID and its associated data from the multi-clusters. Upon success, the response is - * 200 OK and a task is created to remove the userID data and mapping. - * - * @param userID userID to assign. (required) - * @return RemoveUserIdResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public RemoveUserIdResponse removeUserId(String userID) - throws AlgoliaRuntimeException { - Call req = removeUserIdValidateBeforeCall(userID, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.RemoveUserId( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Remove a userID and its associated data from the multi-clusters. Upon success, - * the response is 200 OK and a task is created to remove the userID data and mapping. - * - * @param userID userID to assign. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call removeUserIdAsync( - String userID, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = removeUserIdValidateBeforeCall(userID, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for replaceSources - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call replaceSourcesCall( - List source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = source; - - // create path and map variables - String requestPath = "/1/security/sources"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call replaceSourcesValidateBeforeCall( - List source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'source' is set - if (source == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'source' when calling replaceSources(Async)" - ); - } - - return replaceSourcesCall(source, callback); - } - - /** - * Replace all allowed sources. - * - * @param source The sources to allow. (required) - * @return ReplaceSourceResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public ReplaceSourceResponse replaceSources(List source) - throws AlgoliaRuntimeException { - Call req = replaceSourcesValidateBeforeCall(source, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.ReplaceSources( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Replace all allowed sources. - * - * @param source The sources to allow. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call replaceSourcesAsync( - List source, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = replaceSourcesValidateBeforeCall(source, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for restoreApiKey - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call restoreApiKeyCall( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/keys/{key}/restore".replaceAll( - "\\{key\\}", - this.escapeString(key.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call restoreApiKeyValidateBeforeCall( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'key' is set - if (key == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'key' when calling restoreApiKey(Async)" - ); - } - - return restoreApiKeyCall(key, callback); - } - - /** - * Restore a deleted API key, along with its associated rights. - * - * @param key API Key string. (required) - * @return AddApiKeyResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public AddApiKeyResponse restoreApiKey(String key) - throws AlgoliaRuntimeException { - Call req = restoreApiKeyValidateBeforeCall(key, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.RestoreApiKey( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Restore a deleted API key, along with its associated rights. - * - * @param key API Key string. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call restoreApiKeyAsync( - String key, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = restoreApiKeyValidateBeforeCall(key, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for saveObject - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call saveObjectCall( - String indexName, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = body; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call saveObjectValidateBeforeCall( - String indexName, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling saveObject(Async)" - ); - } - - // verify the required parameter 'body' is set - if (body == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'body' when calling saveObject(Async)" - ); - } - - return saveObjectCall(indexName, body, callback); - } - - /** - * Add an object to the index, automatically assigning it an object ID. - * - * @param indexName The index in which to perform the request. (required) - * @param body The Algolia record. (required) - * @return SaveObjectResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SaveObjectResponse saveObject(String indexName, Object body) - throws AlgoliaRuntimeException { - Call req = saveObjectValidateBeforeCall(indexName, body, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SaveObject(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Add an object to the index, automatically assigning it an object ID. - * - * @param indexName The index in which to perform the request. (required) - * @param body The Algolia record. (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call saveObjectAsync( - String indexName, - Object body, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = saveObjectValidateBeforeCall(indexName, body, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for saveRule - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call saveRuleCall( - String indexName, - String objectID, - Rule rule, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = rule; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call saveRuleValidateBeforeCall( - String indexName, - String objectID, - Rule rule, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling saveRule(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling saveRule(Async)" - ); - } - - // verify the required parameter 'rule' is set - if (rule == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'rule' when calling saveRule(Async)" - ); - } - - return saveRuleCall(indexName, objectID, rule, forwardToReplicas, callback); - } - - /** - * Create or update the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param rule (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return UpdatedRuleResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedRuleResponse saveRule( - String indexName, - String objectID, - Rule rule, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = saveRuleValidateBeforeCall( - indexName, - objectID, - rule, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SaveRule(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedRuleResponse saveRule( - String indexName, - String objectID, - Rule rule - ) throws AlgoliaRuntimeException { - return this.saveRule(indexName, objectID, rule, null); - } - - /** - * (asynchronously) Create or update the Rule with the specified objectID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param rule (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call saveRuleAsync( - String indexName, - String objectID, - Rule rule, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = saveRuleValidateBeforeCall( - indexName, - objectID, - rule, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for saveSynonym - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call saveSynonymCall( - String indexName, - String objectID, - SynonymHit synonymHit, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = synonymHit; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/{objectID}".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{objectID\\}", this.escapeString(objectID.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call saveSynonymValidateBeforeCall( - String indexName, - String objectID, - SynonymHit synonymHit, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling saveSynonym(Async)" - ); - } - - // verify the required parameter 'objectID' is set - if (objectID == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'objectID' when calling saveSynonym(Async)" - ); - } - - // verify the required parameter 'synonymHit' is set - if (synonymHit == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'synonymHit' when calling saveSynonym(Async)" - ); - } - - return saveSynonymCall( - indexName, - objectID, - synonymHit, - forwardToReplicas, - callback - ); - } - - /** - * Create a new synonym object or update the existing synonym object with the given object ID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param synonymHit (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return SaveSynonymResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SaveSynonymResponse saveSynonym( - String indexName, - String objectID, - SynonymHit synonymHit, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = saveSynonymValidateBeforeCall( - indexName, - objectID, - synonymHit, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SaveSynonym( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public SaveSynonymResponse saveSynonym( - String indexName, - String objectID, - SynonymHit synonymHit - ) throws AlgoliaRuntimeException { - return this.saveSynonym(indexName, objectID, synonymHit, null); - } - - /** - * (asynchronously) Create a new synonym object or update the existing synonym object with the - * given object ID. - * - * @param indexName The index in which to perform the request. (required) - * @param objectID Unique identifier of an object. (required) - * @param synonymHit (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call saveSynonymAsync( - String indexName, - String objectID, - SynonymHit synonymHit, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = saveSynonymValidateBeforeCall( - indexName, - objectID, - synonymHit, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for saveSynonyms - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call saveSynonymsCall( - String indexName, - List synonymHit, - Boolean forwardToReplicas, - Boolean replaceExistingSynonyms, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = synonymHit; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/batch".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - if (replaceExistingSynonyms != null) { - queryParams.addAll( - this.parameterToPair("replaceExistingSynonyms", replaceExistingSynonyms) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call saveSynonymsValidateBeforeCall( - String indexName, - List synonymHit, - Boolean forwardToReplicas, - Boolean replaceExistingSynonyms, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling saveSynonyms(Async)" - ); - } - - // verify the required parameter 'synonymHit' is set - if (synonymHit == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'synonymHit' when calling saveSynonyms(Async)" - ); - } - - return saveSynonymsCall( - indexName, - synonymHit, - forwardToReplicas, - replaceExistingSynonyms, - callback - ); - } - - /** - * Create/update multiple synonym objects at once, potentially replacing the entire list of - * synonyms if replaceExistingSynonyms is true. - * - * @param indexName The index in which to perform the request. (required) - * @param synonymHit (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param replaceExistingSynonyms Replace all synonyms of the index with the ones sent with this - * request. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse saveSynonyms( - String indexName, - List synonymHit, - Boolean forwardToReplicas, - Boolean replaceExistingSynonyms - ) throws AlgoliaRuntimeException { - Call req = saveSynonymsValidateBeforeCall( - indexName, - synonymHit, - forwardToReplicas, - replaceExistingSynonyms, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SaveSynonyms( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse saveSynonyms( - String indexName, - List synonymHit - ) throws AlgoliaRuntimeException { - return this.saveSynonyms(indexName, synonymHit, null, null); - } - - /** - * (asynchronously) Create/update multiple synonym objects at once, potentially replacing the - * entire list of synonyms if replaceExistingSynonyms is true. - * - * @param indexName The index in which to perform the request. (required) - * @param synonymHit (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param replaceExistingSynonyms Replace all synonyms of the index with the ones sent with this - * request. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call saveSynonymsAsync( - String indexName, - List synonymHit, - Boolean forwardToReplicas, - Boolean replaceExistingSynonyms, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = saveSynonymsValidateBeforeCall( - indexName, - synonymHit, - forwardToReplicas, - replaceExistingSynonyms, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for search - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchCall( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchParams; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/query".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchValidateBeforeCall( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling search(Async)" - ); - } - - // verify the required parameter 'searchParams' is set - if (searchParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'searchParams' when calling search(Async)" - ); - } - - return searchCall(indexName, searchParams, callback); - } - - /** - * Get search results. - * - * @param indexName The index in which to perform the request. (required) - * @param searchParams (required) - * @return SearchResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SearchResponse search(String indexName, SearchParams searchParams) - throws AlgoliaRuntimeException { - Call req = searchValidateBeforeCall(indexName, searchParams, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.Search(((CallEcho) req).request()); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Get search results. - * - * @param indexName The index in which to perform the request. (required) - * @param searchParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchAsync( - String indexName, - SearchParams searchParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchValidateBeforeCall(indexName, searchParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for searchDictionaryEntries - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchDictionaryEntriesCall( - DictionaryType dictionaryName, - SearchDictionaryEntriesParams searchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchDictionaryEntriesParams; - - // create path and map variables - String requestPath = - "/1/dictionaries/{dictionaryName}/search".replaceAll( - "\\{dictionaryName\\}", - this.escapeString(dictionaryName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchDictionaryEntriesValidateBeforeCall( - DictionaryType dictionaryName, - SearchDictionaryEntriesParams searchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'dictionaryName' is set - if (dictionaryName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'dictionaryName' when calling" + - " searchDictionaryEntries(Async)" - ); - } - - // verify the required parameter 'searchDictionaryEntriesParams' is set - if (searchDictionaryEntriesParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'searchDictionaryEntriesParams' when calling" + - " searchDictionaryEntries(Async)" - ); - } - - return searchDictionaryEntriesCall( - dictionaryName, - searchDictionaryEntriesParams, - callback - ); - } - - /** - * Search the dictionary entries. - * - * @param dictionaryName The dictionary to search in. (required) - * @param searchDictionaryEntriesParams (required) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse searchDictionaryEntries( - DictionaryType dictionaryName, - SearchDictionaryEntriesParams searchDictionaryEntriesParams - ) throws AlgoliaRuntimeException { - Call req = searchDictionaryEntriesValidateBeforeCall( - dictionaryName, - searchDictionaryEntriesParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SearchDictionaryEntries( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Search the dictionary entries. - * - * @param dictionaryName The dictionary to search in. (required) - * @param searchDictionaryEntriesParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchDictionaryEntriesAsync( - DictionaryType dictionaryName, - SearchDictionaryEntriesParams searchDictionaryEntriesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchDictionaryEntriesValidateBeforeCall( - dictionaryName, - searchDictionaryEntriesParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for searchForFacetValues - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchForFacetValuesCall( - String indexName, - String facetName, - SearchForFacetValuesRequest searchForFacetValuesRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchForFacetValuesRequest; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/facets/{facetName}/query".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ) - .replaceAll("\\{facetName\\}", this.escapeString(facetName.toString())); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchForFacetValuesValidateBeforeCall( - String indexName, - String facetName, - SearchForFacetValuesRequest searchForFacetValuesRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling searchForFacetValues(Async)" - ); - } - - // verify the required parameter 'facetName' is set - if (facetName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'facetName' when calling searchForFacetValues(Async)" - ); - } - - return searchForFacetValuesCall( - indexName, - facetName, - searchForFacetValuesRequest, - callback - ); - } - - /** - * Search for values of a given facet, optionally restricting the returned values to those - * contained in objects matching other search criteria. - * - * @param indexName The index in which to perform the request. (required) - * @param facetName The facet name. (required) - * @param searchForFacetValuesRequest (optional) - * @return SearchForFacetValuesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SearchForFacetValuesResponse searchForFacetValues( - String indexName, - String facetName, - SearchForFacetValuesRequest searchForFacetValuesRequest - ) throws AlgoliaRuntimeException { - Call req = searchForFacetValuesValidateBeforeCall( - indexName, - facetName, - searchForFacetValuesRequest, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SearchForFacetValues( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {} - .getType(); - ApiResponse res = - this.execute(call, returnType); - return res.getData(); - } - - public SearchForFacetValuesResponse searchForFacetValues( - String indexName, - String facetName - ) throws AlgoliaRuntimeException { - return this.searchForFacetValues(indexName, facetName, null); - } - - /** - * (asynchronously) Search for values of a given facet, optionally restricting the returned values - * to those contained in objects matching other search criteria. - * - * @param indexName The index in which to perform the request. (required) - * @param facetName The facet name. (required) - * @param searchForFacetValuesRequest (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchForFacetValuesAsync( - String indexName, - String facetName, - SearchForFacetValuesRequest searchForFacetValuesRequest, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchForFacetValuesValidateBeforeCall( - indexName, - facetName, - searchForFacetValuesRequest, - callback - ); - Type returnType = new TypeToken() {} - .getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for searchRules - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchRulesCall( - String indexName, - SearchRulesParams searchRulesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchRulesParams; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/rules/search".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchRulesValidateBeforeCall( - String indexName, - SearchRulesParams searchRulesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling searchRules(Async)" - ); - } - - // verify the required parameter 'searchRulesParams' is set - if (searchRulesParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'searchRulesParams' when calling searchRules(Async)" - ); - } - - return searchRulesCall(indexName, searchRulesParams, callback); - } - - /** - * Search for rules matching various criteria. - * - * @param indexName The index in which to perform the request. (required) - * @param searchRulesParams (required) - * @return SearchRulesResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SearchRulesResponse searchRules( - String indexName, - SearchRulesParams searchRulesParams - ) throws AlgoliaRuntimeException { - Call req = searchRulesValidateBeforeCall( - indexName, - searchRulesParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SearchRules( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Search for rules matching various criteria. - * - * @param indexName The index in which to perform the request. (required) - * @param searchRulesParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchRulesAsync( - String indexName, - SearchRulesParams searchRulesParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchRulesValidateBeforeCall( - indexName, - searchRulesParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for searchSynonyms - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchSynonymsCall( - String indexName, - String query, - SynonymType type, - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = null; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/synonyms/search".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (query != null) { - queryParams.addAll(this.parameterToPair("query", query)); - } - - if (type != null) { - queryParams.addAll(this.parameterToPair("type", type)); - } - - if (page != null) { - queryParams.addAll(this.parameterToPair("page", page)); - } - - if (hitsPerPage != null) { - queryParams.addAll(this.parameterToPair("hitsPerPage", hitsPerPage)); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchSynonymsValidateBeforeCall( - String indexName, - String query, - SynonymType type, - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling searchSynonyms(Async)" - ); - } - - return searchSynonymsCall( - indexName, - query, - type, - page, - hitsPerPage, - callback - ); - } - - /** - * Search or browse all synonyms, optionally filtering them by type. - * - * @param indexName The index in which to perform the request. (required) - * @param query Search for specific synonyms matching this string. (optional, default to ) - * @param type Only search for specific types of synonyms. (optional) - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional, default to 0) - * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) - * @return SearchSynonymsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SearchSynonymsResponse searchSynonyms( - String indexName, - String query, - SynonymType type, - Integer page, - Integer hitsPerPage - ) throws AlgoliaRuntimeException { - Call req = searchSynonymsValidateBeforeCall( - indexName, - query, - type, - page, - hitsPerPage, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SearchSynonyms( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public SearchSynonymsResponse searchSynonyms(String indexName) - throws AlgoliaRuntimeException { - return this.searchSynonyms(indexName, "", null, 0, 100); - } - - /** - * (asynchronously) Search or browse all synonyms, optionally filtering them by type. - * - * @param indexName The index in which to perform the request. (required) - * @param query Search for specific synonyms matching this string. (optional, default to ) - * @param type Only search for specific types of synonyms. (optional) - * @param page Requested page (zero-based). When specified, will retrieve a specific page; the - * page size is implicitly set to 100. When null, will retrieve all indices (no pagination). - * (optional, default to 0) - * @param hitsPerPage Maximum number of objects to retrieve. (optional, default to 100) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchSynonymsAsync( - String indexName, - String query, - SynonymType type, - Integer page, - Integer hitsPerPage, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchSynonymsValidateBeforeCall( - indexName, - query, - type, - page, - hitsPerPage, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for searchUserIds - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call searchUserIdsCall( - SearchUserIdsParams searchUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = searchUserIdsParams; - - // create path and map variables - String requestPath = "/1/clusters/mapping/search"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "POST", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call searchUserIdsValidateBeforeCall( - SearchUserIdsParams searchUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'searchUserIdsParams' is set - if (searchUserIdsParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'searchUserIdsParams' when calling searchUserIds(Async)" - ); - } - - return searchUserIdsCall(searchUserIdsParams, callback); - } - - /** - * Search for userIDs. The data returned will usually be a few seconds behind real time, because - * userID usage may take up to a few seconds propagate to the different clusters. To keep updates - * moving quickly, the index of userIDs isn't built synchronously with the mapping. Instead, the - * index is built once every 12h, at the same time as the update of userID usage. For example, - * when you perform a modification like adding or moving a userID, the search will report an - * outdated value until the next rebuild of the mapping, which takes place every 12h. Upon - * success, the response is 200 OK and contains the following userIDs data. - * - * @param searchUserIdsParams (required) - * @return SearchUserIdsResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public SearchUserIdsResponse searchUserIds( - SearchUserIdsParams searchUserIdsParams - ) throws AlgoliaRuntimeException { - Call req = searchUserIdsValidateBeforeCall(searchUserIdsParams, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SearchUserIds( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Search for userIDs. The data returned will usually be a few seconds behind - * real time, because userID usage may take up to a few seconds propagate to the different - * clusters. To keep updates moving quickly, the index of userIDs isn't built synchronously - * with the mapping. Instead, the index is built once every 12h, at the same time as the update of - * userID usage. For example, when you perform a modification like adding or moving a userID, the - * search will report an outdated value until the next rebuild of the mapping, which takes place - * every 12h. Upon success, the response is 200 OK and contains the following userIDs data. - * - * @param searchUserIdsParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call searchUserIdsAsync( - SearchUserIdsParams searchUserIdsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = searchUserIdsValidateBeforeCall(searchUserIdsParams, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for setDictionarySettings - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call setDictionarySettingsCall( - DictionarySettingsParams dictionarySettingsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = dictionarySettingsParams; - - // create path and map variables - String requestPath = "/1/dictionaries/*/settings"; - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call setDictionarySettingsValidateBeforeCall( - DictionarySettingsParams dictionarySettingsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'dictionarySettingsParams' is set - if (dictionarySettingsParams == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'dictionarySettingsParams' when calling" + - " setDictionarySettings(Async)" - ); - } - - return setDictionarySettingsCall(dictionarySettingsParams, callback); - } - - /** - * Set dictionary settings. - * - * @param dictionarySettingsParams (required) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse setDictionarySettings( - DictionarySettingsParams dictionarySettingsParams - ) throws AlgoliaRuntimeException { - Call req = setDictionarySettingsValidateBeforeCall( - dictionarySettingsParams, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SetDictionarySettings( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Set dictionary settings. - * - * @param dictionarySettingsParams (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call setDictionarySettingsAsync( - DictionarySettingsParams dictionarySettingsParams, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = setDictionarySettingsValidateBeforeCall( - dictionarySettingsParams, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for setSettings - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call setSettingsCall( - String indexName, - IndexSettings indexSettings, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = indexSettings; - - // create path and map variables - String requestPath = - "/1/indexes/{indexName}/settings".replaceAll( - "\\{indexName\\}", - this.escapeString(indexName.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - if (forwardToReplicas != null) { - queryParams.addAll( - this.parameterToPair("forwardToReplicas", forwardToReplicas) - ); - } - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call setSettingsValidateBeforeCall( - String indexName, - IndexSettings indexSettings, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'indexName' is set - if (indexName == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexName' when calling setSettings(Async)" - ); - } - - // verify the required parameter 'indexSettings' is set - if (indexSettings == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'indexSettings' when calling setSettings(Async)" - ); - } - - return setSettingsCall( - indexName, - indexSettings, - forwardToReplicas, - callback - ); - } - - /** - * Update settings of a given indexName. Only specified settings are overridden; unspecified - * settings are left unchanged. Specifying null for a setting resets it to its default value. - * - * @param indexName The index in which to perform the request. (required) - * @param indexSettings (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @return UpdatedAtResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdatedAtResponse setSettings( - String indexName, - IndexSettings indexSettings, - Boolean forwardToReplicas - ) throws AlgoliaRuntimeException { - Call req = setSettingsValidateBeforeCall( - indexName, - indexSettings, - forwardToReplicas, - null - ); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.SetSettings( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - public UpdatedAtResponse setSettings( - String indexName, - IndexSettings indexSettings - ) throws AlgoliaRuntimeException { - return this.setSettings(indexName, indexSettings, null); - } - - /** - * (asynchronously) Update settings of a given indexName. Only specified settings are overridden; - * unspecified settings are left unchanged. Specifying null for a setting resets it to its default - * value. - * - * @param indexName The index in which to perform the request. (required) - * @param indexSettings (required) - * @param forwardToReplicas When true, changes are also propagated to replicas of the given - * indexName. (optional) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call setSettingsAsync( - String indexName, - IndexSettings indexSettings, - Boolean forwardToReplicas, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = setSettingsValidateBeforeCall( - indexName, - indexSettings, - forwardToReplicas, - callback - ); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } - - /** - * Build call for updateApiKey - * - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - */ - private Call updateApiKeyCall( - String key, - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Object bodyObj = apiKey; - - // create path and map variables - String requestPath = - "/1/keys/{key}".replaceAll( - "\\{key\\}", - this.escapeString(key.toString()) - ); - - List queryParams = new ArrayList(); - Map headers = new HashMap(); - - headers.put("Accept", "application/json"); - headers.put("Content-Type", "application/json"); - - return this.buildCall( - requestPath, - "PUT", - queryParams, - bodyObj, - headers, - callback - ); - } - - private Call updateApiKeyValidateBeforeCall( - String key, - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - // verify the required parameter 'key' is set - if (key == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'key' when calling updateApiKey(Async)" - ); - } - - // verify the required parameter 'apiKey' is set - if (apiKey == null) { - throw new AlgoliaRuntimeException( - "Missing the required parameter 'apiKey' when calling updateApiKey(Async)" - ); - } - - return updateApiKeyCall(key, apiKey, callback); - } - - /** - * Replace every permission of an existing API key. - * - * @param key API Key string. (required) - * @param apiKey (required) - * @return UpdateApiKeyResponse - * @throws AlgoliaRuntimeException If fail to call the API, e.g. server error or cannot - * deserialize the response body - */ - public UpdateApiKeyResponse updateApiKey(String key, ApiKey apiKey) - throws AlgoliaRuntimeException { - Call req = updateApiKeyValidateBeforeCall(key, apiKey, null); - if (req instanceof CallEcho) { - return new EchoResponse.SearchEcho.UpdateApiKey( - ((CallEcho) req).request() - ); - } - Call call = (Call) req; - Type returnType = new TypeToken() {}.getType(); - ApiResponse res = this.execute(call, returnType); - return res.getData(); - } - - /** - * (asynchronously) Replace every permission of an existing API key. - * - * @param key API Key string. (required) - * @param apiKey (required) - * @param callback The callback to be executed when the API call finishes - * @return The request call - * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request - * body object - */ - public Call updateApiKeyAsync( - String key, - ApiKey apiKey, - final ApiCallback callback - ) throws AlgoliaRuntimeException { - Call call = updateApiKeyValidateBeforeCall(key, apiKey, callback); - Type returnType = new TypeToken() {}.getType(); - this.executeAsync(call, returnType, callback); - return call; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/utils/echo/EchoResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/utils/echo/EchoResponse.java deleted file mode 100644 index be4971a774..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/utils/echo/EchoResponse.java +++ /dev/null @@ -1,1674 +0,0 @@ -package com.algolia.utils.echo; - -import com.algolia.Pair; -import com.algolia.model.search.*; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okio.Buffer; - -public class EchoResponse { - - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } - } - - private static List buildQueryParams(Request req) { - List params = new ArrayList(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.add(new Pair(name, value)); - } - } - return params; - } - - public static class SearchEcho { - - public static class AddApiKey - extends AddApiKeyResponse - implements EchoResponseInterface { - - private Request request; - - public AddApiKey(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class AddOrUpdateObject - extends UpdatedAtWithObjectIdResponse - implements EchoResponseInterface { - - private Request request; - - public AddOrUpdateObject(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class AppendSource - extends CreatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public AppendSource(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class AssignUserId - extends CreatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public AssignUserId(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class Batch - extends BatchResponse - implements EchoResponseInterface { - - private Request request; - - public Batch(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class BatchAssignUserIds - extends CreatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public BatchAssignUserIds(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class BatchDictionaryEntries - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public BatchDictionaryEntries(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class BatchRules - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public BatchRules(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class Browse - extends BrowseResponse - implements EchoResponseInterface { - - private Request request; - - public Browse(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class ClearAllSynonyms - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public ClearAllSynonyms(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class ClearObjects - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public ClearObjects(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class ClearRules - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public ClearRules(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class Del extends Object implements EchoResponseInterface { - - private Request request; - - public Del(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class DeleteApiKey - extends DeleteApiKeyResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteApiKey(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class DeleteBy - extends DeletedAtResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteBy(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class DeleteIndex - extends DeletedAtResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteIndex(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class DeleteObject - extends DeletedAtResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteObject(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class DeleteRule - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteRule(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class DeleteSource - extends DeleteSourceResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteSource(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class DeleteSynonym - extends DeletedAtResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteSynonym(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class Get extends Object implements EchoResponseInterface { - - private Request request; - - public Get(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetApiKey extends Key implements EchoResponseInterface { - - private Request request; - - public GetApiKey(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetDictionaryLanguages - extends HashMap - implements EchoResponseInterface { - - private Request request; - - public GetDictionaryLanguages(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetDictionarySettings - extends GetDictionarySettingsResponse - implements EchoResponseInterface { - - private Request request; - - public GetDictionarySettings(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetLogs - extends GetLogsResponse - implements EchoResponseInterface { - - private Request request; - - public GetLogs(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetObject - extends HashMap - implements EchoResponseInterface { - - private Request request; - - public GetObject(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetObjects - extends GetObjectsResponse - implements EchoResponseInterface { - - private Request request; - - public GetObjects(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetRule extends Rule implements EchoResponseInterface { - - private Request request; - - public GetRule(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetSettings - extends IndexSettings - implements EchoResponseInterface { - - private Request request; - - public GetSettings(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetSources - extends ArrayList - implements EchoResponseInterface { - - private Request request; - - public GetSources(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetSynonym - extends SynonymHit - implements EchoResponseInterface { - - private Request request; - - public GetSynonym(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetTask - extends GetTaskResponse - implements EchoResponseInterface { - - private Request request; - - public GetTask(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetTopUserIds - extends GetTopUserIdsResponse - implements EchoResponseInterface { - - private Request request; - - public GetTopUserIds(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class GetUserId - extends UserId - implements EchoResponseInterface { - - private Request request; - - public GetUserId(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class HasPendingMappings - extends CreatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public HasPendingMappings(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class ListApiKeys - extends ListApiKeysResponse - implements EchoResponseInterface { - - private Request request; - - public ListApiKeys(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class ListClusters - extends ListClustersResponse - implements EchoResponseInterface { - - private Request request; - - public ListClusters(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class ListIndices - extends ListIndicesResponse - implements EchoResponseInterface { - - private Request request; - - public ListIndices(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class ListUserIds - extends ListUserIdsResponse - implements EchoResponseInterface { - - private Request request; - - public ListUserIds(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class MultipleBatch - extends MultipleBatchResponse - implements EchoResponseInterface { - - private Request request; - - public MultipleBatch(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class MultipleQueries - extends MultipleQueriesResponse - implements EchoResponseInterface { - - private Request request; - - public MultipleQueries(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class OperationIndex - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public OperationIndex(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class PartialUpdateObject - extends UpdatedAtWithObjectIdResponse - implements EchoResponseInterface { - - private Request request; - - public PartialUpdateObject(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class Post extends Object implements EchoResponseInterface { - - private Request request; - - public Post(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class Put extends Object implements EchoResponseInterface { - - private Request request; - - public Put(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class RemoveUserId - extends RemoveUserIdResponse - implements EchoResponseInterface { - - private Request request; - - public RemoveUserId(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class ReplaceSources - extends ReplaceSourceResponse - implements EchoResponseInterface { - - private Request request; - - public ReplaceSources(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class RestoreApiKey - extends AddApiKeyResponse - implements EchoResponseInterface { - - private Request request; - - public RestoreApiKey(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SaveObject - extends SaveObjectResponse - implements EchoResponseInterface { - - private Request request; - - public SaveObject(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SaveRule - extends UpdatedRuleResponse - implements EchoResponseInterface { - - private Request request; - - public SaveRule(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SaveSynonym - extends SaveSynonymResponse - implements EchoResponseInterface { - - private Request request; - - public SaveSynonym(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SaveSynonyms - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public SaveSynonyms(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class Search - extends SearchResponse - implements EchoResponseInterface { - - private Request request; - - public Search(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SearchDictionaryEntries - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public SearchDictionaryEntries(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SearchForFacetValues - extends SearchForFacetValuesResponse - implements EchoResponseInterface { - - private Request request; - - public SearchForFacetValues(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SearchRules - extends SearchRulesResponse - implements EchoResponseInterface { - - private Request request; - - public SearchRules(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SearchSynonyms - extends SearchSynonymsResponse - implements EchoResponseInterface { - - private Request request; - - public SearchSynonyms(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SearchUserIds - extends SearchUserIdsResponse - implements EchoResponseInterface { - - private Request request; - - public SearchUserIds(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SetDictionarySettings - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public SetDictionarySettings(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class SetSettings - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public SetSettings(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - - public static class UpdateApiKey - extends UpdateApiKeyResponse - implements EchoResponseInterface { - - private Request request; - - public UpdateApiKey(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public List getQueryParams() { - return buildQueryParams(request); - } - } - } -} diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java index 2a8c756876..dc4faabcd8 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java @@ -44,7 +44,6 @@ private void generateServer(Map client) { boolean isDeHost = false; String host = ""; String topLevelDomain = ""; - for (Map server : servers) { if (!server.containsKey("url")) { throw new GenerationException( @@ -52,6 +51,19 @@ private void generateServer(Map client) { ); } + // Determine if the current URL with `region` also have an alias without + // variables. + for (Map otherServer : servers) { + if (server == otherServer) { + continue; + } + String otherUrl = (String) otherServer.getOrDefault("url", ""); + if (otherUrl.replace(".{region}", "").equals(server.get("url"))) { + fallbackToAliasHost = true; + break; + } + } + if (!server.containsKey("variables")) { continue; } @@ -73,12 +85,6 @@ private void generateServer(Map client) { URL url = new URL((String) server.get("url")); - if (!fallbackToAliasHost) { - // Determine if the current URL with `region` also have an alias without - // variables. - fallbackToAliasHost = true; - } - if (enums.contains("eu")) { isEuHost = true; } @@ -177,7 +183,17 @@ public Map postProcessSupportingFileData( ((Map>>) bundle.get("apiInfo")).get( "apis" ); + for (Map api : apis) { + String clientName = (String) api.get("baseName"); + supportingFiles.add( + new SupportingFile( + "EchoResponse.mustache", + "algoliasearch-core/com/algolia/utils/echo", + "EchoResponse" + clientName + ".java" + ) + ); + List operations = ((Map>) api.get("operations")).get( "operation" @@ -208,14 +224,6 @@ public String getHelp() { public void processOpts() { super.processOpts(); - supportingFiles.add( - new SupportingFile( - "EchoResponse.mustache", - "algoliasearch-core/com/algolia/utils/echo", - "EchoResponse.java" - ) - ); - // Prevent all useless file to generate apiTestTemplateFiles.clear(); modelTestTemplateFiles.clear(); @@ -237,6 +245,7 @@ public String toEnumVarName(String value, String datatype) { if ("String".equals(datatype)) { // convert camelCase77String to CAMEL_CASE_77_STRING return value + .replaceAll("-", "_") .replaceAll("(.+?)([A-Z]|[0-9])", "$1_$2") .toUpperCase(Locale.ROOT); } diff --git a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java index bfc8fd126e..48a5602ec1 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java @@ -132,7 +132,7 @@ public Map postProcessSupportingFileData( // We can put whatever we want in the bundle, and it will be accessible in the // template bundle.put("client", createClientName()); - bundle.put("import", packageName); + bundle.put("import", createImportName()); bundle.put("hasRegionalHost", hasRegionalHost); bundle.put("lambda", lambda); @@ -252,6 +252,20 @@ private String createClientName() { return clientName + "Api"; } + private String createImportName() { + if (!language.equals("java")) { + return this.packageName; + } + String[] clientParts = client.split("-"); + // do not capitalize the first part + String name = clientParts[0]; + for (int i = 1; i < clientParts.length; i++) { + name += Utils.capitalize(clientParts[i]); + } + + return name; + } + /** * override with any special text escaping logic to handle unsafe characters so as to avoid code * injection diff --git a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java index 9c247f4c83..bf93cade72 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java +++ b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java @@ -138,7 +138,7 @@ private Map traverseParams( // free key but only one type handleMap(paramName, param, testOutput, spec, suffix); } else { - handlePrimitive(param, testOutput); + handlePrimitive(param, testOutput, spec); } return testOutput; } @@ -151,11 +151,15 @@ private Map createDefaultOutput() { testOutput.put("isObject", false); testOutput.put("isArray", false); testOutput.put("isFreeFormObject", false); + testOutput.put("isAnyType", false); testOutput.put("isString", false); testOutput.put("isInteger", false); + testOutput.put("isLong", false); testOutput.put("isDouble", false); testOutput.put("isBoolean", false); testOutput.put("isEnum", false); + testOutput.put("isSimpleObject", false); + testOutput.put("oneOfModel", false); return testOutput; } @@ -219,15 +223,14 @@ private void handleModel( traverseParams(paramName, param, match, parent, suffix) ); - HashMap hashMapOneOfModel = new HashMap(); + HashMap oneOfModel = new HashMap<>(); - hashMapOneOfModel.put("classname", baseType); - hashMapOneOfModel.put( + oneOfModel.put("classname", Utils.capitalize(baseType)); + oneOfModel.put( "name", getTypeName(match).replace("<", "").replace(">", "") ); - - testOutput.put("oneOfModel", hashMapOneOfModel); + testOutput.put("oneOfModel", oneOfModel); return; } @@ -298,6 +301,10 @@ private void handleObject( ) ); } + // sometimes it's really just an object + if (testOutput.get("objectName").equals("Object")) { + testOutput.put("isSimpleObject", true); + } testOutput.put("isFreeFormObject", true); testOutput.put("value", values); @@ -324,7 +331,8 @@ private void handleMap( IJsonSchemaValidationProperties itemType = items; // The generator consider a free form object type as an `object`, which - // is wrong in our case, so we infer it. + // is wrong in our case, so we infer it to explore the right path in the traverseParams + // function, but we keep the any type for the CTS. if ( items == null || (items.openApiType.equals("object") && items.isFreeFormObject) @@ -333,6 +341,7 @@ private void handleMap( String paramType = inferDataType(entry.getValue(), maybeMatch, null); maybeMatch.dataType = paramType; + maybeMatch.isAnyType = true; itemType = maybeMatch; } @@ -351,9 +360,17 @@ private void handleMap( testOutput.put("value", values); } - private void handlePrimitive(Object param, Map testOutput) - throws CTSException { + private void handlePrimitive( + Object param, + Map testOutput, + IJsonSchemaValidationProperties spec + ) throws CTSException { inferDataType(param, null, testOutput); + if ( + spec instanceof CodegenParameter && ((CodegenParameter) spec).isAnyType + ) { + testOutput.put("isAnyType", true); + } testOutput.put("value", param); } @@ -402,7 +419,7 @@ private String inferDataType( return "Integer"; case "Long": if (spec != null) spec.setIsNumber(true); - if (output != null) output.put("isInteger", true); + if (output != null) output.put("isLong", true); return "Long"; case "Double": if (spec != null) spec.setIsNumber(true); diff --git a/openapitools.json b/openapitools.json index fddab6e0a3..d6cc06cdab 100644 --- a/openapitools.json +++ b/openapitools.json @@ -261,7 +261,7 @@ "output": "#{cwd}/clients/algoliasearch-client-java-2", "artifactId": "algoliasearch-client-java-2", "groupId": "com.algolia", - "apiPackage": "com.algolia.search", + "apiPackage": "com.algolia.api", "invokerPackage": "com.algolia", "modelPackage": "com.algolia.model.search", "library": "okhttp-gson", @@ -277,6 +277,191 @@ "packageVersion": "0.0.1" } }, + "java-recommend": { + "generatorName": "algolia-java", + "templateDir": "#{cwd}/templates/java/", + "config": "#{cwd}/openapitools.json", + "output": "#{cwd}/clients/algoliasearch-client-java-2", + "artifactId": "algoliasearch-client-java-2", + "groupId": "com.algolia", + "apiPackage": "com.algolia.api", + "invokerPackage": "com.algolia", + "modelPackage": "com.algolia.model.recommend", + "library": "okhttp-gson", + "glob": "specs/bundled/recommend.yml", + "gitHost": "algolia", + "gitUserId": "algolia", + "gitRepoId": "algoliasearch-client-java-2", + "additionalProperties": { + "sourceFolder": "algoliasearch-core", + "java8": true, + "dateLibrary": "java8", + "packageName": "algoliasearch-client-java-2", + "packageVersion": "0.0.1" + } + }, + "java-personalization": { + "generatorName": "algolia-java", + "templateDir": "#{cwd}/templates/java/", + "config": "#{cwd}/openapitools.json", + "output": "#{cwd}/clients/algoliasearch-client-java-2", + "artifactId": "algoliasearch-client-java-2", + "groupId": "com.algolia", + "apiPackage": "com.algolia.api", + "invokerPackage": "com.algolia", + "modelPackage": "com.algolia.model.personalization", + "library": "okhttp-gson", + "glob": "specs/bundled/personalization.yml", + "gitHost": "algolia", + "gitUserId": "algolia", + "gitRepoId": "algoliasearch-client-java-2", + "additionalProperties": { + "sourceFolder": "algoliasearch-core", + "java8": true, + "dateLibrary": "java8", + "packageName": "algoliasearch-client-java-2", + "packageVersion": "0.0.1", + "hasRegionalHost": true, + "isEuHost": true, + "host": "personalization", + "topLevelDomain": "com" + } + }, + "java-analytics": { + "generatorName": "algolia-java", + "templateDir": "#{cwd}/templates/java/", + "config": "#{cwd}/openapitools.json", + "output": "#{cwd}/clients/algoliasearch-client-java-2", + "artifactId": "algoliasearch-client-java-2", + "groupId": "com.algolia", + "apiPackage": "com.algolia.api", + "invokerPackage": "com.algolia", + "modelPackage": "com.algolia.model.analytics", + "library": "okhttp-gson", + "glob": "specs/bundled/analytics.yml", + "gitHost": "algolia", + "gitUserId": "algolia", + "gitRepoId": "algoliasearch-client-java-2", + "additionalProperties": { + "sourceFolder": "algoliasearch-core", + "java8": true, + "dateLibrary": "java8", + "packageName": "algoliasearch-client-java-2", + "packageVersion": "0.0.1", + "hasRegionalHost": true, + "fallbackToAliasHost": true, + "isDeHost": true, + "host": "analytics", + "topLevelDomain": "com" + } + }, + "java-insights": { + "generatorName": "algolia-java", + "templateDir": "#{cwd}/templates/java/", + "config": "#{cwd}/openapitools.json", + "output": "#{cwd}/clients/algoliasearch-client-java-2", + "artifactId": "algoliasearch-client-java-2", + "groupId": "com.algolia", + "apiPackage": "com.algolia.api", + "invokerPackage": "com.algolia", + "modelPackage": "com.algolia.model.insights", + "library": "okhttp-gson", + "glob": "specs/bundled/insights.yml", + "gitHost": "algolia", + "gitUserId": "algolia", + "gitRepoId": "algoliasearch-client-java-2", + "additionalProperties": { + "sourceFolder": "algoliasearch-core", + "java8": true, + "dateLibrary": "java8", + "packageName": "algoliasearch-client-java-2", + "packageVersion": "0.0.1", + "hasRegionalHost": true, + "fallbackToAliasHost": true, + "isDeHost": true, + "host": "insights", + "topLevelDomain": "io" + } + }, + "java-abtesting": { + "generatorName": "algolia-java", + "templateDir": "#{cwd}/templates/java/", + "config": "#{cwd}/openapitools.json", + "output": "#{cwd}/clients/algoliasearch-client-java-2", + "artifactId": "algoliasearch-client-java-2", + "groupId": "com.algolia", + "apiPackage": "com.algolia.api", + "invokerPackage": "com.algolia", + "modelPackage": "com.algolia.model.abtesting", + "library": "okhttp-gson", + "glob": "specs/bundled/abtesting.yml", + "gitHost": "algolia", + "gitUserId": "algolia", + "gitRepoId": "algoliasearch-client-java-2", + "additionalProperties": { + "sourceFolder": "algoliasearch-core", + "java8": true, + "dateLibrary": "java8", + "packageName": "algoliasearch-client-java-2", + "packageVersion": "0.0.1", + "hasRegionalHost": true, + "fallbackToAliasHost": true, + "isDeHost": true, + "host": "analytics", + "topLevelDomain": "com" + } + }, + "java-query-suggestions": { + "generatorName": "algolia-java", + "templateDir": "#{cwd}/templates/java/", + "config": "#{cwd}/openapitools.json", + "output": "#{cwd}/clients/algoliasearch-client-java-2", + "artifactId": "algoliasearch-client-java-2", + "groupId": "com.algolia", + "apiPackage": "com.algolia.api", + "invokerPackage": "com.algolia", + "modelPackage": "com.algolia.model.querySuggestions", + "library": "okhttp-gson", + "glob": "specs/bundled/query-suggestions.yml", + "gitHost": "algolia", + "gitUserId": "algolia", + "gitRepoId": "algoliasearch-client-java-2", + "additionalProperties": { + "sourceFolder": "algoliasearch-core", + "java8": true, + "dateLibrary": "java8", + "packageName": "algoliasearch-client-java-2", + "packageVersion": "0.0.1", + "hasRegionalHost": true, + "isEuHost": true, + "host": "query-suggestions", + "topLevelDomain": "com" + } + }, + "java-predict": { + "generatorName": "algolia-java", + "templateDir": "#{cwd}/templates/java/", + "config": "#{cwd}/openapitools.json", + "output": "#{cwd}/clients/algoliasearch-client-java-2", + "artifactId": "algoliasearch-client-java-2", + "groupId": "com.algolia", + "apiPackage": "com.algolia.api", + "invokerPackage": "com.algolia", + "modelPackage": "com.algolia.model.predict", + "library": "okhttp-gson", + "glob": "specs/bundled/predict.yml", + "gitHost": "algolia", + "gitUserId": "algolia", + "gitRepoId": "algoliasearch-client-java-2", + "additionalProperties": { + "sourceFolder": "algoliasearch-core", + "java8": true, + "dateLibrary": "java8", + "packageName": "algoliasearch-client-java-2", + "packageVersion": "0.0.1", + "experimentalHost": "predict-api-oslcbws3zq-ew.a.run.app" + } + }, "php-search": { "generatorName": "algolia-php", "templateDir": "#{cwd}/templates/php/", diff --git a/specs/insights/paths/pushEvents.yml b/specs/insights/paths/pushEvents.yml index 6638edff9b..135c27f538 100644 --- a/specs/insights/paths/pushEvents.yml +++ b/specs/insights/paths/pushEvents.yml @@ -36,6 +36,7 @@ post: description: A user identifier. Depending if the user is logged-in or not, several strategies can be used from a sessionId to a technical identifier. timestamp: type: integer + format: int64 description: Time of the event expressed in milliseconds since the Unix epoch. queryID: type: string diff --git a/templates/java/EchoResponse.mustache b/templates/java/EchoResponse.mustache index 6fc98aaf00..3b5faa6ea1 100644 --- a/templates/java/EchoResponse.mustache +++ b/templates/java/EchoResponse.mustache @@ -1,7 +1,7 @@ package com.algolia.utils.echo; import com.algolia.Pair; -import com.algolia.model.search.*; +import {{#apiInfo}}{{#apis}}{{{modelPackage}}}{{/apis}}{{/apiInfo}}.*; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -11,57 +11,60 @@ import okhttp3.HttpUrl; import okhttp3.Request; import okio.Buffer; -public class EchoResponse { - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } +public class EchoResponse{{#apiInfo}}{{#apis}}{{{baseName}}}{{/apis}}{{/apiInfo}} { + private static String parseRequestBody(Request req) { + try { + final Request copy = req.newBuilder().build(); + final Buffer buffer = new Buffer(); + copy.body().writeTo(buffer); + return buffer.readUtf8(); + } catch (final IOException e) { + return "error"; } + } - private static List buildQueryParams(Request req) { - List params = new ArrayList(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.add(new Pair(name, value)); - } - } - return params; + private static List buildQueryParams(Request req) { + List params = new ArrayList(); + HttpUrl url = req.url(); + for (String name : url.queryParameterNames()) { + for (String value : url.queryParameterValues(name)) { + params.add(new Pair(name, value)); + } } + return params; + } - {{#apiInfo}}{{#apis}} - public static class {{baseName}}Echo { - {{#operations}}{{#operation}} - public static class {{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}} extends {{{returnType}}} implements EchoResponseInterface { - private Request request; + {{#apiInfo}}{{#apis}} + {{#operations}}{{#operation}} + public static class {{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}} extends {{{returnType}}} implements EchoResponseInterface { + private Request request; - public {{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}}(Request request) { - this.request = request; - } + public {{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}}(Request request) { + this.request = request; + } + + public String getPath() { + return request.url().encodedPath(); + } - public String getPath() { - return request.url().encodedPath(); - } + public String getMethod() { + return request.method(); + } - public String getMethod() { - return request.method(); - } + public String getBody() { + return parseRequestBody(request); + } - public String getBody() { - return parseRequestBody(request); - } + public List getQueryParams() { + return buildQueryParams(request); + } - public List getQueryParams() { - return buildQueryParams(request); - } - } - {{/operation}}{{/operations}} + // to satisfy CompoundType in case it's a parent + public Object getInsideValue() { + return null; } - {{/apis}}{{/apiInfo}} + } + {{/operation}}{{/operations}} + {{/apis}}{{/apiInfo}} } diff --git a/templates/java/libraries/okhttp-gson/ApiClient.mustache b/templates/java/libraries/okhttp-gson/ApiClient.mustache index 863f87b632..62943e4399 100644 --- a/templates/java/libraries/okhttp-gson/ApiClient.mustache +++ b/templates/java/libraries/okhttp-gson/ApiClient.mustache @@ -180,12 +180,9 @@ public class ApiClient { String jsonStr = JSON.serialize(param); return jsonStr.substring(1, jsonStr.length() - 1); } else if (param instanceof Collection) { - StringBuilder b = new StringBuilder(); + StringJoiner b = new StringJoiner(","); for (Object o : (Collection) param) { - if (b.length() > 0) { - b.append(","); - } - b.append(String.valueOf(o)); + b.add(String.valueOf(o)); } return b.toString(); } else { @@ -206,7 +203,7 @@ public class ApiClient { List params = new ArrayList(); // preconditions - if (name == null || name.isEmpty() || value == null || value instanceof Collection) { + if (name == null || name.isEmpty() || value == null) { return params; } diff --git a/templates/java/libraries/okhttp-gson/api.mustache b/templates/java/libraries/okhttp-gson/api.mustache index 646ed5ecb4..7006bc5b8e 100644 --- a/templates/java/libraries/okhttp-gson/api.mustache +++ b/templates/java/libraries/okhttp-gson/api.mustache @@ -12,7 +12,7 @@ import okhttp3.Request; import com.algolia.utils.*; import com.algolia.utils.echo.*; -import com.algolia.model.search.*; +import {{modelPackage}}.*; import com.algolia.exceptions.*; import com.algolia.utils.retry.CallType; import com.algolia.utils.retry.StatefulHost; @@ -35,7 +35,7 @@ public class {{classname}} extends ApiClient { {{#hasRegionalHost}} {{#fallbackToAliasHost}} public {{classname}}(String appId, String apiKey) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(".")), null); + this(appId, apiKey, new HttpRequester(getDefaultHosts(null)), null); } {{/fallbackToAliasHost}} @@ -50,11 +50,11 @@ public class {{classname}} extends ApiClient { {{^hasRegionalHost}} public {{classname}}(String appId, String apiKey) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(appId)), null); + this(appId, apiKey, new HttpRequester(getDefaultHosts({{^experimentalHost}}appId{{/experimentalHost}})), null); } public {{classname}}(String appId, String apiKey, UserAgent.Segment[] userAgentSegments) { - this(appId, apiKey, new HttpRequester(getDefaultHosts(appId)), userAgentSegments); + this(appId, apiKey, new HttpRequester(getDefaultHosts({{^experimentalHost}}appId{{/experimentalHost}})), userAgentSegments); } {{/hasRegionalHost}} @@ -86,7 +86,7 @@ public class {{classname}} extends ApiClient { {{#experimentalHost}} private static List getDefaultHosts() { List hosts = new ArrayList(); - hosts.add(new StatefulHost("https", "{{{experimentalHost}}}", EnumSet.of(CallType.READ, CallType.WRITE))); + hosts.add(new StatefulHost("{{{experimentalHost}}}", "https", EnumSet.of(CallType.READ, CallType.WRITE))); return hosts; } {{/experimentalHost}} @@ -94,10 +94,7 @@ public class {{classname}} extends ApiClient { {{#hasRegionalHost}} private static List getDefaultHosts(String region) { List hosts = new ArrayList(); - hosts.add(new StatefulHost({{{host}}} + "." + region + ".algolia.{{#topLevelDomain}}{{.}}{{/topLevelDomain}}{{^topLevelDomain}}com{{/topLevelDomain}}", "https", EnumSet.of(CallType.READ, CallType.WRITE))); - - hosts.add(new StatefulHost(appId + "-1.algolianet.com", "https", EnumSet.of(CallType.READ, CallType.WRITE))); - + hosts.add(new StatefulHost("{{{host}}}." + (region == null ? "" : region + ".") + "algolia.{{#topLevelDomain}}{{.}}{{/topLevelDomain}}{{^topLevelDomain}}com{{/topLevelDomain}}", "https", EnumSet.of(CallType.READ, CallType.WRITE))); return hosts; } {{/hasRegionalHost}} @@ -138,7 +135,7 @@ public class {{classname}} extends ApiClient { {{/x-is-custom-request}} {{#x-is-custom-request}} for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll(this.parameterToPair(parameter.getKey(), parameter.getValue().toString())); + queryParams.addAll(this.parameterToPair(parameter.getKey(), parameter.getValue())); } {{/x-is-custom-request}} } @@ -189,7 +186,7 @@ public class {{classname}} extends ApiClient { public {{#returnType}}{{{.}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws AlgoliaRuntimeException { Call req = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}null); if (req instanceof CallEcho) { - {{#returnType}}return new EchoResponse.{{baseName}}Echo.{{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}}(((CallEcho)req).request());{{/returnType}} + {{#returnType}}return new EchoResponse{{baseName}}.{{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}}(((CallEcho)req).request());{{/returnType}} } Call call = (Call)req; {{#returnType}}Type returnType = new TypeToken<{{{.}}}>(){}.getType(); diff --git a/tests/CTS/methods/requests/templates/java/forceMapGenerics.mustache b/tests/CTS/methods/requests/templates/java/forceMapGenerics.mustache new file mode 100644 index 0000000000..9280166d56 --- /dev/null +++ b/tests/CTS/methods/requests/templates/java/forceMapGenerics.mustache @@ -0,0 +1 @@ +{{#isFreeFormObject}} generateGenerics}}{{/isAnyType}}{{/value.0}}>{{/isFreeFormObject}} \ No newline at end of file diff --git a/tests/CTS/methods/requests/templates/java/generateGenerics.mustache b/tests/CTS/methods/requests/templates/java/generateGenerics.mustache new file mode 100644 index 0000000000..c3642bbaac --- /dev/null +++ b/tests/CTS/methods/requests/templates/java/generateGenerics.mustache @@ -0,0 +1,2 @@ +{{#isArray}}{{#value.0}}<{{#oneOfModel}}{{classname}}{{/oneOfModel}}{{^oneOfModel}}{{objectName}}{{/oneOfModel}}{{> generateGenerics}}>{{/value.0}}{{/isArray}} +{{#isFreeFormObject}}{{^isSimpleObject}} generateGenerics}}{{/isAnyType}}{{/value.0}}>{{/isSimpleObject}}{{/isFreeFormObject}} \ No newline at end of file diff --git a/tests/CTS/methods/requests/templates/java/generateParams.mustache b/tests/CTS/methods/requests/templates/java/generateParams.mustache index 539c774dbc..f2bc7d9062 100644 --- a/tests/CTS/methods/requests/templates/java/generateParams.mustache +++ b/tests/CTS/methods/requests/templates/java/generateParams.mustache @@ -1,11 +1,12 @@ {{#isString}}String {{{key}}}{{suffix}} = "{{{value}}}";{{/isString}} {{#isInteger}}int {{{key}}}{{suffix}} = {{{value}}};{{/isInteger}} +{{#isLong}}long {{{key}}}{{suffix}} = {{{value}}}L;{{/isLong}} {{#isDouble}}double {{{key}}}{{suffix}} = {{{value}}};{{/isDouble}} {{#isBoolean}}boolean {{{key}}}{{suffix}} = {{{value}}};{{/isBoolean}} {{#isEnum}}{{{objectName}}} {{{key}}}{{suffix}} = {{{objectName}}}.fromValue("{{{value}}}");{{/isEnum}} -{{#isArray}}List {{{key}}}{{suffix}} = new ArrayList(); { {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.add({{{key}}}{{suffix}});{{/value}} }{{/isArray}} +{{#isArray}}List{{> generateGenerics}} {{{key}}}{{suffix}} = new ArrayList<>(); { {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.add({{> maybeConvertOneOf}});{{/value}} }{{/isArray}} {{#isObject}}{{{objectName}}} {{{key}}}{{suffix}} = new {{{objectName}}}(); -{ {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.set{{#lambda.titlecase}}{{{key}}}{{/lambda.titlecase}}({{{key}}}{{suffix}}); -{{/value}} }{{/isObject}}{{#isFreeFormObject}}HashMap {{{key}}}{{suffix}} = new HashMap(); -{ {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.put("{{{key}}}", {{{key}}}{{suffix}}); -{{/value}} }{{/isFreeFormObject}} +{ {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.set{{#lambda.titlecase}}{{{key}}}{{/lambda.titlecase}}({{> maybeConvertOneOf}}); +{{/value}} }{{/isObject}}{{#isFreeFormObject}}Map{{> forceMapGenerics}} {{{key}}}{{suffix}} = new HashMap<>(); +{ {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.put("{{{key}}}", {{> maybeConvertOneOf}}); +{{/value}} }{{/isFreeFormObject}} \ No newline at end of file diff --git a/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache b/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache new file mode 100644 index 0000000000..8fbf61e976 --- /dev/null +++ b/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache @@ -0,0 +1 @@ +{{#oneOfModel}}{{{classname}}}.of{{{name}}}({{{key}}}{{suffix}}){{/oneOfModel}}{{^oneOfModel}}{{{key}}}{{suffix}}{{/oneOfModel}} \ No newline at end of file diff --git a/tests/CTS/methods/requests/templates/java/requests.mustache b/tests/CTS/methods/requests/templates/java/requests.mustache index 47318abbe7..255e83dea0 100644 --- a/tests/CTS/methods/requests/templates/java/requests.mustache +++ b/tests/CTS/methods/requests/templates/java/requests.mustache @@ -1,6 +1,7 @@ package com.algolia.methods.requests; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import java.util.*; @@ -13,8 +14,8 @@ import com.google.gson.reflect.TypeToken; import com.algolia.JSON; import com.algolia.Pair; -import com.algolia.model.search.*; -import com.algolia.search.{{client}}; +import com.algolia.model.{{import}}.*; +import com.algolia.api.{{client}}; import com.algolia.utils.echo.*; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; @@ -36,7 +37,7 @@ class {{client}}Tests { {{#parametersWithDataType}}{{> generateParams}}{{/parametersWithDataType}} EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.{{method}}({{#parametersWithDataType}}{{#oneOfModel}}{{{classname}}}.of{{{name}}}({{{key}}}{{suffix}}){{/oneOfModel}}{{^oneOfModel}}{{{key}}}{{suffix}}{{/oneOfModel}}{{^-last}},{{/-last}}{{/parametersWithDataType}}); + return client.{{method}}({{#parametersWithDataType}}{{> maybeConvertOneOf}}{{^-last}},{{/-last}}{{/parametersWithDataType}}); }); assertEquals(req.getPath(), "{{{request.path}}}"); @@ -49,10 +50,16 @@ class {{client}}Tests { {{/request.data}} {{#request.searchParams}} - HashMap expectedQuery = JSON.deserialize("{{#lambda.escapequotes}}{{{request.searchParams}}}{{/lambda.escapequotes}}", new TypeToken>() {}.getType()); + Map expectedQuery = JSON.deserialize("{{#lambda.escapequotes}}{{{request.searchParams}}}{{/lambda.escapequotes}}", new TypeToken>() {}.getType()); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if (p.getName().equals(entry.getKey()) && p.getValue().equals(entry.getValue())) { + found = true; + } + } + assertTrue(found, "Query parameter " + entry.getKey() + " not found in the actual query"); } {{/request.searchParams}} } diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/abtesting.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/abtesting.test.java new file mode 100644 index 0000000000..d7ae7ac106 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/abtesting.test.java @@ -0,0 +1,421 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.AbtestingApi; +import com.algolia.model.abtesting.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class AbtestingApiTests { + + private AbtestingApi client; + + @BeforeAll + void init() { + client = new AbtestingApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("addABTests with minimal parameters") + void addABTestsTest0() { + AddABTestsRequest addABTestsRequest0 = new AddABTestsRequest(); + { + String endAt1 = "2022-12-31T00:00:00.000Z"; + + addABTestsRequest0.setEndAt(endAt1); + String name1 = "myABTest"; + + addABTestsRequest0.setName(name1); + + List variant1 = new ArrayList<>(); + { + AbTestsVariant variant_02 = new AbTestsVariant(); + { + String index3 = "AB_TEST_1"; + + variant_02.setIndex(index3); + + int trafficPercentage3 = 30; + + variant_02.setTrafficPercentage(trafficPercentage3); + } + variant1.add(AddABTestsVariant.ofAbTestsVariant(variant_02)); + + AbTestsVariant variant_12 = new AbTestsVariant(); + { + String index3 = "AB_TEST_2"; + + variant_12.setIndex(index3); + + int trafficPercentage3 = 50; + + variant_12.setTrafficPercentage(trafficPercentage3); + } + variant1.add(AddABTestsVariant.ofAbTestsVariant(variant_12)); + } + addABTestsRequest0.setVariant(variant1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.addABTests(addABTestsRequest0); + } + ); + + assertEquals(req.getPath(), "/2/abtests"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"endAt\":\"2022-12-31T00:00:00.000Z\",\"name\":\"myABTest\",\"variant\":[{\"index\":\"AB_TEST_1\",\"trafficPercentage\":30},{\"index\":\"AB_TEST_2\",\"trafficPercentage\":50}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("deleteABTest") + void deleteABTestTest0() { + int id0 = 42; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.deleteABTest(id0); + } + ); + + assertEquals(req.getPath(), "/2/abtests/42"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("getABTest") + void getABTestTest0() { + int id0 = 42; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getABTest(id0); + } + ); + + assertEquals(req.getPath(), "/2/abtests/42"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("listABTests with minimal parameters") + void listABTestsTest0() { + int offset0 = 42; + + int limit0 = 21; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.listABTests(offset0, limit0); + } + ); + + assertEquals(req.getPath(), "/2/abtests"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"offset\":\"42\",\"limit\":\"21\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("stopABTest") + void stopABTestTest0() { + int id0 = 42; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.stopABTest(id0); + } + ); + + assertEquals(req.getPath(), "/2/abtests/42/stop"); + assertEquals(req.getMethod(), "POST"); + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/analytics.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/analytics.test.java new file mode 100644 index 0000000000..c10e9c5147 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/analytics.test.java @@ -0,0 +1,1756 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.AnalyticsApi; +import com.algolia.model.analytics.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class AnalyticsApiTests { + + private AnalyticsApi client; + + @BeforeAll + void init() { + client = new AnalyticsApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getAverageClickPosition with minimal parameters") + void getAverageClickPositionTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getAverageClickPosition(index0); + } + ); + + assertEquals(req.getPath(), "/2/clicks/averageClickPosition"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getAverageClickPosition with all parameters") + void getAverageClickPositionTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getAverageClickPosition( + index0, + startDate0, + endDate0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/clicks/averageClickPosition"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getClickPositions with minimal parameters") + void getClickPositionsTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getClickPositions(index0); + } + ); + + assertEquals(req.getPath(), "/2/clicks/positions"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getClickPositions with all parameters") + void getClickPositionsTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getClickPositions(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/clicks/positions"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getClickThroughRate with minimal parameters") + void getClickThroughRateTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getClickThroughRate(index0); + } + ); + + assertEquals(req.getPath(), "/2/clicks/clickThroughRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getClickThroughRate with all parameters") + void getClickThroughRateTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getClickThroughRate(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/clicks/clickThroughRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getConversationRate with minimal parameters") + void getConversationRateTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getConversationRate(index0); + } + ); + + assertEquals(req.getPath(), "/2/conversions/conversionRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getConversationRate with all parameters") + void getConversationRateTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getConversationRate(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/conversions/conversionRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getNoClickRate with minimal parameters") + void getNoClickRateTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getNoClickRate(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noClickRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getNoClickRate with all parameters") + void getNoClickRateTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getNoClickRate(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noClickRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getNoResultsRate with minimal parameters") + void getNoResultsRateTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getNoResultsRate(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noResultRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getNoResultsRate with all parameters") + void getNoResultsRateTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getNoResultsRate(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noResultRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesCount with minimal parameters") + void getSearchesCountTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesCount(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches/count"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesCount with all parameters") + void getSearchesCountTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesCount(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/searches/count"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesNoClicks with minimal parameters") + void getSearchesNoClicksTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesNoClicks(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noClicks"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesNoClicks with all parameters") + void getSearchesNoClicksTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesNoClicks( + index0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/searches/noClicks"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesNoResults with minimal parameters") + void getSearchesNoResultsTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesNoResults(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noResults"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesNoResults with all parameters") + void getSearchesNoResultsTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesNoResults( + index0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/searches/noResults"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getStatus with minimal parameters") + void getStatusTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getStatus(index0); + } + ); + + assertEquals(req.getPath(), "/2/status"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopCountries with minimal parameters") + void getTopCountriesTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopCountries(index0); + } + ); + + assertEquals(req.getPath(), "/2/countries"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopCountries with all parameters") + void getTopCountriesTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopCountries( + index0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/countries"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFilterAttributes with minimal parameters") + void getTopFilterAttributesTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterAttributes(index0); + } + ); + + assertEquals(req.getPath(), "/2/filters"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFilterAttributes with all parameters") + void getTopFilterAttributesTest1() { + String index0 = "index"; + + String search0 = "mySearch"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterAttributes( + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/filters"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFilterForAttribute with minimal parameters") + void getTopFilterForAttributeTest0() { + String attribute0 = "myAttribute"; + + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterForAttribute(attribute0, index0); + } + ); + + assertEquals(req.getPath(), "/2/filters/myAttribute"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName( + "get getTopFilterForAttribute with minimal parameters and multiple attributes" + ) + void getTopFilterForAttributeTest1() { + String attribute0 = "myAttribute1,myAttribute2"; + + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterForAttribute(attribute0, index0); + } + ); + + assertEquals(req.getPath(), "/2/filters/myAttribute1%2CmyAttribute2"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFilterForAttribute with all parameters") + void getTopFilterForAttributeTest2() { + String attribute0 = "myAttribute"; + + String index0 = "index"; + + String search0 = "mySearch"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterForAttribute( + attribute0, + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/filters/myAttribute"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName( + "get getTopFilterForAttribute with all parameters and multiple attributes" + ) + void getTopFilterForAttributeTest3() { + String attribute0 = "myAttribute1,myAttribute2"; + + String index0 = "index"; + + String search0 = "mySearch"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterForAttribute( + attribute0, + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/filters/myAttribute1%2CmyAttribute2"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFiltersNoResults with minimal parameters") + void getTopFiltersNoResultsTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFiltersNoResults(index0); + } + ); + + assertEquals(req.getPath(), "/2/filters/noResults"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFiltersNoResults with all parameters") + void getTopFiltersNoResultsTest1() { + String index0 = "index"; + + String search0 = "mySearch"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFiltersNoResults( + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/filters/noResults"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopHits with minimal parameters") + void getTopHitsTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopHits(index0); + } + ); + + assertEquals(req.getPath(), "/2/hits"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopHits with all parameters") + void getTopHitsTest1() { + String index0 = "index"; + + String search0 = "mySearch"; + + boolean clickAnalytics0 = true; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopHits( + index0, + search0, + clickAnalytics0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/hits"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"search\":\"mySearch\",\"clickAnalytics\":\"true\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopSearches with minimal parameters") + void getTopSearchesTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopSearches(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopSearches with all parameters") + void getTopSearchesTest1() { + String index0 = "index"; + + boolean clickAnalytics0 = true; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + OrderBy orderBy0 = OrderBy.fromValue("searchCount"); + + Direction direction0 = Direction.fromValue("asc"); + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopSearches( + index0, + clickAnalytics0, + startDate0, + endDate0, + orderBy0, + direction0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/searches"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"clickAnalytics\":\"true\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"orderBy\":\"searchCount\",\"direction\":\"asc\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getUsersCount with minimal parameters") + void getUsersCountTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getUsersCount(index0); + } + ); + + assertEquals(req.getPath(), "/2/users/count"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getUsersCount with all parameters") + void getUsersCountTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getUsersCount(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/users/count"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/insights.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/insights.test.java new file mode 100644 index 0000000000..f211036175 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/insights.test.java @@ -0,0 +1,428 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.InsightsApi; +import com.algolia.model.insights.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class InsightsApiTests { + + private InsightsApi client; + + @BeforeAll + void init() { + client = new InsightsApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("pushEvents") + void pushEventsTest0() { + InsightEvents insightEvents0 = new InsightEvents(); + { + List events1 = new ArrayList<>(); + { + InsightEvent events_02 = new InsightEvent(); + { + EventType eventType3 = EventType.fromValue("click"); + + events_02.setEventType(eventType3); + String eventName3 = "Product Clicked"; + + events_02.setEventName(eventName3); + String index3 = "products"; + + events_02.setIndex(index3); + String userToken3 = "user-123456"; + + events_02.setUserToken(userToken3); + + long timestamp3 = 1641290601962L; + + events_02.setTimestamp(timestamp3); + + List objectIDs3 = new ArrayList<>(); + { + String objectIDs_04 = "9780545139700"; + + objectIDs3.add(objectIDs_04); + String objectIDs_14 = "9780439784542"; + + objectIDs3.add(objectIDs_14); + } + events_02.setObjectIDs(objectIDs3); + String queryID3 = "43b15df305339e827f0ac0bdc5ebcaa7"; + + events_02.setQueryID(queryID3); + + List positions3 = new ArrayList<>(); + { + int positions_04 = 7; + + positions3.add(positions_04); + int positions_14 = 6; + + positions3.add(positions_14); + } + events_02.setPositions(positions3); + } + events1.add(events_02); + + InsightEvent events_12 = new InsightEvent(); + { + EventType eventType3 = EventType.fromValue("view"); + + events_12.setEventType(eventType3); + String eventName3 = "Product Detail Page Viewed"; + + events_12.setEventName(eventName3); + String index3 = "products"; + + events_12.setIndex(index3); + String userToken3 = "user-123456"; + + events_12.setUserToken(userToken3); + + long timestamp3 = 1641290601962L; + + events_12.setTimestamp(timestamp3); + + List objectIDs3 = new ArrayList<>(); + { + String objectIDs_04 = "9780545139700"; + + objectIDs3.add(objectIDs_04); + String objectIDs_14 = "9780439784542"; + + objectIDs3.add(objectIDs_14); + } + events_12.setObjectIDs(objectIDs3); + } + events1.add(events_12); + + InsightEvent events_22 = new InsightEvent(); + { + EventType eventType3 = EventType.fromValue("conversion"); + + events_22.setEventType(eventType3); + String eventName3 = "Product Purchased"; + + events_22.setEventName(eventName3); + String index3 = "products"; + + events_22.setIndex(index3); + String userToken3 = "user-123456"; + + events_22.setUserToken(userToken3); + + long timestamp3 = 1641290601962L; + + events_22.setTimestamp(timestamp3); + + List objectIDs3 = new ArrayList<>(); + { + String objectIDs_04 = "9780545139700"; + + objectIDs3.add(objectIDs_04); + String objectIDs_14 = "9780439784542"; + + objectIDs3.add(objectIDs_14); + } + events_22.setObjectIDs(objectIDs3); + String queryID3 = "43b15df305339e827f0ac0bdc5ebcaa7"; + + events_22.setQueryID(queryID3); + } + events1.add(events_22); + } + insightEvents0.setEvents(events1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.pushEvents(insightEvents0); + } + ); + + assertEquals(req.getPath(), "/1/events"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"events\":[{\"eventType\":\"click\",\"eventName\":\"Product" + + " Clicked\",\"index\":\"products\",\"userToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\",\"positions\":[7,6]},{\"eventType\":\"view\",\"eventName\":\"Product" + + " Detail Page" + + " Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]},{\"eventType\":\"conversion\",\"eventName\":\"Product" + + " Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/personalization.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/personalization.test.java new file mode 100644 index 0000000000..f29ff3dc48 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/personalization.test.java @@ -0,0 +1,388 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.PersonalizationApi; +import com.algolia.model.personalization.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class PersonalizationApiTests { + + private PersonalizationApi client; + + @BeforeAll + void init() { + client = new PersonalizationApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("delete deleteUserProfile") + void deleteUserProfileTest0() { + String userToken0 = "UserToken"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.deleteUserProfile(userToken0); + } + ); + + assertEquals(req.getPath(), "/1/profiles/UserToken"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getPersonalizationStrategy") + void getPersonalizationStrategyTest0() { + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getPersonalizationStrategy(); + } + ); + + assertEquals(req.getPath(), "/1/strategies/personalization"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("get getUserTokenProfile") + void getUserTokenProfileTest0() { + String userToken0 = "UserToken"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getUserTokenProfile(userToken0); + } + ); + + assertEquals(req.getPath(), "/1/profiles/personalization/UserToken"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("set setPersonalizationStrategy") + void setPersonalizationStrategyTest0() { + PersonalizationStrategyParams personalizationStrategyParams0 = new PersonalizationStrategyParams(); + { + List eventScoring1 = new ArrayList<>(); + { + EventScoring eventScoring_02 = new EventScoring(); + { + int score3 = 42; + + eventScoring_02.setScore(score3); + String eventName3 = "Algolia"; + + eventScoring_02.setEventName(eventName3); + String eventType3 = "Event"; + + eventScoring_02.setEventType(eventType3); + } + eventScoring1.add(eventScoring_02); + } + personalizationStrategyParams0.setEventScoring(eventScoring1); + + List facetScoring1 = new ArrayList<>(); + { + FacetScoring facetScoring_02 = new FacetScoring(); + { + int score3 = 42; + + facetScoring_02.setScore(score3); + String facetName3 = "Event"; + + facetScoring_02.setFacetName(facetName3); + } + facetScoring1.add(facetScoring_02); + } + personalizationStrategyParams0.setFacetScoring(facetScoring1); + + int personalizationImpact1 = 42; + + personalizationStrategyParams0.setPersonalizationImpact( + personalizationImpact1 + ); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.setPersonalizationStrategy( + personalizationStrategyParams0 + ); + } + ); + + assertEquals(req.getPath(), "/1/strategies/personalization"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"eventScoring\":[{\"score\":42,\"eventName\":\"Algolia\",\"eventType\":\"Event\"}],\"facetScoring\":[{\"score\":42,\"facetName\":\"Event\"}],\"personalizationImpact\":42}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/query-suggestions.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/query-suggestions.test.java new file mode 100644 index 0000000000..a709f46f24 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/query-suggestions.test.java @@ -0,0 +1,530 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.QuerySuggestionsApi; +import com.algolia.model.querySuggestions.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class QuerySuggestionsApiTests { + + private QuerySuggestionsApi client; + + @BeforeAll + void init() { + client = new QuerySuggestionsApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("createConfig") + void createConfigTest0() { + QuerySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam0 = new QuerySuggestionsIndexWithIndexParam(); + { + String indexName1 = "theIndexName"; + + querySuggestionsIndexWithIndexParam0.setIndexName(indexName1); + + List sourceIndices1 = new ArrayList<>(); + { + SourceIndex sourceIndices_02 = new SourceIndex(); + { + String indexName3 = "testIndex"; + + sourceIndices_02.setIndexName(indexName3); + + List facets3 = new ArrayList<>(); + { + Map facets_04 = new HashMap<>(); + { + String attributes5 = "test"; + + facets_04.put("attributes", attributes5); + } + facets3.add(facets_04); + } + sourceIndices_02.setFacets(facets3); + + List> generate3 = new ArrayList<>(); + { + List generate_04 = new ArrayList<>(); + { + String generate_0_05 = "facetA"; + + generate_04.add(generate_0_05); + String generate_0_15 = "facetB"; + + generate_04.add(generate_0_15); + } + generate3.add(generate_04); + + List generate_14 = new ArrayList<>(); + { + String generate_1_05 = "facetC"; + + generate_14.add(generate_1_05); + } + generate3.add(generate_14); + } + sourceIndices_02.setGenerate(generate3); + } + sourceIndices1.add(sourceIndices_02); + } + querySuggestionsIndexWithIndexParam0.setSourceIndices(sourceIndices1); + + List languages1 = new ArrayList<>(); + { + String languages_02 = "french"; + + languages1.add(languages_02); + } + querySuggestionsIndexWithIndexParam0.setLanguages(languages1); + + List exclude1 = new ArrayList<>(); + { + String exclude_02 = "test"; + + exclude1.add(exclude_02); + } + querySuggestionsIndexWithIndexParam0.setExclude(exclude1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.createConfig(querySuggestionsIndexWithIndexParam0); + } + ); + + assertEquals(req.getPath(), "/1/configs"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"indexName\":\"theIndexName\",\"sourceIndices\":[{\"indexName\":\"testIndex\",\"facets\":[{\"attributes\":\"test\"}],\"generate\":[[\"facetA\",\"facetB\"],[\"facetC\"]]}],\"languages\":[\"french\"],\"exclude\":[\"test\"]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("deleteConfig") + void deleteConfigTest0() { + String indexName0 = "theIndexName"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.deleteConfig(indexName0); + } + ); + + assertEquals(req.getPath(), "/1/configs/theIndexName"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("getAllConfigs") + void getAllConfigsTest0() { + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getAllConfigs(); + } + ); + + assertEquals(req.getPath(), "/1/configs"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("getConfig") + void getConfigTest0() { + String indexName0 = "theIndexName"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getConfig(indexName0); + } + ); + + assertEquals(req.getPath(), "/1/configs/theIndexName"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("getConfigStatus") + void getConfigStatusTest0() { + String indexName0 = "theIndexName"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getConfigStatus(indexName0); + } + ); + + assertEquals(req.getPath(), "/1/configs/theIndexName/status"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("getLogFile") + void getLogFileTest0() { + String indexName0 = "theIndexName"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getLogFile(indexName0); + } + ); + + assertEquals(req.getPath(), "/1/logs/theIndexName"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("updateConfig") + void updateConfigTest0() { + String indexName0 = "theIndexName"; + + QuerySuggestionsIndexParam querySuggestionsIndexParam0 = new QuerySuggestionsIndexParam(); + { + List sourceIndices1 = new ArrayList<>(); + { + SourceIndex sourceIndices_02 = new SourceIndex(); + { + String indexName3 = "testIndex"; + + sourceIndices_02.setIndexName(indexName3); + + List facets3 = new ArrayList<>(); + { + Map facets_04 = new HashMap<>(); + { + String attributes5 = "test"; + + facets_04.put("attributes", attributes5); + } + facets3.add(facets_04); + } + sourceIndices_02.setFacets(facets3); + + List> generate3 = new ArrayList<>(); + { + List generate_04 = new ArrayList<>(); + { + String generate_0_05 = "facetA"; + + generate_04.add(generate_0_05); + String generate_0_15 = "facetB"; + + generate_04.add(generate_0_15); + } + generate3.add(generate_04); + + List generate_14 = new ArrayList<>(); + { + String generate_1_05 = "facetC"; + + generate_14.add(generate_1_05); + } + generate3.add(generate_14); + } + sourceIndices_02.setGenerate(generate3); + } + sourceIndices1.add(sourceIndices_02); + } + querySuggestionsIndexParam0.setSourceIndices(sourceIndices1); + + List languages1 = new ArrayList<>(); + { + String languages_02 = "french"; + + languages1.add(languages_02); + } + querySuggestionsIndexParam0.setLanguages(languages1); + + List exclude1 = new ArrayList<>(); + { + String exclude_02 = "test"; + + exclude1.add(exclude_02); + } + querySuggestionsIndexParam0.setExclude(exclude1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.updateConfig(indexName0, querySuggestionsIndexParam0); + } + ); + + assertEquals(req.getPath(), "/1/configs/theIndexName"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"sourceIndices\":[{\"indexName\":\"testIndex\",\"facets\":[{\"attributes\":\"test\"}],\"generate\":[[\"facetA\",\"facetB\"],[\"facetC\"]]}],\"languages\":[\"french\"],\"exclude\":[\"test\"]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java new file mode 100644 index 0000000000..9352bd6b17 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java @@ -0,0 +1,818 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.RecommendApi; +import com.algolia.model.recommend.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class RecommendApiTests { + + private RecommendApi client; + + @BeforeAll + void init() { + client = new RecommendApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName( + "get recommendations for recommend model with minimal parameters" + ) + void getRecommendationsTest0() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + RecommendationRequest requests_02 = new RecommendationRequest(); + { + String indexName3 = "indexName"; + + requests_02.setIndexName(indexName3); + String objectID3 = "objectID"; + + requests_02.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_02.setModel(model3); + + int threshold3 = 42; + + requests_02.setThreshold(threshold3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_02) + ); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName\",\"objectID\":\"objectID\",\"model\":\"related-products\",\"threshold\":42}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get recommendations for recommend model with all parameters") + void getRecommendationsTest1() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + RecommendationRequest requests_02 = new RecommendationRequest(); + { + String indexName3 = "indexName"; + + requests_02.setIndexName(indexName3); + String objectID3 = "objectID"; + + requests_02.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_02.setModel(model3); + + int threshold3 = 42; + + requests_02.setThreshold(threshold3); + + int maxRecommendations3 = 10; + + requests_02.setMaxRecommendations(maxRecommendations3); + + SearchParamsObject queryParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + queryParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "query"; + + facetFilters4.add(facetFilters_05); + } + queryParameters3.setFacetFilters(facetFilters4); + } + requests_02.setQueryParameters(queryParameters3); + + SearchParamsObject fallbackParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + fallbackParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "fallback"; + + facetFilters4.add(facetFilters_05); + } + fallbackParameters3.setFacetFilters(facetFilters4); + } + requests_02.setFallbackParameters(fallbackParameters3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_02) + ); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName\",\"objectID\":\"objectID\",\"model\":\"related-products\",\"threshold\":42,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback\"]}}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get recommendations for trending model with minimal parameters") + void getRecommendationsTest2() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + TrendingRequest requests_02 = new TrendingRequest(); + { + String indexName3 = "indexName"; + + requests_02.setIndexName(indexName3); + + TrendingModels model3 = TrendingModels.fromValue("trending-items"); + + requests_02.setModel(model3); + + int threshold3 = 42; + + requests_02.setThreshold(threshold3); + } + requests1.add(RecommendationsRequest.ofTrendingRequest(requests_02)); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName\",\"model\":\"trending-items\",\"threshold\":42}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get recommendations for trending model with all parameters") + void getRecommendationsTest3() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + TrendingRequest requests_02 = new TrendingRequest(); + { + String indexName3 = "indexName"; + + requests_02.setIndexName(indexName3); + + TrendingModels model3 = TrendingModels.fromValue("trending-items"); + + requests_02.setModel(model3); + + int threshold3 = 42; + + requests_02.setThreshold(threshold3); + + int maxRecommendations3 = 10; + + requests_02.setMaxRecommendations(maxRecommendations3); + String facetName3 = "myFacetName"; + + requests_02.setFacetName(facetName3); + String facetValue3 = "myFacetValue"; + + requests_02.setFacetValue(facetValue3); + + SearchParamsObject queryParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + queryParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "query"; + + facetFilters4.add(facetFilters_05); + } + queryParameters3.setFacetFilters(facetFilters4); + } + requests_02.setQueryParameters(queryParameters3); + + SearchParamsObject fallbackParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + fallbackParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "fallback"; + + facetFilters4.add(facetFilters_05); + } + fallbackParameters3.setFacetFilters(facetFilters4); + } + requests_02.setFallbackParameters(fallbackParameters3); + } + requests1.add(RecommendationsRequest.ofTrendingRequest(requests_02)); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName\",\"model\":\"trending-items\",\"threshold\":42,\"maxRecommendations\":10,\"facetName\":\"myFacetName\",\"facetValue\":\"myFacetValue\",\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback\"]}}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get multiple recommendations with minimal parameters") + void getRecommendationsTest4() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + RecommendationRequest requests_02 = new RecommendationRequest(); + { + String indexName3 = "indexName1"; + + requests_02.setIndexName(indexName3); + String objectID3 = "objectID1"; + + requests_02.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_02.setModel(model3); + + int threshold3 = 21; + + requests_02.setThreshold(threshold3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_02) + ); + + RecommendationRequest requests_12 = new RecommendationRequest(); + { + String indexName3 = "indexName2"; + + requests_12.setIndexName(indexName3); + String objectID3 = "objectID2"; + + requests_12.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_12.setModel(model3); + + int threshold3 = 21; + + requests_12.setThreshold(threshold3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_12) + ); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"related-products\",\"threshold\":21},{\"indexName\":\"indexName2\",\"objectID\":\"objectID2\",\"model\":\"related-products\",\"threshold\":21}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get multiple recommendations with all parameters") + void getRecommendationsTest5() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + RecommendationRequest requests_02 = new RecommendationRequest(); + { + String indexName3 = "indexName1"; + + requests_02.setIndexName(indexName3); + String objectID3 = "objectID1"; + + requests_02.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_02.setModel(model3); + + int threshold3 = 21; + + requests_02.setThreshold(threshold3); + + int maxRecommendations3 = 10; + + requests_02.setMaxRecommendations(maxRecommendations3); + + SearchParamsObject queryParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + queryParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "query1"; + + facetFilters4.add(facetFilters_05); + } + queryParameters3.setFacetFilters(facetFilters4); + } + requests_02.setQueryParameters(queryParameters3); + + SearchParamsObject fallbackParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + fallbackParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "fallback1"; + + facetFilters4.add(facetFilters_05); + } + fallbackParameters3.setFacetFilters(facetFilters4); + } + requests_02.setFallbackParameters(fallbackParameters3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_02) + ); + + RecommendationRequest requests_12 = new RecommendationRequest(); + { + String indexName3 = "indexName2"; + + requests_12.setIndexName(indexName3); + String objectID3 = "objectID2"; + + requests_12.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_12.setModel(model3); + + int threshold3 = 21; + + requests_12.setThreshold(threshold3); + + int maxRecommendations3 = 10; + + requests_12.setMaxRecommendations(maxRecommendations3); + + SearchParamsObject queryParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + queryParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "query2"; + + facetFilters4.add(facetFilters_05); + } + queryParameters3.setFacetFilters(facetFilters4); + } + requests_12.setQueryParameters(queryParameters3); + + SearchParamsObject fallbackParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + fallbackParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "fallback2"; + + facetFilters4.add(facetFilters_05); + } + fallbackParameters3.setFacetFilters(facetFilters4); + } + requests_12.setFallbackParameters(fallbackParameters3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_12) + ); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"related-products\",\"threshold\":21,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query1\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback1\"]}},{\"indexName\":\"indexName2\",\"objectID\":\"objectID2\",\"model\":\"related-products\",\"threshold\":21,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query2\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback2\"]}}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get frequently bought together recommendations") + void getRecommendationsTest6() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + RecommendationRequest requests_02 = new RecommendationRequest(); + { + String indexName3 = "indexName1"; + + requests_02.setIndexName(indexName3); + String objectID3 = "objectID1"; + + requests_02.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "bought-together" + ); + + requests_02.setModel(model3); + + int threshold3 = 42; + + requests_02.setThreshold(threshold3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_02) + ); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"bought-together\",\"threshold\":42}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java index 07978e2488..c6c1b1ec31 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java @@ -2,11 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.algolia.JSON; import com.algolia.Pair; +import com.algolia.api.SearchApi; import com.algolia.model.search.*; -import com.algolia.search.SearchApi; import com.algolia.utils.echo.*; import com.google.gson.reflect.TypeToken; import java.util.*; @@ -32,7 +33,7 @@ void init() { void addApiKeyTest0() { ApiKey apiKey0 = new ApiKey(); { - List acl1 = new ArrayList(); + List acl1 = new ArrayList<>(); { Acl acl_02 = Acl.fromValue("search"); @@ -42,7 +43,6 @@ void addApiKeyTest0() { acl1.add(acl_12); } - apiKey0.setAcl(acl1); String description1 = "my new api key"; @@ -86,7 +86,7 @@ void addOrUpdateObjectTest0() { String objectID0 = "uniqueID"; - HashMap body0 = new HashMap(); + Map body0 = new HashMap<>(); { String key1 = "value"; @@ -168,13 +168,25 @@ void assignUserIdTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"X-Algolia-User-ID\":\"userID\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -185,7 +197,7 @@ void batchTest0() { BatchWriteParams batchWriteParams0 = new BatchWriteParams(); { - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { BatchOperation requests_02 = new BatchOperation(); { @@ -193,7 +205,7 @@ void batchTest0() { requests_02.setAction(action3); - HashMap body3 = new HashMap(); + Map body3 = new HashMap<>(); { String key4 = "value"; @@ -203,7 +215,6 @@ void batchTest0() { } requests1.add(requests_02); } - batchWriteParams0.setRequests(requests1); } @@ -235,7 +246,7 @@ void batchAssignUserIdsTest0() { batchAssignUserIdsParams0.setCluster(cluster1); - List users1 = new ArrayList(); + List users1 = new ArrayList<>(); { String users_02 = "user1"; @@ -244,7 +255,6 @@ void batchAssignUserIdsTest0() { users1.add(users_12); } - batchAssignUserIdsParams0.setUsers(users1); } @@ -267,13 +277,25 @@ void batchAssignUserIdsTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"X-Algolia-User-ID\":\"userID\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -284,7 +306,7 @@ void batchDictionaryEntriesTest0() { BatchDictionaryEntriesParams batchDictionaryEntriesParams0 = new BatchDictionaryEntriesParams(); { - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { BatchDictionaryEntriesRequest requests_02 = new BatchDictionaryEntriesRequest(); { @@ -324,7 +346,6 @@ void batchDictionaryEntriesTest0() { } requests1.add(requests_12); } - batchDictionaryEntriesParams0.setRequests(requests1); } @@ -361,7 +382,7 @@ void batchDictionaryEntriesTest1() { clearExistingDictionaryEntries1 ); - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { BatchDictionaryEntriesRequest requests_02 = new BatchDictionaryEntriesRequest(); { @@ -381,7 +402,7 @@ void batchDictionaryEntriesTest1() { body3.setWord(word4); - List words4 = new ArrayList(); + List words4 = new ArrayList<>(); { String words_05 = "believe"; @@ -390,10 +411,9 @@ void batchDictionaryEntriesTest1() { words4.add(words_15); } - body3.setWords(words4); - List decomposition4 = new ArrayList(); + List decomposition4 = new ArrayList<>(); { String decomposition_05 = "trust"; @@ -402,7 +422,6 @@ void batchDictionaryEntriesTest1() { decomposition4.add(decomposition_15); } - body3.setDecomposition(decomposition4); DictionaryEntryState state4 = DictionaryEntryState.fromValue( @@ -433,7 +452,7 @@ void batchDictionaryEntriesTest1() { body3.setWord(word4); - List words4 = new ArrayList(); + List words4 = new ArrayList<>(); { String words_05 = "candor"; @@ -442,10 +461,9 @@ void batchDictionaryEntriesTest1() { words4.add(words_15); } - body3.setWords(words4); - List decomposition4 = new ArrayList(); + List decomposition4 = new ArrayList<>(); { String decomposition_05 = "grit"; @@ -454,7 +472,6 @@ void batchDictionaryEntriesTest1() { decomposition4.add(decomposition_15); } - body3.setDecomposition(decomposition4); DictionaryEntryState state4 = DictionaryEntryState.fromValue( @@ -467,7 +484,6 @@ void batchDictionaryEntriesTest1() { } requests1.add(requests_12); } - batchDictionaryEntriesParams0.setRequests(requests1); } @@ -496,7 +512,7 @@ void batchDictionaryEntriesTest1() { void batchRulesTest0() { String indexName0 = "indexName"; - List rule0 = new ArrayList(); + List rule0 = new ArrayList<>(); { Rule rule_01 = new Rule(); { @@ -504,7 +520,7 @@ void batchRulesTest0() { rule_01.setObjectID(objectID2); - List conditions2 = new ArrayList(); + List conditions2 = new ArrayList<>(); { Condition conditions_03 = new Condition(); { @@ -518,7 +534,6 @@ void batchRulesTest0() { } conditions2.add(conditions_03); } - rule_01.setConditions(conditions2); Consequence consequence2 = new Consequence(); @@ -541,7 +556,7 @@ void batchRulesTest0() { rule_11.setObjectID(objectID2); - List conditions2 = new ArrayList(); + List conditions2 = new ArrayList<>(); { Condition conditions_03 = new Condition(); { @@ -555,7 +570,6 @@ void batchRulesTest0() { } conditions2.add(conditions_03); } - rule_11.setConditions(conditions2); Consequence consequence2 = new Consequence(); @@ -598,13 +612,25 @@ void batchRulesTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"forwardToReplicas\":\"true\",\"clearExistingRules\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -715,7 +741,7 @@ void delTest0() { void delTest1() { String path0 = "/test/all"; - HashMap parameters0 = new HashMap(); + Map parameters0 = new HashMap<>(); { String query1 = "parameters"; @@ -730,13 +756,25 @@ void delTest1() { assertEquals(req.getPath(), "/1/test/all"); assertEquals(req.getMethod(), "DELETE"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -881,7 +919,7 @@ void getTest0() { void getTest1() { String path0 = "/test/all"; - HashMap parameters0 = new HashMap(); + Map parameters0 = new HashMap<>(); { String query1 = "parameters"; @@ -896,13 +934,25 @@ void getTest1() { assertEquals(req.getPath(), "/1/test/all"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -963,13 +1013,25 @@ void getLogsTest0() { assertEquals(req.getPath(), "/1/logs"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"offset\":\"5\",\"length\":\"10\",\"indexName\":\"theIndexName\",\"type\":\"all\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -980,7 +1042,7 @@ void getObjectTest0() { String objectID0 = "uniqueID"; - List attributesToRetrieve0 = new ArrayList(); + List attributesToRetrieve0 = new ArrayList<>(); { String attributesToRetrieve_01 = "attr1"; @@ -998,13 +1060,25 @@ void getObjectTest0() { assertEquals(req.getPath(), "/1/indexes/theIndexName/uniqueID"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"attributesToRetrieve\":\"attr1,attr2\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1013,11 +1087,11 @@ void getObjectTest0() { void getObjectsTest0() { GetObjectsParams getObjectsParams0 = new GetObjectsParams(); { - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { MultipleGetObjectsParams requests_02 = new MultipleGetObjectsParams(); { - List attributesToRetrieve3 = new ArrayList(); + List attributesToRetrieve3 = new ArrayList<>(); { String attributesToRetrieve_04 = "attr1"; @@ -1026,7 +1100,6 @@ void getObjectsTest0() { attributesToRetrieve3.add(attributesToRetrieve_14); } - requests_02.setAttributesToRetrieve(attributesToRetrieve3); String objectID3 = "uniqueID"; @@ -1037,7 +1110,6 @@ void getObjectsTest0() { } requests1.add(requests_02); } - getObjectsParams0.setRequests(requests1); } @@ -1171,13 +1243,25 @@ void hasPendingMappingsTest0() { assertEquals(req.getPath(), "/1/clusters/mapping/pending"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"getClusters\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1218,13 +1302,25 @@ void listIndicesTest0() { assertEquals(req.getPath(), "/1/indexes"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"page\":\"8\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1243,13 +1339,25 @@ void listUserIdsTest0() { assertEquals(req.getPath(), "/1/clusters/mapping"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"page\":\"8\",\"hitsPerPage\":\"100\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1258,7 +1366,7 @@ void listUserIdsTest0() { void multipleBatchTest0() { BatchParams batchParams0 = new BatchParams(); { - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { MultipleBatchOperation requests_02 = new MultipleBatchOperation(); { @@ -1266,7 +1374,7 @@ void multipleBatchTest0() { requests_02.setAction(action3); - HashMap body3 = new HashMap(); + Map body3 = new HashMap<>(); { String key4 = "value"; @@ -1279,7 +1387,6 @@ void multipleBatchTest0() { } requests1.add(requests_02); } - batchParams0.setRequests(requests1); } @@ -1305,7 +1412,7 @@ void multipleBatchTest0() { void multipleQueriesTest0() { MultipleQueriesParams multipleQueriesParams0 = new MultipleQueriesParams(); { - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { MultipleQueries requests_02 = new MultipleQueries(); { @@ -1328,7 +1435,6 @@ void multipleQueriesTest0() { } requests1.add(requests_02); } - multipleQueriesParams0.setRequests(requests1); MultipleQueriesStrategy strategy1 = MultipleQueriesStrategy.fromValue( @@ -1369,7 +1475,7 @@ void operationIndexTest0() { operationIndexParams0.setDestination(destination1); - List scope1 = new ArrayList(); + List scope1 = new ArrayList<>(); { ScopeType scope_02 = ScopeType.fromValue("rules"); @@ -1379,7 +1485,6 @@ void operationIndexTest0() { scope1.add(scope_12); } - operationIndexParams0.setScope(scope1); } @@ -1407,13 +1512,16 @@ void partialUpdateObjectTest0() { String objectID0 = "uniqueID"; - List attributeOrBuiltInOperation0 = new ArrayList(); + List> attributeOrBuiltInOperation0 = new ArrayList<>(); { - HashMap attributeOrBuiltInOperation_01 = new HashMap(); + Map attributeOrBuiltInOperation_01 = new HashMap<>(); { String id12 = "test"; - attributeOrBuiltInOperation_01.put("id1", id12); + attributeOrBuiltInOperation_01.put( + "id1", + AttributeOrBuiltInOperation.ofString(id12) + ); BuiltInOperation id22 = new BuiltInOperation(); { @@ -1426,7 +1534,10 @@ void partialUpdateObjectTest0() { id22.setValue(value3); } - attributeOrBuiltInOperation_01.put("id2", id22); + attributeOrBuiltInOperation_01.put( + "id2", + AttributeOrBuiltInOperation.ofBuiltInOperation(id22) + ); } attributeOrBuiltInOperation0.add(attributeOrBuiltInOperation_01); } @@ -1454,13 +1565,25 @@ void partialUpdateObjectTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"createIfNotExists\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1483,14 +1606,14 @@ void postTest0() { void postTest1() { String path0 = "/test/all"; - HashMap parameters0 = new HashMap(); + Map parameters0 = new HashMap<>(); { String query1 = "parameters"; parameters0.put("query", query1); } - HashMap body0 = new HashMap(); + Map body0 = new HashMap<>(); { String body1 = "parameters"; @@ -1513,13 +1636,25 @@ void postTest1() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1542,14 +1677,14 @@ void putTest0() { void putTest1() { String path0 = "/test/all"; - HashMap parameters0 = new HashMap(); + Map parameters0 = new HashMap<>(); { String query1 = "parameters"; parameters0.put("query", query1); } - HashMap body0 = new HashMap(); + Map body0 = new HashMap<>(); { String body1 = "parameters"; @@ -1572,13 +1707,25 @@ void putTest1() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1599,7 +1746,7 @@ void removeUserIdTest0() { @Test @DisplayName("replaceSources") void replaceSourcesTest0() { - List source0 = new ArrayList(); + List source0 = new ArrayList<>(); { Source source_01 = new Source(); { @@ -1649,7 +1796,7 @@ void restoreApiKeyTest0() { void saveObjectTest0() { String indexName0 = "theIndexName"; - HashMap body0 = new HashMap(); + Map body0 = new HashMap<>(); { String objectID1 = "id"; @@ -1689,7 +1836,7 @@ void saveRuleTest0() { rule0.setObjectID(objectID1); - List conditions1 = new ArrayList(); + List conditions1 = new ArrayList<>(); { Condition conditions_02 = new Condition(); { @@ -1703,7 +1850,6 @@ void saveRuleTest0() { } conditions1.add(conditions_02); } - rule0.setConditions(conditions1); Consequence consequence1 = new Consequence(); @@ -1742,13 +1888,25 @@ void saveRuleTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1769,7 +1927,7 @@ void saveSynonymTest0() { synonymHit0.setType(type1); - List synonyms1 = new ArrayList(); + List synonyms1 = new ArrayList<>(); { String synonyms_02 = "car"; @@ -1781,7 +1939,6 @@ void saveSynonymTest0() { synonyms1.add(synonyms_22); } - synonymHit0.setSynonyms(synonyms1); } @@ -1808,13 +1965,25 @@ void saveSynonymTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1823,7 +1992,7 @@ void saveSynonymTest0() { void saveSynonymsTest0() { String indexName0 = "indexName"; - List synonymHit0 = new ArrayList(); + List synonymHit0 = new ArrayList<>(); { SynonymHit synonymHit_01 = new SynonymHit(); { @@ -1835,7 +2004,7 @@ void saveSynonymsTest0() { synonymHit_01.setType(type2); - List synonyms2 = new ArrayList(); + List synonyms2 = new ArrayList<>(); { String synonyms_03 = "car"; @@ -1847,7 +2016,6 @@ void saveSynonymsTest0() { synonyms2.add(synonyms_23); } - synonymHit_01.setSynonyms(synonyms2); } synonymHit0.add(synonymHit_01); @@ -1865,7 +2033,7 @@ void saveSynonymsTest0() { synonymHit_11.setInput(input2); - List synonyms2 = new ArrayList(); + List synonyms2 = new ArrayList<>(); { String synonyms_03 = "ephone"; @@ -1877,7 +2045,6 @@ void saveSynonymsTest0() { synonyms2.add(synonyms_23); } - synonymHit_11.setSynonyms(synonyms2); } synonymHit0.add(synonymHit_11); @@ -1908,13 +2075,25 @@ void saveSynonymsTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"forwardToReplicas\":\"true\",\"replaceExistingSynonyms\":\"false\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -2171,7 +2350,7 @@ void setDictionarySettingsTest0() { { StandardEntries disableStandardEntries1 = new StandardEntries(); { - HashMap plurals2 = new HashMap(); + Map plurals2 = new HashMap<>(); { boolean fr3 = false; @@ -2216,7 +2395,7 @@ void setDictionarySettingsTest1() { { StandardEntries disableStandardEntries1 = new StandardEntries(); { - HashMap plurals2 = new HashMap(); + Map plurals2 = new HashMap<>(); { boolean fr3 = false; @@ -2232,7 +2411,7 @@ void setDictionarySettingsTest1() { } disableStandardEntries1.setPlurals(plurals2); - HashMap stopwords2 = new HashMap(); + Map stopwords2 = new HashMap<>(); { boolean fr3 = false; @@ -2240,7 +2419,7 @@ void setDictionarySettingsTest1() { } disableStandardEntries1.setStopwords(stopwords2); - HashMap compounds2 = new HashMap(); + Map compounds2 = new HashMap<>(); { boolean ru3 = true; @@ -2304,13 +2483,25 @@ void setSettingsTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -2321,7 +2512,7 @@ void updateApiKeyTest0() { ApiKey apiKey0 = new ApiKey(); { - List acl1 = new ArrayList(); + List acl1 = new ArrayList<>(); { Acl acl_02 = Acl.fromValue("search"); @@ -2331,7 +2522,6 @@ void updateApiKeyTest0() { acl1.add(acl_12); } - apiKey0.setAcl(acl1); int validity1 = 300;