@@ -5801,8 +5801,8 @@ public void waitForAppTask(Long taskID) {
5801
5801
* the transporter requestOptions. (optional)
5802
5802
*/
5803
5803
public GetApiKeyResponse waitForApiKey (
5804
- ApiKeyOperation operation ,
5805
5804
String key ,
5805
+ ApiKeyOperation operation ,
5806
5806
ApiKey apiKey ,
5807
5807
int maxRetries ,
5808
5808
IntUnaryOperator timeout ,
@@ -5835,28 +5835,26 @@ public GetApiKeyResponse waitForApiKey(
5835
5835
);
5836
5836
}
5837
5837
5838
- // bypass lambda restriction to modify final object
5839
- final GetApiKeyResponse [] addedKey = new GetApiKeyResponse [] { null };
5840
-
5841
- // check the status of the getApiKey method
5842
- TaskUtils .retryUntil (
5838
+ return TaskUtils .retryUntil (
5843
5839
() -> {
5844
5840
try {
5845
- addedKey [0 ] = this .getApiKey (key , requestOptions );
5846
- // magic number to signify we found the key
5847
- return -2 ;
5841
+ return this .getApiKey (key , requestOptions );
5848
5842
} catch (AlgoliaApiException e ) {
5849
- return e .getStatusCode ();
5843
+ if (e .getStatusCode () == 404 ) {
5844
+ return null ;
5845
+ }
5846
+
5847
+ throw e ;
5850
5848
}
5851
5849
},
5852
- (Integer status ) -> {
5850
+ (GetApiKeyResponse response ) -> {
5853
5851
switch (operation ) {
5854
5852
case ADD :
5855
- // stop either when the key is created or when we don't receive 404
5856
- return status == - 2 || status != 404 ;
5853
+ // stop when we don't receive 404 meaning the key is created
5854
+ return response != null ;
5857
5855
case DELETE :
5858
5856
// stop when the key is not found
5859
- return status == 404 ;
5857
+ return response == null ;
5860
5858
default :
5861
5859
// continue
5862
5860
return false ;
@@ -5865,105 +5863,103 @@ public GetApiKeyResponse waitForApiKey(
5865
5863
maxRetries ,
5866
5864
timeout
5867
5865
);
5868
-
5869
- return addedKey [0 ];
5870
5866
}
5871
5867
5872
5868
/**
5873
5869
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
5874
5870
*
5875
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
5876
5871
* @param key The `key` that has been added or deleted.
5872
+ * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
5877
5873
* @param maxRetries The maximum number of retry. 50 by default. (optional)
5878
5874
* @param timeout The function to decide how long to wait between retries. min(retries * 200,
5879
5875
* 5000) by default. (optional)
5880
5876
* @param requestOptions The requestOptions to send along with the query, they will be merged with
5881
5877
* the transporter requestOptions. (optional)
5882
5878
*/
5883
5879
public GetApiKeyResponse waitForApiKey (
5884
- ApiKeyOperation operation ,
5885
5880
String key ,
5881
+ ApiKeyOperation operation ,
5886
5882
int maxRetries ,
5887
5883
IntUnaryOperator timeout ,
5888
5884
RequestOptions requestOptions
5889
5885
) {
5890
- return this .waitForApiKey (operation , key , null , maxRetries , timeout , requestOptions );
5886
+ return this .waitForApiKey (key , operation , null , maxRetries , timeout , requestOptions );
5891
5887
}
5892
5888
5893
5889
/**
5894
5890
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
5895
5891
*
5896
- * @param operation The `operation` that was done on a `key`.
5897
5892
* @param key The `key` that has been added, deleted or updated.
5893
+ * @param operation The `operation` that was done on a `key`.
5898
5894
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of
5899
5895
* the response with it.
5900
5896
* @param requestOptions The requestOptions to send along with the query, they will be merged with
5901
5897
* the transporter requestOptions. (optional)
5902
5898
*/
5903
- public GetApiKeyResponse waitForApiKey (ApiKeyOperation operation , String key , ApiKey apiKey , RequestOptions requestOptions ) {
5904
- return this .waitForApiKey (operation , key , apiKey , TaskUtils .DEFAULT_MAX_RETRIES , TaskUtils .DEFAULT_TIMEOUT , requestOptions );
5899
+ public GetApiKeyResponse waitForApiKey (String key , ApiKeyOperation operation , ApiKey apiKey , RequestOptions requestOptions ) {
5900
+ return this .waitForApiKey (key , operation , apiKey , TaskUtils .DEFAULT_MAX_RETRIES , TaskUtils .DEFAULT_TIMEOUT , requestOptions );
5905
5901
}
5906
5902
5907
5903
/**
5908
5904
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
5909
5905
*
5910
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
5911
5906
* @param key The `key` that has been added or deleted.
5907
+ * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
5912
5908
* @param requestOptions The requestOptions to send along with the query, they will be merged with
5913
5909
* the transporter requestOptions. (optional)
5914
5910
*/
5915
- public GetApiKeyResponse waitForApiKey (ApiKeyOperation operation , String key , RequestOptions requestOptions ) {
5916
- return this .waitForApiKey (operation , key , null , TaskUtils .DEFAULT_MAX_RETRIES , TaskUtils .DEFAULT_TIMEOUT , requestOptions );
5911
+ public GetApiKeyResponse waitForApiKey (String key , ApiKeyOperation operation , RequestOptions requestOptions ) {
5912
+ return this .waitForApiKey (key , operation , null , TaskUtils .DEFAULT_MAX_RETRIES , TaskUtils .DEFAULT_TIMEOUT , requestOptions );
5917
5913
}
5918
5914
5919
5915
/**
5920
5916
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
5921
5917
*
5922
- * @param operation The `operation` that was done on a `key`.
5923
5918
* @param key The `key` that has been added, deleted or updated.
5919
+ * @param operation The `operation` that was done on a `key`.
5924
5920
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of
5925
5921
* the response with it.
5926
5922
* @param maxRetries The maximum number of retry. 50 by default. (optional)
5927
5923
* @param timeout The function to decide how long to wait between retries. min(retries * 200,
5928
5924
* 5000) by default. (optional)
5929
5925
*/
5930
- public GetApiKeyResponse waitForApiKey (ApiKeyOperation operation , String key , ApiKey apiKey , int maxRetries , IntUnaryOperator timeout ) {
5931
- return this .waitForApiKey (operation , key , apiKey , maxRetries , timeout , null );
5926
+ public GetApiKeyResponse waitForApiKey (String key , ApiKeyOperation operation , ApiKey apiKey , int maxRetries , IntUnaryOperator timeout ) {
5927
+ return this .waitForApiKey (key , operation , apiKey , maxRetries , timeout , null );
5932
5928
}
5933
5929
5934
5930
/**
5935
5931
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
5936
5932
*
5937
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
5938
5933
* @param key The `key` that has been added or deleted.
5934
+ * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
5939
5935
* @param maxRetries The maximum number of retry. 50 by default. (optional)
5940
5936
* @param timeout The function to decide how long to wait between retries. min(retries * 200,
5941
5937
* 5000) by default. (optional)
5942
5938
*/
5943
- public GetApiKeyResponse waitForApiKey (ApiKeyOperation operation , String key , int maxRetries , IntUnaryOperator timeout ) {
5944
- return this .waitForApiKey (operation , key , null , maxRetries , timeout , null );
5939
+ public GetApiKeyResponse waitForApiKey (String key , ApiKeyOperation operation , int maxRetries , IntUnaryOperator timeout ) {
5940
+ return this .waitForApiKey (key , operation , null , maxRetries , timeout , null );
5945
5941
}
5946
5942
5947
5943
/**
5948
5944
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
5949
5945
*
5950
- * @param operation The `operation` that was done on a `key`.
5951
5946
* @param key The `key` that has been added, deleted or updated.
5947
+ * @param operation The `operation` that was done on a `key`.
5952
5948
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of
5953
5949
* the response with it.
5954
5950
*/
5955
- public GetApiKeyResponse waitForApiKey (ApiKeyOperation operation , String key , ApiKey apiKey ) {
5956
- return this .waitForApiKey (operation , key , apiKey , TaskUtils .DEFAULT_MAX_RETRIES , TaskUtils .DEFAULT_TIMEOUT , null );
5951
+ public GetApiKeyResponse waitForApiKey (String key , ApiKeyOperation operation , ApiKey apiKey ) {
5952
+ return this .waitForApiKey (key , operation , apiKey , TaskUtils .DEFAULT_MAX_RETRIES , TaskUtils .DEFAULT_TIMEOUT , null );
5957
5953
}
5958
5954
5959
5955
/**
5960
5956
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
5961
5957
*
5962
- * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
5963
5958
* @param key The `key` that has been added or deleted.
5959
+ * @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
5964
5960
*/
5965
- public GetApiKeyResponse waitForApiKey (ApiKeyOperation operation , String key ) {
5966
- return this .waitForApiKey (operation , key , null , TaskUtils .DEFAULT_MAX_RETRIES , TaskUtils .DEFAULT_TIMEOUT , null );
5961
+ public GetApiKeyResponse waitForApiKey (String key , ApiKeyOperation operation ) {
5962
+ return this .waitForApiKey (key , operation , null , TaskUtils .DEFAULT_MAX_RETRIES , TaskUtils .DEFAULT_TIMEOUT , null );
5967
5963
}
5968
5964
5969
5965
/**
0 commit comments