Skip to content

Commit a160398

Browse files
committed
fix: java
1 parent 416f480 commit a160398

File tree

2 files changed

+49
-39
lines changed

2 files changed

+49
-39
lines changed

templates/java/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import java.util.Base64;
4646
import javax.annotation.Nonnull;
4747
import javax.crypto.Mac;
4848
import javax.crypto.spec.SecretKeySpec;
49+
import com.algolia.model.ingestion.Event;
4950
import com.algolia.model.ingestion.PushTaskPayload;
5051
import com.algolia.model.ingestion.PushTaskRecords;
5152
import com.algolia.model.ingestion.WatchResponse;

templates/java/api_helpers.mustache

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,9 @@ public CompletableFuture<List<SearchForFacetValuesResponse>> searchForFacetsAsyn
586586
}
587587
588588
/**
589-
* Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `push` requests by leveraging the Transformation pipeline setup in the Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/).
589+
* Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit
590+
* in `push` requests by leveraging the Transformation pipeline setup in the Push connector
591+
* (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/).
590592
*
591593
* @summary Helper: Chunks the given `objects` list in subset of 1000 elements max in order to
592594
* make it fit in `batch` requests.
@@ -598,14 +600,16 @@ public CompletableFuture<List<SearchForFacetValuesResponse>> searchForFacetsAsyn
598600
* reliable.
599601
* @param batchSize - The size of the chunk of `objects`. The number of `batch` calls will be
600602
* equal to `length(objects) / batchSize`. Defaults to 1000.
601-
* @param referenceIndexName - This is required when targeting an index that does not have a push connector setup (e.g. a tmp index), but you wish to attach another index's transformation to it (e.g. the source index name).
603+
* @param referenceIndexName - This is required when targeting an index that does not have a push
604+
* connector setup (e.g. a tmp index), but you wish to attach another index's transformation
605+
* to it (e.g. the source index name).
602606
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded
603607
* to the `getTask` method and merged with the transporter requestOptions.
604608
*/
605609
public <T> List<WatchResponse> chunkedPush(
606610
String indexName,
607611
Iterable<T> objects,
608-
Action action,
612+
com.algolia.model.ingestion.Action action,
609613
boolean waitForTasks,
610614
int batchSize,
611615
String referenceIndexName,
@@ -616,17 +620,18 @@ public <T> List<WatchResponse> chunkedPush(
616620
}
617621

618622
List<WatchResponse> responses = new ArrayList<>();
619-
Iterable<T> records = new ArrayList<>();
623+
List<T> records = new ArrayList<>();
620624

621625
for (T item : objects) {
622-
if (requests.size() == batchSize) {
623-
WatchResponse watch = this.ingestionTransporter.push(
624-
indexName,
625-
new PushTaskPayload().setAction(action).setRecords(this.objectsToPushTaskRecords(records)),
626-
waitForTasks,
627-
null,
628-
requestOptions
629-
);
626+
if (records.size() == batchSize) {
627+
WatchResponse watch =
628+
this.ingestionTransporter.push(
629+
indexName,
630+
new PushTaskPayload().setAction(action).setRecords(this.objectsToPushTaskRecords(records)),
631+
waitForTasks,
632+
referenceIndexName,
633+
requestOptions
634+
);
630635
responses.add(watch);
631636
records.clear();
632637
}
@@ -635,35 +640,38 @@ public <T> List<WatchResponse> chunkedPush(
635640
}
636641

637642
if (records.size() > 0) {
638-
WatchResponse watch = this.ingestionTransporter.push(
639-
indexName,
640-
new PushTaskPayload().setAction(action).setRecords(this.objectsToPushTaskRecords(records)),
641-
waitForTasks,
642-
null,
643-
requestOptions
644-
);
645-
responses.add(watch);
643+
WatchResponse watch =
644+
this.ingestionTransporter.push(
645+
indexName,
646+
new PushTaskPayload().setAction(action).setRecords(this.objectsToPushTaskRecords(records)),
647+
waitForTasks,
648+
referenceIndexName,
649+
requestOptions
650+
);
651+
responses.add(watch);
646652
}
647653

648654
if (waitForTasks) {
649-
responses.forEach(response -> TaskUtils.retryUntil(
650-
() -> {
651-
try {
652-
return this.ingestionTransporter.getEvent(response.runID, response.eventID);
653-
} catch (AlgoliaApiException e) {
654-
if (e.getStatusCode() == 404) {
655-
return null;
655+
responses.forEach(response -> {
656+
TaskUtils.retryUntil(
657+
() -> {
658+
try {
659+
return this.ingestionTransporter.getEvent(response.getRunID(), response.getEventID());
660+
} catch (AlgoliaApiException e) {
661+
if (e.getStatusCode() == 404) {
662+
return null;
663+
}
664+
665+
throw e;
656666
}
657-
658-
throw e;
659-
}
660-
},
661-
(Event response) -> {
662-
return response != null;
663-
},
664-
50,
665-
null
666-
)
667+
},
668+
(Event resp) -> {
669+
return resp != null;
670+
},
671+
50,
672+
null
673+
);
674+
}
667675
);
668676
}
669677

@@ -815,7 +823,7 @@ public <T> List<WatchResponse> saveObjectsWithTransformation(
815823
int batchSize,
816824
RequestOptions requestOptions
817825
) {
818-
return chunkedPush(indexName, objects, Action.ADD_OBJECT, waitForTasks, batchSize, null, requestOptions);
826+
return chunkedPush(indexName, objects, com.algolia.model.ingestion.Action.ADD_OBJECT, waitForTasks, batchSize, null, requestOptions);
819827
}
820828

821829
private <T> List<PushTaskRecords> objectsToPushTaskRecords(Iterable<T> objects) {
@@ -1048,9 +1056,10 @@ public <T> List<WatchResponse> partialUpdateObjectsWithTransformation(
10481056
return chunkedPush(
10491057
indexName,
10501058
objects,
1051-
createIfNotExists ? Action.PARTIAL_UPDATE_OBJECT : Action.PARTIAL_UPDATE_OBJECT_NO_CREATE,
1059+
createIfNotExists ? com.algolia.model.ingestion.Action.PARTIAL_UPDATE_OBJECT : com.algolia.model.ingestion.Action.PARTIAL_UPDATE_OBJECT_NO_CREATE,
10521060
waitForTasks,
10531061
batchSize,
1062+
null,
10541063
requestOptions
10551064
);
10561065
}

0 commit comments

Comments
 (0)