@@ -261,231 +261,6 @@ public class {{classname}} extends ApiClient {
261
261
{ {/optionalParams.0} }
262
262
{ {/operation} }
263
263
264
- { {#isSearchClient} }
265
- /**
266
- * Helper: Wait for a task to complete with `indexName` and `taskID`.
267
- *
268
- * @summary Wait for a task to complete.
269
- * @param indexName The `indexName` where the operation was performed.
270
- * @param taskID The `taskID` returned in the method response.
271
- * @param maxRetries The maximum number of retry. 50 by default. (optional)
272
- * @param timeout The function to decide how long to wait between retries. min(retries * 200, 5000) by default. (optional)
273
- * @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
274
- */
275
- public void waitForTask(String indexName, Long taskID, int maxRetries, IntUnaryOperator timeout, RequestOptions requestOptions) {
276
- TaskUtils.retryUntil(() -> {
277
- return this.getTask(indexName, taskID, requestOptions);
278
- } , (GetTaskResponse task) -> {
279
- return task.getStatus() == TaskStatus.PUBLISHED;
280
- } , maxRetries, timeout);
281
- }
282
-
283
- /**
284
- * Helper: Wait for a task to complete with `indexName` and `taskID`.
285
- *
286
- * @summary Wait for a task to complete.
287
- * @param indexName The `indexName` where the operation was performed.
288
- * @param taskID The `taskID` returned in the method response.
289
- * @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
290
- */
291
- public void waitForTask(String indexName, Long taskID, RequestOptions requestOptions) {
292
- this.waitForTask(indexName, taskID, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
293
- }
294
-
295
- /**
296
- * Helper: Wait for a task to complete with `indexName` and `taskID`.
297
- *
298
- * @summary Wait for a task to complete.
299
- * @param indexName The `indexName` where the operation was performed.
300
- * @param taskID The `taskID` returned in the method response.
301
- * @param maxRetries The maximum number of retry. 50 by default. (optional)
302
- * @param timeout The function to decide how long to wait between retries. min(retries * 200, 5000) by default. (optional)
303
- */
304
- public void waitForTask(String indexName, Long taskID, int maxRetries, IntUnaryOperator timeout) {
305
- this.waitForTask(indexName, taskID, maxRetries, timeout, null);
306
- }
307
-
308
- /**
309
- * Helper: Wait for a task to complete with `indexName` and `taskID`.
310
- *
311
- * @summary Wait for a task to complete.
312
- * @param indexName The `indexName` where the operation was performed.
313
- * @param taskID The `taskID` returned in the method response.
314
- */
315
- public void waitForTask(String indexName, Long taskID) {
316
- this.waitForTask(indexName, taskID, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
317
- }
318
-
319
- /**
320
- * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
321
- *
322
- * @summary Wait for an API key task to be processed.
323
- * @param operation The `operation` that was done on a `key`.
324
- * @param key The `key` that has been added, deleted or updated.
325
- * @param apiKey Necessary to know if an `update` operation has been processed, compare fields of the response with it.
326
- * @param maxRetries The maximum number of retry. 50 by default. (optional)
327
- * @param timeout The function to decide how long to wait between retries. min(retries * 200, 5000) by default. (optional)
328
- * @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
329
- */
330
- public GetApiKeyResponse waitForApiKey(
331
- ApiKeyOperation operation,
332
- String key,
333
- ApiKey apiKey,
334
- int maxRetries,
335
- IntUnaryOperator timeout,
336
- RequestOptions requestOptions
337
- ) {
338
- if (operation == ApiKeyOperation.UPDATE) {
339
- if (apiKey == null) {
340
- throw new AlgoliaRetryException(" `apiKey` is required when waiting for an `update` operation." );
341
- }
342
-
343
- // when updating an api key, we poll the api until we receive a different key
344
- return TaskUtils.retryUntil(
345
- () -> {
346
- return this.getApiKey(key, requestOptions);
347
- } ,
348
- (GetApiKeyResponse respKey) -> {
349
- // we need to convert to an ApiKey object to use the `equals` method
350
- ApiKey sameType = new ApiKey()
351
- .setAcl(respKey.getAcl())
352
- .setDescription(respKey.getDescription())
353
- .setIndexes(respKey.getIndexes())
354
- .setMaxHitsPerQuery(respKey.getMaxHitsPerQuery())
355
- .setMaxQueriesPerIPPerHour(respKey.getMaxQueriesPerIPPerHour())
356
- .setQueryParameters(respKey.getQueryParameters())
357
- .setReferers(respKey.getReferers())
358
- .setValidity(respKey.getValidity());
359
-
360
- return apiKey.equals(sameType);
361
- } ,
362
- maxRetries,
363
- timeout
364
- );
365
- }
366
-
367
- // bypass lambda restriction to modify final object
368
- final GetApiKeyResponse[] addedKey = new GetApiKeyResponse[] { null } ;
369
-
370
- // check the status of the getApiKey method
371
- TaskUtils.retryUntil(
372
- () -> {
373
- try {
374
- addedKey[0] = this.getApiKey(key, requestOptions);
375
- // magic number to signify we found the key
376
- return -2;
377
- } catch (AlgoliaApiException e) {
378
- return e.getHttpErrorCode();
379
- }
380
- },
381
- (Integer status) -> {
382
- switch (operation) {
383
- case ADD:
384
- // stop either when the key is created or when we don' t receive 404
385
- return status == -2 || status != 404;
386
- case DELETE:
387
- // stop when the key is not found
388
- return status == 404;
389
- default:
390
- // continue
391
- return false;
392
- }
393
- },
394
- maxRetries,
395
- timeout
396
- );
397
-
398
- return addedKey[0];
399
- }
400
-
401
- /**
402
- * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
403
- *
404
- * @summary Wait for an API key task to be processed.
405
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
406
- * @param key The `key` that has been added, deleted or updated.
407
- * @param maxRetries The maximum number of retry. 50 by default. (optional)
408
- * @param timeout The function to decide how long to wait between retries. min(retries * 200, 5000) by default. (optional)
409
- * @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
410
- */
411
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, int maxRetries, IntUnaryOperator timeout, RequestOptions requestOptions) {
412
- return this.waitForApiKey(operation, key, null, maxRetries, timeout, requestOptions);
413
- }
414
-
415
- /**
416
- * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
417
- *
418
- * @summary Wait for an API key task to be processed.
419
- * @param operation The `operation` that was done on a `key`.
420
- * @param key The `key` that has been added, deleted or updated.
421
- * @param apiKey Necessary to know if an `update` operation has been processed, compare fields of the response with it.
422
- * @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
423
- */
424
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, ApiKey apiKey, RequestOptions requestOptions) {
425
- return this.waitForApiKey(operation, key, apiKey, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
426
- }
427
-
428
- /**
429
- * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
430
- *
431
- * @summary Wait for an API key task to be processed.
432
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
433
- * @param key The `key` that has been added, deleted or updated.
434
- * @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
435
- */
436
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, RequestOptions requestOptions) {
437
- return this.waitForApiKey(operation, key, null, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
438
- }
439
-
440
- /**
441
- * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
442
- *
443
- * @summary Wait for an API key task to be processed.
444
- * @param operation The `operation` that was done on a `key`.
445
- * @param key The `key` that has been added, deleted or updated.
446
- * @param apiKey Necessary to know if an `update` operation has been processed, compare fields of the response with it.
447
- * @param maxRetries The maximum number of retry. 50 by default. (optional)
448
- * @param timeout The function to decide how long to wait between retries. min(retries * 200, 5000) by default. (optional)
449
- */
450
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, ApiKey apiKey, int maxRetries, IntUnaryOperator timeout) {
451
- return this.waitForApiKey(operation, key, apiKey, maxRetries, timeout, null);
452
- }
453
-
454
- /**
455
- * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
456
- *
457
- * @summary Wait for an API key task to be processed.
458
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
459
- * @param key The `key` that has been added, deleted or updated.
460
- * @param maxRetries The maximum number of retry. 50 by default. (optional)
461
- * @param timeout The function to decide how long to wait between retries. min(retries * 200, 5000) by default. (optional)
462
- */
463
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, int maxRetries, IntUnaryOperator timeout) {
464
- return this.waitForApiKey(operation, key, null, maxRetries, timeout, null);
465
- }
466
-
467
- /**
468
- * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
469
- *
470
- * @summary Wait for an API key task to be processed.
471
- * @param operation The `operation` that was done on a `key`.
472
- * @param key The `key` that has been added, deleted or updated.
473
- * @param apiKey Necessary to know if an `update` operation has been processed, compare fields of the response with it.
474
- */
475
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, ApiKey apiKey) {
476
- return this.waitForApiKey(operation, key, apiKey, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
477
- }
478
-
479
- /**
480
- * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
481
- *
482
- * @summary Wait for an API key task to be processed.
483
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
484
- * @param key The `key` that has been added, deleted or updated.
485
- */
486
- public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key) {
487
- return this.waitForApiKey(operation, key, null, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
488
- }
489
- {{/isSearchClient}}
264
+ { {> api_helpers} }
490
265
}
491
266
{ {/operations} }
0 commit comments