Skip to content

Commit 856d11b

Browse files
committed
feat: forward client opts
1 parent d3558d4 commit 856d11b

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/ApiClient.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public abstract class ApiClient implements Closeable {
2828

2929
private final Requester requester;
3030
private final ExecutorService executor;
31+
public final ClientOptions clientOptions;
3132
public AuthInterceptor authInterceptor;
3233

3334
/** Constructs a new instance of the {@link ApiClient}. */
@@ -47,11 +48,11 @@ protected ApiClient(
4748
if (apiKey == null || apiKey.isEmpty()) {
4849
throw new AlgoliaRuntimeException("`apiKey` is missing.");
4950
}
50-
final ClientOptions clientOptions = options != null ? options : new ClientOptions();
51-
this.executor = clientOptions.getExecutor();
52-
this.requester = clientOptions.getCustomRequester() != null
53-
? clientOptions.getCustomRequester()
54-
: defaultRequester(appId, apiKey, clientName, clientOptions, defaultHosts, connectTimeout, readTimeout, writeTimeout);
51+
this.clientOptions = options != null ? options : new ClientOptions();
52+
this.executor = this.clientOptions.getExecutor();
53+
this.requester = this.clientOptions.getCustomRequester() != null
54+
? this.clientOptions.getCustomRequester()
55+
: defaultRequester(appId, apiKey, clientName, this.clientOptions, defaultHosts, connectTimeout, readTimeout, writeTimeout);
5556
}
5657

5758
/** Creates a default {@link Requester} for executing API requests. */

specs/search/helpers/partialUpdateObjectsWithTransformation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ method:
55
- javascript
66
- go
77
- python
8+
- java
89
tags:
910
- Records
1011
operationId: partialUpdateObjectsWithTransformation

templates/java/api.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {{invokerPackage}}.ApiClient;
66
import {{invokerPackage}}.config.ClientOptions;
77

88
import com.fasterxml.jackson.core.type.TypeReference;
9+
import com.fasterxml.jackson.databind.ObjectMapper;
910
import javax.annotation.Nullable;
1011

1112
import okhttp3.Call;
@@ -56,7 +57,7 @@ public class {{classname}} extends ApiClient {
5657
private IngestionClient ingestionTransporter;
5758

5859
public void setTransformationRegion(String region) {
59-
this.ingestionTransporter = new IngestionClient(this.authInterceptor.getApplicationId(), this.authInterceptor.getApiKey(), region);
60+
this.ingestionTransporter = new IngestionClient(this.authInterceptor.getApplicationId(), this.authInterceptor.getApiKey(), region, this.clientOptions);
6061
}
6162
{{/isSearchClient}}
6263

templates/java/api_helpers.mustache

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -742,18 +742,17 @@ public <T> WatchResponse saveObjectsWithTransformation(
742742
);
743743
}
744744
745-
private <T> List<PushTaskRecords> objectsToPushTaskRecords(Iterable<T> iterable) {
746-
List<PushTaskRecords> payload = new ArrayList<>();
747-
for (T item : iterable) {
748-
if (item instanceof PushTaskRecords) {
749-
payload.add((PushTaskRecords) item);
750-
} else {
745+
private <T> List<PushTaskRecords> objectsToPushTaskRecords(Iterable<T> objects) {
746+
try {
747+
ObjectMapper mapper = new ObjectMapper();
748+
String json = mapper.writeValueAsString(objects);
749+
750+
return mapper.readValue(json, new TypeReference<List<PushTaskRecords>>() {});
751+
} catch (Exception e) {
751752
throw new AlgoliaRuntimeException(
752753
"each object must have an `objectID` key in order to be used with the" + " WithTransformation methods"
753754
);
754755
}
755-
}
756-
return payload;
757756
}
758757
759758
/**

templates/java/tests/client/client.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import com.algolia.EchoInterceptor;
1010
import com.algolia.EchoResponse;
1111
import com.algolia.api.{{client}};
1212
import com.algolia.model.{{import}}.*;
13+
{{#isSearchClient}}
14+
import com.algolia.model.ingestion.WatchResponse;
15+
{{/isSearchClient}}
1316
import com.algolia.config.*;
1417
import java.util.*;
1518
import java.time.Duration;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
{{^autoCreateClient}}{{client}} client = {{/autoCreateClient}}new {{client}}("{{parametersWithDataTypeMap.appId.value}}","{{parametersWithDataTypeMap.apiKey.value}}"{{#hasRegionalHost}}{{#parametersWithDataTypeMap.region}},"{{parametersWithDataTypeMap.region.value}}"{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}}{{#useEchoRequester}},withEchoRequester(){{/useEchoRequester}}{{#hasCustomHosts}},withCustomHosts(Arrays.asList({{#customHosts}}new Host("true".equals(System.getenv("CI")) ? "localhost" : "host.docker.internal", EnumSet.of(CallType.READ, CallType.WRITE), "http", {{port}}){{^-last}},{{/-last}}{{/customHosts}}), {{gzipEncoding}}){{/hasCustomHosts}});
1+
{{^autoCreateClient}}{{client}} client = {{/autoCreateClient}}new {{client}}("{{parametersWithDataTypeMap.appId.value}}","{{parametersWithDataTypeMap.apiKey.value}}"{{#hasRegionalHost}}{{#parametersWithDataTypeMap.region}},"{{parametersWithDataTypeMap.region.value}}"{{/parametersWithDataTypeMap.region}}{{/hasRegionalHost}}{{#useEchoRequester}},withEchoRequester(){{/useEchoRequester}}{{#hasCustomHosts}},withCustomHosts(Arrays.asList({{#customHosts}}new Host("true".equals(System.getenv("CI")) ? "localhost" : "host.docker.internal", EnumSet.of(CallType.READ, CallType.WRITE), "http", {{port}}){{^-last}},{{/-last}}{{/customHosts}}), {{gzipEncoding}}){{/hasCustomHosts}});
2+
{{#hasTransformationRegion}}client.setTransformationRegion("{{{transformationRegion}}}");{{/hasTransformationRegion}}

0 commit comments

Comments
 (0)