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
1 change: 1 addition & 0 deletions .github/workflows/_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
strategy:
matrix:
java-version:
- "21"
- "11"
- "8"
distribution:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/_test-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
strategy:
matrix:
java-version:
- "21"
- "11"
- "8"
distribution:
Expand Down
57 changes: 45 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${org.apache.maven.surfire.version}</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<argLine>
${surefire.addOpens}
-Djunit.jupiter.extensions.autodetection.enabled=true
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
Expand All @@ -148,6 +162,22 @@
</build>

<profiles>
<profile>
<id>jdk-9-plus</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<properties>
<surefire.addOpens>
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
--add-opens java.base/java.net=ALL-UNNAMED
--add-opens java.base/sun.net.www.protocol.https=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED
--add-opens java.base/java.lang.reflect=ALL-UNNAMED
</surefire.addOpens>
</properties>
</profile>
<profile>
<id>release</id>
<build>
Expand Down Expand Up @@ -178,16 +208,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${org.apache.maven.surfire.version}</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand Down Expand Up @@ -361,6 +381,18 @@
<scope>test</scope>
<version>${org.mockito.inline.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.15.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.15.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
Expand Down Expand Up @@ -412,12 +444,13 @@
<org.junit.platform.version>1.8.2</org.junit.platform.version>
<org.hamcrest.version>2.2</org.hamcrest.version>
<org.mapstruct.version>1.5.3.Final</org.mapstruct.version>
<org.mockito.inline.version>4.6.1</org.mockito.inline.version>
<org.mockito.junit.jupiter.version>4.5.1</org.mockito.junit.jupiter.version>
<org.mockito.inline.version>4.11.0</org.mockito.inline.version>
<org.mockito.junit.jupiter.version>4.11.0</org.mockito.junit.jupiter.version>
<org.projectlombok.lombok-mapstruct-binding.version>0.2.0</org.projectlombok.lombok-mapstruct-binding.version>
<org.projectlombok.version>1.18.32</org.projectlombok.version>
<org.slf4j.version>2.0.17</org.slf4j.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.addOpens></surefire.addOpens>
<wiremock.version>2.35.2</wiremock.version>
</properties>

Expand Down
91 changes: 91 additions & 0 deletions src/main/java/com/mindee/parsing/v2/field/ObjectField.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,97 @@ public LinkedHashMap<String, SimpleField> getSimpleFields() throws IllegalStateE
return simpleFields;
}

/**
* Retrieves all subfields from the {@code fields} map as a {@link LinkedHashMap} of
* {@code ListField} objects, keyed by their field names.
*
* @return a {@link LinkedHashMap} containing the field names as keys and their corresponding
* {@code ListField} instances as values (only includes fields that are list fields)
*/
public LinkedHashMap<String, ListField> getListFields() {
LinkedHashMap<String, ListField> listFields = new LinkedHashMap<>();
if (fields != null) {
for (String fieldName : fields.keySet()) {
DynamicField field = fields.get(fieldName);
if (field != null && field.getType() == DynamicField.FieldType.LIST_FIELD) {
listFields.put(fieldName, field.getListField());
}
}
}
return listFields;
}

/**
* Retrieves all subfields from the {@code fields} map as a {@link LinkedHashMap} of
* {@code ObjectField} objects, keyed by their field names.
*
* @return a {@link LinkedHashMap} containing the field names as keys and their corresponding
* {@code ObjectField} objects as values
*/
public LinkedHashMap<String, ObjectField> getObjectFields() {
LinkedHashMap<String, ObjectField> objectFields = new LinkedHashMap<>();
if (fields != null) {
for (String fieldName : fields.keySet()) {
DynamicField field = fields.get(fieldName);
if (field != null && field.getType() == DynamicField.FieldType.OBJECT_FIELD) {
objectFields.put(fieldName, field.getObjectField());
}
}
}
return objectFields;
}

/**
* Retrieves a single sub-field from the {@code fields} map as a {@link SimpleField}.
*
* @param fieldKey the name/key of the field to retrieve
* @return the corresponding {@link SimpleField}, or {@code null} if {@code fields} is
* {@code null}
* or if no field exists for {@code fieldKey} (depending on {@code fields}' behavior)
* @throws IllegalStateException if the referenced field exists but is not of type
* {@code SIMPLE_FIELD}
*/
public SimpleField getSimpleField(String fieldKey) throws IllegalStateException {
if (fields == null) {
return null;
}
return fields.getSimpleField(fieldKey);
}

/**
* Retrieves a list sub-field from the {@code fields} map as a {@link ListField}.
*
* @param fieldKey the name/key of the field to retrieve
* @return the corresponding {@link ListField}, or {@code null} if {@code fields} is
* {@code null}
* or if no field exists for {@code fieldKey} (depending on {@code fields}' behavior)
* @throws IllegalStateException if the referenced field exists but is not of type
* {@code LIST_FIELD}
*/
public ListField getListField(String fieldKey) {
if (fields == null) {
return null;
}
return fields.getListField(fieldKey);
}

