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
8 changes: 8 additions & 0 deletions .betterleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[extend]
useDefault = true

[[allowlists]]
description = "Dummy HMAC secret used in LocalResponse unit tests"
condition = "AND"
paths = ['''^src/test/.*\.java$''']
regexes = ['''ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH''']
4 changes: 0 additions & 4 deletions .betterleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@

50e7a1a5deade5f3ea4f4478211fc29eb36bba86:src/test/java/com/mindee/v2/http/MindeeHttpApiV2Test.java:generic-credential-uri:73
fce24ac9d3dabfdc2ba2cae55a7dd83bbdc32244:src/main/java/com/mindee/input/URLInputSource.java:generic-credential-uri:68
c17d58ed662f09341863cf80360ad265a8a7077e:src/test/java/com/mindee/v2/parsing/LocalResponseTest.java:generic-api-key:19
6c390b1b76954f1b42f4acce9e7540a25a39f406:src/test/java/com/mindee/v1/parsing/LocalResponseTest.java:generic-api-key:21
30192fe5af49c977f9a2680c3b5f2f231a47ff80:src/test/java/com/mindee/input/LocalResponseV2Test.java:generic-api-key:19
503570dd1ca44074c7da2c7f1f060e6eac546ad7:.github/workflows/_publish-code.yml:generic-password:29
8a437effa2694ed811c09ec4b88af45c5073cda3:src/test/java/com/mindee/input/LocalResponseTest.java:generic-api-key:15
40ebc5e3d6d28e92097f99505aa908df7e557f38:.github/workflows/maven-publish.yml:generic-password:22
40 changes: 0 additions & 40 deletions docs/code_samples/workflow_execution.txt

This file was deleted.

54 changes: 0 additions & 54 deletions src/main/java/com/mindee/v1/MindeeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
import com.mindee.pdf.PDFInputOperator;
import com.mindee.v1.clientoptions.PollingOptions;
import com.mindee.v1.clientoptions.PredictOptions;
import com.mindee.v1.clientoptions.WorkflowOptions;
import com.mindee.v1.http.Endpoint;
import com.mindee.v1.http.MindeeApiV1;
import com.mindee.v1.http.MindeeHttpApiV1;
import com.mindee.v1.http.RequestParameters;
import com.mindee.v1.parsing.common.AsyncPredictResponse;
import com.mindee.v1.parsing.common.Inference;
import com.mindee.v1.parsing.common.PredictResponse;
import com.mindee.v1.parsing.common.WorkflowResponse;
import com.mindee.v1.product.generated.GeneratedV1;
import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -476,58 +474,6 @@ private <T extends Inference> AsyncPredictResponse<T> enqueueAndParse(
);
}

