diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md index f5b4e9ff48ade..34564c309ed53 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md +++ b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md @@ -1,6 +1,7 @@ # Release History ## 1.0.0-beta.5 (Unreleased) +- Added support for context passing. ### Key Bug Fixes - Fixed `getFields()` to preserve service side ordering of fields. diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClient.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClient.java index 6e9dc5a0a9629..78539d2df27e0 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClient.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClient.java @@ -22,6 +22,7 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpPipeline; import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; import com.azure.core.util.polling.LongRunningOperationStatus; @@ -118,14 +119,21 @@ public final class FormRecognizerAsyncClient { @ServiceMethod(returns = ReturnType.COLLECTION) public PollerFlux> beginRecognizeCustomFormsFromUrl(String formUrl, String modelId, RecognizeOptions recognizeOptions) { + return beginRecognizeCustomFormsFromUrl(formUrl, modelId, recognizeOptions, Context.NONE); + } + + PollerFlux> + beginRecognizeCustomFormsFromUrl(String formUrl, String modelId, RecognizeOptions recognizeOptions, + Context context) { try { recognizeOptions = getRecognizeOptionsProperties(recognizeOptions); return new PollerFlux>( recognizeOptions.getPollInterval(), - analyzeFormActivationOperation(formUrl, modelId, recognizeOptions.isIncludeFieldElements()), - createAnalyzeFormPollOperation(modelId), - (activationResponse, context) -> Mono.error(new RuntimeException("Cancellation is not supported")), - fetchAnalyzeFormResultOperation(modelId, recognizeOptions.isIncludeFieldElements())); + analyzeFormActivationOperation(formUrl, modelId, recognizeOptions.isIncludeFieldElements(), context), + createAnalyzeFormPollOperation(modelId, context), + (activationResponse, pollingContext) -> + Mono.error(new RuntimeException("Cancellation is not supported")), + fetchAnalyzeFormResultOperation(modelId, recognizeOptions.isIncludeFieldElements(), context)); } catch (RuntimeException ex) { return PollerFlux.error(ex); } @@ -181,22 +189,29 @@ public final class FormRecognizerAsyncClient { * or has been cancelled. The completed operation returns a List of {@link RecognizedForm}. * @throws FormRecognizerException If recognize operation fails and the {@link AnalyzeOperationResult} returned with * an {@link OperationStatus#FAILED}. - * @throws NullPointerException If {@code recognizeOptions} is {@code null}. + * @throws NullPointerException If {@code form}, {@code modelId} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PollerFlux> beginRecognizeCustomForms(Flux form, long length, String modelId, RecognizeOptions recognizeOptions) { + return beginRecognizeCustomForms(form, length, modelId, recognizeOptions, Context.NONE); + } + + PollerFlux> + beginRecognizeCustomForms(Flux form, long length, String modelId, + RecognizeOptions recognizeOptions, Context context) { try { recognizeOptions = getRecognizeOptionsProperties(recognizeOptions); return new PollerFlux>( recognizeOptions.getPollInterval(), analyzeFormStreamActivationOperation(form, modelId, length, recognizeOptions.getContentType(), - recognizeOptions.isIncludeFieldElements()), - createAnalyzeFormPollOperation(modelId), - (activationResponse, context) -> Mono.error(new RuntimeException("Cancellation is not supported")), - fetchAnalyzeFormResultOperation(modelId, recognizeOptions.isIncludeFieldElements())); + recognizeOptions.isIncludeFieldElements(), context), + createAnalyzeFormPollOperation(modelId, context), + (activationResponse, pollingContext) -> + Mono.error(new RuntimeException("Cancellation is not supported")), + fetchAnalyzeFormResultOperation(modelId, recognizeOptions.isIncludeFieldElements(), context)); } catch (RuntimeException ex) { return PollerFlux.error(ex); } @@ -245,15 +260,20 @@ public PollerFlux> beginRecognizeContentFromUrl( @ServiceMethod(returns = ReturnType.COLLECTION) public PollerFlux> beginRecognizeContentFromUrl(String formUrl, RecognizeOptions recognizeOptions) { + return beginRecognizeContentFromUrl(formUrl, recognizeOptions, Context.NONE); + } + + PollerFlux> + beginRecognizeContentFromUrl(String formUrl, RecognizeOptions recognizeOptions, Context context) { try { recognizeOptions = getRecognizeOptionsProperties(recognizeOptions); return new PollerFlux>( recognizeOptions.getPollInterval(), - contentAnalyzeActivationOperation(formUrl), - extractContentPollOperation(), - (activationResponse, context) -> + contentAnalyzeActivationOperation(formUrl, context), + extractContentPollOperation(context), + (activationResponse, pollingContext) -> monoError(logger, new RuntimeException("Cancellation is not supported")), - fetchExtractContentResult()); + fetchExtractContentResult(context)); } catch (RuntimeException ex) { return PollerFlux.error(ex); } @@ -305,20 +325,25 @@ public PollerFlux> beginRecognizeContent( * been cancelled. The completed operation returns a List of {@link FormPage}. * @throws FormRecognizerException If recognize operation fails and the {@link AnalyzeOperationResult} returned with * an {@link OperationStatus#FAILED}. - * @throws NullPointerException If {@code recognizeOptions} is {@code null}. + * @throws NullPointerException If {@code form} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PollerFlux> beginRecognizeContent(Flux form, long length, RecognizeOptions recognizeOptions) { + return beginRecognizeContent(form, length, recognizeOptions, Context.NONE); + } + + PollerFlux> beginRecognizeContent(Flux form, long length, + RecognizeOptions recognizeOptions, Context context) { try { recognizeOptions = getRecognizeOptionsProperties(recognizeOptions); return new PollerFlux<>( recognizeOptions.getPollInterval(), - contentStreamActivationOperation(form, length, recognizeOptions.getContentType()), - extractContentPollOperation(), - (activationResponse, context) -> + contentStreamActivationOperation(form, length, recognizeOptions.getContentType(), context), + extractContentPollOperation(context), + (activationResponse, pollingContext) -> monoError(logger, new RuntimeException("Cancellation is not supported")), - fetchExtractContentResult()); + fetchExtractContentResult(context)); } catch (RuntimeException ex) { return PollerFlux.error(ex); } @@ -370,15 +395,20 @@ public PollerFlux> beginRecognizeContent(Flux> beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeOptions recognizeOptions) { + return beginRecognizeReceiptsFromUrl(receiptUrl, recognizeOptions, Context.NONE); + } + + PollerFlux> + beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeOptions recognizeOptions, Context context) { try { recognizeOptions = getRecognizeOptionsProperties(recognizeOptions); return new PollerFlux>( recognizeOptions.getPollInterval(), - receiptAnalyzeActivationOperation(receiptUrl, recognizeOptions.isIncludeFieldElements()), - extractReceiptPollOperation(), - (activationResponse, context) -> monoError(logger, + receiptAnalyzeActivationOperation(receiptUrl, recognizeOptions.isIncludeFieldElements(), context), + extractReceiptPollOperation(context), + (activationResponse, pollingContext) -> monoError(logger, new RuntimeException("Cancellation is not supported")), - fetchExtractReceiptResult(recognizeOptions.isIncludeFieldElements())); + fetchExtractReceiptResult(recognizeOptions.isIncludeFieldElements(), context)); } catch (RuntimeException ex) { return PollerFlux.error(ex); } @@ -434,33 +464,39 @@ public PollerFlux> beginRecognizeReceipts( * or has been cancelled. The completed operation returns a List of {@link RecognizedForm}. * @throws FormRecognizerException If recognize operation fails and the {@link AnalyzeOperationResult} returned with * an {@link OperationStatus#FAILED}. - * @throws NullPointerException If {@code recognizeOptions} is {@code null}. + * @throws NullPointerException If {@code receipt} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PollerFlux> beginRecognizeReceipts(Flux receipt, long length, RecognizeOptions recognizeOptions) { + return beginRecognizeReceipts(receipt, length, recognizeOptions, Context.NONE); + } + + PollerFlux> + beginRecognizeReceipts(Flux receipt, long length, RecognizeOptions recognizeOptions, + Context context) { try { recognizeOptions = getRecognizeOptionsProperties(recognizeOptions); return new PollerFlux<>( recognizeOptions.getPollInterval(), receiptStreamActivationOperation(receipt, length, - recognizeOptions.getContentType(), recognizeOptions.isIncludeFieldElements()), - extractReceiptPollOperation(), - (activationResponse, context) -> monoError(logger, + recognizeOptions.getContentType(), recognizeOptions.isIncludeFieldElements(), context), + extractReceiptPollOperation(context), + (activationResponse, pollingContext) -> monoError(logger, new RuntimeException("Cancellation is not supported")), - fetchExtractReceiptResult(recognizeOptions.isIncludeFieldElements())); + fetchExtractReceiptResult(recognizeOptions.isIncludeFieldElements(), context)); } catch (RuntimeException ex) { return PollerFlux.error(ex); } } private Function, Mono> receiptAnalyzeActivationOperation( - String receiptUrl, boolean includeFieldElements) { + String receiptUrl, boolean includeFieldElements, Context context) { return (pollingContext) -> { try { Objects.requireNonNull(receiptUrl, "'receiptUrl' is required and cannot be null."); return service.analyzeReceiptAsyncWithResponseAsync(includeFieldElements, - new SourcePath().setSource(receiptUrl)) + new SourcePath().setSource(receiptUrl), context) .map(response -> new OperationResult(parseModelId(response.getDeserializedHeaders().getOperationLocation()))) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); @@ -471,13 +507,14 @@ private Function, Mono> receipt } private Function, Mono> receiptStreamActivationOperation( - Flux form, long length, FormContentType contentType, boolean includeFieldElements) { + Flux form, long length, FormContentType contentType, boolean includeFieldElements, + Context context) { return pollingContext -> { try { Objects.requireNonNull(form, "'form' is required and cannot be null."); if (contentType != null) { return service.analyzeReceiptAsyncWithResponseAsync( - ContentType.fromString(contentType.toString()), form, length, includeFieldElements) + ContentType.fromString(contentType.toString()), form, length, includeFieldElements, context) .map(response -> new OperationResult( parseModelId(response.getDeserializedHeaders().getOperationLocation()))) .onErrorMap(throwable -> throwable); @@ -485,7 +522,7 @@ private Function, Mono> receipt return detectContentType(form) .flatMap(detectedContentType -> service.analyzeReceiptAsyncWithResponseAsync(detectedContentType, form, length, - includeFieldElements) + includeFieldElements, context) .map(response -> new OperationResult( parseModelId(response.getDeserializedHeaders().getOperationLocation())))) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); @@ -497,12 +534,12 @@ private Function, Mono> receipt } private Function, Mono>> - extractReceiptPollOperation() { + extractReceiptPollOperation(Context context) { return (pollingContext) -> { try { PollResponse operationResultPollResponse = pollingContext.getLatestResponse(); UUID resultUid = UUID.fromString(operationResultPollResponse.getValue().getResultId()); - return service.getAnalyzeReceiptResultWithResponseAsync(resultUid) + return service.getAnalyzeReceiptResultWithResponseAsync(resultUid, context) .flatMap(modelSimpleResponse -> processAnalyzeModelResponse(modelSimpleResponse, operationResultPollResponse)); } catch (HttpResponseException e) { @@ -513,11 +550,11 @@ private Function, Mono> receipt } private Function, Mono>> - fetchExtractReceiptResult(boolean includeFieldElements) { + fetchExtractReceiptResult(boolean includeFieldElements, Context context) { return (pollingContext) -> { try { final UUID resultUid = UUID.fromString(pollingContext.getLatestResponse().getValue().getResultId()); - return service.getAnalyzeReceiptResultWithResponseAsync(resultUid) + return service.getAnalyzeReceiptResultWithResponseAsync(resultUid, context) .map(modelSimpleResponse -> { throwIfAnalyzeStatusInvalid(modelSimpleResponse.getValue()); return toRecognizedForm(modelSimpleResponse.getValue().getAnalyzeResult(), @@ -531,11 +568,11 @@ private Function, Mono> receipt } private Function, Mono> contentAnalyzeActivationOperation( - String formUrl) { + String formUrl, Context context) { return (pollingContext) -> { try { Objects.requireNonNull(formUrl, "'formUrl' is required and cannot be null."); - return service.analyzeLayoutAsyncWithResponseAsync(new SourcePath().setSource(formUrl)) + return service.analyzeLayoutAsyncWithResponseAsync(new SourcePath().setSource(formUrl), context) .map(response -> new OperationResult(parseModelId(response.getDeserializedHeaders().getOperationLocation()))) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); @@ -546,20 +583,20 @@ private Function, Mono> content } private Function, Mono> contentStreamActivationOperation( - Flux form, long length, FormContentType contentType) { + Flux form, long length, FormContentType contentType, Context context) { return pollingContext -> { try { Objects.requireNonNull(form, "'form' is required and cannot be null."); if (contentType != null) { return service.analyzeLayoutAsyncWithResponseAsync( - ContentType.fromString(contentType.toString()), form, length) + ContentType.fromString(contentType.toString()), form, length, context) .map(response -> new OperationResult(parseModelId( response.getDeserializedHeaders().getOperationLocation()))) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); } else { return detectContentType(form) .flatMap(detectedContentType -> - service.analyzeLayoutAsyncWithResponseAsync(detectedContentType, form, length) + service.analyzeLayoutAsyncWithResponseAsync(detectedContentType, form, length, context) .map(response -> new OperationResult( parseModelId(response.getDeserializedHeaders().getOperationLocation())))) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); @@ -571,12 +608,12 @@ private Function, Mono> content } private Function, Mono>> - extractContentPollOperation() { + extractContentPollOperation(Context context) { return (pollingContext) -> { try { PollResponse operationResultPollResponse = pollingContext.getLatestResponse(); UUID resultUid = UUID.fromString(operationResultPollResponse.getValue().getResultId()); - return service.getAnalyzeLayoutResultWithResponseAsync(resultUid) + return service.getAnalyzeLayoutResultWithResponseAsync(resultUid, context) .flatMap(modelSimpleResponse -> processAnalyzeModelResponse(modelSimpleResponse, operationResultPollResponse)); } catch (HttpResponseException e) { @@ -587,11 +624,11 @@ private Function, Mono> content } private Function, Mono>> - fetchExtractContentResult() { + fetchExtractContentResult(Context context) { return (pollingContext) -> { try { final UUID resultUid = UUID.fromString(pollingContext.getLatestResponse().getValue().getResultId()); - return service.getAnalyzeLayoutResultWithResponseAsync(resultUid) + return service.getAnalyzeLayoutResultWithResponseAsync(resultUid, context) .map(modelSimpleResponse -> { throwIfAnalyzeStatusInvalid(modelSimpleResponse.getValue()); return toRecognizedLayout(modelSimpleResponse.getValue().getAnalyzeResult(), true); @@ -604,13 +641,13 @@ private Function, Mono> content } private Function, Mono>> - fetchAnalyzeFormResultOperation(String modelId, boolean includeFieldElements) { + fetchAnalyzeFormResultOperation(String modelId, boolean includeFieldElements, Context context) { return (pollingContext) -> { try { Objects.requireNonNull(modelId, "'modelId' is required and cannot be null."); UUID resultUid = UUID.fromString(pollingContext.getLatestResponse().getValue().getResultId()); UUID modelUid = UUID.fromString(modelId); - return service.getAnalyzeFormResultWithResponseAsync(modelUid, resultUid) + return service.getAnalyzeFormResultWithResponseAsync(modelUid, resultUid, context) .map(modelSimpleResponse -> { throwIfAnalyzeStatusInvalid(modelSimpleResponse.getValue()); return toRecognizedForm(modelSimpleResponse.getValue().getAnalyzeResult(), @@ -640,14 +677,14 @@ private void throwIfAnalyzeStatusInvalid(AnalyzeOperationResult analyzeResponse) } private Function, Mono>> - createAnalyzeFormPollOperation(String modelId) { + createAnalyzeFormPollOperation(String modelId, Context context) { return (pollingContext) -> { try { PollResponse operationResultPollResponse = pollingContext.getLatestResponse(); Objects.requireNonNull(modelId, "'modelId' is required and cannot be null."); UUID resultUid = UUID.fromString(operationResultPollResponse.getValue().getResultId()); UUID modelUid = UUID.fromString(modelId); - return service.getAnalyzeFormResultWithResponseAsync(modelUid, resultUid) + return service.getAnalyzeFormResultWithResponseAsync(modelUid, resultUid, context) .flatMap(modelSimpleResponse -> processAnalyzeModelResponse(modelSimpleResponse, operationResultPollResponse)) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); @@ -659,13 +696,13 @@ private void throwIfAnalyzeStatusInvalid(AnalyzeOperationResult analyzeResponse) } private Function, Mono> analyzeFormActivationOperation( - String formUrl, String modelId, boolean includeFieldElements) { + String formUrl, String modelId, boolean includeFieldElements, Context context) { return (pollingContext) -> { try { Objects.requireNonNull(formUrl, "'formUrl' is required and cannot be null."); Objects.requireNonNull(modelId, "'modelId' is required and cannot be null."); return service.analyzeWithCustomModelWithResponseAsync(UUID.fromString(modelId), includeFieldElements, - new SourcePath().setSource(formUrl)) + new SourcePath().setSource(formUrl), context) .map(response -> new OperationResult(parseModelId(response.getDeserializedHeaders().getOperationLocation()))) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); @@ -677,7 +714,7 @@ private Function, Mono> analyze private Function, Mono> analyzeFormStreamActivationOperation( Flux form, String modelId, long length, FormContentType contentType, - boolean includeFieldElements) { + boolean includeFieldElements, Context context) { return pollingContext -> { try { @@ -685,7 +722,7 @@ private Function, Mono> analyze Objects.requireNonNull(modelId, "'modelId' is required and cannot be null."); if (contentType != null) { return service.analyzeWithCustomModelWithResponseAsync(UUID.fromString(modelId), - ContentType.fromString(contentType.toString()), form, length, includeFieldElements) + ContentType.fromString(contentType.toString()), form, length, includeFieldElements, context) .map(response -> new OperationResult(parseModelId( response.getDeserializedHeaders().getOperationLocation()))) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); @@ -693,7 +730,7 @@ private Function, Mono> analyze return detectContentType(form) .flatMap(detectedContentType -> service.analyzeWithCustomModelWithResponseAsync(UUID.fromString(modelId), - detectedContentType, form, length, includeFieldElements) + detectedContentType, form, length, includeFieldElements, context) .map(response -> new OperationResult( parseModelId(response.getDeserializedHeaders().getOperationLocation())))) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerClient.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerClient.java index be8c2332fc80e..e0b905fe39d6a 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerClient.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerClient.java @@ -14,6 +14,7 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; +import com.azure.core.util.Context; import com.azure.core.util.polling.SyncPoller; import reactor.core.publisher.Flux; @@ -66,7 +67,7 @@ public final class FormRecognizerClient { @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> beginRecognizeCustomFormsFromUrl(String formUrl, String modelId) { - return beginRecognizeCustomFormsFromUrl(formUrl, modelId, null); + return beginRecognizeCustomFormsFromUrl(formUrl, modelId, null, Context.NONE); } /** @@ -76,12 +77,13 @@ public final class FormRecognizerClient { * error message indicating absence of cancellation support

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomFormsFromUrl#string-string-recognizeOptions} + * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomFormsFromUrl#string-string-recognizeOptions-Context} * * @param formUrl The source URL to the input form. * @param modelId The UUID string format custom trained model Id to be used. * @param recognizeOptions The additional configurable {@link RecognizeOptions options} that may be passed when * recognizing custom form. + * @param context Additional context that is passed through the HTTP pipeline during the service call. * * @return A {@link SyncPoller} to poll the progress of the recognize custom form operation until it has completed, * has failed, or has been cancelled. The completed operation returns a List of {@link RecognizedForm}. @@ -91,8 +93,9 @@ public final class FormRecognizerClient { */ @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> - beginRecognizeCustomFormsFromUrl(String formUrl, String modelId, RecognizeOptions recognizeOptions) { - return client.beginRecognizeCustomFormsFromUrl(formUrl, modelId, recognizeOptions).getSyncPoller(); + beginRecognizeCustomFormsFromUrl(String formUrl, String modelId, RecognizeOptions recognizeOptions, + Context context) { + return client.beginRecognizeCustomFormsFromUrl(formUrl, modelId, recognizeOptions, context).getSyncPoller(); } /** @@ -117,7 +120,7 @@ public final class FormRecognizerClient { @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> beginRecognizeCustomForms(InputStream form, long length, String modelId) { - return beginRecognizeCustomForms(form, length, modelId, null); + return beginRecognizeCustomForms(form, length, modelId, null, Context.NONE); } /** @@ -127,25 +130,27 @@ public final class FormRecognizerClient { * error message indicating absence of cancellation support.

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomForms#InputStream-long-string-recognizeOptions} + * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomForms#InputStream-long-string-recognizeOptions-Context} * * @param form The data of the form to recognize form information from. * @param length The exact length of the data. * @param modelId The UUID string format custom trained model Id to be used. * @param recognizeOptions The additional configurable {@link RecognizeOptions options} that may be passed when * recognizing custom form. + * @param context Additional context that is passed through the HTTP pipeline during the service call. * * @return A {@link SyncPoller} that polls the recognize custom form operation until it has completed, * has failed, or has been cancelled. The completed operation returns a List of {@link RecognizedForm}. * @throws FormRecognizerException If recognize operation fails and the {@link AnalyzeOperationResult} returned with * an {@link OperationStatus#FAILED}. - * @throws NullPointerException If {@code recognizeOptions} is {@code null}. + * @throws NullPointerException If {@code form}, {@code modelId} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> - beginRecognizeCustomForms(InputStream form, long length, String modelId, RecognizeOptions recognizeOptions) { + beginRecognizeCustomForms(InputStream form, long length, String modelId, RecognizeOptions recognizeOptions, + Context context) { Flux buffer = Utility.toFluxByteBuffer(form); - return client.beginRecognizeCustomForms(buffer, length, modelId, recognizeOptions).getSyncPoller(); + return client.beginRecognizeCustomForms(buffer, length, modelId, recognizeOptions, context).getSyncPoller(); } /** @@ -166,7 +171,7 @@ public final class FormRecognizerClient { */ @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> beginRecognizeContentFromUrl(String formUrl) { - return beginRecognizeContentFromUrl(formUrl, null); + return beginRecognizeContentFromUrl(formUrl, null, Context.NONE); } /** @@ -175,11 +180,12 @@ public SyncPoller> beginRecognizeContentFromUrl( * error message indicating absence of cancellation support.

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContentFromUrl#string-recognizeOptions} + * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContentFromUrl#string-recognizeOptions-Context} * * @param formUrl The source URL to the input form. * @param recognizeOptions The additional configurable {@link RecognizeOptions options} that may be passed when * recognizing content/layout on a form. + * @param context Additional context that is passed through the HTTP pipeline during the service call. * * @return A {@link SyncPoller} that polls the recognize layout operation until it has completed, has * failed, or has been cancelled. The completed operation returns a List of {@link FormPage}. @@ -189,8 +195,8 @@ public SyncPoller> beginRecognizeContentFromUrl( */ @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> - beginRecognizeContentFromUrl(String formUrl, RecognizeOptions recognizeOptions) { - return client.beginRecognizeContentFromUrl(formUrl, recognizeOptions).getSyncPoller(); + beginRecognizeContentFromUrl(String formUrl, RecognizeOptions recognizeOptions, Context context) { + return client.beginRecognizeContentFromUrl(formUrl, recognizeOptions, context).getSyncPoller(); } /** @@ -213,7 +219,7 @@ public SyncPoller> beginRecognizeContentFromUrl( @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> beginRecognizeContent(InputStream form, long length) { - return beginRecognizeContent(form, length, null); + return beginRecognizeContent(form, length, null, Context.NONE); } /** @@ -222,25 +228,26 @@ public SyncPoller> beginRecognizeContentFromUrl( * error message indicating absence of cancellation support

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContent#InputStream-long-recognizeOptions} + * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContent#InputStream-long-recognizeOptions-Context} * * @param form The data of the form to recognize content information from. * @param length The exact length of the data. * @param recognizeOptions The additional configurable {@link RecognizeOptions options} that may be passed when * analyzing a receipt. The configurable {@code RecognizeOptions options} that may be passed when recognizing * content on a form. + * @param context Additional context that is passed through the HTTP pipeline during the service call. * * @return A {@link SyncPoller} that polls the recognize content operation until it has completed, * has failed, or has been cancelled. The completed operation returns a List of {@link FormPage}. * @throws FormRecognizerException If recognize operation fails and the {@link AnalyzeOperationResult} returned with * an {@link OperationStatus#FAILED}. - * @throws NullPointerException If {@code recognizeOptions} is {@code null}. + * @throws NullPointerException If {@code form} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> beginRecognizeContent(InputStream form, long length, - RecognizeOptions recognizeOptions) { + RecognizeOptions recognizeOptions, Context context) { Flux buffer = Utility.toFluxByteBuffer(form); - return client.beginRecognizeContent(buffer, length, recognizeOptions).getSyncPoller(); + return client.beginRecognizeContent(buffer, length, recognizeOptions, context).getSyncPoller(); } /** @@ -263,7 +270,7 @@ public SyncPoller> beginRecognizeContent(InputSt */ @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> beginRecognizeReceiptsFromUrl(String receiptUrl) { - return beginRecognizeReceiptsFromUrl(receiptUrl, null); + return beginRecognizeReceiptsFromUrl(receiptUrl, null, Context.NONE); } /** @@ -273,11 +280,12 @@ public SyncPoller> beginRecognizeReceiptsF * error message indicating absence of cancellation support

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceiptsFromUrl#string-recognizeOptions} + * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceiptsFromUrl#string-recognizeOptions-Context} * * @param receiptUrl The source URL to the input receipt. * @param recognizeOptions The additional configurable {@link RecognizeOptions options} that may be passed when * analyzing a receipt. Include text lines and element references in the result. + * @param context Additional context that is passed through the HTTP pipeline during the service call. * * @return A {@link SyncPoller} to poll the progress of the recognize receipt operation until it has completed, * has failed, or has been cancelled. The completed operation returns a List of {@link RecognizedForm}. @@ -287,8 +295,8 @@ public SyncPoller> beginRecognizeReceiptsF */ @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> - beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeOptions recognizeOptions) { - return client.beginRecognizeReceiptsFromUrl(receiptUrl, recognizeOptions).getSyncPoller(); + beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeOptions recognizeOptions, Context context) { + return client.beginRecognizeReceiptsFromUrl(receiptUrl, recognizeOptions, context).getSyncPoller(); } /** @@ -313,7 +321,7 @@ public SyncPoller> beginRecognizeReceiptsF @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> beginRecognizeReceipts(InputStream receipt, long length) { - return beginRecognizeReceipts(receipt, length, null); + return beginRecognizeReceipts(receipt, length, null, Context.NONE); } /** @@ -324,23 +332,24 @@ public SyncPoller> beginRecognizeReceiptsF * See here for fields found on a receipt. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceipts#InputStream-long-recognizeOptions} + * {@codesnippet com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceipts#InputStream-long-recognizeOptions-Context} * * @param receipt The data of the receipt to recognize receipt information from. * @param length The exact length of the data. * @param recognizeOptions The additional configurable {@link RecognizeOptions options} that may be passed when * analyzing a receipt. + * @param context Additional context that is passed through the HTTP pipeline during the service call. * * @return A {@link SyncPoller} that polls the recognize receipt operation until it has completed, has failed, * or has been cancelled. The completed operation returns a List of {@link RecognizedForm}. * @throws FormRecognizerException If recognize operation fails and the {@link AnalyzeOperationResult} returned with * an {@link OperationStatus#FAILED}. - * @throws NullPointerException If {@code recognizeOptions} is {@code null}. + * @throws NullPointerException If {@code receipt} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) public SyncPoller> - beginRecognizeReceipts(InputStream receipt, long length, RecognizeOptions recognizeOptions) { + beginRecognizeReceipts(InputStream receipt, long length, RecognizeOptions recognizeOptions, Context context) { Flux buffer = Utility.toFluxByteBuffer(receipt); - return client.beginRecognizeReceipts(buffer, length, recognizeOptions).getSyncPoller(); + return client.beginRecognizeReceipts(buffer, length, recognizeOptions, context).getSyncPoller(); } } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingAsyncClient.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingAsyncClient.java index 11198cc9b78fc..1526894a70a9d 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingAsyncClient.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingAsyncClient.java @@ -174,16 +174,21 @@ public PollerFlux beginTraining(String trainin @ServiceMethod(returns = ReturnType.SINGLE) public PollerFlux beginTraining(String trainingFilesUrl, boolean useTrainingLabels, TrainingFileFilter trainingFileFilter, Duration pollInterval) { + return beginTraining(trainingFilesUrl, useTrainingLabels, trainingFileFilter, pollInterval, Context.NONE); + } + + PollerFlux beginTraining(String trainingFilesUrl, + boolean useTrainingLabels, TrainingFileFilter trainingFileFilter, Duration pollInterval, Context context) { final Duration interval = pollInterval != null ? pollInterval : DEFAULT_DURATION; return new PollerFlux( interval, getTrainingActivationOperation(trainingFilesUrl, trainingFileFilter != null ? trainingFileFilter.isIncludeSubFolders() : false, trainingFileFilter != null ? trainingFileFilter.getPrefix() : null, - useTrainingLabels), - createTrainingPollOperation(), - (activationResponse, context) -> Mono.error(new RuntimeException("Cancellation is not supported")), - fetchTrainingModelResultOperation()); + useTrainingLabels, context), + createTrainingPollOperation(context), + (activationResponse, pollingContext) -> Mono.error(new RuntimeException("Cancellation is not supported")), + fetchTrainingModelResultOperation(context)); } /** @@ -405,13 +410,18 @@ public PollerFlux beginCopyModel(String mo @ServiceMethod(returns = ReturnType.SINGLE) public PollerFlux beginCopyModel(String modelId, CopyAuthorization target, Duration pollInterval) { + return beginCopyModel(modelId, target, pollInterval, Context.NONE); + } + + PollerFlux beginCopyModel(String modelId, + CopyAuthorization target, Duration pollInterval, Context context) { final Duration interval = pollInterval != null ? pollInterval : DEFAULT_DURATION; return new PollerFlux( interval, - getCopyActivationOperation(modelId, target), - createCopyPollOperation(modelId), - (activationResponse, context) -> Mono.error(new RuntimeException("Cancellation is not supported")), - fetchCopyModelResultOperation(modelId, target.getModelId())); + getCopyActivationOperation(modelId, target, context), + createCopyPollOperation(modelId, context), + (activationResponse, pollingContext) -> Mono.error(new RuntimeException("Cancellation is not supported")), + fetchCopyModelResultOperation(modelId, target.getModelId(), context)); } /** @@ -507,12 +517,12 @@ private Mono> listNextPageModelInfo(String ne } private Function, Mono> fetchCopyModelResultOperation( - String modelId, String copyModelId) { + String modelId, String copyModelId, Context context) { return (pollingContext) -> { try { final UUID resultUid = UUID.fromString(pollingContext.getLatestResponse().getValue().getResultId()); Objects.requireNonNull(modelId, "'modelId' cannot be null."); - return service.getCustomModelCopyResultWithResponseAsync(UUID.fromString(modelId), resultUid) + return service.getCustomModelCopyResultWithResponseAsync(UUID.fromString(modelId), resultUid, context) .map(modelSimpleResponse -> { CopyOperationResult copyOperationResult = modelSimpleResponse.getValue(); throwIfCopyOperationStatusInvalid(copyOperationResult); @@ -531,12 +541,12 @@ private Function, Mono> fet } private Function, Mono>> - createCopyPollOperation(String modelId) { + createCopyPollOperation(String modelId, Context context) { return (pollingContext) -> { try { PollResponse operationResultPollResponse = pollingContext.getLatestResponse(); UUID targetId = UUID.fromString(operationResultPollResponse.getValue().getResultId()); - return service.getCustomModelCopyResultWithResponseAsync(UUID.fromString(modelId), targetId) + return service.getCustomModelCopyResultWithResponseAsync(UUID.fromString(modelId), targetId, context) .flatMap(modelSimpleResponse -> processCopyModelResponse(modelSimpleResponse, operationResultPollResponse)) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); @@ -547,7 +557,7 @@ private Function, Mono> fet } private Function, Mono> getCopyActivationOperation( - String modelId, CopyAuthorization target) { + String modelId, CopyAuthorization target, Context context) { return (pollingContext) -> { try { Objects.requireNonNull(modelId, "'modelId' cannot be null."); @@ -559,7 +569,7 @@ private Function, Mono> getCopy .setModelId(target.getModelId()) .setAccessToken(target.getAccessToken()) .setExpirationDateTimeTicks(target.getExpiresOn().toEpochSecond())); - return service.copyCustomModelWithResponseAsync(UUID.fromString(modelId), copyRequest) + return service.copyCustomModelWithResponseAsync(UUID.fromString(modelId), copyRequest, context) .map(response -> new OperationResult(parseModelId(response.getDeserializedHeaders().getOperationLocation()))) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); @@ -591,11 +601,12 @@ private Mono> processCopyModelResponse( return Mono.just(new PollResponse<>(status, copyModelOperationResponse.getValue())); } - private Function, Mono> fetchTrainingModelResultOperation() { + private Function, Mono> + fetchTrainingModelResultOperation(Context context) { return (pollingContext) -> { try { final UUID modelUid = UUID.fromString(pollingContext.getLatestResponse().getValue().getResultId()); - return service.getCustomModelWithResponseAsync(modelUid, true) + return service.getCustomModelWithResponseAsync(modelUid, true, context) .map(modelSimpleResponse -> { throwIfModelStatusInvalid(modelSimpleResponse.getValue()); return toCustomFormModel(modelSimpleResponse.getValue()); @@ -608,12 +619,12 @@ private Function, Mono> fetchTr } private Function, Mono>> - createTrainingPollOperation() { + createTrainingPollOperation(Context context) { return (pollingContext) -> { try { PollResponse operationResultPollResponse = pollingContext.getLatestResponse(); UUID modelUid = UUID.fromString(operationResultPollResponse.getValue().getResultId()); - return service.getCustomModelWithResponseAsync(modelUid, true) + return service.getCustomModelWithResponseAsync(modelUid, true, context) .flatMap(modelSimpleResponse -> processTrainingModelResponse(modelSimpleResponse, operationResultPollResponse)) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); @@ -625,7 +636,8 @@ private Function, Mono> fetchTr } private Function, Mono> getTrainingActivationOperation( - String trainingFilesUrl, boolean includeSubFolders, String filePrefix, boolean useTrainingLabels) { + String trainingFilesUrl, boolean includeSubFolders, String filePrefix, boolean useTrainingLabels, + Context context) { return (pollingContext) -> { try { Objects.requireNonNull(trainingFilesUrl, "'trainingFilesUrl' cannot be null."); @@ -633,7 +645,7 @@ private Function, Mono> getTrai .setPrefix(filePrefix); TrainRequest serviceTrainRequest = new TrainRequest().setSource(trainingFilesUrl). setSourceFilter(trainSourceFilter).setUseLabelFile(useTrainingLabels); - return service.trainCustomModelAsyncWithResponseAsync(serviceTrainRequest) + return service.trainCustomModelAsyncWithResponseAsync(serviceTrainRequest, context) .map(response -> new OperationResult(parseModelId(response.getDeserializedHeaders().getLocation()))) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingClient.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingClient.java index dcab77ad6e210..3d87066da7764 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingClient.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingClient.java @@ -87,7 +87,7 @@ public FormRecognizerClient getFormRecognizerClient() { @ServiceMethod(returns = ReturnType.SINGLE) public SyncPoller beginTraining(String trainingFilesUrl, boolean useTrainingLabels) { - return beginTraining(trainingFilesUrl, useTrainingLabels, null, null); + return beginTraining(trainingFilesUrl, useTrainingLabels, null, null, Context.NONE); } /** @@ -99,7 +99,7 @@ public SyncPoller beginTraining(String trainin * error message indicating absence of cancellation support.

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean-trainingFileFilter-Duration} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean-trainingFileFilter-Duration-Context} * * @param trainingFilesUrl an externally accessible Azure storage blob container Uri (preferably a * Shared Access Signature Uri). @@ -109,6 +109,7 @@ public SyncPoller beginTraining(String trainin * @param trainingFileFilter Filter to apply to the documents in the source path for training. * @param pollInterval Duration between each poll for the operation status. If none is specified, a default of * 5 seconds is used. + * @param context Additional context that is passed through the HTTP pipeline during the service call. * * @return A {@link SyncPoller} that polls the training model operation until it has completed, has failed, or has * been cancelled. The completed operation returns the trained {@link CustomFormModel custom form model}. @@ -117,8 +118,8 @@ public SyncPoller beginTraining(String trainin */ @ServiceMethod(returns = ReturnType.SINGLE) public SyncPoller beginTraining(String trainingFilesUrl, - boolean useTrainingLabels, TrainingFileFilter trainingFileFilter, Duration pollInterval) { - return client.beginTraining(trainingFilesUrl, useTrainingLabels, trainingFileFilter, pollInterval) + boolean useTrainingLabels, TrainingFileFilter trainingFileFilter, Duration pollInterval, Context context) { + return client.beginTraining(trainingFilesUrl, useTrainingLabels, trainingFileFilter, pollInterval, context) .getSyncPoller(); } @@ -268,7 +269,7 @@ public PagedIterable listCustomModels(Context context) { @ServiceMethod(returns = ReturnType.SINGLE) public SyncPoller beginCopyModel(String modelId, CopyAuthorization target) { - return beginCopyModel(modelId, target, null); + return beginCopyModel(modelId, target, null, Context.NONE); } /** @@ -283,21 +284,22 @@ public SyncPoller beginCopyModel(String mo * error message indicating absence of cancellation support.

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.beginCopyModel#string-copyAuthorization-Duration} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.beginCopyModel#string-copyAuthorization-Duration-Context} * * @param modelId Model identifier of the model to copy to the target Form Recognizer resource * @param target the copy authorization to the target Form Recognizer resource. The copy authorization can be * generated from the target resource's call to {@link FormTrainingClient#getCopyAuthorization(String, String)} * @param pollInterval Duration between each poll for the operation status. If none is specified, a default of * 5 seconds is used. + * @param context Additional context that is passed through the HTTP pipeline during the service call. * * @return A {@link SyncPoller} that polls the copy model operation until it has completed, has failed, * or has been cancelled. */ @ServiceMethod(returns = ReturnType.SINGLE) public SyncPoller beginCopyModel(String modelId, - CopyAuthorization target, Duration pollInterval) { - return client.beginCopyModel(modelId, target, pollInterval).getSyncPoller(); + CopyAuthorization target, Duration pollInterval, Context context) { + return client.beginCopyModel(modelId, target, pollInterval, context).getSyncPoller(); } /** diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/AdvancedDiffLabeledUnlabeledData.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/AdvancedDiffLabeledUnlabeledData.java index 972394c3a2884..cd98e6575756d 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/AdvancedDiffLabeledUnlabeledData.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/AdvancedDiffLabeledUnlabeledData.java @@ -7,6 +7,7 @@ import com.azure.ai.formrecognizer.models.RecognizeOptions; import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.core.credential.AzureKeyCredential; +import com.azure.core.util.Context; import java.io.File; import java.io.FileInputStream; @@ -53,7 +54,7 @@ public static void main(String[] args) throws IOException { new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF) .setIncludeFieldElements(true) - .setPollInterval(Duration.ofSeconds(5))) + .setPollInterval(Duration.ofSeconds(5)), Context.NONE) .getFinalResult(); List formsWithUnlabeledModel = @@ -62,7 +63,7 @@ public static void main(String[] args) throws IOException { new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF) .setIncludeFieldElements(true) - .setPollInterval(Duration.ofSeconds(5))) + .setPollInterval(Duration.ofSeconds(5)), Context.NONE) .getFinalResult(); System.out.println("--------Recognizing forms with labeled custom model--------"); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormRecognizerClientJavaDocCodeSnippets.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormRecognizerClientJavaDocCodeSnippets.java index ff6c25bf2bf1f..0f3279e4f2def 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormRecognizerClientJavaDocCodeSnippets.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormRecognizerClientJavaDocCodeSnippets.java @@ -12,6 +12,7 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.util.Context; import java.io.ByteArrayInputStream; import java.io.File; @@ -82,19 +83,18 @@ public void beginRecognizeCustomFormsFromUrl() { } /** - * Code snippet for {@link FormRecognizerClient#beginRecognizeCustomFormsFromUrl(String, String, RecognizeOptions)} + * Code snippet for {@link FormRecognizerClient#beginRecognizeCustomFormsFromUrl(String, String, RecognizeOptions, Context)} */ public void beginRecognizeCustomFormsFromUrlWithOptions() { - // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomFormsFromUrl#string-string-recognizeOptions + // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomFormsFromUrl#string-string-recognizeOptions-Context String analyzeFilePath = "{file_source_url}"; String modelId = "{model_id}"; boolean includeFieldElements = true; formRecognizerClient.beginRecognizeCustomFormsFromUrl(analyzeFilePath, modelId, new RecognizeOptions() - .setContentType(FormContentType.IMAGE_JPEG) .setIncludeFieldElements(includeFieldElements) - .setPollInterval(Duration.ofSeconds(10))) + .setPollInterval(Duration.ofSeconds(10)), Context.NONE) .getFinalResult() .stream() .map(RecognizedForm::getFields) @@ -103,7 +103,7 @@ public void beginRecognizeCustomFormsFromUrlWithOptions() { System.out.printf("Field value: %s%n", formField.getValue()); System.out.printf("Confidence score: %.2f%n", formField.getConfidence()); })); - // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomFormsFromUrl#string-string-recognizeOptions + // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomFormsFromUrl#string-string-recognizeOptions-Context } /** @@ -134,12 +134,12 @@ public void beginRecognizeCustomForms() throws IOException { /** * Code snippet for - * {@link FormRecognizerClient#beginRecognizeCustomForms(InputStream, long, String, RecognizeOptions)} with options + * {@link FormRecognizerClient#beginRecognizeCustomForms(InputStream, long, String, RecognizeOptions, Context)} with options * * @throws IOException Exception thrown when there is an error in reading all the bytes from the File. */ public void beginRecognizeCustomFormsWithOptions() throws IOException { - // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomForms#InputStream-long-string-recognizeOptions + // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomForms#InputStream-long-string-recognizeOptions-Context File form = new File("{local/file_path/fileName.jpg}"); String modelId = "{custom_trained_model_id}"; boolean includeFieldElements = true; @@ -150,7 +150,7 @@ public void beginRecognizeCustomFormsWithOptions() throws IOException { new RecognizeOptions() .setContentType(FormContentType.IMAGE_JPEG) .setIncludeFieldElements(includeFieldElements) - .setPollInterval(Duration.ofSeconds(10))) + .setPollInterval(Duration.ofSeconds(10)), Context.NONE) .getFinalResult() .stream() .map(RecognizedForm::getFields) @@ -160,7 +160,7 @@ public void beginRecognizeCustomFormsWithOptions() throws IOException { System.out.printf("Confidence score: %.2f%n", formField.getConfidence()); })); } - // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomForms#InputStream-long-string-recognizeOptions + // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomForms#InputStream-long-string-recognizeOptions-Context } // Recognize Content @@ -187,15 +187,16 @@ public void beginRecognizeContentFromUrl() { } /** - * Code snippet for {@link FormRecognizerClient#beginRecognizeContentFromUrl(String, RecognizeOptions)} with + * Code snippet for {@link FormRecognizerClient#beginRecognizeContentFromUrl(String, RecognizeOptions, Context)} with * options. */ public void beginRecognizeContentFromUrlWithOptions() { - // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContentFromUrl#string-recognizeOptions + // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContentFromUrl#string-recognizeOptions-Context String formPath = "{file_source_url}"; formRecognizerClient.beginRecognizeContentFromUrl(formPath, new RecognizeOptions() - .setPollInterval(Duration.ofSeconds(5))) + .setPollInterval(Duration.ofSeconds(5)) + .setIncludeFieldElements(true), Context.NONE) .getFinalResult() .forEach(formPage -> { System.out.printf("Page Angle: %s%n", formPage.getTextAngle()); @@ -207,7 +208,7 @@ public void beginRecognizeContentFromUrlWithOptions() { .flatMap(formTable -> formTable.getCells().stream()) .forEach(recognizedTableCell -> System.out.printf("%s ", recognizedTableCell.getText())); }); - // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContentFromUrl#string-recognizeOptions + // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContentFromUrl#string-recognizeOptions-Context } /** @@ -237,20 +238,21 @@ public void beginRecognizeContent() throws IOException { } /** - * Code snippet for {@link FormRecognizerClient#beginRecognizeContent(InputStream, long, RecognizeOptions)} with + * Code snippet for {@link FormRecognizerClient#beginRecognizeContent(InputStream, long, RecognizeOptions, Context)} with * options. * * @throws IOException Exception thrown when there is an error in reading all the bytes from the File. */ public void beginRecognizeContentWithOptions() throws IOException { - // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContent#InputStream-long-recognizeOptions + // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContent#InputStream-long-recognizeOptions-Context File form = new File("{file_source_url}"); byte[] fileContent = Files.readAllBytes(form.toPath()); try (InputStream targetStream = new ByteArrayInputStream(fileContent)) { for (FormPage formPage : formRecognizerClient.beginRecognizeContent(targetStream, form.length(), new RecognizeOptions() - .setPollInterval(Duration.ofSeconds(5))) + .setPollInterval(Duration.ofSeconds(5)) + .setIncludeFieldElements(true), Context.NONE) .getFinalResult()) { System.out.printf("Page Angle: %s%n", formPage.getTextAngle()); System.out.printf("Page Dimension unit: %s%n", formPage.getUnit()); @@ -262,7 +264,7 @@ public void beginRecognizeContentWithOptions() throws IOException { .forEach(recognizedTableCell -> System.out.printf("%s ", recognizedTableCell.getText())); } } - // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContent#InputStream-long-recognizeOptions + // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeContent#InputStream-long-recognizeOptions-Context } // Recognize Receipts @@ -330,12 +332,15 @@ public void beginRecognizeReceiptsFromUrl() { } /** - * Code snippet for {@link FormRecognizerClient#beginRecognizeReceiptsFromUrl(String, RecognizeOptions)} + * Code snippet for {@link FormRecognizerClient#beginRecognizeReceiptsFromUrl(String, RecognizeOptions, Context)} */ public void beginRecognizeReceiptsFromUrlWithOptions() { - // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceiptsFromUrl#string-recognizeOptions + // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceiptsFromUrl#string-recognizeOptions-Context String receiptUrl = "{receipt_url}"; - formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl).getFinalResult() + formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl, + new RecognizeOptions() + .setPollInterval(Duration.ofSeconds(5)) + .setIncludeFieldElements(true), Context.NONE).getFinalResult() .forEach(recognizedReceipt -> { Map> recognizedFields = recognizedReceipt.getFields(); FormField merchantNameField = recognizedFields.get("MerchantName"); @@ -385,7 +390,7 @@ public void beginRecognizeReceiptsFromUrlWithOptions() { } } }); - // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceiptsFromUrl#string-recognizeOptions + // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceiptsFromUrl#string-recognizeOptions-Context } /** @@ -454,14 +459,14 @@ public void beginRecognizeReceipts() throws IOException { } /** - * Code snippet for {@link FormRecognizerClient#beginRecognizeReceipts(InputStream, long, RecognizeOptions)} + * Code snippet for {@link FormRecognizerClient#beginRecognizeReceipts(InputStream, long, RecognizeOptions, Context)} * with options * * @throws IOException Exception thrown when there is an error in reading all the bytes from the File. */ public void beginRecognizeReceiptsWithOptions() throws IOException { - // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceipts#InputStream-long-recognizeOptions + // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceipts#InputStream-long-recognizeOptions-Context File receipt = new File("{local/file_path/fileName.jpg}"); boolean includeFieldElements = true; byte[] fileContent = Files.readAllBytes(receipt.toPath()); @@ -470,7 +475,7 @@ public void beginRecognizeReceiptsWithOptions() throws IOException { new RecognizeOptions() .setContentType(FormContentType.IMAGE_JPEG) .setIncludeFieldElements(includeFieldElements) - .setPollInterval(Duration.ofSeconds(5))) + .setPollInterval(Duration.ofSeconds(5)), Context.NONE) .getFinalResult()) { Map> recognizedFields = recognizedForm.getFields(); FormField merchantNameField = recognizedFields.get("MerchantName"); @@ -518,6 +523,6 @@ public void beginRecognizeReceiptsWithOptions() throws IOException { } } } - // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceipts#InputStream-long-recognizeOptions + // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceipts#InputStream-long-recognizeOptions-Context } } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingClientJavaDocCodeSnippets.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingClientJavaDocCodeSnippets.java index 2137a636f1b89..66268b2eebef0 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingClientJavaDocCodeSnippets.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingClientJavaDocCodeSnippets.java @@ -50,17 +50,17 @@ public void beginTraining() { } /** - * Code snippet for {@link FormTrainingClient#beginTraining(String, boolean, TrainingFileFilter, Duration)} + * Code snippet for {@link FormTrainingClient#beginTraining(String, boolean, TrainingFileFilter, Duration, Context)} * with options */ public void beginTrainingWithOptions() { - // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean-trainingFileFilter-Duration + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean-trainingFileFilter-Duration-Context String trainingFilesUrl = "{SAS-URL-of-your-container-in-blob-storage}"; TrainingFileFilter trainingFileFilter = new TrainingFileFilter().setIncludeSubFolders(false).setPrefix("Invoice"); boolean useTrainingLabels = true; CustomFormModel customFormModel = formTrainingClient.beginTraining(trainingFilesUrl, useTrainingLabels, - trainingFileFilter, Duration.ofSeconds(5)).getFinalResult(); + trainingFileFilter, Duration.ofSeconds(5), Context.NONE).getFinalResult(); System.out.printf("Model Id: %s%n", customFormModel.getModelId()); System.out.printf("Model Status: %s%n", customFormModel.getModelStatus()); @@ -69,7 +69,7 @@ public void beginTrainingWithOptions() { .forEach((key, customFormModelField) -> System.out.printf("Form Type: %s Field Text: %s Field Accuracy: %f%n", key, customFormModelField.getName(), customFormModelField.getAccuracy()))); - // END: com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean-trainingFileFilter-Duration + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean-trainingFileFilter-Duration-Context } /** @@ -214,10 +214,10 @@ public void beginCopy() { } /** - * Code snippet for {@link FormTrainingClient#beginCopyModel(String, CopyAuthorization, Duration)} + * Code snippet for {@link FormTrainingClient#beginCopyModel(String, CopyAuthorization, Duration, Context)} */ public void beginCopyOverload() { - // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.beginCopyModel#string-copyAuthorization-Duration + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.beginCopyModel#string-copyAuthorization-Duration-Context // The resource to copy model to String resourceId = "target-resource-Id"; String resourceRegion = "target-resource-region"; @@ -226,7 +226,8 @@ public void beginCopyOverload() { CopyAuthorization copyAuthorization = targetFormTrainingClient.getCopyAuthorization(resourceId, resourceRegion); - formTrainingClient.beginCopyModel(copyModelId, copyAuthorization, Duration.ofSeconds(5)).waitForCompletion(); + formTrainingClient.beginCopyModel(copyModelId, copyAuthorization, Duration.ofSeconds(5), Context.NONE) + .waitForCompletion(); CustomFormModel modelCopy = targetFormTrainingClient.getCustomModel(copyAuthorization.getModelId()); System.out.printf("Copied model has model Id: %s, model status: %s, was requested on: %s," + " transfer completed on: %s.%n", @@ -234,7 +235,7 @@ public void beginCopyOverload() { modelCopy.getModelStatus(), modelCopy.getTrainingStartedOn(), modelCopy.getTrainingCompletedOn()); - // END: com.azure.ai.formrecognizer.training.FormTrainingClient.beginCopyModel#string-copyAuthorization-Duration + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.beginCopyModel#string-copyAuthorization-Duration-Context } /** diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxes.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxes.java index b4f881cd7aabc..4949eb1af09b2 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxes.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxes.java @@ -10,6 +10,7 @@ import com.azure.ai.formrecognizer.models.RecognizeOptions; import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.core.credential.AzureKeyCredential; +import com.azure.core.util.Context; import com.azure.core.util.polling.SyncPoller; import java.util.List; @@ -36,7 +37,7 @@ public static void main(String[] args) { String formUrl = "{form_url}"; SyncPoller> recognizeFormPoller = client.beginRecognizeCustomFormsFromUrl(formUrl, modelId, new RecognizeOptions() - .setIncludeFieldElements(true)); + .setIncludeFieldElements(true), Context.NONE); List recognizedForms = recognizeFormPoller.getFinalResult(); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java index ca8741c86814d..a03ec93afd0cd 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java @@ -14,6 +14,7 @@ import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpClient; +import com.azure.core.util.Context; import com.azure.core.util.polling.SyncPoller; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -64,7 +65,7 @@ public void recognizeReceiptData(HttpClient httpClient, FormRecognizerServiceVer receiptDataRunner((data, dataLength) -> { SyncPoller> syncPoller = client.beginRecognizeReceipts(data, dataLength, new RecognizeOptions() - .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode)); + .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateReceiptResultData(syncPoller.getFinalResult(), false); }); @@ -92,7 +93,7 @@ public void recognizeReceiptDataWithContentTypeAutoDetection(HttpClient httpClie client = getFormRecognizerClient(httpClient, serviceVersion); SyncPoller> syncPoller = client.beginRecognizeReceipts( getContentDetectionFileData(RECEIPT_LOCAL_URL), RECEIPT_FILE_LENGTH, new RecognizeOptions() - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateReceiptResultData(syncPoller.getFinalResult(), false); } @@ -108,7 +109,7 @@ public void recognizeReceiptDataIncludeFieldElements(HttpClient httpClient, Form receiptDataRunnerFieldElements((data, includeFieldElements) -> { SyncPoller> syncPoller = client.beginRecognizeReceipts( data, RECEIPT_FILE_LENGTH, new RecognizeOptions().setContentType(FormContentType.IMAGE_JPEG) - .setIncludeFieldElements(includeFieldElements).setPollInterval(durationTestMode)); + .setIncludeFieldElements(includeFieldElements).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements); }); @@ -126,7 +127,7 @@ public void recognizeReceiptDataWithPngFile(HttpClient httpClient, SyncPoller> syncPoller = client.beginRecognizeReceipts(data, RECEIPT_PNG_FILE_LENGTH, new RecognizeOptions().setContentType( FormContentType.IMAGE_PNG).setIncludeFieldElements(includeFieldElements) - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements); }); @@ -143,7 +144,7 @@ public void recognizeReceiptDataWithBlankPdf(HttpClient httpClient, blankPdfDataRunner((data, dataLength) -> { SyncPoller> syncPoller = client.beginRecognizeReceipts( data, dataLength, new RecognizeOptions().setContentType(FormContentType.APPLICATION_PDF) - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateBlankPdfResultData(syncPoller.getFinalResult()); }); @@ -156,7 +157,7 @@ public void recognizeReceiptFromDataMultiPage(HttpClient httpClient, FormRecogni multipageFromDataRunner((data, dataLength) -> { SyncPoller> syncPoller = client.beginRecognizeReceipts( data, dataLength, new RecognizeOptions().setContentType(FormContentType.APPLICATION_PDF) - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateMultipageReceiptData(syncPoller.getFinalResult()); }); @@ -188,7 +189,7 @@ public void recognizeReceiptInvalidSourceUrl(HttpClient httpClient, FormRecogniz client = getFormRecognizerClient(httpClient, serviceVersion); invalidSourceUrlRunner((sourceUrl) -> assertThrows(HttpResponseException.class, () -> client.beginRecognizeReceiptsFromUrl(sourceUrl, - new RecognizeOptions().setPollInterval(durationTestMode)))); + new RecognizeOptions().setPollInterval(durationTestMode), Context.NONE))); } /** @@ -203,7 +204,7 @@ public void recognizeReceiptFromUrlIncludeFieldElements(HttpClient httpClient, receiptSourceUrlRunnerFieldElements((sourceUrl, includeFieldElements) -> { SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( sourceUrl, new RecognizeOptions().setIncludeFieldElements(includeFieldElements) - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements); }); @@ -222,7 +223,7 @@ public void recognizeReceiptSourceUrlWithPngFile(HttpClient httpClient, SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( sourceUrl, new RecognizeOptions().setIncludeFieldElements(includeFieldElements) - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateReceiptResultData(syncPoller.getFinalResult(), includeFieldElements); }); @@ -234,7 +235,7 @@ public void recognizeReceiptFromUrlMultiPage(HttpClient httpClient, FormRecogniz client = getFormRecognizerClient(httpClient, serviceVersion); multipageFromUrlRunner(receiptUrl -> { SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( - receiptUrl, new RecognizeOptions().setPollInterval(durationTestMode)); + receiptUrl, new RecognizeOptions().setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateMultipageReceiptData(syncPoller.getFinalResult()); }); @@ -254,7 +255,7 @@ public void recognizeContent(HttpClient httpClient, FormRecognizerServiceVersion contentFromDataRunner((data, dataLength) -> { SyncPoller> syncPoller = client.beginRecognizeContent(data, dataLength, new RecognizeOptions() - .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode)); + .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateContentResultData(syncPoller.getFinalResult(), false); }); @@ -269,7 +270,7 @@ public void recognizeContentResultWithNullData(HttpClient httpClient, FormRecogn client = getFormRecognizerClient(httpClient, serviceVersion); assertThrows(RuntimeException.class, () -> client.beginRecognizeContent(null, LAYOUT_FILE_LENGTH, new RecognizeOptions() - .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode))); + .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode), Context.NONE)); } /** @@ -282,7 +283,7 @@ public void recognizeContentResultWithContentTypeAutoDetection(HttpClient httpCl client = getFormRecognizerClient(httpClient, serviceVersion); SyncPoller> syncPoller = client.beginRecognizeContent( getContentDetectionFileData(LAYOUT_LOCAL_URL), LAYOUT_FILE_LENGTH, new RecognizeOptions() - .setContentType(null).setPollInterval(durationTestMode)); + .setContentType(null).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateContentResultData(syncPoller.getFinalResult(), false); @@ -299,7 +300,7 @@ public void recognizeContentResultWithBlankPdf(HttpClient httpClient, FormRecogn blankPdfDataRunner((data, dataLength) -> { SyncPoller> syncPoller = client.beginRecognizeContent(data, dataLength, new RecognizeOptions() - .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)); + .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateContentResultData(syncPoller.getFinalResult(), false); }); @@ -312,7 +313,7 @@ public void recognizeContentFromDataMultiPage(HttpClient httpClient, FormRecogni multipageFromDataRunner((data, dataLength) -> { SyncPoller> syncPoller = client.beginRecognizeContent(data, dataLength, new RecognizeOptions() - .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)); + .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateContentResultData(syncPoller.getFinalResult(), false); }); @@ -340,7 +341,7 @@ public void recognizeContentFromUrlWithPdf(HttpClient httpClient, FormRecognizer client = getFormRecognizerClient(httpClient, serviceVersion); pdfContentFromUrlRunner(sourceUrl -> { SyncPoller> syncPoller = client.beginRecognizeContentFromUrl(sourceUrl, - new RecognizeOptions().setPollInterval(durationTestMode)); + new RecognizeOptions().setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateContentResultData(syncPoller.getFinalResult(), false); }); @@ -356,7 +357,7 @@ public void recognizeContentInvalidSourceUrl(HttpClient httpClient, FormRecogniz invalidSourceUrlRunner((invalidSourceUrl) -> assertThrows( HttpResponseException.class, () -> client.beginRecognizeContentFromUrl(invalidSourceUrl, - new RecognizeOptions().setPollInterval(durationTestMode)))); + new RecognizeOptions().setPollInterval(durationTestMode), Context.NONE))); } @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) @@ -365,7 +366,8 @@ public void recognizeContentFromUrlMultiPage(HttpClient httpClient, FormRecogniz client = getFormRecognizerClient(httpClient, serviceVersion); multipageFromUrlRunner((formUrl) -> { SyncPoller> syncPoller = - client.beginRecognizeContentFromUrl(formUrl, new RecognizeOptions().setPollInterval(durationTestMode)); + client.beginRecognizeContentFromUrl(formUrl, new RecognizeOptions().setPollInterval(durationTestMode), + Context.NONE); syncPoller.waitForCompletion(); validateContentResultData(syncPoller.getFinalResult(), false); }); @@ -386,13 +388,13 @@ public void recognizeCustomFormLabeledData(HttpClient httpClient, FormRecognizer beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( data, dataLength, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF).setIncludeFieldElements(true) - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), true, true); })); @@ -410,12 +412,12 @@ public void recognizeCustomFormLabeledDataWithJpgContentType(HttpClient httpClie beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels, - null, durationTestMode); + null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( data, dataLength, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode)); + .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), false, true); })); @@ -432,12 +434,12 @@ public void recognizeCustomFormLabeledDataWithBlankPdfContentType(HttpClient htt blankPdfDataRunner((data, dataLength) -> beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels, - null, durationTestMode); + null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( data, dataLength, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)); + .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), false, true); })); @@ -455,12 +457,12 @@ public void recognizeCustomFormLabeledDataExcludeFieldElements(HttpClient httpCl customFormDataRunner((data, dataLength) -> beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels, - null, durationTestMode); + null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( data, dataLength, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)); + .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), false, true); })); @@ -478,13 +480,13 @@ public void recognizeCustomFormLabeledDataWithNullFormData(HttpClient httpClient beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); syncPoller.waitForCompletion(); assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomForms( (InputStream) null, dataLength, syncPoller.getFinalResult().getModelId(), new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF).setIncludeFieldElements(true) - .setPollInterval(durationTestMode))); + .setPollInterval(durationTestMode), Context.NONE)); }) ); } @@ -501,7 +503,7 @@ public void recognizeCustomFormLabeledDataWithNullModelId(HttpClient httpClient, Exception ex = assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomForms( data, dataLength, null, new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF).setIncludeFieldElements(true) - .setPollInterval(durationTestMode))); + .setPollInterval(durationTestMode), Context.NONE)); assertEquals(EXPECTED_MODEL_ID_IS_REQUIRED_EXCEPTION_MESSAGE, ex.getMessage()); }); } @@ -519,7 +521,7 @@ public void recognizeCustomFormLabeledDataWithEmptyModelId(HttpClient httpClient Exception ex = assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomForms( data, dataLength, "", new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF).setIncludeFieldElements(true) - .setPollInterval(durationTestMode))); + .setPollInterval(durationTestMode), Context.NONE)); assertEquals(EXPECTED_INVALID_UUID_EXCEPTION_MESSAGE, ex.getMessage()); }); } @@ -532,12 +534,13 @@ public void recognizeCustomFormInvalidStatus(HttpClient httpClient, FormRecogniz beginTrainingLabeledRunner((training, useTrainingLabels) -> { SyncPoller syncPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(training, useTrainingLabels, - null, durationTestMode); + null, durationTestMode, Context.NONE); syncPoller.waitForCompletion(); CustomFormModel createdModel = syncPoller.getFinalResult(); FormRecognizerException formRecognizerException = assertThrows(FormRecognizerException.class, () -> client.beginRecognizeCustomFormsFromUrl(invalidSourceUrl, - createdModel.getModelId(), new RecognizeOptions().setPollInterval(durationTestMode)).getFinalResult()); + createdModel.getModelId(), new RecognizeOptions().setPollInterval(durationTestMode), + Context.NONE).getFinalResult()); ErrorInformation errorInformation = formRecognizerException.getErrorInformation().get(0); // TODO: Service bug https://github.com/Azure/azure-sdk-for-java/issues/12046 // assertEquals(EXPECTED_INVALID_URL_ERROR_CODE, errorInformation.getCode()); @@ -558,13 +561,13 @@ public void recognizeCustomFormLabeledDataWithContentTypeAutoDetection(HttpClien beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels, - null, durationTestMode); + null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( getContentDetectionFileData(FORM_LOCAL_URL), CUSTOM_FORM_FILE_LENGTH, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setIncludeFieldElements(true).setPollInterval(durationTestMode)); + .setIncludeFieldElements(true).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), true, true); }); @@ -578,12 +581,12 @@ public void recognizeCustomFormMultiPageLabeled(HttpClient httpClient, multipageFromDataRunner((data, dataLength) -> beginTrainingMultipageRunner((trainingFilesUrl) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, true, - null, durationTestMode); + null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( data, dataLength, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)); + .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateMultiPageDataLabeled(syncPoller.getFinalResult()); })); @@ -602,12 +605,12 @@ public void recognizeCustomFormUnlabeledData(HttpClient httpClient, FormRecogniz beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( data, dataLength, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)); + .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), false, false); })); @@ -625,13 +628,13 @@ public void recognizeCustomFormUnlabeledDataIncludeFieldElements(HttpClient http customFormDataRunner((data, dataLength) -> beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( data, dataLength, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF).setIncludeFieldElements(true) - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), true, false); })); @@ -645,12 +648,12 @@ public void recognizeCustomFormMultiPageUnlabeled(HttpClient httpClient, multipageFromDataRunner((data, dataLength) -> beginTrainingMultipageRunner((trainingFilesUrl) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, false, - null, durationTestMode); + null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( data, dataLength, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)); + .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateMultiPageDataUnlabeled(syncPoller.getFinalResult()); })); @@ -668,12 +671,12 @@ public void recognizeCustomFormUnlabeledDataWithJpgContentType(HttpClient httpCl beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( data, dataLength, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode)); + .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), false, false); })); @@ -690,12 +693,12 @@ public void recognizeCustomFormUnlabeledDataWithBlankPdfContentType(HttpClient h blankPdfDataRunner((data, dataLength) -> beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( data, dataLength, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)); + .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), false, false); })); @@ -714,12 +717,12 @@ public void recognizeCustomFormUrlUnlabeledData(HttpClient httpClient, urlRunner(fileUrl -> beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels, - null, durationTestMode); + null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomFormsFromUrl( fileUrl, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), false, false); }), FORM_JPG); @@ -736,12 +739,12 @@ public void recognizeCustomFormUrlUnlabeledDataIncludeFieldElements(HttpClient h urlRunner(fileUrl -> beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels, - null, durationTestMode); + null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomFormsFromUrl( fileUrl, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setIncludeFieldElements(true).setPollInterval(durationTestMode)); + .setIncludeFieldElements(true).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), true, false); }), FORM_JPG); @@ -755,12 +758,12 @@ public void recognizeCustomFormUrlMultiPageUnlabeled(HttpClient httpClient, multipageFromUrlRunner(fileUrl -> beginTrainingMultipageRunner((trainingFilesUrl) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, false, - null, durationTestMode); + null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomFormsFromUrl( fileUrl, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateMultiPageDataUnlabeled(syncPoller.getFinalResult()); })); @@ -779,13 +782,13 @@ public void recognizeCustomFormInvalidSourceUrl(HttpClient httpClient, beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels, - null, durationTestMode); + null, durationTestMode, Context.NONE); syncPoller.waitForCompletion(); CustomFormModel createdModel = syncPoller.getFinalResult(); HttpResponseException httpResponseException = assertThrows( HttpResponseException.class, () -> client.beginRecognizeCustomFormsFromUrl( INVALID_URL, createdModel.getModelId(), new RecognizeOptions() - .setPollInterval(durationTestMode)).getFinalResult()); + .setPollInterval(durationTestMode), Context.NONE).getFinalResult()); assertEquals(httpResponseException.getMessage(), (INVALID_SOURCE_URL_ERROR)); }); } @@ -800,7 +803,7 @@ public void recognizeCustomFormFromUrlLabeledDataWithNullModelId(HttpClient http client = getFormRecognizerClient(httpClient, serviceVersion); multipageFromUrlRunner(fileUrl -> { Exception ex = assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomFormsFromUrl( - fileUrl, null, new RecognizeOptions().setPollInterval(durationTestMode))); + fileUrl, null, new RecognizeOptions().setPollInterval(durationTestMode), Context.NONE)); assertEquals(EXPECTED_MODEL_ID_IS_REQUIRED_EXCEPTION_MESSAGE, ex.getMessage()); }); } @@ -815,7 +818,7 @@ public void recognizeCustomFormFromUrlLabeledDataWithEmptyModelId(HttpClient htt client = getFormRecognizerClient(httpClient, serviceVersion); multipageFromUrlRunner(fileUrl -> beginTrainingMultipageRunner((trainingFilesUrl) -> { Exception ex = assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomFormsFromUrl( - fileUrl, "", new RecognizeOptions().setPollInterval(durationTestMode))); + fileUrl, "", new RecognizeOptions().setPollInterval(durationTestMode), Context.NONE)); assertEquals(EXPECTED_INVALID_UUID_EXCEPTION_MESSAGE, ex.getMessage()); })); } @@ -832,12 +835,12 @@ public void recognizeCustomFormUrlLabeledDataIncludeFieldElements(HttpClient htt urlRunner(fileUrl -> beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomFormsFromUrl( fileUrl, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setIncludeFieldElements(true).setPollInterval(durationTestMode)); + .setIncludeFieldElements(true).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), true, true); }), FORM_JPG); @@ -854,12 +857,12 @@ public void recognizeCustomFormUrlLabeledData(HttpClient httpClient, FormRecogni SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomFormsFromUrl( fileUrl, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateRecognizedResult(syncPoller.getFinalResult(), false, true); }), FORM_JPG); @@ -876,12 +879,12 @@ public void recognizeCustomFormUrlMultiPageLabeled(HttpClient httpClient, multipageFromUrlRunner(fileUrl -> beginTrainingMultipageRunner((trainingFilesUrl) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, true, - null, durationTestMode); + null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomFormsFromUrl( fileUrl, trainingPoller.getFinalResult().getModelId(), new RecognizeOptions() - .setPollInterval(durationTestMode)); + .setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateMultiPageDataLabeled(syncPoller.getFinalResult()); })); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java index 340889097b86c..148fd3c6cd9f0 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java @@ -57,7 +57,7 @@ public void getFormRecognizerClientAndValidate(HttpClient httpClient, FormRecogn blankPdfDataRunner(data -> { SyncPoller> syncPoller = formRecognizerClient.beginRecognizeReceipts(data, BLANK_FORM_FILE_LENGTH, new RecognizeOptions() - .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)); + .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode), Context.NONE); syncPoller.waitForCompletion(); validateBlankPdfResultData(syncPoller.getFinalResult()); }); @@ -93,7 +93,7 @@ public void getCustomModelWithResponse(HttpClient httpClient, FormRecognizerServ client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingUnlabeledRunner((trainingDataSasUrl, useTrainingLabels) -> { CustomFormModel trainedUnlabeledModel = client.beginTraining(trainingDataSasUrl, useTrainingLabels, - null, durationTestMode).getFinalResult(); + null, durationTestMode, Context.NONE).getFinalResult(); Response customModelWithResponse = client.getCustomModelWithResponse(trainedUnlabeledModel.getModelId(), Context.NONE); @@ -111,7 +111,7 @@ public void getCustomModelUnlabeled(HttpClient httpClient, FormRecognizerService client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = client.beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); syncPoller.waitForCompletion(); CustomFormModel trainedUnlabeledModel = syncPoller.getFinalResult(); validateCustomModelData(client.getCustomModel(trainedUnlabeledModel.getModelId()), false); @@ -127,7 +127,7 @@ public void getCustomModelLabeled(HttpClient httpClient, FormRecognizerServiceVe client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingLabeledRunner((trainingDataSASUrl, useTrainingLabels) -> { CustomFormModel customFormModel = client.beginTraining(trainingDataSASUrl, useTrainingLabels, - null, durationTestMode).getFinalResult(); + null, durationTestMode, Context.NONE).getFinalResult(); validateCustomModelData(client.getCustomModel(customFormModel.getModelId()), true); }); } @@ -172,7 +172,7 @@ public void deleteModelValidModelIdWithResponse(HttpClient httpClient, FormRecog client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingLabeledRunner((trainingDataSASUrl, useTrainingLabels) -> { SyncPoller syncPoller = client.beginTraining(trainingDataSASUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); syncPoller.waitForCompletion(); CustomFormModel createdModel = syncPoller.getFinalResult(); @@ -233,7 +233,7 @@ public void beginCopy(HttpClient httpClient, FormRecognizerServiceVersion servic client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(trainingFilesUrl, useTrainingLabels, null, durationTestMode); + client.beginTraining(trainingFilesUrl, useTrainingLabels, null, durationTestMode, Context.NONE); syncPoller.waitForCompletion(); CustomFormModel actualModel = syncPoller.getFinalResult(); @@ -260,7 +260,7 @@ public void beginCopyInvalidRegion(HttpClient httpClient, FormRecognizerServiceV client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(trainingFilesUrl, useTrainingLabels, null, durationTestMode); + client.beginTraining(trainingFilesUrl, useTrainingLabels, null, durationTestMode, Context.NONE); syncPoller.waitForCompletion(); final CustomFormModel actualModel = syncPoller.getFinalResult(); @@ -283,7 +283,7 @@ public void beginCopyIncorrectRegion(HttpClient httpClient, FormRecognizerServic client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(trainingFilesUrl, useTrainingLabels, null, durationTestMode); + client.beginTraining(trainingFilesUrl, useTrainingLabels, null, durationTestMode, Context.NONE); syncPoller.waitForCompletion(); CustomFormModel actualModel = syncPoller.getFinalResult(); @@ -337,7 +337,7 @@ public void beginTrainingWithTrainingLabelsForJPGTrainingSet(HttpClient httpClie client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = client.beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); validateCustomModelData(trainingPoller.getFinalResult(), true); }); @@ -353,7 +353,7 @@ public void beginTrainingWithoutTrainingLabelsForJPGTrainingSet(HttpClient httpC client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = client.beginTraining(trainingFilesUrl, - useTrainingLabels, null, durationTestMode); + useTrainingLabels, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); validateCustomModelData(trainingPoller.getFinalResult(), false); }); @@ -369,7 +369,7 @@ public void beginTrainingWithTrainingLabelsForMultiPagePDFTrainingSet(HttpClient client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingMultipageRunner(trainingFilesUrl -> { SyncPoller trainingPoller = client.beginTraining(trainingFilesUrl, - true, null, durationTestMode); + true, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); validateCustomModelData(trainingPoller.getFinalResult(), true); }); @@ -385,7 +385,7 @@ public void beginTrainingWithoutTrainingLabelsForMultiPagePDFTrainingSet(HttpCli client = getFormTrainingClient(httpClient, serviceVersion); beginTrainingMultipageRunner(trainingFilesUrl -> { SyncPoller trainingPoller = client.beginTraining(trainingFilesUrl, - false, null, durationTestMode); + false, null, durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); validateCustomModelData(trainingPoller.getFinalResult(), false); }); @@ -403,7 +403,7 @@ public void beginTrainingWithoutTrainingLabelsIncludeSubfolderWithPrefixName(Htt beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = client.beginTraining(trainingFilesUrl, useTrainingLabels, new TrainingFileFilter().setIncludeSubFolders(true).setPrefix(PREFIX_SUBFOLDER), - durationTestMode); + durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); validateCustomModelData(trainingPoller.getFinalResult(), false); }); @@ -421,7 +421,7 @@ public void beginTrainingWithoutTrainingLabelsExcludeSubfolderWithPrefixName(Htt beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = client.beginTraining(trainingFilesUrl, useTrainingLabels, new TrainingFileFilter().setPrefix(PREFIX_SUBFOLDER), - durationTestMode); + durationTestMode, Context.NONE); trainingPoller.waitForCompletion(); validateCustomModelData(trainingPoller.getFinalResult(), false); }); @@ -440,7 +440,7 @@ public void beginTrainingWithoutTrainingLabelsIncludeSubfolderWithNonExistPrefix FormRecognizerException thrown = assertThrows(FormRecognizerException.class, () -> client.beginTraining(trainingFilesUrl, false, new TrainingFileFilter().setIncludeSubFolders(true).setPrefix(INVALID_PREFIX_FILE_NAME), - durationTestMode).getFinalResult()); + durationTestMode, Context.NONE).getFinalResult()); assertEquals(NO_VALID_BLOB_FOUND, thrown.getErrorInformation().get(0).getMessage()); }); } @@ -457,7 +457,7 @@ public void beginTrainingWithoutTrainingLabelsExcludeSubfolderWithNonExistPrefix beginTrainingMultipageRunner(trainingFilesUrl -> { FormRecognizerException thrown = assertThrows(FormRecognizerException.class, () -> client.beginTraining(trainingFilesUrl, false, - new TrainingFileFilter().setPrefix(INVALID_PREFIX_FILE_NAME), durationTestMode) + new TrainingFileFilter().setPrefix(INVALID_PREFIX_FILE_NAME), durationTestMode, Context.NONE) .getFinalResult()); assertEquals(NO_VALID_BLOB_FOUND, thrown.getErrorInformation().get(0).getMessage()); });