Skip to content

Commit 7c658cf

Browse files
committed
use array instead of list for webhook ids
1 parent 0318904 commit 7c658cf

3 files changed

Lines changed: 45 additions & 24 deletions

File tree

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

Lines changed: 3 additions & 7 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,7 +25,7 @@ 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;
28+
private final String[] webhookIds;
3229
/**
3330
* Polling options. Set only if having timeout issues.
3431
*/
@@ -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: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +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 = InferenceParameters
33+
InferenceParameters params = InferenceParameters
3434
.builder(modelId)
3535
.rag(false)
3636
.alias("java-integration-test")
37+
.pollingOptions(
38+
AsyncPollingOptions.builder()
39+
.initialDelaySec(3.0)
40+
.intervalSec(1.5)
41+
.maxRetries(80)
42+
.build()
43+
)
3744
.build();
3845

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

4148
assertNotNull(response);
4249
assertNotNull(response.getInference());
@@ -93,15 +100,33 @@ void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedExc
93100
@DisplayName("Invalid model ID – enqueue must raise 422")
94101
void invalidModel_mustThrowError() throws IOException {
95102
LocalInputSource source = new LocalInputSource(
96-
new File("src/test/resources/file_types/pdf/multipage_cut-2.pdf"));
103+
new File("src/test/resources/file_types/pdf/blank_1.pdf"));
97104

98-
InferenceParameters options = InferenceParameters
99-
.builder("INVALID MODEL ID")
105+
InferenceParameters params = InferenceParameters
106+
.builder("INVALID_MODEL_ID")
107+
.build();
108+
109+
MindeeHttpExceptionV2 ex = assertThrows(
110+
MindeeHttpExceptionV2.class,
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"})
100125
.build();
101126

102127
MindeeHttpExceptionV2 ex = assertThrows(
103128
MindeeHttpExceptionV2.class,
104-
() -> mindeeClient.enqueueInference(source, options)
129+
() -> mindeeClient.enqueueInference(source, params)
105130
);
106131
assertEquals(422, ex.getStatus());
107132
}
@@ -111,7 +136,7 @@ void invalidModel_mustThrowError() throws IOException {
111136
void invalidJob_mustThrowError() {
112137
MindeeHttpExceptionV2 ex = assertThrows(
113138
MindeeHttpExceptionV2.class,
114-
() -> mindeeClient.getInference("not-a-valid-job-ID")
139+
() -> mindeeClient.getInference("INVALID_JOB_ID")
115140
);
116141
assertEquals(422, ex.getStatus());
117142
assertNotNull(ex);

0 commit comments

Comments
 (0)