/**
* 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.
* @return A workflow response.
* @throws IOException Throws if the file can't be accessed.
*/
public WorkflowResponse<GeneratedV1> executeWorkflow(
String workflowId,
LocalInputSource localInputSource,
WorkflowOptions workflowOptions
) throws IOException {
return this.mindeeApi
.executeWorkflowPost(
GeneratedV1.class,
workflowId,
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.
* @throws IOException Throws if the file can't be accessed.
*/
public WorkflowResponse<GeneratedV1> executeWorkflow(
String workflowId,
LocalInputSource localInputSource
) throws IOException {
return this.mindeeApi
.executeWorkflowPost(
GeneratedV1.class,
workflowId,
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.
*
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/mindee/v1/http/MindeeApiV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mindee.v1.parsing.common.AsyncPredictResponse;
import com.mindee.v1.parsing.common.Inference;
import com.mindee.v1.parsing.common.PredictResponse;
import com.mindee.v1.parsing.common.WorkflowResponse;
import java.io.IOException;

/**
Expand Down Expand Up @@ -38,13 +37,4 @@ public abstract <DocT extends Inference> PredictResponse<DocT> predictPost(
Endpoint endpoint,
RequestParameters requestParameters
) throws IOException;

/**
* Execute a workflow.
*/
public abstract <DocT extends Inference> WorkflowResponse<DocT> executeWorkflowPost(
Class<DocT> documentClass,
String workflowId,
RequestParameters requestParameters
) throws IOException;
}
56 changes: 2 additions & 54 deletions src/main/java/com/mindee/v1/http/MindeeHttpApiV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.mindee.v1.parsing.common.ErrorDetails;
import com.mindee.v1.parsing.common.Inference;
import com.mindee.v1.parsing.common.PredictResponse;
import com.mindee.v1.parsing.common.WorkflowResponse;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -44,7 +43,7 @@ public final class MindeeHttpApiV1 extends MindeeApiV1 {
private static final ObjectMapper mapper = JsonMapper.builder().findAndAddModules().build();
private final Function<Endpoint, String> buildProductPredicBasetUrl = this::buildProductPredictBaseUrl;
private final Function<String, String> buildWorkflowPredictBaseUrl = this::buildWorkflowPredictBaseUrl;
private final Function<String, String> buildWorkflowExecutionBaseUrl = this::buildWorkflowExecutionUrl;

/**
* The MindeeSetting needed to make the api call.
*/
Expand Down Expand Up @@ -74,14 +73,9 @@ public final class MindeeHttpApiV1 extends MindeeApiV1 {
* Only needs to be set if the api calls need to be directed through internal URLs.
*/
private final Function<Endpoint, String> documentUrlFromEndpoint;
/**
* The function used to generate the Job status URL for workflow execution calls.
* Only needs to be set if the api calls need to be directed through internal URLs.
*/
private final Function<String, String> workflowUrlFromId;

public MindeeHttpApiV1(MindeeSettings mindeeSettings) {
this(mindeeSettings, null, null, null, null, null, null);
this(mindeeSettings, null, null, null, null, null);
}

@Builder
Expand All @@ -91,7 +85,6 @@ private MindeeHttpApiV1(
Function<Endpoint, String> urlFromEndpoint,
Function<Endpoint, String> asyncUrlFromEndpoint,
Function<Endpoint, String> documentUrlFromEndpoint,
Function<String, String> workflowUrlFromEndpoint,
Function<String, String> asyncUrlFromWorkflow
) {
this.mindeeSettings = mindeeSettings;
Expand Down Expand Up @@ -128,12 +121,6 @@ private MindeeHttpApiV1(
this.documentUrlFromEndpoint = this.buildProductPredicBasetUrl
.andThen((url) -> url.concat("/documents/queue/"));
}

if (workflowUrlFromEndpoint != null) {
this.workflowUrlFromId = workflowUrlFromEndpoint;
} else {
this.workflowUrlFromId = this.buildWorkflowExecutionBaseUrl;
}
}

/**
Expand Down Expand Up @@ -260,41 +247,6 @@ public <DocT extends Inference> AsyncPredictResponse<DocT> predictAsyncPost(
}
}

/**
* POST a prediction request for a workflow response.
*/
public <DocT extends Inference> WorkflowResponse<DocT> executeWorkflowPost(
Class<DocT> documentClass,
String workflowId,
RequestParameters requestParameters
) throws IOException {

String url = workflowUrlFromId.apply(workflowId);
HttpPost post = buildHttpPost(url, requestParameters);

JavaType parametricType = mapper
.getTypeFactory()
.constructParametricType(WorkflowResponse.class, documentClass);
try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
return httpClient.execute(post, response -> {
HttpEntity responseEntity = response.getEntity();
int statusCode = response.getCode();
if (isInvalidStatusCode(statusCode)) {
throw getHttpError(parametricType, response);
}
if (responseEntity.getContentLength() == 0) {
throw new MindeeException("Empty response from server.");
}
String rawResponse = readRawResponse(responseEntity);
WorkflowResponse<DocT> mappedResponse = mapper.readValue(rawResponse, parametricType);
mappedResponse.setRawResponse(rawResponse);
return mappedResponse;
});
} catch (IOException err) {
throw new MindeeException(err.getMessage(), err);
}
}

private <ResponseT extends ApiResponse> MindeeHttpExceptionV1 getHttpError(
JavaType parametricType,
ClassicHttpResponse response
Expand Down Expand Up @@ -344,10 +296,6 @@ private String buildWorkflowPredictBaseUrl(String workflowId) {
return this.mindeeSettings.getBaseUrl() + "/workflows/" + workflowId;
}

private String buildWorkflowExecutionUrl(String workflowId) {
return this.mindeeSettings.getBaseUrl() + "/workflows/" + workflowId + "/executions";
}

private HttpPost buildHttpPost(
String url,
RequestParameters requestParameters
Expand Down
9 changes: 0 additions & 9 deletions src/test/java/com/mindee/v1/FakeMindeeApiV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,4 @@ public <DocT extends Inference> PredictResponse<DocT> predictPost(
) throws IOException {
return (PredictResponse<DocT>) predictResponse;
}

@Override
public <DocT extends Inference> WorkflowResponse<DocT> executeWorkflowPost(
Class<DocT> documentClass,
String workflowId,
RequestParameters requestParameters
) throws IOException {
return (WorkflowResponse<DocT>) workflowResponse;
}
}
21 changes: 0 additions & 21 deletions src/test/java/com/mindee/v1/workflow/WorkflowIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
import com.mindee.input.LocalInputSource;
import com.mindee.v1.MindeeClient;
import com.mindee.v1.clientoptions.PredictOptions;
import com.mindee.v1.clientoptions.WorkflowOptions;
import com.mindee.v1.parsing.common.AsyncPredictResponse;
import com.mindee.v1.parsing.common.Execution;
import com.mindee.v1.parsing.common.ExecutionPriority;
import com.mindee.v1.parsing.common.WorkflowResponse;
import com.mindee.v1.product.financialdocument.FinancialDocumentV1;
import com.mindee.v1.product.generated.GeneratedV1;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand All @@ -37,22 +32,6 @@ static void clientSetUp() throws IOException {
);
}

@Test
public void givenAWorkflowIdUploadShouldReturnACorrectWorkflowObject() throws IOException {

WorkflowOptions options = WorkflowOptions
.builder()
.alias("java-" + currentDateTime)
.priority(ExecutionPriority.LOW)
.rag(true)
.build();
WorkflowResponse<GeneratedV1> response = client
.executeWorkflow(workflowId, financialDocumentInputSource, options);
Execution<GeneratedV1> execution = response.getExecution();
Assertions.assertEquals("low", execution.getPriority());
Assertions.assertEquals("java-" + currentDateTime, execution.getFile().getAlias());
}

@Test
public void GivenAWorkflowIdPredictCustomShouldPollAndNotMatchRag() throws IOException, InterruptedException {

Expand Down
Loading
Loading