/**
* Retrieves an object sub-field from the {@code fields} map as a {@link ObjectField}.
*
* @param fieldKey the name/key of the field to retrieve
* @return the corresponding {@link ObjectField}, or {@code null} if {@code fields} is
* {@code null}
* or if no field exists for {@code fieldKey} (depending on {@code fields}' behavior)
* @throws IllegalStateException if the referenced field exists but is not of type
* {@code OBJECT_FIELD}
*/
public ObjectField getObjectField(String fieldKey) {
if (fields == null) {
return null;
}
return fields.getObjectField(fieldKey);
}

@Override
public String toString() {
return "\n" + (fields != null ? fields.toString(1) : "");
Expand Down
8 changes: 5 additions & 3 deletions src/test/java/com/mindee/MindeeClientV2IT.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedExcep
@DisplayName("Filled, single-page image – enqueue & parse must succeed")
void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedException {
LocalInputSource source = new LocalInputSource(
getV2ResourcePath("products/financial_document/default_sample.jpg")
getV2ResourcePath("products/extraction/financial_document/default_sample.jpg")
);

InferenceParameters params = InferenceParameters
Expand Down Expand Up @@ -135,14 +135,16 @@ void parseFile_filledSinglePage_mustSucceed() throws IOException, InterruptedExc
@DisplayName("Data Schema Replace – enqueue & parse must succeed")
void parseFile_dataSchemaReplace_mustSucceed() throws IOException, InterruptedException {
LocalInputSource source = new LocalInputSource(
getV2ResourcePath("products/financial_document/default_sample.jpg")
getV2ResourcePath("products/extraction/financial_document/default_sample.jpg")
);

InferenceParameters params = InferenceParameters
.builder(modelId)
.rag(false)
.alias("java-integration-test_data-schema-replace")
.dataSchema(readFileAsString(getV2ResourcePath("inference/data_schema_replace_param.json")))
.dataSchema(
readFileAsString(getV2ResourcePath("products/extraction/data_schema_replace_param.json"))
)
.build();

InferenceResponse response = mindeeClient.enqueueAndGetInference(source, params);
Expand Down
16 changes: 11 additions & 5 deletions src/test/java/com/mindee/MindeeClientV2Test.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.mindee;

import static com.mindee.TestingUtilities.getResourcePath;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atMostOnce;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -87,7 +91,9 @@ void document_getInference_async() throws IOException {
MindeeApiV2 predictable = Mockito.mock(MindeeApiV2.class);

String json = FileUtils
.readFileToString(getResourcePath("v2/products/financial_document/complete.json").toFile());
.readFileToString(
getResourcePath("v2/products/extraction/financial_document/complete.json").toFile()
);

ObjectMapper mapper = new ObjectMapper();
mapper.findAndRegisterModules();
Expand Down Expand Up @@ -129,7 +135,7 @@ class DeserializeResponse {
@DisplayName("parses local JSON and exposes correct field values")
void inference_loadsLocally() throws IOException {
LocalResponse localResponse = new LocalResponse(
getResourcePath("v2/products/financial_document/complete.json")
getResourcePath("v2/products/extraction/financial_document/complete.json")
);
InferenceResponse loaded = localResponse.deserializeResponse(InferenceResponse.class);

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/mindee/MindeeSettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MindeeSettingsTest {
@SetEnvironmentVariable(key = "MINDEE_API_URL", value = "https://example.com")
void setEnvironmentVariablesAndEmptyParams() {
MindeeSettings settings = new MindeeSettings("", "");
Assertions.assertEquals(settings.getApiKey().orElse(""), "abcd");
Assertions.assertEquals(settings.getBaseUrl(), "https://example.com");
Assertions.assertEquals("abcd", settings.getApiKey().orElse(""));
Assertions.assertEquals("https://example.com", settings.getBaseUrl());
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/mindee/input/LocalResponseV2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public class LocalResponseV2Test {
/**
* Real signature using fake secret key.
*/
String signature = "1df388c992d87897fe61dfc56c444c58fc3c7369c31e2b5fd20d867695e93e85";
String signature = "e51bdf80f1a08ed44ee161100fc30a25cb35b4ede671b0a575dc9064a3f5dbf1";

/**
* File which the signature applies to.
*/
Path filePath = getV2ResourcePath("inference/standard_field_types.json");
Path filePath = getV2ResourcePath("products/extraction/standard_field_types.json");

protected void assertLocalResponse(LocalResponse localResponse) {
Assertions.assertNotNull(localResponse.getFile());
Expand Down
Loading
Loading