Skip to content

Commit 65fe3c2

Browse files
authored
♻️ 💥 use array instead of List for webhook ids (#260)
1 parent 61c42d4 commit 65fe3c2

File tree

3 files changed

+58
-30
lines changed

3 files changed

+58
-30
lines changed

src/main/java/com/mindee/InferenceParameters.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.mindee;
22

3-
import com.mindee.input.PageOptions;
4-
import java.util.Collections;
5-
import java.util.List;
63
import java.util.Objects;
74
import lombok.Data;
85
import lombok.Getter;
@@ -28,9 +25,9 @@ public final class InferenceParameters {
2825
/**
2926
* IDs of webhooks to propagate the API response to (may be empty).
3027
*/
31-
private final List<String> webhookIds;
32-
/*
33-
* Asynchronous polling options.
28+
private final String[] webhookIds;
29+
/**
30+
* Polling options. Set only if having timeout issues.
3431
*/
3532
private final AsyncPollingOptions pollingOptions;
3633

@@ -52,7 +49,7 @@ public static final class Builder {
5249
private final String modelId;
5350
private boolean rag = false;
5451
private String alias;
55-
private List<String> webhookIds = Collections.emptyList();
52+
private String[] webhookIds = new String[]{};
5653
private AsyncPollingOptions pollingOptions = AsyncPollingOptions.builder().build();
5754

5855
private Builder(String modelId) {
@@ -72,12 +69,11 @@ public Builder alias(String alias) {
7269
}
7370

7471
/** Provide IDs of webhooks to forward the API response to. */
75-
public Builder webhookIds(List<String> webhookIds) {
72+
public Builder webhookIds(String[] webhookIds) {
7673
this.webhookIds = webhookIds;
7774
return this;
7875
}
7976

80-
8177
public Builder pollingOptions(AsyncPollingOptions pollingOptions) {
8278
this.pollingOptions = pollingOptions;
8379
return this;

src/main/java/com/mindee/http/MindeeHttpApiV2.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,33 +248,33 @@ private MindeeHttpExceptionV2 getHttpError(ClassicHttpResponse response) {
248248

249249
private HttpEntity buildHttpBody(
250250
MultipartEntityBuilder builder,
251-
InferenceParameters options
251+
InferenceParameters params
252252
) {
253253

254-
if (options.getAlias() != null) {
254+
if (params.getAlias() != null) {
255255
builder.addTextBody(
256256
"alias",
257-
options.getAlias().toLowerCase()
257+
params.getAlias().toLowerCase()
258258
);
259259
}
260260

261-
builder.addTextBody("model_id", options.getModelId());
262-
if (options.isRag()) {
261+
builder.addTextBody("model_id", params.getModelId());
262+
if (params.isRag()) {
263263
builder.addTextBody("rag", "true");
264264
}
265-
if (options.getAlias() != null) {
266-
builder.addTextBody("alias", options.getAlias());
265+
if (params.getAlias() != null) {
266+
builder.addTextBody("alias", params.getAlias());
267267
}
268-
if (!options.getWebhookIds().isEmpty()) {
269-
builder.addTextBody("webhook_ids", String.join(",", options.getWebhookIds()));
268+
if (params.getWebhookIds().length > 0) {
269+
builder.addTextBody("webhook_ids", String.join(",", params.getWebhookIds()));
270270
}
271271
return builder.build();
272272
}
273273

274274

275275
private HttpPost buildHttpPost(
276276
String url,
277-
InferenceParameters options
277+
InferenceParameters params
278278
) {
279279
HttpPost post;
280280
try {

src/test/java/com/mindee/MindeeClientV2IT.java

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,20 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep
3030
LocalInputSource source = new LocalInputSource(
3131
new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf"));
3232

33-
InferenceParameters options =
34-
InferenceParameters.builder(modelId).build();
33+
InferenceParameters params = InferenceParameters
34+
.builder(modelId)
35+
.rag(false)
36+
.alias("java-integration-test")
37+
.pollingOptions(
38+
AsyncPollingOptions.builder()
39+
.initialDelaySec(3.0)
40+
.intervalSec(1.5)
41+
.maxRetries(80)
42+
.build()
43+
)
44+
.build();
3545

36-
InferenceResponse response = mindeeClient.enqueueAndGetInference(source, options);
46+
InferenceResponse response = mindeeClient.enqueueAndGetInference(source, params);
3747

3848
assertNotNull(response);
3949
assertNotNull(response.getInference());
@@ -54,8 +64,10 @@ void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedExc
5464
LocalInputSource source = new LocalInputSource(
5565
new File("src/test/resources/products/financial_document/default_sample.jpg"));
5666

57-
InferenceParameters options = InferenceParameters.builder(modelId)
67+
InferenceParameters options = InferenceParameters
68+
.builder(modelId)
5869
.rag(false)
70+
.alias("java-integration-test")
5971
.build();
6072

6173
InferenceResponse response = mindeeClient.enqueueAndGetInference(source, options);
@@ -88,14 +100,33 @@ void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedExc
88100
@DisplayName("Invalid model ID – enqueue must raise 422")
89101
void invalidModel_mustThrowError() throws IOException {
90102
LocalInputSource source = new LocalInputSource(
91-
new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf"));
103+
new File("src/test/resources/file_types/pdf/blank_1.pdf"));
92104

93-
InferenceParameters options =
94-
InferenceParameters.builder("INVALID MODEL ID").build();
105+
InferenceParameters params = InferenceParameters
106+
.builder("INVALID_MODEL_ID")
107+
.build();
95108

96109
MindeeHttpExceptionV2 ex = assertThrows(
97110
MindeeHttpExceptionV2.class,
98-
() -> mindeeClient.enqueueInference(source, options)
111+
() -> mindeeClient.enqueueInference(source, params)
112+
);
113+
assertEquals(422, ex.getStatus());
114+
}
115+
116+
@Test
117+
@DisplayName("Invalid webhook ID – enqueue must raise 422")
118+
void invalidWebhook_mustThrowError() throws IOException {
119+
LocalInputSource source = new LocalInputSource(
120+
new File("src/test/resources/file_types/pdf/blank_1.pdf"));
121+
122+
InferenceParameters params = InferenceParameters
123+
.builder(modelId)
124+
.webhookIds(new String[]{"INVALID_WEBHOOK_ID"})
125+
.build();
126+
127+
MindeeHttpExceptionV2 ex = assertThrows(
128+
MindeeHttpExceptionV2.class,
129+
() -> mindeeClient.enqueueInference(source, params)
99130
);
100131
assertEquals(422, ex.getStatus());
101132
}
@@ -105,7 +136,7 @@ void invalidModel_mustThrowError() throws IOException {
105136
void invalidJob_mustThrowError() {
106137
MindeeHttpExceptionV2 ex = assertThrows(
107138
MindeeHttpExceptionV2.class,
108-
() -> mindeeClient.getInference("not-a-valid-job-ID")
139+
() -> mindeeClient.getInference("INVALID_JOB_ID")
109140
);
110141
assertEquals(422, ex.getStatus());
111142
assertNotNull(ex);
@@ -118,8 +149,9 @@ void urlInputSource_mustNotRaiseErrors() throws IOException, InterruptedExceptio
118149
"https://upload.wikimedia.org/wikipedia/commons/1/1d/Blank_Page.pdf"
119150
).build();
120151

121-
InferenceParameters options =
122-
InferenceParameters.builder(modelId).build();
152+
InferenceParameters options = InferenceParameters
153+
.builder(modelId)
154+
.build();
123155

124156
InferenceResponse response = mindeeClient.enqueueAndGetInference(urlSource, options);
125157

0 commit comments

Comments
 (0)