Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/mindee/http/MindeeHttpApiV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public JobResponse reqPostInferenceEnqueue(
LocalInputSource inputSource,
InferenceParameters options
) {
String url = this.mindeeSettings.getBaseUrl() + "/inferences/enqueue";
String url = this.mindeeSettings.getBaseUrl() + "/products/extraction/enqueue";
HttpPost post = buildHttpPost(url);

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
Expand Down Expand Up @@ -100,7 +100,7 @@ public JobResponse reqPostInferenceEnqueue(
URLInputSource inputSource,
InferenceParameters options
) {
String url = this.mindeeSettings.getBaseUrl() + "/inferences/enqueue";
String url = this.mindeeSettings.getBaseUrl() + "/products/extraction/enqueue";
HttpPost post = buildHttpPost(url);

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
Expand Down Expand Up @@ -175,7 +175,7 @@ public JobResponse reqGetJob(String jobId) {
@Override
public InferenceResponse reqGetInference(String inferenceId) {

String url = this.mindeeSettings.getBaseUrl() + "/inferences/" + inferenceId;
String url = this.mindeeSettings.getBaseUrl() + "/products/extraction/results/" + inferenceId;
HttpGet get = new HttpGet(url);

if (this.mindeeSettings.getApiKey().isPresent()) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/mindee/parsing/v2/Inference.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class Inference {
@JsonProperty("id")
private String id;

/**
* Job the inference belongs to.
*/
@JsonProperty("job")
private InferenceJob job;

/**
* Model info.
*/
Expand Down Expand Up @@ -53,6 +59,8 @@ public String toString() {
joiner
.add("Inference")
.add("#########")
.add(job.toString())
.add("")
.add(model.toString())
.add("")
.add(file.toString())
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/mindee/parsing/v2/InferenceJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mindee.parsing.v2;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.StringJoiner;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* Information on the Job associated to a given Inference.
*/
@Getter
@EqualsAndHashCode
@JsonIgnoreProperties(ignoreUnknown = true)
@AllArgsConstructor
@NoArgsConstructor
public class InferenceJob {
/**
* UUID of the Job.
*/
@JsonProperty("id")
private String id;

public String toString() {

StringJoiner joiner = new StringJoiner("\n");
joiner.add("Job").add("===").add(":ID: " + id);
return joiner.toString();
}
}
11 changes: 9 additions & 2 deletions src/main/java/com/mindee/parsing/v2/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import lombok.NoArgsConstructor;

/**
* Defines an enqueued Job.
* Information on the processing of a file sent to the Mindee API.
*/

@Getter
Expand All @@ -22,12 +22,19 @@
@NoArgsConstructor
public final class Job {
/**
* Date and time the job was created at.
* Date and time of the Job creation.
*/
@JsonProperty("created_at")
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime createdAt;

/**
* Date and time of the Job completion. Filled once processing is finished.
*/
@JsonProperty("completed_at")
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime completedAt;

/**
* ID of the job.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/com/mindee/parsing/v2/InferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ void asyncPredict_whenComplete_mustExposeAllProperties() throws IOException {
assertNotNull(inference);
assertEquals("12345678-1234-1234-1234-123456789abc", inference.getId());

InferenceJob job = inference.getJob();
assertEquals("12345678-1234-1234-1234-jobid1234567", job.getId());

InferenceModel model = inference.getModel();
assertNotNull(model, "Model must not be null");
assertEquals("12345678-1234-1234-1234-123456789abc", model.getId());
Expand Down
27 changes: 25 additions & 2 deletions src/test/java/com/mindee/parsing/v2/JobTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,35 @@ private JobResponse loadJob(String filePath) throws IOException {
}

@Nested
@DisplayName("When the Job is OK")
class OkTest {
@DisplayName("When the Job is processing")
class ProcessingTest {
@Test
@DisplayName("properties must be valid")
void whenProcessing_mustHaveValidProperties() throws IOException {
JobResponse response = loadJob("job/ok_processing.json");
Job job = response.getJob();
assertNotNull(job);
assertEquals("Processing", job.getStatus());
assertNotNull(job.getCreatedAt());
assertNull(job.getCompletedAt());
assertNull(job.getResultUrl());
assertNull(job.getError());
}
}

@Nested
@DisplayName("When the Job is processed")
class ProcessedTest {
@Test
@DisplayName("properties must be valid")
void whenProcessing_mustHaveValidProperties() throws IOException {
JobResponse response = loadJob("job/ok_processed_webhooks_ok.json");
Job job = response.getJob();
assertNotNull(job);
assertEquals("Processed", job.getStatus());
assertNotNull(job.getCreatedAt());
assertNotNull(job.getCompletedAt());
assertNotNull(job.getResultUrl());
assertNull(job.getError());
}
}
Expand All @@ -41,6 +61,9 @@ void when422_mustHaveValidProperties() throws IOException {
JobResponse response = loadJob("job/fail_422.json");
Job job = response.getJob();
assertNotNull(job);
assertNotNull(job.getCreatedAt());
assertNotNull(job.getCompletedAt());
assertNull(job.getResultUrl());
ErrorResponse jobError = job.getError();
assertNotNull(jobError);
assertEquals(422, jobError.getStatus());
Expand Down
Loading