41
41
public final class MindeeHttpApi extends MindeeApi {
42
42
43
43
private static final ObjectMapper mapper = new ObjectMapper ();
44
- private final Function <Endpoint , String > buildBaseUrl = this ::buildProductUrl ;
45
- private final Function <String , String > buildWorkflowBaseUrl = this ::buildWorkflowUrl ;
44
+ private final Function <Endpoint , String > buildProductPredictUrl = this ::buildProductPredictUrl ;
45
+ private final Function <String , String > buildWorkflowPredictUrl = this ::buildWorkflowPredictUrl ;
46
+ private final Function <String , String > buildWorkflowBaseUrl = this ::buildWorkflowExecutionUrl ;
46
47
/**
47
48
* The MindeeSetting needed to make the api call.
48
49
*/
@@ -53,24 +54,27 @@ public final class MindeeHttpApi extends MindeeApi {
53
54
*/
54
55
private final HttpClientBuilder httpClientBuilder ;
55
56
/**
56
- * The function used to generate the API endpoint URL.
57
+ * The function used to generate the synchronous API endpoint URL.
57
58
* Only needs to be set if the api calls need to be directed through internal URLs.
58
59
*/
59
60
private final Function <Endpoint , String > urlFromEndpoint ;
60
-
61
61
/**
62
- * The function used to generate the API endpoint URL for workflow execution calls .
62
+ * The function used to generate the asynchronous API endpoint URL.
63
63
* Only needs to be set if the api calls need to be directed through internal URLs.
64
64
*/
65
65
private final Function <Endpoint , String > asyncUrlFromEndpoint ;
66
+ /**
67
+ * The function used to generate the asynchronous API endpoint URL.
68
+ * Only needs to be set if the api calls need to be directed through internal URLs.
69
+ */
70
+ private final Function <String , String > asyncUrlFromWorkflow ;
66
71
/**
67
72
* The function used to generate the Job status URL for Async calls.
68
73
* Only needs to be set if the api calls need to be directed through internal URLs.
69
74
*/
70
75
private final Function <Endpoint , String > documentUrlFromEndpoint ;
71
-
72
76
/**
73
- * The function used to generate the Job status URL for Async calls.
77
+ * The function used to generate the Job status URL for workflow execution calls.
74
78
* Only needs to be set if the api calls need to be directed through internal URLs.
75
79
*/
76
80
private final Function <String , String > workflowUrlFromId ;
@@ -82,6 +86,7 @@ public MindeeHttpApi(MindeeSettings mindeeSettings) {
82
86
null ,
83
87
null ,
84
88
null ,
89
+ null ,
85
90
null
86
91
);
87
92
}
@@ -93,7 +98,8 @@ private MindeeHttpApi(
93
98
Function <Endpoint , String > urlFromEndpoint ,
94
99
Function <Endpoint , String > asyncUrlFromEndpoint ,
95
100
Function <Endpoint , String > documentUrlFromEndpoint ,
96
- Function <String , String > workflowUrlFromEndpoint
101
+ Function <String , String > workflowUrlFromEndpoint ,
102
+ Function <String , String > asyncUrlFromWorkflow
97
103
) {
98
104
this .mindeeSettings = mindeeSettings ;
99
105
@@ -106,19 +112,28 @@ private MindeeHttpApi(
106
112
if (urlFromEndpoint != null ) {
107
113
this .urlFromEndpoint = urlFromEndpoint ;
108
114
} else {
109
- this .urlFromEndpoint = buildBaseUrl .andThen ((url ) -> url .concat ("/predict" ));
115
+ this .urlFromEndpoint = buildProductPredictUrl .andThen (
116
+ (url ) -> url .concat ("/predict" ));
117
+ }
118
+
119
+ if (asyncUrlFromWorkflow != null ) {
120
+ this .asyncUrlFromWorkflow = asyncUrlFromWorkflow ;
121
+ } else {
122
+ this .asyncUrlFromWorkflow = this .buildWorkflowPredictUrl .andThen (
123
+ (url ) -> url .concat ("/predict_async" ));
110
124
}
111
125
112
126
if (asyncUrlFromEndpoint != null ) {
113
127
this .asyncUrlFromEndpoint = asyncUrlFromEndpoint ;
114
128
} else {
115
- this .asyncUrlFromEndpoint = this .urlFromEndpoint .andThen ((url ) -> url .concat ("_async" ));
129
+ this .asyncUrlFromEndpoint = this .buildProductPredictUrl .andThen (
130
+ (url ) -> url .concat ("/predict_async" ));
116
131
}
117
132
118
133
if (documentUrlFromEndpoint != null ) {
119
134
this .documentUrlFromEndpoint = documentUrlFromEndpoint ;
120
135
} else {
121
- this .documentUrlFromEndpoint = this .buildBaseUrl .andThen (
136
+ this .documentUrlFromEndpoint = this .buildProductPredictUrl .andThen (
122
137
(url ) -> url .concat ("/documents/queue/" ));
123
138
}
124
139
@@ -340,7 +355,7 @@ private <ResponseT extends ApiResponse> MindeeHttpException getHttpError(
340
355
return new MindeeHttpException (statusCode , message , details , errorCode );
341
356
}
342
357
343
- private String buildProductUrl (Endpoint endpoint ) {
358
+ private String buildProductPredictUrl (Endpoint endpoint ) {
344
359
return this .mindeeSettings .getBaseUrl ()
345
360
+ "/products/"
346
361
+ endpoint .getAccountName ()
@@ -350,7 +365,11 @@ private String buildProductUrl(Endpoint endpoint) {
350
365
+ endpoint .getVersion ();
351
366
}
352
367
353
- private String buildWorkflowUrl (String workflowId ) {
368
+ private String buildWorkflowPredictUrl (String workflowId ) {
369
+ return this .mindeeSettings .getBaseUrl () + "/workflows/" + workflowId ;
370
+ }
371
+
372
+ private String buildWorkflowExecutionUrl (String workflowId ) {
354
373
return this .mindeeSettings .getBaseUrl () + "/workflows/" + workflowId + "/executions" ;
355
374
}
356
375
0 commit comments