diff --git a/.github/workflows/_static-analysis.yml b/.github/workflows/_static-analysis.yml
index b95c9c16d..cc96ec2e8 100644
--- a/.github/workflows/_static-analysis.yml
+++ b/.github/workflows/_static-analysis.yml
@@ -20,4 +20,4 @@ jobs:
cache: "maven"
- name: Check Code Style
- run: mvn --update-snapshots --no-transfer-progress checkstyle:check
+ run: mvn --update-snapshots --no-transfer-progress spotless:check
diff --git a/.gitignore b/.gitignore
index 389f8e478..cbad0e621 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,6 +36,8 @@ hs_err_pid*
.idea
*.iml
.run
+.project
+.settings
# Mac OS
.DS_Store
diff --git a/checkstyle.xml b/checkstyle.xml
deleted file mode 100644
index 51b8e10d5..000000000
--- a/checkstyle.xml
+++ /dev/null
@@ -1,391 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml
new file mode 100644
index 000000000..c38bfde7f
--- /dev/null
+++ b/eclipse-formatter.xml
@@ -0,0 +1,405 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 8e59689fc..7f77f70f9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -95,34 +95,24 @@
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 3.2.1
-
-
- com.puppycrawl.tools
- checkstyle
- 10.9.3
-
-
+ com.diffplug.spotless
+ spotless-maven-plugin
+
+ 2.46.1
- checkstyle.xml
- true
- true
- error
+
+
+
+
+ ${project.basedir}/eclipse-formatter.xml
+
+
+
-
-
- validate
- validate
-
- check
-
-
-
+
org.apache.maven.plugins
diff --git a/src/main/java/com/mindee/AsyncPollingOptions.java b/src/main/java/com/mindee/AsyncPollingOptions.java
index bcbb22f41..004c6f72a 100644
--- a/src/main/java/com/mindee/AsyncPollingOptions.java
+++ b/src/main/java/com/mindee/AsyncPollingOptions.java
@@ -22,11 +22,7 @@ public class AsyncPollingOptions {
Integer maxRetries;
@Builder
- private AsyncPollingOptions(
- Double initialDelaySec,
- Double intervalSec,
- Integer maxRetries
- ) {
+ private AsyncPollingOptions(Double initialDelaySec, Double intervalSec, Integer maxRetries) {
this.initialDelaySec = initialDelaySec == null ? 2.0 : initialDelaySec;
this.intervalSec = intervalSec == null ? 1.5 : intervalSec;
this.maxRetries = maxRetries == null ? 80 : maxRetries;
diff --git a/src/main/java/com/mindee/CommandLineInterface.java b/src/main/java/com/mindee/CommandLineInterface.java
index 7b4e908e7..3e19341ba 100644
--- a/src/main/java/com/mindee/CommandLineInterface.java
+++ b/src/main/java/com/mindee/CommandLineInterface.java
@@ -33,7 +33,7 @@
@Command(
name = "CLI",
description = "Invoke Off The Shelf API for invoice, receipt, and passports",
- subcommands = {CommandLine.HelpCommand.class},
+ subcommands = { CommandLine.HelpCommand.class },
mixinStandardHelpOptions = true
)
public class CommandLineInterface implements ProductProcessor {
@@ -42,7 +42,7 @@ public class CommandLineInterface implements ProductProcessor {
CommandSpec spec;
@Option(
- names = {"-w", "--all-words"},
+ names = { "-w", "--all-words" },
scope = ScopeType.INHERIT,
paramLabel = "WORDS",
description = "Include all document words in the response"
@@ -50,43 +50,50 @@ public class CommandLineInterface implements ProductProcessor {
private boolean words;
@Option(
- names = {"-f", "--full-text"},
+ names = { "-f", "--full-text" },
scope = ScopeType.INHERIT,
paramLabel = "FULL_TEXT",
description = "Include full text response, if available"
)
private boolean fullText;
- private enum OutputChoices { summary, full, raw }
+ private enum OutputChoices {
+ summary,
+ full,
+ raw
+ }
@Option(
- names = {"-o", "--output-type"},
+ names = { "-o", "--output-type" },
scope = ScopeType.INHERIT,
paramLabel = "OUTPUT_TYPE",
description = "Output type, one of:\n"
- + " summary - document predictions\n"
- + " full - all predictions\n"
- + " raw - raw response from the server",
+ + " summary - document predictions\n"
+ + " full - all predictions\n"
+ + " raw - raw response from the server",
defaultValue = "summary"
)
private OutputChoices outputType;
@Option(
- names = {"-k", "--api-key"},
+ names = { "-k", "--api-key" },
scope = ScopeType.INHERIT,
paramLabel = "MINDEE_API_KEY",
- description = "API key, if not set, will use system property")
+ description = "API key, if not set, will use system property"
+ )
private String apiKey;
@Option(
- names = {"-c", "--cut-doc"},
+ names = { "-c", "--cut-doc" },
scope = ScopeType.INHERIT,
paramLabel = "",
- description = "Keep only the first 5 pages of the document")
+ description = "Keep only the first 5 pages of the document"
+ )
private boolean cutDoc;
/**
- * Instantiates all products one by one in a separate picocli instance and relays the command to them.
+ * Instantiates all products one by one in a separate picocli instance and relays the command to
+ * them.
*
* @param args CLI args.
*/
@@ -112,7 +119,10 @@ public static void main(String[] args) {
/**
* Adds all commands from CommandLineInterfaceProducts automatically.
*/
- @CommandLine.Command(mixinStandardHelpOptions = true, description = "Auto-generated product command")
+ @CommandLine.Command(
+ mixinStandardHelpOptions = true,
+ description = "Auto-generated product command"
+ )
public static class ProductCommandHandler implements Callable {
private final CommandLineInterfaceProducts products;
private final Method method;
@@ -145,23 +155,20 @@ public Integer call() throws Exception {
)
void customMethod(
@Option(
- names = {"-a", "--account"},
+ names = { "-a", "--account" },
scope = ScopeType.LOCAL,
required = true,
paramLabel = "accountName",
description = "The name of the account"
- )
- String accountName,
+ ) String accountName,
@Option(
- names = {"-e", "--endpointName"},
+ names = { "-e", "--endpointName" },
scope = ScopeType.LOCAL,
required = true,
paramLabel = "endpointName",
description = "The name of the endpoint"
- )
- String endpointName,
- @Parameters(index = "0", scope = ScopeType.LOCAL, paramLabel = "")
- File file
+ ) String endpointName,
+ @Parameters(index = "0", scope = ScopeType.LOCAL, paramLabel = "") File file
) throws IOException {
MindeeClient mindeeClient = new MindeeClient(apiKey);
@@ -170,14 +177,9 @@ void customMethod(
Endpoint endpoint = new Endpoint(endpointName, accountName, "1");
if (cutDoc) {
- document = mindeeClient.parse(
- new LocalInputSource(file),
- endpoint,
- getDefaultPageOptions());
+ document = mindeeClient.parse(new LocalInputSource(file), endpoint, getDefaultPageOptions());
} else {
- document = mindeeClient.parse(
- new LocalInputSource(file),
- endpoint);
+ document = mindeeClient.parse(new LocalInputSource(file), endpoint);
}
System.out.println(document.toString());
}
@@ -185,38 +187,33 @@ void customMethod(
@Command(name = "generated", description = "Invokes a Generated API")
void generatedMethod(
@Option(
- names = {"-a", "--account"},
+ names = { "-a", "--account" },
scope = ScopeType.LOCAL,
required = true,
paramLabel = "accountName",
description = "The name of the account"
- )
- String accountName,
+ ) String accountName,
@Option(
- names = {"-e", "--endpointName"},
+ names = { "-e", "--endpointName" },
scope = ScopeType.LOCAL,
required = true,
paramLabel = "endpointName",
description = "The name of the endpoint"
- )
- String endpointName,
+ ) String endpointName,
@Option(
- names = {"-v", "--productVersion"},
+ names = { "-v", "--productVersion" },
scope = ScopeType.LOCAL,
paramLabel = "productVersion",
description = "The version of the endpoint",
defaultValue = "1"
- )
- String productVersion,
+ ) String productVersion,
@Option(
- names = {"-m", "--parsingMode"},
+ names = { "-m", "--parsingMode" },
description = "Whether to parse the document in synchronous mode or polling.",
scope = ScopeType.LOCAL,
defaultValue = "async"
- )
- String parsingMode,
- @Parameters(index = "0", scope = ScopeType.LOCAL, paramLabel = "")
- File file
+ ) String parsingMode,
+ @Parameters(index = "0", scope = ScopeType.LOCAL, paramLabel = "") File file
) throws IOException, InterruptedException {
MindeeClient mindeeClient = new MindeeClient(apiKey);
@@ -225,38 +222,29 @@ void generatedMethod(
if (Objects.equals(parsingMode, "sync")) {
if (cutDoc) {
- PredictResponse document = mindeeClient.parse(
- GeneratedV1.class,
- endpoint,
- new LocalInputSource(file),
- getDefaultPageOptions()
- );
+ PredictResponse document = mindeeClient
+ .parse(GeneratedV1.class, endpoint, new LocalInputSource(file), getDefaultPageOptions());
System.out.println(document.toString());
} else {
- PredictResponse document = mindeeClient.parse(
- GeneratedV1.class,
- endpoint,
- new LocalInputSource(file)
- );
+ PredictResponse document = mindeeClient
+ .parse(GeneratedV1.class, endpoint, new LocalInputSource(file));
System.out.println(document.toString());
}
} else if (Objects.equals(parsingMode, "async")) {
if (cutDoc) {
- AsyncPredictResponse document = mindeeClient.enqueueAndParse(
+ AsyncPredictResponse document = mindeeClient
+ .enqueueAndParse(
GeneratedV1.class,
endpoint,
new LocalInputSource(file),
PredictOptions.builder().build(),
getDefaultPageOptions(),
AsyncPollingOptions.builder().build()
- );
+ );
System.out.println(document.toString());
} else {
- AsyncPredictResponse document = mindeeClient.enqueueAndParse(
- GeneratedV1.class,
- endpoint,
- new LocalInputSource(file)
- );
+ AsyncPredictResponse document = mindeeClient
+ .enqueueAndParse(GeneratedV1.class, endpoint, new LocalInputSource(file));
System.out.println(document.toString());
}
} else {
@@ -266,31 +254,40 @@ void generatedMethod(
protected PageOptions getDefaultPageOptions() {
return new PageOptions.Builder()
- .pageIndexes(new Integer[]{0, 1, 2, 3, 4})
- .operation(PageOptionsOperation.KEEP_ONLY)
- .build();
+ .pageIndexes(new Integer[] { 0, 1, 2, 3, 4 })
+ .operation(PageOptionsOperation.KEEP_ONLY)
+ .build();
}
private String wordsOutput(Ocr ocr) {
StringBuilder output = new StringBuilder();
output.append("\n#############\nDocument Text\n#############\n::\n ");
- output.append(
- Arrays.stream(ocr.toString().split(String.format("%n")))
- .collect(Collectors.joining(String.format("%n ")))
- );
+ output
+ .append(
+ Arrays
+ .stream(ocr.toString().split(String.format("%n")))
+ .collect(Collectors.joining(String.format("%n ")))
+ );
output.append("\n");
return output.toString();
}
@Override
- public > String standardProductOutput(Class productClass, File file)
- throws IOException {
+ public > String standardProductOutput(
+ Class productClass,
+ File file
+ ) throws IOException {
MindeeClient mindeeClient = new MindeeClient(apiKey);
LocalInputSource inputSource = new LocalInputSource(file);
PredictResponse response;
- PredictOptions predictOptions = PredictOptions.builder().allWords(words).fullText(fullText).build();
+ PredictOptions predictOptions = PredictOptions
+ .builder()
+ .allWords(words)
+ .fullText(fullText)
+ .build();
if (cutDoc) {
- response = mindeeClient.parse(productClass, inputSource, predictOptions, getDefaultPageOptions());
+ response = mindeeClient
+ .parse(productClass, inputSource, predictOptions, getDefaultPageOptions());
} else {
response = mindeeClient.parse(productClass, inputSource, predictOptions);
}
@@ -304,9 +301,7 @@ private String wordsOutput(Ocr ocr) {
output.append(response.getRawResponse());
break;
default:
- output.append(
- response.getDocument().getInference().getPrediction().toString()
- );
+ output.append(response.getDocument().getInference().getPrediction().toString());
}
if (words) {
output.append(wordsOutput(response.getDocument().getOcr()));
@@ -315,20 +310,24 @@ private String wordsOutput(Ocr ocr) {
}
@Override
- public > String standardProductAsyncOutput(Class productClass, File file)
- throws IOException, InterruptedException {
+ public > String standardProductAsyncOutput(
+ Class productClass,
+ File file
+ ) throws IOException, InterruptedException {
MindeeClient mindeeClient = new MindeeClient(apiKey);
LocalInputSource inputSource = new LocalInputSource(file);
AsyncPredictResponse response;
- PredictOptions predictOptions = PredictOptions.builder().allWords(words).fullText(fullText).build();
+ PredictOptions predictOptions = PredictOptions
+ .builder()
+ .allWords(words)
+ .fullText(fullText)
+ .build();
if (cutDoc) {
- response = mindeeClient.enqueueAndParse(
- productClass, inputSource, predictOptions, getDefaultPageOptions(), null
- );
+ response = mindeeClient
+ .enqueueAndParse(productClass, inputSource, predictOptions, getDefaultPageOptions(), null);
} else {
- response = mindeeClient.enqueueAndParse(
- productClass, inputSource, predictOptions, null, null
- );
+ response = mindeeClient
+ .enqueueAndParse(productClass, inputSource, predictOptions, null, null);
}
StringBuilder output = new StringBuilder();
@@ -340,9 +339,7 @@ productClass, inputSource, predictOptions, getDefaultPageOptions(), null
output.append(response.getRawResponse());
break;
default:
- output.append(
- response.getDocumentObj().getInference().getPrediction().toString()
- );
+ output.append(response.getDocumentObj().getInference().getPrediction().toString());
}
if (words) {
output.append(wordsOutput(response.getDocumentObj().getOcr()));
diff --git a/src/main/java/com/mindee/InferenceParameters.java b/src/main/java/com/mindee/InferenceParameters.java
index 81c043bdb..f27e84f40 100644
--- a/src/main/java/com/mindee/InferenceParameters.java
+++ b/src/main/java/com/mindee/InferenceParameters.java
@@ -36,7 +36,8 @@ public final class InferenceParameters {
*/
private final String alias;
/**
- * Webhook IDs to call after all processing is finished. If empty, no webhooks will be used.
+ * Webhook IDs to call after all processing is finished.
+ * If empty, no webhooks will be used.
*/
private final String[] webhookIds;
/**
@@ -44,7 +45,8 @@ public final class InferenceParameters {
*/
private final AsyncPollingOptions pollingOptions;
/**
- * Additional text context used by the model during inference. Not recommended, for specific use only.
+ * Additional text context used by the model during inference.
+ * Not recommended, for specific use only.
*/
private final String textContext;
/**
@@ -73,7 +75,7 @@ public static final class Builder {
private Boolean polygon = null;
private Boolean confidence = null;
private String alias;
- private String[] webhookIds = new String[]{};
+ private String[] webhookIds = new String[] {};
private String textContext;
private String dataSchema;
private AsyncPollingOptions pollingOptions = AsyncPollingOptions.builder().build();
@@ -142,16 +144,16 @@ public Builder pollingOptions(AsyncPollingOptions pollingOptions) {
/** Build an immutable {@link InferenceParameters} instance. */
public InferenceParameters build() {
return new InferenceParameters(
- modelId,
- rag,
- rawText,
- polygon,
- confidence,
- alias,
- webhookIds,
- pollingOptions,
- textContext,
- dataSchema
+ modelId,
+ rag,
+ rawText,
+ polygon,
+ confidence,
+ alias,
+ webhookIds,
+ pollingOptions,
+ textContext,
+ dataSchema
);
}
}
diff --git a/src/main/java/com/mindee/MindeeClient.java b/src/main/java/com/mindee/MindeeClient.java
index ec0a98c88..32d961ceb 100644
--- a/src/main/java/com/mindee/MindeeClient.java
+++ b/src/main/java/com/mindee/MindeeClient.java
@@ -61,6 +61,7 @@ public MindeeClient(MindeeApi mindeeApi) {
/**
* Create a MindeeClient.
+ *
* @param pdfOperation The PdfOperation implementation to be used by the created MindeeClient.
* @param mindeeApi The MindeeApi implementation to be used by the created MindeeClient.
*/
@@ -76,31 +77,24 @@ private static MindeeApi createDefaultApi(String apiKey) {
} else {
mindeeSettings = new MindeeSettings();
}
- return MindeeHttpApi.builder()
- .mindeeSettings(mindeeSettings)
- .build();
+ return MindeeHttpApi.builder().mindeeSettings(mindeeSettings).build();
}
/**
* Parse a document from an async queue.
+ *
* @param Type of inference.
* @param type Type of inference;
* @param jobId ID of the job.
* @return A valid prediction.
*/
- public AsyncPredictResponse parseQueued(
- Class type,
- String jobId
- ) {
- return this.mindeeApi.documentQueueGet(
- type,
- new Endpoint(type),
- jobId
- );
+ public AsyncPredictResponse parseQueued(Class type, String jobId) {
+ return this.mindeeApi.documentQueueGet(type, new Endpoint(type), jobId);
}
/**
* Send a local file to an async queue.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -111,17 +105,20 @@ public AsyncPredictResponse enqueue(
Class type,
LocalInputSource localInputSource
) throws IOException {
- return this.enqueue(
+ return this
+ .enqueue(
type,
new Endpoint(type),
localInputSource.getFile(),
localInputSource.getFilename(),
null,
- null);
+ null
+ );
}
/**
* Retrieves the file after applying page operations to it.
+ *
* @param localInputSource Local input source to apply operations to.
* @param pageOptions Options to apply.
* @return A byte array of the file after applying page operations.
@@ -135,15 +132,16 @@ protected byte[] getSplitFile(
if (pageOptions == null || !localInputSource.isPdf()) {
splitFile = localInputSource.getFile();
} else {
- splitFile = pdfOperation.split(
- new SplitQuery(localInputSource.getFile(), pageOptions)
- ).getFile();
+ splitFile = pdfOperation
+ .split(new SplitQuery(localInputSource.getFile(), pageOptions))
+ .getFile();
}
return splitFile;
}
/**
* Send a local file to an async queue.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -158,18 +156,20 @@ public AsyncPredictResponse enqueue(
PredictOptions predictOptions,
PageOptions pageOptions
) throws IOException {
- return this.enqueue(
+ return this
+ .enqueue(
type,
new Endpoint(type),
getSplitFile(localInputSource, pageOptions),
localInputSource.getFilename(),
predictOptions,
- null
- );
+ null
+ );
}
/**
* Send a local file to an async queue.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -182,18 +182,20 @@ public AsyncPredictResponse enqueue(
LocalInputSource localInputSource,
PredictOptions predictOptions
) throws IOException {
- return this.enqueue(
+ return this
+ .enqueue(
type,
new Endpoint(type),
localInputSource.getFile(),
localInputSource.getFilename(),
predictOptions,
null
- );
+ );
}
/**
* Send a remote file to an async queue.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param sourceUrl A URL to a remote file.
@@ -205,18 +207,12 @@ public AsyncPredictResponse enqueue(
URL sourceUrl
) throws IOException {
InputSourceUtils.validateUrl(sourceUrl);
- return this.enqueue(
- type,
- new Endpoint(type),
- null,
- null,
- null,
- sourceUrl
- );
+ return this.enqueue(type, new Endpoint(type), null, null, null, sourceUrl);
}
/**
* Send a remote file to an async queue.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param sourceUrl A URL to a remote file.
@@ -230,14 +226,7 @@ public AsyncPredictResponse enqueue(
PredictOptions predictOptions
) throws IOException {
InputSourceUtils.validateUrl(sourceUrl);
- return this.enqueue(
- type,
- new Endpoint(type),
- null,
- null,
- predictOptions,
- sourceUrl
- );
+ return this.enqueue(type, new Endpoint(type), null, null, predictOptions, sourceUrl);
}
private AsyncPredictResponse enqueue(
@@ -248,17 +237,19 @@ private AsyncPredictResponse enqueue(
PredictOptions predictOptions,
URL urlInputSource
) throws IOException {
- RequestParameters params = RequestParameters.builder()
- .file(file)
- .fileName(filename)
- .predictOptions(predictOptions)
- .urlInputSource(urlInputSource)
- .build();
+ RequestParameters params = RequestParameters
+ .builder()
+ .file(file)
+ .fileName(filename)
+ .predictOptions(predictOptions)
+ .urlInputSource(urlInputSource)
+ .build();
return this.mindeeApi.predictAsyncPost(type, endpoint, params);
}
/**
* Send a local file to an async queue, poll, and parse when complete.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -270,18 +261,21 @@ public AsyncPredictResponse enqueueAndParse(
Class type,
LocalInputSource localInputSource
) throws IOException, InterruptedException {
- return this.enqueueAndParse(
- type,
- new Endpoint(type),
- null,
- localInputSource.getFile(),
- localInputSource.getFilename(),
- null,
- null);
+ return this
+ .enqueueAndParse(
+ type,
+ new Endpoint(type),
+ null,
+ localInputSource.getFile(),
+ localInputSource.getFilename(),
+ null,
+ null
+ );
}
/**
* Send a local file to an async queue, poll, and parse when complete.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -295,19 +289,21 @@ public AsyncPredictResponse enqueueAndParse(
LocalInputSource localInputSource,
AsyncPollingOptions pollingOptions
) throws IOException, InterruptedException {
- return this.enqueueAndParse(
- type,
- new Endpoint(type),
- pollingOptions,
- localInputSource.getFile(),
- localInputSource.getFilename(),
- null,
- null
- );
+ return this
+ .enqueueAndParse(
+ type,
+ new Endpoint(type),
+ pollingOptions,
+ localInputSource.getFile(),
+ localInputSource.getFilename(),
+ null,
+ null
+ );
}
/**
* Send a local file to an async queue, poll, and parse when complete.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -325,19 +321,21 @@ public AsyncPredictResponse enqueueAndParse(
PageOptions pageOptions,
AsyncPollingOptions pollingOptions
) throws IOException, InterruptedException {
- return this.enqueueAndParse(
- type,
- new Endpoint(type),
- pollingOptions,
- getSplitFile(localInputSource, pageOptions),
- localInputSource.getFilename(),
- predictOptions,
- null
- );
+ return this
+ .enqueueAndParse(
+ type,
+ new Endpoint(type),
+ pollingOptions,
+ getSplitFile(localInputSource, pageOptions),
+ localInputSource.getFilename(),
+ predictOptions,
+ null
+ );
}
/**
* Send a local file to an async queue, poll, and parse when complete.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -353,7 +351,8 @@ public AsyncPredictResponse enqueueAndParse(
PredictOptions predictOptions,
AsyncPollingOptions pollingOptions
) throws IOException, InterruptedException {
- return this.enqueueAndParse(
+ return this
+ .enqueueAndParse(
type,
new Endpoint(type),
pollingOptions,
@@ -361,11 +360,12 @@ public AsyncPredictResponse enqueueAndParse(
localInputSource.getFilename(),
predictOptions,
null
- );
+ );
}
/**
* Send a local file to an async queue, poll, and parse when complete.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -379,7 +379,8 @@ public AsyncPredictResponse enqueueAndParse(
LocalInputSource localInputSource,
PredictOptions predictOptions
) throws IOException, InterruptedException {
- return this.enqueueAndParse(
+ return this
+ .enqueueAndParse(
type,
new Endpoint(type),
null,
@@ -387,11 +388,12 @@ public AsyncPredictResponse enqueueAndParse(
localInputSource.getFilename(),
predictOptions,
null
- );
+ );
}
/**
* Send a remote file to an async queue, poll, and parse when complete.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param sourceUrl A URL to a remote file.
@@ -404,18 +406,12 @@ public AsyncPredictResponse enqueueAndParse(
URL sourceUrl
) throws IOException, InterruptedException {
InputSourceUtils.validateUrl(sourceUrl);
- return this.enqueueAndParse(
- type,
- new Endpoint(type),
- null,
- null,
- null,
- null,
- sourceUrl
- );
+ return this.enqueueAndParse(type, new Endpoint(type), null, null, null, null, sourceUrl);
}
/**
+ * Validate async polling options.
+ *
* @param pollingOptions Options for async call parameters
* @throws MindeeException Throws if settings aren't set properly.
*/
@@ -424,19 +420,20 @@ private void validateAsyncParams(AsyncPollingOptions pollingOptions) {
Double minimumIntervalSec = 1.0;
Integer minimumRetry = 2;
if (pollingOptions.getInitialDelaySec() < minimumInitialDelaySec) {
- throw new MindeeException(String.format(
- "Cannot set initial delay to less than %.0f second(s)", minimumInitialDelaySec
- ));
+ throw new MindeeException(
+ String
+ .format("Cannot set initial delay to less than %.0f second(s)", minimumInitialDelaySec)
+ );
}
if (pollingOptions.getIntervalSec() < minimumIntervalSec) {
- throw new MindeeException(String.format(
- "Cannot set auto-poll delay to less than %.0f second(s)", minimumIntervalSec
- ));
+ throw new MindeeException(
+ String.format("Cannot set auto-poll delay to less than %.0f second(s)", minimumIntervalSec)
+ );
}
if (pollingOptions.getMaxRetries() < minimumRetry) {
- throw new MindeeException(String.format(
- "Cannot set async retries to less than %d attempts", minimumRetry
- ));
+ throw new MindeeException(
+ String.format("Cannot set async retries to less than %d attempts", minimumRetry)
+ );
}
}
@@ -457,12 +454,12 @@ private AsyncPredictResponse enqueueAndParse(
final int intervalSec = (int) (pollingOptions.getIntervalSec() * 1000);
AsyncPredictResponse enqueueResponse = enqueue(
- type,
- endpoint,
- file,
- filename,
- predictOptions,
- urlInputSource
+ type,
+ endpoint,
+ file,
+ filename,
+ predictOptions,
+ urlInputSource
);
String jobId = enqueueResponse.getJob().getId();
@@ -480,11 +477,14 @@ private AsyncPredictResponse enqueueAndParse(
retryCount++;
Thread.sleep(intervalSec);
}
- throw new RuntimeException("Max retries exceeded: " + retryCount +". Failed to get the document.");
+ throw new RuntimeException(
+ "Max retries exceeded: " + retryCount + ". Failed to get the document."
+ );
}
/**
* Send a local file to a workflow execution.
+ *
* @param workflowId ID of the workflow to send the document to.
* @param localInputSource A local input source file.
* @param workflowOptions Options for the workflow execution.
@@ -496,18 +496,22 @@ public WorkflowResponse executeWorkflow(
LocalInputSource localInputSource,
WorkflowOptions workflowOptions
) throws IOException {
- return this.mindeeApi.executeWorkflowPost(
+ return this.mindeeApi
+ .executeWorkflowPost(
GeneratedV1.class,
workflowId,
- RequestParameters.builder()
- .file(localInputSource.getFile())
- .fileName(localInputSource.getFilename())
- .workflowOptions(workflowOptions)
- .build()
- );
+ RequestParameters
+ .builder()
+ .file(localInputSource.getFile())
+ .fileName(localInputSource.getFilename())
+ .workflowOptions(workflowOptions)
+ .build()
+ );
}
+
/**
* Send a local file to a workflow execution.
+ *
* @param workflowId ID of the workflow to send the document to.
* @param localInputSource A local input source file.
* @return A workflow response.
@@ -517,19 +521,22 @@ public WorkflowResponse executeWorkflow(
String workflowId,
LocalInputSource localInputSource
) throws IOException {
- return this.mindeeApi.executeWorkflowPost(
+ return this.mindeeApi
+ .executeWorkflowPost(
GeneratedV1.class,
workflowId,
- RequestParameters.builder()
- .file(localInputSource.getFile())
- .fileName(localInputSource.getFilename())
- .workflowOptions(WorkflowOptions.builder().build())
- .build()
- );
+ RequestParameters
+ .builder()
+ .file(localInputSource.getFile())
+ .fileName(localInputSource.getFilename())
+ .workflowOptions(WorkflowOptions.builder().build())
+ .build()
+ );
}
/**
* Send a local file to a Standard prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -540,18 +547,20 @@ public PredictResponse parse(
Class type,
LocalInputSource localInputSource
) throws IOException {
- return this.parse(
+ return this
+ .parse(
type,
new Endpoint(type),
localInputSource.getFile(),
localInputSource.getFilename(),
null,
null
- );
+ );
}
/**
* Send a local file to a Standard prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -564,18 +573,20 @@ public PredictResponse parse(
LocalInputSource localInputSource,
PredictOptions predictOptions
) throws IOException {
- return this.parse(
+ return this
+ .parse(
type,
new Endpoint(type),
localInputSource.getFile(),
localInputSource.getFilename(),
predictOptions,
null
- );
+ );
}
/**
* Send a local file to a Standard prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -588,18 +599,20 @@ public PredictResponse parse(
LocalInputSource localInputSource,
PageOptions pageOptions
) throws IOException {
- return this.parse(
+ return this
+ .parse(
type,
new Endpoint(type),
getSplitFile(localInputSource, pageOptions),
localInputSource.getFilename(),
null,
null
- );
+ );
}
/**
* Send a local file to a Standard prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -614,18 +627,20 @@ public PredictResponse parse(
PredictOptions predictOptions,
PageOptions pageOptions
) throws IOException {
- return this.parse(
+ return this
+ .parse(
type,
new Endpoint(type),
getSplitFile(localInputSource, pageOptions),
localInputSource.getFilename(),
predictOptions,
null
- );
+ );
}
/**
* Send a remote file to a Standard prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param urlInputSource A URL to a remote file.
@@ -642,6 +657,7 @@ public PredictResponse parse(
/**
* Send a remote file to a Standard prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param urlInputSource A URL to a remote file.
@@ -666,17 +682,19 @@ private PredictResponse parse(
PredictOptions predictOptions,
URL urlInputSource
) throws IOException {
- RequestParameters params = RequestParameters.builder()
- .file(file)
- .fileName(filename)
- .predictOptions(predictOptions)
- .urlInputSource(urlInputSource)
- .build();
+ RequestParameters params = RequestParameters
+ .builder()
+ .file(file)
+ .fileName(filename)
+ .predictOptions(predictOptions)
+ .urlInputSource(urlInputSource)
+ .build();
return this.mindeeApi.predictPost(type, endpoint, params);
}
/**
* Send a local file to a Custom prediction API and parse the results.
+ *
* @param localInputSource A local input source file.
* @param endpoint Custom endpoint to send the document to.
* @return an instance of {@link PredictResponse}.
@@ -686,15 +704,12 @@ public PredictResponse parse(
LocalInputSource localInputSource,
Endpoint endpoint
) throws IOException {
- return this.parse(
- localInputSource.getFile(),
- localInputSource.getFilename(),
- endpoint,
- null);
+ return this.parse(localInputSource.getFile(), localInputSource.getFilename(), endpoint, null);
}
/**
* Send a local file to a Custom prediction API and parse the results.
+ *
* @param localInputSource A local input source file.
* @param endpoint Custom endpoint to send the document to.
* @param pageOptions Page options for PDF documents.
@@ -706,24 +721,24 @@ public PredictResponse parse(
Endpoint endpoint,
PageOptions pageOptions
) throws IOException {
- return this.parse(
- getSplitFile(localInputSource, pageOptions),
- localInputSource.getFilename(),
- endpoint, null
- );
+ return this
+ .parse(
+ getSplitFile(localInputSource, pageOptions),
+ localInputSource.getFilename(),
+ endpoint,
+ null
+ );
}
/**
* Send a remote file to a Custom prediction API and parse the results.
+ *
* @param documentUrl A URL to a remote file.
* @param endpoint Custom endpoint to send the document to.
* @return an instance of {@link PredictResponse}.
* @throws IOException Throws if the file can't be accessed.
*/
- public PredictResponse parse(
- URL documentUrl,
- Endpoint endpoint
- ) throws IOException {
+ public PredictResponse parse(URL documentUrl, Endpoint endpoint) throws IOException {
InputSourceUtils.validateUrl(documentUrl);
return this.parse(null, null, endpoint, documentUrl);
}
@@ -734,18 +749,22 @@ private PredictResponse parse(
Endpoint endpoint,
URL urlInputSource
) throws IOException {
- return this.mindeeApi.predictPost(
- CustomV1.class,
- endpoint,
- RequestParameters.builder()
+ return this.mindeeApi
+ .predictPost(
+ CustomV1.class,
+ endpoint,
+ RequestParameters
+ .builder()
.file(file)
.fileName(filename)
.urlInputSource(urlInputSource)
- .build());
+ .build()
+ );
}
/**
* Send a local file to a Generated prediction async API queue.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -758,18 +777,20 @@ public AsyncPredictResponse enqueue(
Endpoint endpoint,
LocalInputSource localInputSource
) throws IOException {
- return this.enqueue(
- type,
- endpoint,
- localInputSource.getFile(),
- localInputSource.getFilename(),
- null,
- null
- );
+ return this
+ .enqueue(
+ type,
+ endpoint,
+ localInputSource.getFile(),
+ localInputSource.getFilename(),
+ null,
+ null
+ );
}
/**
* Send a local file to a Generated prediction async API queue.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -786,18 +807,20 @@ public AsyncPredictResponse enqueue(
PredictOptions predictOptions,
PageOptions pageOptions
) throws IOException {
- return this.enqueue(
- type,
- endpoint,
- getSplitFile(localInputSource, pageOptions),
- localInputSource.getFilename(),
- predictOptions,
- null
- );
+ return this
+ .enqueue(
+ type,
+ endpoint,
+ getSplitFile(localInputSource, pageOptions),
+ localInputSource.getFilename(),
+ predictOptions,
+ null
+ );
}
/**
* Send a remote file to a Generated prediction async API queue.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param endpoint Custom endpoint to send the document to.
@@ -811,18 +834,12 @@ public AsyncPredictResponse enqueue(
URL sourceUrl
) throws IOException {
InputSourceUtils.validateUrl(sourceUrl);
- return this.enqueue(
- type,
- endpoint,
- null,
- null,
- null,
- sourceUrl
- );
+ return this.enqueue(type, endpoint, null, null, null, sourceUrl);
}
/**
* Send a remote file to a Generated prediction async API queue.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param sourceUrl A URL to a remote file.
@@ -838,19 +855,12 @@ public AsyncPredictResponse enqueue(
PredictOptions predictOptions
) throws IOException {
InputSourceUtils.validateUrl(sourceUrl);
- return this.enqueue(
- type,
- endpoint,
- null,
- null,
- predictOptions,
- sourceUrl
- );
+ return this.enqueue(type, endpoint, null, null, predictOptions, sourceUrl);
}
-
/**
* Send a local file to a Generated prediction API async queue, poll, and parse when complete.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -864,18 +874,21 @@ public AsyncPredictResponse enqueueAndParse(
Endpoint endpoint,
LocalInputSource localInputSource
) throws IOException, InterruptedException {
- return this.enqueueAndParse(
- type,
- endpoint,
- null,
- localInputSource.getFile(),
- localInputSource.getFilename(),
- null,
- null);
+ return this
+ .enqueueAndParse(
+ type,
+ endpoint,
+ null,
+ localInputSource.getFile(),
+ localInputSource.getFilename(),
+ null,
+ null
+ );
}
/**
* Send a local file to a Generated prediction API async queue, poll, and parse when complete.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -891,19 +904,21 @@ public AsyncPredictResponse enqueueAndParse(
LocalInputSource localInputSource,
AsyncPollingOptions pollingOptions
) throws IOException, InterruptedException {
- return this.enqueueAndParse(
- type,
- endpoint,
- pollingOptions,
- localInputSource.getFile(),
- localInputSource.getFilename(),
- null,
- null
- );
+ return this
+ .enqueueAndParse(
+ type,
+ endpoint,
+ pollingOptions,
+ localInputSource.getFile(),
+ localInputSource.getFilename(),
+ null,
+ null
+ );
}
/**
* Send a local file to a Generated prediction API async queue, poll, and parse when complete.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -923,19 +938,21 @@ public AsyncPredictResponse enqueueAndParse(
PageOptions pageOptions,
AsyncPollingOptions pollingOptions
) throws IOException, InterruptedException {
- return this.enqueueAndParse(
- type,
- endpoint,
- pollingOptions,
- getSplitFile(localInputSource, pageOptions),
- localInputSource.getFilename(),
- predictOptions,
- null
- );
+ return this
+ .enqueueAndParse(
+ type,
+ endpoint,
+ pollingOptions,
+ getSplitFile(localInputSource, pageOptions),
+ localInputSource.getFilename(),
+ predictOptions,
+ null
+ );
}
/**
* Send a remote file to a Generated prediction API async queue, poll, and parse when complete.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param endpoint Custom endpoint to send the document to.
@@ -950,19 +967,12 @@ public AsyncPredictResponse enqueueAndParse(
URL sourceUrl
) throws IOException, InterruptedException {
InputSourceUtils.validateUrl(sourceUrl);
- return this.enqueueAndParse(
- type,
- endpoint,
- null,
- null,
- null,
- null,
- sourceUrl
- );
+ return this.enqueueAndParse(type, endpoint, null, null, null, null, sourceUrl);
}
/**
* Send a local file to a Generated prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -975,18 +985,20 @@ public PredictResponse parse(
Endpoint endpoint,
LocalInputSource localInputSource
) throws IOException {
- return this.parse(
- type,
- endpoint,
- localInputSource.getFile(),
- localInputSource.getFilename(),
- null,
- null
- );
+ return this
+ .parse(
+ type,
+ endpoint,
+ localInputSource.getFile(),
+ localInputSource.getFilename(),
+ null,
+ null
+ );
}
/**
* Send a local file to a Generated prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -1001,18 +1013,20 @@ public PredictResponse parse(
LocalInputSource localInputSource,
PredictOptions predictOptions
) throws IOException {
- return this.parse(
- type,
- endpoint,
- localInputSource.getFile(),
- localInputSource.getFilename(),
- predictOptions,
- null
- );
+ return this
+ .parse(
+ type,
+ endpoint,
+ localInputSource.getFile(),
+ localInputSource.getFilename(),
+ predictOptions,
+ null
+ );
}
/**
* Send a local file to a Generated prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -1027,18 +1041,20 @@ public PredictResponse parse(
LocalInputSource localInputSource,
PageOptions pageOptions
) throws IOException {
- return this.parse(
- type,
- endpoint,
- getSplitFile(localInputSource, pageOptions),
- localInputSource.getFilename(),
- null,
- null
- );
+ return this
+ .parse(
+ type,
+ endpoint,
+ getSplitFile(localInputSource, pageOptions),
+ localInputSource.getFilename(),
+ null,
+ null
+ );
}
/**
* Send a local file to a Standard prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localInputSource A local input source file.
@@ -1055,18 +1071,20 @@ public PredictResponse parse(
PredictOptions predictOptions,
PageOptions pageOptions
) throws IOException {
- return this.parse(
- type,
- endpoint,
- getSplitFile(localInputSource, pageOptions),
- localInputSource.getFilename(),
- predictOptions,
- null
- );
+ return this
+ .parse(
+ type,
+ endpoint,
+ getSplitFile(localInputSource, pageOptions),
+ localInputSource.getFilename(),
+ predictOptions,
+ null
+ );
}
/**
* Send a remote file to a Generated prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param endpoint Custom endpoint to send the document to.
@@ -1085,6 +1103,7 @@ public PredictResponse parse(
/**
* Send a remote file to a Generated prediction API and parse the results.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param documentUrl A URL to a remote file.
@@ -1105,6 +1124,7 @@ public PredictResponse parse(
/**
* Parse a document from a Generated prediction API async queue.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param endpoint Custom endpoint to send the document to.
@@ -1116,17 +1136,14 @@ public AsyncPredictResponse parseQueued(
Endpoint endpoint,
String jobId
) {
- return this.mindeeApi.documentQueueGet(
- type,
- endpoint,
- jobId
- );
+ return this.mindeeApi.documentQueueGet(type, endpoint, jobId);
}
/**
* Load a local prediction.
* Typically used when wanting to load from a webhook callback.
* However, any kind of Mindee response may be loaded.
+ *
* @param Type of inference.
* @param type Type of inference.
* @param localResponse A loaded local response.
@@ -1139,10 +1156,9 @@ public AsyncPredictResponse loadPrediction(
) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.findAndRegisterModules();
- JavaType parametricType = objectMapper.getTypeFactory().constructParametricType(
- AsyncPredictResponse.class,
- type
- );
+ JavaType parametricType = objectMapper
+ .getTypeFactory()
+ .constructParametricType(AsyncPredictResponse.class, type);
return objectMapper.readValue(localResponse.getFile(), parametricType);
}
diff --git a/src/main/java/com/mindee/MindeeClientV2.java b/src/main/java/com/mindee/MindeeClientV2.java
index cf8a68942..12097af80 100644
--- a/src/main/java/com/mindee/MindeeClientV2.java
+++ b/src/main/java/com/mindee/MindeeClientV2.java
@@ -26,7 +26,6 @@ public MindeeClientV2(String apiKey) {
this(createDefaultApiV2(apiKey));
}
-
/** Inject both a PDF implementation and an HTTP implementation. */
public MindeeClientV2(MindeeApiV2 mindeeApi) {
this.mindeeApi = mindeeApi;
@@ -42,7 +41,6 @@ public JobResponse enqueueInference(
return mindeeApi.reqPostInferenceEnqueue(inputSource, params);
}
-
/**
* Enqueue a document in the asynchronous queue.
*/
@@ -77,6 +75,7 @@ public InferenceResponse getInference(String inferenceId) {
/**
* Send a local file to an async queue, poll, and parse when complete.
+ *
* @param inputSource The input source to send.
* @param options The options to send along with the file.
* @return an instance of {@link InferenceResponse}.
@@ -92,10 +91,9 @@ public InferenceResponse enqueueAndGetInference(
return pollAndFetch(job, options);
}
-
-
/**
* Send a local file to an async queue, poll, and parse when complete.
+ *
* @param inputSource The input source to send.
* @param options The options to send along with the file.
* @return an instance of {@link InferenceResponse}.
@@ -111,9 +109,9 @@ public InferenceResponse enqueueAndGetInference(
return pollAndFetch(job, options);
}
-
/**
* Common logic for polling an asynchronous job for local & url files.
+ *
* @param initialJob The initial job response.
* @return an instance of {@link InferenceResponse}.
* @throws InterruptedException Throws if interrupted.
@@ -152,9 +150,7 @@ private static MindeeApiV2 createDefaultApiV2(String apiKey) {
MindeeSettingsV2 settings = apiKey == null || apiKey.trim().isEmpty()
? new MindeeSettingsV2()
: new MindeeSettingsV2(apiKey);
- return MindeeHttpApiV2.builder()
- .mindeeSettings(settings)
- .build();
+ return MindeeHttpApiV2.builder().mindeeSettings(settings).build();
}
private static void validatePollingOptions(AsyncPollingOptions p) {
diff --git a/src/main/java/com/mindee/cli/CommandLineInterfaceProducts.java b/src/main/java/com/mindee/cli/CommandLineInterfaceProducts.java
index 1e5908286..ab7d4e8d4 100644
--- a/src/main/java/com/mindee/cli/CommandLineInterfaceProducts.java
+++ b/src/main/java/com/mindee/cli/CommandLineInterfaceProducts.java
@@ -36,208 +36,300 @@ public class CommandLineInterfaceProducts {
private final ProductProcessor processor;
/**
+ * Default constructor.
+ *
* @param processor Processor instance to render the products.
*/
public CommandLineInterfaceProducts(ProductProcessor processor) {
this.processor = processor;
}
- @CommandLine.Command(name = "fr-bank-account-details", description = "Parse using FR Bank Account Details")
+ @CommandLine.Command(
+ name = "fr-bank-account-details",
+ description = "Parse using FR Bank Account Details"
+ )
void bankAccountDetailsV2Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductOutput(BankAccountDetailsV2.class, file));
}
@CommandLine.Command(name = "us-bank-check", description = "Parse using US Bank Check")
void bankCheckV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductOutput(BankCheckV1.class, file));
}
@CommandLine.Command(name = "barcode-reader", description = "Parse using Barcode Reader")
void barcodeReaderV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductOutput(BarcodeReaderV1.class, file));
}
@CommandLine.Command(name = "bill-of-lading", description = "Parse using Bill of Lading")
void billOfLadingV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(BillOfLadingV1.class, file));
}
@CommandLine.Command(name = "business-card", description = "Parse using Business Card")
void businessCardV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(BusinessCardV1.class, file));
}
@CommandLine.Command(name = "fr-carte-grise", description = "Parse using FR Carte Grise")
void carteGriseV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductOutput(CarteGriseV1.class, file));
}
@CommandLine.Command(name = "cropper", description = "Parse using Cropper")
void cropperV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductOutput(CropperV1.class, file));
}
@CommandLine.Command(name = "delivery-note", description = "Parse using Delivery note")
void deliveryNoteV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(DeliveryNoteV1.class, file));
}
@CommandLine.Command(name = "driver-license", description = "Parse using Driver License")
void driverLicenseV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(DriverLicenseV1.class, file));
}
@CommandLine.Command(name = "fr-energy-bill", description = "Parse using FR Energy Bill")
void energyBillV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(EnergyBillV1.class, file));
}
@CommandLine.Command(name = "financial-document", description = "Parse using Financial Document")
void financialDocumentV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(FinancialDocumentV1.class, file));
}
@CommandLine.Command(name = "fr-health-card", description = "Parse using FR Health Card")
void healthCardV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(HealthCardV1.class, file));
}
@CommandLine.Command(name = "us-healthcare-card", description = "Parse using US Healthcare Card")
void healthcareCardV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(HealthcareCardV1.class, file));
}
- @CommandLine.Command(name = "fr-carte-nationale-d-identite", description = "Parse using FR Carte Nationale d'Identité")
+ @CommandLine.Command(
+ name = "fr-carte-nationale-d-identite",
+ description = "Parse using FR Carte Nationale d'Identité"
+ )
void idCardV2Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductOutput(IdCardV2.class, file));
}
- @CommandLine.Command(name = "ind-passport-india", description = "Parse using IND Passport - India")
+ @CommandLine.Command(
+ name = "ind-passport-india",
+ description = "Parse using IND Passport - India"
+ )
void indianPassportV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(IndianPassportV1.class, file));
}
@CommandLine.Command(name = "international-id", description = "Parse using International ID")
void internationalIdV2Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(InternationalIdV2.class, file));
}
@CommandLine.Command(name = "invoice-splitter", description = "Parse using Invoice Splitter")
void invoiceSplitterV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(InvoiceSplitterV1.class, file));
}
@CommandLine.Command(name = "invoice", description = "Parse using Invoice")
void invoiceV4Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(InvoiceV4.class, file));
}
- @CommandLine.Command(name = "multi-receipts-detector", description = "Parse using Multi Receipts Detector")
+ @CommandLine.Command(
+ name = "multi-receipts-detector",
+ description = "Parse using Multi Receipts Detector"
+ )
void multiReceiptsDetectorV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductOutput(MultiReceiptsDetectorV1.class, file));
}
- @CommandLine.Command(name = "nutrition-facts-label", description = "Parse using Nutrition Facts Label")
+ @CommandLine.Command(
+ name = "nutrition-facts-label",
+ description = "Parse using Nutrition Facts Label"
+ )
void nutritionFactsLabelV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(NutritionFactsLabelV1.class, file));
}
@CommandLine.Command(name = "passport", description = "Parse using Passport")
void passportV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductOutput(PassportV1.class, file));
}
@CommandLine.Command(name = "fr-payslip", description = "Parse using FR Payslip")
void payslipV3Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(PayslipV3.class, file));
}
@CommandLine.Command(name = "receipt", description = "Parse using Receipt")
void receiptV5Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(ReceiptV5.class, file));
}
@CommandLine.Command(name = "resume", description = "Parse using Resume")
void resumeV1Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(ResumeV1.class, file));
}
@CommandLine.Command(name = "us-us-mail", description = "Parse using US US Mail")
void usMailV3Method(
- @CommandLine.Parameters(index = "0", paramLabel = "", scope = CommandLine.ScopeType.LOCAL)
- File file
+ @CommandLine.Parameters(
+ index = "0",
+ paramLabel = "",
+ scope = CommandLine.ScopeType.LOCAL
+ ) File file
) throws IOException, InterruptedException {
System.out.println(processor.standardProductAsyncOutput(UsMailV3.class, file));
}
diff --git a/src/main/java/com/mindee/cli/ProductProcessor.java b/src/main/java/com/mindee/cli/ProductProcessor.java
index 3931d3485..181ecf2ee 100644
--- a/src/main/java/com/mindee/cli/ProductProcessor.java
+++ b/src/main/java/com/mindee/cli/ProductProcessor.java
@@ -11,20 +11,27 @@
@CommandLine.Command(
name = "CLI",
scope = CommandLine.ScopeType.INHERIT,
- subcommands = {CommandLine.HelpCommand.class},
+ subcommands = { CommandLine.HelpCommand.class },
description = "Invoke Off The Shelf API for invoice, receipt, and passports"
)
public interface ProductProcessor {
/**
+ * Process a product synchronously.
+ *
* @param productClass Product class to be processed for synchronous products.
* @param file Input file.
* @param Type of the product.
* @return A string representation of the result of the parsing.
* @throws IOException Throws if the parsing goes wrong.
*/
- > String standardProductOutput(Class productClass, File file) throws IOException;
+ > String standardProductOutput(
+ Class productClass,
+ File file
+ ) throws IOException;
/**
+ * Process a product asynchronously.
+ *
* @param productClass Product class to be processed for asynchronous products.
* @param file Input file.
* @param Type of the product.
@@ -32,5 +39,8 @@ public interface ProductProcessor {
* @throws IOException Throws if the parsing goes wrong.
* @throws InterruptedException Throws if the polling is interrupted.
*/
- > String standardProductAsyncOutput(Class productClass, File file) throws IOException, InterruptedException;
+ > String standardProductAsyncOutput(
+ Class productClass,
+ File file
+ ) throws IOException, InterruptedException;
}
diff --git a/src/main/java/com/mindee/extraction/ExtractedImage.java b/src/main/java/com/mindee/extraction/ExtractedImage.java
index c5e84a4a5..e5e383238 100644
--- a/src/main/java/com/mindee/extraction/ExtractedImage.java
+++ b/src/main/java/com/mindee/extraction/ExtractedImage.java
@@ -20,6 +20,8 @@ public class ExtractedImage {
private final String saveFormat;
/**
+ * Default constructor.
+ *
* @param image Buffered image object.
* @param filename Name of the extracted image.
* @param saveFormat Format to save the image as, defaults to PNG.
@@ -33,6 +35,7 @@ public ExtractedImage(BufferedImage image, String filename, String saveFormat) {
/**
* Write the image to a file.
* Uses the default image format and filename.
+ *
* @param outputPath the output directory (must exist).
* @throws IOException Throws if the file can't be accessed.
*/
@@ -45,6 +48,7 @@ public void writeToFile(String outputPath) throws IOException {
/**
* Write the image to a file.
* Uses the default image format and filename.
+ *
* @param outputPath the output directory (must exist).
* @throws IOException Throws if the file can't be accessed.
*/
@@ -56,6 +60,7 @@ public void writeToFile(Path outputPath) throws IOException {
/**
* Return the image in a format suitable for sending to MindeeClient for parsing.
+ *
* @return an instance of {@link LocalInputSource}
* @throws IOException Throws if the file can't be accessed.
*/
diff --git a/src/main/java/com/mindee/extraction/ExtractedPDF.java b/src/main/java/com/mindee/extraction/ExtractedPDF.java
index bbe0ad912..fdc859aec 100644
--- a/src/main/java/com/mindee/extraction/ExtractedPDF.java
+++ b/src/main/java/com/mindee/extraction/ExtractedPDF.java
@@ -1,6 +1,5 @@
package com.mindee.extraction;
-import com.mindee.MindeeException;
import com.mindee.input.LocalInputSource;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -19,6 +18,8 @@ public class ExtractedPDF {
private final String filename;
/**
+ * Default constructor.
+ *
* @param pdf PDF wrapper object.
* @param filename Name of the extracted file.
*/
diff --git a/src/main/java/com/mindee/extraction/ImageExtractor.java b/src/main/java/com/mindee/extraction/ImageExtractor.java
index c48fda835..403d497e2 100644
--- a/src/main/java/com/mindee/extraction/ImageExtractor.java
+++ b/src/main/java/com/mindee/extraction/ImageExtractor.java
@@ -25,6 +25,7 @@ public class ImageExtractor {
/**
* Init from a path.
+ *
* @param filePath Path to the file.
* @throws IOException Throws if the file can't be accessed.
*/
@@ -34,6 +35,7 @@ public ImageExtractor(String filePath) throws IOException {
/**
* Init from a {@link LocalInputSource}.
+ *
* @param source The local source.
* @throws IOException Throws if the file can't be accessed.
*/
@@ -57,6 +59,8 @@ public ImageExtractor(LocalInputSource source) throws IOException {
}
/**
+ * Get the number of pages in the file.
+ *
* @return The number of pages in the file.
*/
public int getPageCount() {
@@ -65,6 +69,7 @@ public int getPageCount() {
/**
* Extract multiple images on a given page from a list of fields having position data.
+ *
* @param Type of field (needs to support positioning data).
* @param fields List of Fields to extract.
* @param pageIndex The page index to extract, begins at 0.
@@ -79,6 +84,7 @@ public List extractImagesFromPage(
/**
* Extract multiple images on a given page from a list of fields having position data.
+ *
* @param Type of field (needs to support positioning data).
* @param fields List of Fields to extract.
* @param pageIndex The page index to extract, begins at 0.
@@ -106,12 +112,13 @@ private List extractFromPage(
String outputName
) {
String[] splitName = InputSourceUtils.splitNameStrict(outputName);
- String filename = String.format("%s_page-%3s.%s", splitName[0], pageIndex + 1, splitName[1])
- .replace(" ", "0");
+ String filename = String
+ .format("%s_page-%3s.%s", splitName[0], pageIndex + 1, splitName[1])
+ .replace(" ", "0");
List extractedImages = new ArrayList<>();
for (int i = 0; i < fields.size(); i++) {
- ExtractedImage extractedImage = extractImage(fields.get(i), pageIndex, i+1, filename);
+ ExtractedImage extractedImage = extractImage(fields.get(i), pageIndex, i + 1, filename);
if (extractedImage != null) {
extractedImages.add(extractedImage);
}
@@ -121,12 +128,14 @@ private List extractFromPage(
/**
* Extract a single image from a field having position data.
+ *
* @param Type of field (needs to support positioning data).
* @param field The field to extract.
* @param index The index to use for naming the extracted image.
* @param filename Name of the file.
* @param pageIndex The page index to extract, begins at 0.
- * @return The {@link ExtractedImage}, or null if the field does not have valid position data.
+ * @return The {@link ExtractedImage}, or null if the field does not have valid
+ * position data.
*/
public ExtractedImage extractImage(
FieldT field,
@@ -142,21 +151,27 @@ public ExtractedImage extractImage(
}
Bbox bbox = BboxUtils.generate(boundingBox);
String fieldFilename = splitName[0]
- + String.format("_%3s", index).replace(" ", "0")
- + "."
- + saveFormat;
+ + String.format("_%3s", index).replace(" ", "0")
+ + "."
+ + saveFormat;
return new ExtractedImage(extractImage(bbox, pageIndex), fieldFilename, saveFormat);
}
/**
* Extract a single image from a field having position data.
+ *
* @param Type of field (needs to support positioning data).
* @param field The field to extract.
* @param index The index to use for naming the extracted image.
* @param pageIndex The page index to extract, begins at 0.
- * @return The {@link ExtractedImage}, or null if the field does not have valid position data.
+ * @return The {@link ExtractedImage}, or null if the field does not have valid
+ * position data.
*/
- public ExtractedImage extractImage(FieldT field, int pageIndex, int index) {
+ public ExtractedImage extractImage(
+ FieldT field,
+ int pageIndex,
+ int index
+ ) {
return extractImage(field, pageIndex, index, this.filename);
}
diff --git a/src/main/java/com/mindee/extraction/PDFExtractor.java b/src/main/java/com/mindee/extraction/PDFExtractor.java
index 55b5f7b02..7f014ad8e 100644
--- a/src/main/java/com/mindee/extraction/PDFExtractor.java
+++ b/src/main/java/com/mindee/extraction/PDFExtractor.java
@@ -55,8 +55,14 @@ public PDFExtractor(LocalInputSource source) throws IOException {
BufferedImage bufferedImage = byteArrayToBufferedImage(source.getFile());
PDImageXObject pdImage = LosslessFactory.createFromImage(document, bufferedImage);
try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
- contentStream.drawImage(pdImage, 100, 600, (float) pdImage.getWidth() / 2,
- (float) pdImage.getHeight() / 2);
+ contentStream
+ .drawImage(
+ pdImage,
+ 100,
+ 600,
+ (float) pdImage.getWidth() / 2,
+ (float) pdImage.getHeight() / 2
+ );
}
this.sourcePdf = document;
@@ -64,7 +70,9 @@ public PDFExtractor(LocalInputSource source) throws IOException {
}
/**
- * @return The number of pages in the file.
+ * Get the number of pages in the PDF file.
+ *
+ * @return The number of pages in the PDF file.
*/
public int getPageCount() {
return sourcePdf.getNumberOfPages();
@@ -90,8 +98,9 @@ public static BufferedImage byteArrayToBufferedImage(byte[] byteArray) throws IO
* @return A list of extracted files.
* @throws IOException Throws if the file can't be accessed.
*/
- public List extractSubDocuments(List> pageIndexes)
- throws IOException {
+ public List extractSubDocuments(
+ List> pageIndexes
+ ) throws IOException {
List extractedPDFs = new ArrayList<>();
for (List pageIndexElement : pageIndexes) {
@@ -99,14 +108,21 @@ public List extractSubDocuments(List> pageIndexes)
throw new MindeeException("Empty indexes not allowed for extraction.");
}
String[] splitName = InputSourceUtils.splitNameStrict(filename);
- String fieldFilename =
- splitName[0] + String.format("_%3s", pageIndexElement.get(0) + 1).replace(" ", "0")
- + "-"
- + String.format("%3s", pageIndexElement.get(pageIndexElement.size() - 1) + 1)
- .replace(" ", "0") + "." + splitName[1];
- extractedPDFs.add(
- new ExtractedPDF(Loader.loadPDF(mergePdfPages(this.sourcePdf, pageIndexElement, false)),
- fieldFilename));
+ String fieldFilename = splitName[0]
+ + String.format("_%3s", pageIndexElement.get(0) + 1).replace(" ", "0")
+ + "-"
+ + String
+ .format("%3s", pageIndexElement.get(pageIndexElement.size() - 1) + 1)
+ .replace(" ", "0")
+ + "."
+ + splitName[1];
+ extractedPDFs
+ .add(
+ new ExtractedPDF(
+ Loader.loadPDF(mergePdfPages(this.sourcePdf, pageIndexElement, false)),
+ fieldFilename
+ )
+ );
}
return extractedPDFs;
}
@@ -122,9 +138,10 @@ public List extractInvoices(
List pageIndexes
) throws IOException {
- List> indexes =
- pageIndexes.stream().map(InvoiceSplitterV1InvoicePageGroup::getPageIndexes)
- .collect(Collectors.toList());
+ List> indexes = pageIndexes
+ .stream()
+ .map(InvoiceSplitterV1InvoicePageGroup::getPageIndexes)
+ .collect(Collectors.toList());
return extractSubDocuments(indexes);
}
diff --git a/src/main/java/com/mindee/geometry/Bbox.java b/src/main/java/com/mindee/geometry/Bbox.java
index 891a3565e..4f4f3dd8b 100644
--- a/src/main/java/com/mindee/geometry/Bbox.java
+++ b/src/main/java/com/mindee/geometry/Bbox.java
@@ -1,6 +1,5 @@
package com.mindee.geometry;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.Getter;
@@ -35,12 +34,13 @@ public Bbox(double minX, double maxX, double minY, double maxY) {
* Get the Bbox as a Polygon.
*/
public Polygon getAsPolygon() {
- List points = Arrays.asList(
+ List points = Arrays
+ .asList(
new Point(this.minX, this.minY),
new Point(this.maxX, this.minY),
new Point(this.maxX, this.maxY),
new Point(this.minX, this.maxY)
- );
+ );
return new Polygon(points);
}
}
diff --git a/src/main/java/com/mindee/geometry/BboxUtils.java b/src/main/java/com/mindee/geometry/BboxUtils.java
index 8ee0db999..0b4ca8bcd 100644
--- a/src/main/java/com/mindee/geometry/BboxUtils.java
+++ b/src/main/java/com/mindee/geometry/BboxUtils.java
@@ -20,22 +20,19 @@ public static Bbox generate(Polygon polygon) {
return null;
}
- DoubleSummaryStatistics statsX = polygon.getCoordinates()
- .stream()
- .mapToDouble(Point::getX)
- .summaryStatistics();
+ DoubleSummaryStatistics statsX = polygon
+ .getCoordinates()
+ .stream()
+ .mapToDouble(Point::getX)
+ .summaryStatistics();
- DoubleSummaryStatistics statsY = polygon.getCoordinates()
- .stream()
- .mapToDouble(Point::getY)
- .summaryStatistics();
+ DoubleSummaryStatistics statsY = polygon
+ .getCoordinates()
+ .stream()
+ .mapToDouble(Point::getY)
+ .summaryStatistics();
- return new Bbox(
- statsX.getMin(),
- statsX.getMax(),
- statsY.getMin(),
- statsY.getMax()
- );
+ return new Bbox(statsX.getMin(), statsX.getMax(), statsY.getMin(), statsY.getMax());
}
/**
@@ -47,8 +44,7 @@ public static Bbox generate(List polygons) {
return null;
}
- Optional mergedPolygon = polygons.stream()
- .reduce(PolygonUtils::combine);
+ Optional mergedPolygon = polygons.stream().reduce(PolygonUtils::combine);
if (!mergedPolygon.isPresent()) {
return null;
diff --git a/src/main/java/com/mindee/geometry/BoundingBoxUtils.java b/src/main/java/com/mindee/geometry/BoundingBoxUtils.java
index 413f7ce59..d4b8e31bf 100644
--- a/src/main/java/com/mindee/geometry/BoundingBoxUtils.java
+++ b/src/main/java/com/mindee/geometry/BoundingBoxUtils.java
@@ -11,18 +11,26 @@ private BoundingBoxUtils() {
}
public static Polygon createBoundingBoxFrom(Polygon polygon) {
- DoubleSummaryStatistics xStatistics = polygon.getCoordinates().stream()
- .mapToDouble(Point::getX)
- .summaryStatistics();
+ DoubleSummaryStatistics xStatistics = polygon
+ .getCoordinates()
+ .stream()
+ .mapToDouble(Point::getX)
+ .summaryStatistics();
- DoubleSummaryStatistics yStatistics = polygon.getCoordinates()
- .stream().mapToDouble(Point::getY)
- .summaryStatistics();
+ DoubleSummaryStatistics yStatistics = polygon
+ .getCoordinates()
+ .stream()
+ .mapToDouble(Point::getY)
+ .summaryStatistics();
- return new Polygon(Arrays.asList(
- new Point(xStatistics.getMin(), yStatistics.getMin()),
- new Point(xStatistics.getMax(), yStatistics.getMin()),
- new Point(xStatistics.getMax(), yStatistics.getMax()),
- new Point(xStatistics.getMin(), yStatistics.getMax())));
+ return new Polygon(
+ Arrays
+ .asList(
+ new Point(xStatistics.getMin(), yStatistics.getMin()),
+ new Point(xStatistics.getMax(), yStatistics.getMin()),
+ new Point(xStatistics.getMax(), yStatistics.getMax()),
+ new Point(xStatistics.getMin(), yStatistics.getMax())
+ )
+ );
}
}
diff --git a/src/main/java/com/mindee/geometry/MinMax.java b/src/main/java/com/mindee/geometry/MinMax.java
index 38fdba751..6dead2368 100644
--- a/src/main/java/com/mindee/geometry/MinMax.java
+++ b/src/main/java/com/mindee/geometry/MinMax.java
@@ -1,4 +1,5 @@
package com.mindee.geometry;
+
import lombok.Getter;
/** Minimum and maximum values. */
diff --git a/src/main/java/com/mindee/geometry/PolygonDeserializer.java b/src/main/java/com/mindee/geometry/PolygonDeserializer.java
index a9567f000..22b4ead3b 100644
--- a/src/main/java/com/mindee/geometry/PolygonDeserializer.java
+++ b/src/main/java/com/mindee/geometry/PolygonDeserializer.java
@@ -31,7 +31,9 @@ public Polygon deserialize(
) throws IOException {
ArrayNode node = jsonParser.getCodec().readTree(jsonParser);
- List> polygonList = mapper.readerFor(new TypeReference>>() {}).readValue(node);
+ TypeReference>> typeRef = new TypeReference>>() {
+ };
+ List> polygonList = mapper.readerFor(typeRef).readValue(node);
return PolygonUtils.getFrom(polygonList);
}
diff --git a/src/main/java/com/mindee/geometry/PolygonUtils.java b/src/main/java/com/mindee/geometry/PolygonUtils.java
index aca931750..ee32a294f 100644
--- a/src/main/java/com/mindee/geometry/PolygonUtils.java
+++ b/src/main/java/com/mindee/geometry/PolygonUtils.java
@@ -17,9 +17,10 @@ private PolygonUtils() {
* Create a Polygon from a list of a list of floats.
*/
public static Polygon getFrom(List> polygon) {
- List coordinates = polygon.stream()
- .map(coordinate -> new Point(coordinate.get(0), coordinate.get(1)))
- .collect(Collectors.toList());
+ List