diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 670f9828cc167..e05646bfe713a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -17,7 +17,7 @@ /sdk/core/ @alzimmermsft @jianghaolu @srnagar @hemanttanwar @anuchandy /sdk/core/azure-core-tracing-opentelemetry/ @samvaity @alzimmermsft /sdk/cosmos/ @moderakh @kushagraThapar @David-Noble-at-work @kirankumarkolli @mbhaskar -/sdk/cosmos/azure-spring-data-cosmosdb/ @kushagraThapar +/sdk/cosmos/azure-spring-data-cosmosdb/ @kushagraThapar @saragluna @yiliuTo @chenrujun @zhoufenqin @jialindai /sdk/eventhubs/ @conniey @srnagar @mssfang /sdk/formrecognizer/ @samvaity @mssfang @sima-zhu /sdk/identity/ @schaabs @g2vinay @jianghaolu @@ -27,7 +27,7 @@ /sdk/servicebus/ @yvgopal @nemakam @hemanttanwar @conniey /sdk/storage/ @amishra-dev @rickle-msft @jaschrep-msft @gapra-msft @alzimmermsft @sima-zhu /sdk/textanalytics/ @samvaity @mssfang @sima-zhu -/sdk/spring/ @saragluna @yiliuTo @chenrujun @jialindai +/sdk/spring/ @saragluna @yiliuTo @chenrujun @zhoufenqin @jialindai # end to end tests /sdk/e2e/ @jianghaolu @g2vinay diff --git a/.gitignore b/.gitignore index b95a70475b316..8071d0f700c3d 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,4 @@ package-lock.json # VS Code .vscode/ .factorypath +jacoco.exec diff --git a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml index 11048593d7430..e7baf627fd477 100755 --- a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml +++ b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml @@ -417,6 +417,8 @@ + + diff --git a/eng/common/pipelines/templates/steps/verify-changelog.yml b/eng/common/pipelines/templates/steps/verify-changelog.yml index 914adcc660e8e..f6005124a87f3 100644 --- a/eng/common/pipelines/templates/steps/verify-changelog.yml +++ b/eng/common/pipelines/templates/steps/verify-changelog.yml @@ -21,5 +21,5 @@ steps: -ForRelease $${{ parameters.ForRelease }} pwsh: true workingDirectory: $(Pipeline.Workspace) - displayName: Verify ChangeLog / Release Notes + displayName: Verify ChangeLogEntry for ${{ parameters.PackageName }} continueOnError: false \ No newline at end of file diff --git a/eng/common/scripts/create-tags-and-git-release.ps1 b/eng/common/scripts/create-tags-and-git-release.ps1 index cec45536b7044..1667cddd7e22a 100644 --- a/eng/common/scripts/create-tags-and-git-release.ps1 +++ b/eng/common/scripts/create-tags-and-git-release.ps1 @@ -6,7 +6,6 @@ param ( # used by VerifyPackages $artifactLocation, # the root of the artifact folder. DevOps $(System.ArtifactsDirectory) $workingDirectory, # directory that package artifacts will be extracted into for examination (if necessary) - [ValidateSet("Nuget","NPM","PyPI","Maven")] $packageRepository, # used to indicate destination against which we will check the existing version. # valid options: PyPI, Nuget, NPM, Maven, C # used by CreateTags diff --git a/eng/common/scripts/modules/ChangeLog-Operations.psm1 b/eng/common/scripts/modules/ChangeLog-Operations.psm1 index 5c173876124ea..e92070b195b33 100644 --- a/eng/common/scripts/modules/ChangeLog-Operations.psm1 +++ b/eng/common/scripts/modules/ChangeLog-Operations.psm1 @@ -94,9 +94,8 @@ function Confirm-ChangeLogEntry { } if ($ForRelease -eq $True) { - $CurrentDate = Get-Date -Format "yyyy-MM-dd" - if ($changeLogEntry.ReleaseStatus -ne "($CurrentDate)") { - Write-Host ("##[warning]Incorrect Date: Please use the current date in the Changelog '{0}' before releasing the package" -f $ChangeLogLocation) + if ($changeLogEntry.ReleaseStatus -eq "(Unreleased)") { + Write-Host ("##[error]No release date set. Please set a release date with format 'yyyy-MM-dd' in the heading for version '{0}' in the changelog '{1}'." -f $VersionString, $ChangelogLocation) exit 1 } diff --git a/eng/common/scripts/modules/Package-Properties.psm1 b/eng/common/scripts/modules/Package-Properties.psm1 index 294f6609dab81..dca123f929f71 100644 --- a/eng/common/scripts/modules/Package-Properties.psm1 +++ b/eng/common/scripts/modules/Package-Properties.psm1 @@ -106,7 +106,7 @@ function Extract-PythonPkgProps ($pkgPath, $serviceName, $pkgName) { $setupLocation = $pkgPath.Replace('\','/') pushd $RepoRoot - $setupProps = (python -c "import scripts.devops_tasks.common_tasks; obj=scripts.devops_tasks.common_tasks.parse_setup('$setupLocation'); print('{0},{1}'.format(obj[0], obj[1]));") -split "," + $setupProps = (python -c "import sys; import os; sys.path.append(os.path.join('scripts', 'devops_tasks')); from common_tasks import parse_setup; obj=parse_setup('$setupLocation'); print('{0},{1}'.format(obj[0], obj[1]));") -split "," popd if (($setupProps -ne $null) -and ($setupProps[0] -eq $pkgName)) { diff --git a/eng/pipelines/templates/stages/cosmos-sdk-client.yml b/eng/pipelines/templates/stages/cosmos-sdk-client.yml index 3fea2eef3eea3..d59a746bd1bc7 100644 --- a/eng/pipelines/templates/stages/cosmos-sdk-client.yml +++ b/eng/pipelines/templates/stages/cosmos-sdk-client.yml @@ -94,6 +94,7 @@ stages: DisplayName: 'Emulator only Integration Tests' PROTOCOLS: '["Tcp"]' DESIRED_CONSISTENCIES: '["Strong", "Session"]' + AdditionalArgs: '-DargLine="-DACCOUNT_HOST=https://localhost:8081/"' Https_Integration_Tests_Java8: OSVmImage: 'windows-2019' JavaTestVersion: '1.8' @@ -101,10 +102,17 @@ stages: DisplayName: 'Emulator only Integration Tests' PROTOCOLS: '["Https"]' DESIRED_CONSISTENCIES: '["Strong", "Session"]' + AdditionalArgs: '-DargLine="-DACCOUNT_HOST=https://localhost:8081/"' + Spring_Integration_Tests_Java8: + OSVmImage: 'windows-2019' + JavaTestVersion: '1.8' + ProfileFlag: '-P integration-test-emulator' + DisplayName: 'Spring Emulator only Integration Tests' + AdditionalArgs: '-DargLine="-DACCOUNT_HOST=https://localhost:8081/ -DACCOUNT_KEY=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== -DSECONDARY_ACCOUNT_KEY=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="' TestStepMavenInputs: goals: 'verify' - options: '$(ProfileFlag) -Dgpg.skip -DargLine="-DACCOUNT_HOST=https://localhost:8081/" -pl $(ProjectList)' + options: '$(ProfileFlag) -Dgpg.skip $(AdditionalArgs) -pl $(ProjectList)' mavenAuthenticateFeed: true jdkVersionOption: $(JavaTestVersion) diff --git a/sdk/appservice/mgmt/src/test/java/com/azure/resourcemanager/appservice/AppServiceTest.java b/sdk/appservice/mgmt/src/test/java/com/azure/resourcemanager/appservice/AppServiceTest.java index 814bc570538f1..a7cfd3991bafd 100644 --- a/sdk/appservice/mgmt/src/test/java/com/azure/resourcemanager/appservice/AppServiceTest.java +++ b/sdk/appservice/mgmt/src/test/java/com/azure/resourcemanager/appservice/AppServiceTest.java @@ -34,11 +34,11 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; -import java.net.URL; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.time.temporal.ChronoUnit; +import com.azure.resourcemanager.resources.fluentcore.utils.Utils; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.junit.jupiter.api.Assertions; @@ -171,7 +171,7 @@ public static void uploadFileToWebApp(PublishingProfile profile, String fileName protected Response curl(String urlString) throws IOException { try { - return stringResponse(httpClient.getString(getHost(urlString), getPathAndQuery(urlString))).block(); + return stringResponse(httpClient.getString(Utils.getHost(urlString), Utils.getPathAndQuery(urlString))).block(); } catch (MalformedURLException e) { Assertions.fail(); return null; @@ -180,7 +180,7 @@ protected Response curl(String urlString) throws IOException { protected String post(String urlString, String body) { try { - return stringResponse(httpClient.postString(getHost(urlString), getPathAndQuery(urlString), body)) + return stringResponse(httpClient.postString(Utils.getHost(urlString), Utils.getPathAndQuery(urlString), body)) .block() .getValue(); } catch (Exception e) { @@ -201,23 +201,6 @@ private static Mono> stringResponse(Mono Mono executeRetry(Callable> callbackMethod, }).retryWhen(RetryUtils.toRetryWhenFunc(retryPolicy)); } + static public Flux fluxExecuteRetry(Callable> callbackMethod, IRetryPolicy retryPolicy) { + + return Flux.defer(() -> { + try { + return callbackMethod.call(); + } catch (Exception e) { + return Flux.error(e); + } + }).retryWhen(RetryUtils.toRetryWhenFunc(retryPolicy)); + } + static public Mono executeAsync( Function, Mono> callbackMethod, IRetryPolicy retryPolicy, Function, Mono> inBackoffAlternateCallbackMethod, diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/InvalidPartitionExceptionRetryPolicy.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/InvalidPartitionExceptionRetryPolicy.java index 4c05f78ed8434..5083b6210aac9 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/InvalidPartitionExceptionRetryPolicy.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/InvalidPartitionExceptionRetryPolicy.java @@ -41,7 +41,9 @@ public InvalidPartitionExceptionRetryPolicy(RxCollectionCache collectionCache, @Override public void onBeforeSendRequest(RxDocumentServiceRequest request) { this.request = request; - this.nextPolicy.onBeforeSendRequest(request); + if (this.nextPolicy != null) { + this.nextPolicy.onBeforeSendRequest(request); + } } @Override @@ -56,7 +58,7 @@ public Mono shouldRetry(Exception e) { // TODO: this is blocking. is that fine? if(this.cosmosQueryRequestOptions != null) { this.clientCollectionCache.refresh( - BridgeInternal.getMetaDataDiagnosticContext(this.request.requestContext.cosmosDiagnostics), + this.request != null ? BridgeInternal.getMetaDataDiagnosticContext(this.request.requestContext.cosmosDiagnostics) : null, collectionLink, ModelBridgeInternal.getPropertiesFromQueryRequestOptions(this.cosmosQueryRequestOptions)); } else { @@ -73,6 +75,9 @@ public Mono shouldRetry(Exception e) { } } - return this.nextPolicy.shouldRetry(e); + if (this.nextPolicy != null) { + return this.nextPolicy.shouldRetry(e); + } + return Mono.just(ShouldRetryResult.error(e)); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ObservableHelper.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ObservableHelper.java index 91309bb3e0b2b..2865eb351370d 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ObservableHelper.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ObservableHelper.java @@ -44,4 +44,21 @@ static public Mono inlineIfPossibleAsObs(Callable> function, IRet return BackoffRetryUtility.executeRetry(() -> function.call(), retryPolicy); } } + + static public Flux fluxInlineIfPossibleAsObs(Callable> function, IRetryPolicy retryPolicy) { + + if (retryPolicy == null) { + // shortcut + return Flux.defer(() -> { + try { + return function.call(); + } catch (Exception e) { + return Flux.error(e); + } + }); + + } else { + return BackoffRetryUtility.fluxExecuteRetry(() -> function.call(), retryPolicy); + } + } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java index 152da0570689c..a004f7ab68bc5 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java @@ -560,18 +560,42 @@ private String parentResourceLinkToQueryLink(String parentResouceLink, ResourceT } private Flux> createQuery( - String parentResourceLink, + String parentResourceLink, + SqlQuerySpec sqlQuery, + CosmosQueryRequestOptions options, + Class klass, + ResourceType resourceTypeEnum) { + + String resourceLink = parentResourceLinkToQueryLink(parentResourceLink, resourceTypeEnum); + UUID activityId = Utils.randomUUID(); + IDocumentQueryClient queryClient = documentQueryClientImpl(RxDocumentClientImpl.this); + + // Trying to put this logic as low as the query pipeline + // Since for parallelQuery, each partition will have its own request, so at this point, there will be no request associate with this retry policy. + // For default document context, it already wired up InvalidPartitionExceptionRetry, but there is no harm to wire it again here + InvalidPartitionExceptionRetryPolicy invalidPartitionExceptionRetryPolicy = new InvalidPartitionExceptionRetryPolicy( + this.collectionCache, + null, + resourceLink, + options); + + return ObservableHelper.fluxInlineIfPossibleAsObs( + () -> createQueryInternal(resourceLink, sqlQuery, options, klass, resourceTypeEnum, queryClient, activityId), + invalidPartitionExceptionRetryPolicy); + } + + private Flux> createQueryInternal( + String resourceLink, SqlQuerySpec sqlQuery, CosmosQueryRequestOptions options, Class klass, - ResourceType resourceTypeEnum) { + ResourceType resourceTypeEnum, + IDocumentQueryClient queryClient, + UUID activityId) { - String queryResourceLink = parentResourceLinkToQueryLink(parentResourceLink, resourceTypeEnum); - - UUID activityId = Utils.randomUUID(); - IDocumentQueryClient queryClient = documentQueryClientImpl(RxDocumentClientImpl.this); Flux> executionContext = - DocumentQueryExecutionContextFactory.createDocumentQueryExecutionContextAsync(queryClient, resourceTypeEnum, klass, sqlQuery , options, queryResourceLink, false, activityId); + DocumentQueryExecutionContextFactory.createDocumentQueryExecutionContextAsync(queryClient, resourceTypeEnum, klass, sqlQuery , options, resourceLink, false, activityId); + return executionContext.flatMap(iDocumentQueryExecutionContext -> { QueryInfo queryInfo = null; if (iDocumentQueryExecutionContext instanceof PipelinedDocumentQueryExecutionContext) { diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/AzureKeyCredentialTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/AzureKeyCredentialTest.java index 9e161fe0662e5..e8c80957fa06f 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/AzureKeyCredentialTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/AzureKeyCredentialTest.java @@ -1,25 +1,24 @@ package com.azure.cosmos; -import com.azure.cosmos.implementation.InternalObjectNode; import com.azure.cosmos.implementation.FailureValidator; +import com.azure.cosmos.implementation.InternalObjectNode; import com.azure.cosmos.implementation.RetryAnalyzer; -import com.azure.cosmos.models.CosmosContainerResponse; -import com.azure.cosmos.models.CosmosDatabaseResponse; -import com.azure.cosmos.models.CosmosItemResponse; +import com.azure.cosmos.implementation.TestConfigurations; import com.azure.cosmos.models.CosmosContainerProperties; import com.azure.cosmos.models.CosmosContainerRequestOptions; +import com.azure.cosmos.models.CosmosContainerResponse; import com.azure.cosmos.models.CosmosDatabaseProperties; import com.azure.cosmos.models.CosmosDatabaseRequestOptions; +import com.azure.cosmos.models.CosmosDatabaseResponse; import com.azure.cosmos.models.CosmosItemRequestOptions; +import com.azure.cosmos.models.CosmosItemResponse; import com.azure.cosmos.models.CosmosResponse; import com.azure.cosmos.models.IndexingMode; import com.azure.cosmos.models.IndexingPolicy; import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.models.PartitionKey; -import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.rx.CosmosItemResponseValidator; import com.azure.cosmos.rx.TestSuiteBase; -import com.azure.cosmos.implementation.TestConfigurations; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; @@ -65,17 +64,6 @@ public Object[][] crudArgProvider() { }; } - private CosmosContainerProperties getCollectionDefinition(String collectionName) { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList<>(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - - return new CosmosContainerProperties( - collectionName, - partitionKeyDef); - } - private InternalObjectNode getDocumentDefinition(String documentId) { final String uuid = UUID.randomUUID().toString(); return new InternalObjectNode(String.format("{ " diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosContainerContentResponseOnWriteTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosContainerContentResponseOnWriteTest.java index efaab4cdf95f7..c9c473d7ae75f 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosContainerContentResponseOnWriteTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosContainerContentResponseOnWriteTest.java @@ -11,14 +11,12 @@ import com.azure.cosmos.models.CosmosContainerResponse; import com.azure.cosmos.models.IndexingMode; import com.azure.cosmos.models.IndexingPolicy; -import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.rx.TestSuiteBase; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Factory; import org.testng.annotations.Test; -import java.util.ArrayList; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; @@ -102,17 +100,6 @@ public void replaceContainer_withContentResponseOnWriteDisabled() throws Excepti } - private CosmosContainerProperties getCollectionDefinition(String collectionName) { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - - return new CosmosContainerProperties( - collectionName, - partitionKeyDef); - } - private void validateContainerResponse(CosmosContainerProperties containerProperties, CosmosContainerResponse createResponse) { // Basic validation diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosContainerTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosContainerTest.java index 65970732ce53c..39c7f7f9d1292 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosContainerTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosContainerTest.java @@ -6,17 +6,16 @@ package com.azure.cosmos; +import com.azure.cosmos.implementation.HttpConstants; import com.azure.cosmos.models.CosmosContainerProperties; import com.azure.cosmos.models.CosmosContainerRequestOptions; import com.azure.cosmos.models.CosmosContainerResponse; import com.azure.cosmos.models.CosmosQueryRequestOptions; import com.azure.cosmos.models.IndexingMode; import com.azure.cosmos.models.IndexingPolicy; -import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.models.SqlQuerySpec; import com.azure.cosmos.models.ThroughputProperties; import com.azure.cosmos.rx.TestSuiteBase; -import com.azure.cosmos.implementation.HttpConstants; import com.azure.cosmos.util.CosmosPagedIterable; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -24,7 +23,6 @@ import org.testng.annotations.Factory; import org.testng.annotations.Test; -import java.util.ArrayList; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; @@ -53,19 +51,6 @@ public void afterClass() { safeCloseSyncClient(client); } - private CosmosContainerProperties getCollectionDefinition(String collectionName) { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - - CosmosContainerProperties collectionDefinition = new CosmosContainerProperties( - collectionName, - partitionKeyDef); - - return collectionDefinition; - } - @Test(groups = { "emulator" }, timeOut = TIMEOUT) public void createContainer_withProperties() throws Exception { String collectionName = UUID.randomUUID().toString(); diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosItemContentResponseOnWriteTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosItemContentResponseOnWriteTest.java index 767d96aafc4c7..e4d0b96e2174e 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosItemContentResponseOnWriteTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosItemContentResponseOnWriteTest.java @@ -7,19 +7,16 @@ package com.azure.cosmos; import com.azure.cosmos.implementation.InternalObjectNode; -import com.azure.cosmos.models.CosmosContainerProperties; import com.azure.cosmos.models.CosmosItemRequestOptions; import com.azure.cosmos.models.CosmosItemResponse; import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.models.PartitionKey; -import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.rx.TestSuiteBase; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Factory; import org.testng.annotations.Test; -import java.util.ArrayList; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; @@ -106,17 +103,6 @@ public void deleteItem_withContentResponseOnWriteDisabled() throws Exception { validateMinimalItemResponse(properties, deleteResponse, false); } - private CosmosContainerProperties getCollectionDefinition(String collectionName) { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - - return new CosmosContainerProperties( - collectionName, - partitionKeyDef); - } - private InternalObjectNode getDocumentDefinition(String documentId) { final String uuid = UUID.randomUUID().toString(); final InternalObjectNode properties = diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/CollectionCrudTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/CollectionCrudTest.java index f2d660ce53ca2..1b05b05355b7d 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/CollectionCrudTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/CollectionCrudTest.java @@ -70,19 +70,6 @@ public Object[][] collectionCrudArgProvider() { }; } - private CosmosContainerProperties getCollectionDefinition(String collectionName) { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - - CosmosContainerProperties collectionDefinition = new CosmosContainerProperties( - collectionName, - partitionKeyDef); - - return collectionDefinition; - } - @Test(groups = { "emulator" }, timeOut = TIMEOUT, dataProvider = "collectionCrudArgProvider") public void createCollection(String collectionName) throws InterruptedException { CosmosContainerProperties collectionDefinition = getCollectionDefinition(collectionName); diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ContainerCreateDeleteWithSameNameTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ContainerCreateDeleteWithSameNameTest.java new file mode 100644 index 0000000000000..24380fcdb4f3a --- /dev/null +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ContainerCreateDeleteWithSameNameTest.java @@ -0,0 +1,354 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.cosmos.rx; + +import com.azure.cosmos.ChangeFeedProcessor; +import com.azure.cosmos.ChangeFeedProcessorBuilder; +import com.azure.cosmos.CosmosAsyncClient; +import com.azure.cosmos.CosmosAsyncContainer; +import com.azure.cosmos.CosmosAsyncDatabase; +import com.azure.cosmos.CosmosClientBuilder; +import com.azure.cosmos.implementation.FeedResponseListValidator; +import com.azure.cosmos.implementation.Utils; +import com.azure.cosmos.models.ChangeFeedProcessorOptions; +import com.azure.cosmos.models.CosmosContainerProperties; +import com.azure.cosmos.models.CosmosContainerRequestOptions; +import com.azure.cosmos.models.CosmosItemRequestOptions; +import com.azure.cosmos.models.CosmosItemResponse; +import com.azure.cosmos.models.CosmosQueryRequestOptions; +import com.azure.cosmos.models.PartitionKey; +import com.azure.cosmos.util.CosmosPagedFlux; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.RandomStringUtils; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Factory; +import org.testng.annotations.Test; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ContainerCreateDeleteWithSameNameTest extends TestSuiteBase { + private final static int TIMEOUT = 300000; + // Delete collections in emulator is not instant, + // so to avoid get 500 back, we are adding delay for creating the collection with same name, since in this case we want to test 410/1000 + private final static int COLLECTION_RECREATION_TIME_DELAY = 2000; + private CosmosAsyncClient client; + private CosmosAsyncDatabase createdDatabase; + + @Factory(dataProvider = "clientBuildersWithSessionConsistency") + public ContainerCreateDeleteWithSameNameTest(CosmosClientBuilder clientBuilder) { + super(clientBuilder); + this.subscriberValidationTimeout = TIMEOUT; + } + + @Test(groups = {"emulator"}, timeOut = TIMEOUT) + public void query() throws Exception { + String query = "SELECT * FROM r"; + + Consumer func = (container) -> { + TestObject docDefinition = getDocumentDefinition(); + container.createItem(docDefinition).block(); + + CosmosQueryRequestOptions requestOptions = new CosmosQueryRequestOptions(); + CosmosPagedFlux queryFlux = container.queryItems(query, requestOptions, TestObject.class); + FeedResponseListValidator queryValidator = new FeedResponseListValidator.Builder() + .totalSize(1) + .numberOfPages(1) + .build(); + validateQuerySuccess(queryFlux.byPage(10), queryValidator); + }; + + createDeleteContainerWithSameName(func); + } + + @Test(groups = {"emulator"}, timeOut = TIMEOUT) + public void readItem() throws Exception { + + Consumer func = (container) -> { + TestObject docDefinition = getDocumentDefinition(); + container.createItem(docDefinition).block(); + + Mono> responseMono = container.readItem(docDefinition.getId(), + new PartitionKey(docDefinition.getMypk()), + new CosmosItemRequestOptions(), + TestObject.class); + + CosmosItemResponseValidator validator = + new CosmosItemResponseValidator.Builder>() + .withId(docDefinition.getId()) + .build(); + + this.validateItemSuccess(responseMono, validator); + }; + + createDeleteContainerWithSameName(func); + } + + @Test(groups = {"emulator"}, timeOut = TIMEOUT) + public void deleteItem() throws Exception { + + Consumer func = (container) -> { + TestObject docDefinition = getDocumentDefinition(); + container.createItem(docDefinition).block(); + + Mono> deleteObservable = container.deleteItem( + docDefinition.getId(), + new PartitionKey(docDefinition.getMypk()), + new CosmosItemRequestOptions()); + + CosmosItemResponseValidator validator = + new CosmosItemResponseValidator.Builder>() + .nullResource() + .build(); + this.validateItemSuccess(deleteObservable, validator); + }; + + createDeleteContainerWithSameName(func); + } + + @Test(groups = {"emulator"}, timeOut = TIMEOUT) + public void upsertItem() throws Exception { + + Consumer func = (container) -> { + TestObject docDefinition = getDocumentDefinition(); + docDefinition = container.createItem(docDefinition).block().getItem(); + + docDefinition.setProp(UUID.randomUUID().toString()); + + Mono> readObservable = container.upsertItem(docDefinition, new CosmosItemRequestOptions()); + + // Validate result + CosmosItemResponseValidator validator = + new CosmosItemResponseValidator.Builder>() + .withProperty("prop", docDefinition.getProp()) + .build(); + + this.validateItemSuccess(readObservable, validator); + }; + + createDeleteContainerWithSameName(func); + } + + @Test(groups = {"emulator"}, timeOut = TIMEOUT) + public void changeFeed() throws Exception { + + ObjectMapper objectMapper = Utils.getSimpleObjectMapper(); + BiConsumer func = (feedContainer, leaseContainer) -> { + String hostName = RandomStringUtils.randomAlphabetic(6); + int CHANGE_FEED_PROCESSOR_TIMEOUT = 5000; + final int FEED_COUNT = 5; + List createdDocuments = new ArrayList<>(); + Map receivedDocuments = new ConcurrentHashMap<>(); + + setupReadFeedDocuments(createdDocuments, feedContainer, FEED_COUNT); + + ChangeFeedProcessor changeFeedProcessor = new ChangeFeedProcessorBuilder() + .hostName(hostName) + .handleChanges((docs) -> { + for (JsonNode item : docs) { + try { + TestObject obj = objectMapper.treeToValue(item, TestObject.class); + receivedDocuments.put(obj.getId(), obj); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + } + }) + .feedContainer(feedContainer) + .leaseContainer(leaseContainer) + .options(new ChangeFeedProcessorOptions() + .setLeaseRenewInterval(Duration.ofSeconds(20)) + .setLeaseAcquireInterval(Duration.ofSeconds(10)) + .setLeaseExpirationInterval(Duration.ofSeconds(30)) + .setFeedPollDelay(Duration.ofSeconds(2)) + .setLeasePrefix("TEST") + .setMaxItemCount(10) + .setStartFromBeginning(true) + .setMaxScaleCount(0) // unlimited + ) + .buildChangeFeedProcessor(); + + try { + changeFeedProcessor.start().subscribeOn(Schedulers.elastic()) + .timeout(Duration.ofMillis(2 * CHANGE_FEED_PROCESSOR_TIMEOUT)) + .subscribe(); + } catch (Exception ex) { + throw ex; + } + + // Wait for the feed processor to receive and process the documents. + try { + Thread.sleep(2 * CHANGE_FEED_PROCESSOR_TIMEOUT); + assertThat(changeFeedProcessor.isStarted()).as("Change Feed Processor instance is running").isTrue(); + + long remainingWork = 2 * CHANGE_FEED_PROCESSOR_TIMEOUT; + while (remainingWork > 0 && receivedDocuments.size() < createdDocuments.size()) { + remainingWork -= 100; + Thread.sleep(100); + } + + assertThat(remainingWork >= 0).as("Failed to receive all the feed documents").isTrue(); + + changeFeedProcessor.stop().subscribeOn(Schedulers.elastic()).timeout(Duration.ofMillis(CHANGE_FEED_PROCESSOR_TIMEOUT)).subscribe(); + + // Wait for the feed processor to shutdown. + Thread.sleep(CHANGE_FEED_PROCESSOR_TIMEOUT); + + } catch (InterruptedException e) { + throw new RuntimeException("Interrupted exception", e); + } + }; + + changeFeedCreateDeleteContainerWithSameName(func); + } + + @BeforeClass(groups = {"emulator"}, timeOut = SETUP_TIMEOUT) + public void before_ContainerCreateDeleteWithSameNameTest() throws Exception { + client = getClientBuilder().buildAsyncClient(); + createdDatabase = getSharedCosmosDatabase(client); + } + + @AfterClass(groups = {"emulator"}, timeOut = SETUP_TIMEOUT) + public void after_ContainerCreateDeleteWithSameNameTest() throws Exception { + safeDeleteAllCollections(createdDatabase); + } + + private void createDeleteContainerWithSameName(Consumer validateFunc) throws InterruptedException { + CosmosAsyncContainer container = null; + try { + // step1: create container + String testContainerId = UUID.randomUUID().toString(); + CosmosContainerProperties containerProperties = getCollectionDefinition(testContainerId); + container = createCollection(this.createdDatabase, containerProperties, new CosmosContainerRequestOptions()); + + // Step2: execute func + validateFunc.accept(container); + + // step3: delete the container + safeDeleteCollection(container); + Thread.sleep(COLLECTION_RECREATION_TIME_DELAY); + + // step4: recreate the container with same id as step1 + container = createCollection(this.createdDatabase, containerProperties, new CosmosContainerRequestOptions()); + + // step5: same as step2. + // This part will confirm the cache refreshed correctly + validateFunc.accept(container); + } finally { + safeDeleteCollection(container); + } + } + + private void changeFeedCreateDeleteContainerWithSameName(BiConsumer validateFunc) throws InterruptedException { + CosmosAsyncContainer feedContainer = null; + CosmosAsyncContainer leaseContainer = null; + + try { + // step1: create feed container and lease container + String feedContainerId = UUID.randomUUID().toString(); + CosmosContainerProperties feedContainerProperties = getCollectionDefinition(feedContainerId); + feedContainer = createCollection(this.createdDatabase, feedContainerProperties, new CosmosContainerRequestOptions()); + + String leaseContainerId = UUID.randomUUID().toString(); + CosmosContainerProperties leaseContainerProperties = getCollectionDefinition(leaseContainerId); + leaseContainer = createLeaseContainer(leaseContainerProperties.getId()); + + // Step2: execute func + validateFunc.accept(feedContainer, leaseContainer); + + // step3: delete the lease container + safeDeleteCollection(leaseContainer); + truncateCollection(feedContainer); + Thread.sleep(COLLECTION_RECREATION_TIME_DELAY); + + // step4: recreate the lease container and lease container with same ids as step1 + leaseContainer = createLeaseContainer(leaseContainerProperties.getId()); + + // step5: same as step2. + // This part will confirm the cache refreshed correctly + validateFunc.accept(feedContainer, leaseContainer); + } finally { + safeDeleteCollection(feedContainer); + safeDeleteCollection(leaseContainer); + } + } + + private static TestObject getDocumentDefinition() { + return new TestObject( + UUID.randomUUID().toString(), + UUID.randomUUID().toString(), + UUID.randomUUID().toString() + ); + } + + private void setupReadFeedDocuments(List createdDocuments, CosmosAsyncContainer feedContainer, long count) { + List docDefList = new ArrayList<>(); + + for (int i = 0; i < count; i++) { + docDefList.add(getDocumentDefinition()); + } + + createdDocuments.addAll(bulkInsertBlocking(feedContainer, docDefList)); + waitIfNeededForReplicasToCatchUp(getClientBuilder()); + } + + private CosmosAsyncContainer createLeaseContainer(String conatinerId) { + CosmosContainerRequestOptions options = new CosmosContainerRequestOptions(); + CosmosContainerProperties collectionDefinition = new CosmosContainerProperties(conatinerId, "/id"); + return createCollection(createdDatabase, collectionDefinition, options); + } + + static class TestObject { + String id; + String mypk; + String prop; + + public TestObject() { + } + + public TestObject(String id, String mypk, String prop) { + this.id = id; + this.mypk = mypk; + this.prop = prop; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getMypk() { + return mypk; + } + + public void setMypk(String mypk) { + this.mypk = mypk; + } + + public String getProp() { + return prop; + } + + public void setProp(String prop) { + this.prop = prop; + } + } +} diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/CollectionQueryTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ContainerQueryTest.java similarity index 67% rename from sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/CollectionQueryTest.java rename to sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ContainerQueryTest.java index 1349df5d905b4..2e2fb261377e3 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/CollectionQueryTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/ContainerQueryTest.java @@ -6,11 +6,12 @@ import com.azure.cosmos.CosmosAsyncContainer; import com.azure.cosmos.CosmosAsyncDatabase; import com.azure.cosmos.CosmosClientBuilder; +import com.azure.cosmos.implementation.InternalObjectNode; import com.azure.cosmos.models.CosmosContainerProperties; +import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.util.CosmosPagedFlux; import com.azure.cosmos.CosmosDatabaseForTest; import com.azure.cosmos.models.CosmosQueryRequestOptions; -import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.implementation.FeedResponseListValidator; import com.azure.cosmos.implementation.FeedResponseValidator; import org.apache.commons.lang3.StringUtils; @@ -26,39 +27,39 @@ import static org.assertj.core.api.Assertions.assertThat; -public class CollectionQueryTest extends TestSuiteBase { +public class ContainerQueryTest extends TestSuiteBase { private final static int TIMEOUT = 30000; private final String databaseId = CosmosDatabaseForTest.generateId(); - private List createdCollections = new ArrayList<>(); + private List createdContainers = new ArrayList<>(); private CosmosAsyncClient client; private CosmosAsyncDatabase createdDatabase; @Factory(dataProvider = "clientBuilders") - public CollectionQueryTest(CosmosClientBuilder clientBuilder) { + public ContainerQueryTest(CosmosClientBuilder clientBuilder) { super(clientBuilder); this.subscriberValidationTimeout = TIMEOUT; } @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryCollectionsWithFilter() throws Exception { + public void queryContainersWithFilter() throws Exception { - String filterCollectionId = createdCollections.get(0).getId(); - String query = String.format("SELECT * from c where c.id = '%s'", filterCollectionId); + String filterContainerId = createdContainers.get(0).getId(); + String query = String.format("SELECT * from c where c.id = '%s'", filterContainerId); CosmosQueryRequestOptions options = new CosmosQueryRequestOptions(); int maxItemCount = 2; CosmosPagedFlux queryObservable = createdDatabase.queryContainers(query, options); - List expectedCollections = createdCollections.stream() - .filter(c -> StringUtils.equals(filterCollectionId, c.getId()) ).collect(Collectors.toList()); + List expectedContainers = createdContainers.stream() + .filter(c -> StringUtils.equals(filterContainerId, c.getId()) ).collect(Collectors.toList()); - assertThat(expectedCollections).isNotEmpty(); + assertThat(expectedContainers).isNotEmpty(); - int expectedPageSize = (expectedCollections.size() + maxItemCount - 1) / maxItemCount; + int expectedPageSize = (expectedContainers.size() + maxItemCount - 1) / maxItemCount; FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedCollections.size()) - .exactlyContainsInAnyOrder(expectedCollections.stream().map(d -> d.read().block().getProperties().getResourceId()).collect(Collectors.toList())) + .totalSize(expectedContainers.size()) + .exactlyContainsInAnyOrder(expectedContainers.stream().map(d -> d.read().block().getProperties().getResourceId()).collect(Collectors.toList())) .numberOfPages(expectedPageSize) .pageSatisfy(0, new FeedResponseValidator.Builder() .requestChargeGreaterThanOrEqualTo(1.0).build()) @@ -68,7 +69,7 @@ public void queryCollectionsWithFilter() throws Exception { } @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryAllCollections() throws Exception { + public void queryAllContainers() throws Exception { String query = "SELECT * from c"; @@ -76,15 +77,15 @@ public void queryAllCollections() throws Exception { int maxItemCount = 2; CosmosPagedFlux queryObservable = createdDatabase.queryContainers(query, options); - List expectedCollections = createdCollections; + List expectedContainers = createdContainers; - assertThat(expectedCollections).isNotEmpty(); + assertThat(expectedContainers).isNotEmpty(); - int expectedPageSize = (expectedCollections.size() + maxItemCount - 1) / maxItemCount; + int expectedPageSize = (expectedContainers.size() + maxItemCount - 1) / maxItemCount; FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedCollections.size()) - .exactlyContainsInAnyOrder(expectedCollections.stream().map(d -> d.read().block().getProperties().getResourceId()).collect(Collectors.toList())) + .totalSize(expectedContainers.size()) + .exactlyContainsInAnyOrder(expectedContainers.stream().map(d -> d.read().block().getProperties().getResourceId()).collect(Collectors.toList())) .numberOfPages(expectedPageSize) .pageSatisfy(0, new FeedResponseValidator.Builder() .requestChargeGreaterThanOrEqualTo(1.0).build()) @@ -94,7 +95,7 @@ public void queryAllCollections() throws Exception { } @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryCollections_NoResults() throws Exception { + public void queryContainers_NoResults() throws Exception { String query = "SELECT * from root r where r.id = '2'"; CosmosQueryRequestOptions options = new CosmosQueryRequestOptions(); @@ -110,7 +111,7 @@ public void queryCollections_NoResults() throws Exception { } @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void before_CollectionQueryTest() throws Exception { + public void before_ContainerQueryTest() throws Exception { client = getClientBuilder().buildAsyncClient(); createdDatabase = createDatabase(client, databaseId); @@ -119,8 +120,8 @@ public void before_CollectionQueryTest() throws Exception { paths.add("/mypk"); partitionKeyDef.setPaths(paths); - CosmosContainerProperties collection = new CosmosContainerProperties(UUID.randomUUID().toString(), partitionKeyDef); - createdCollections.add(createCollection(client, databaseId, collection)); + CosmosContainerProperties container = new CosmosContainerProperties(UUID.randomUUID().toString(), partitionKeyDef); + createdContainers.add(createCollection(client, databaseId, container)); } @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) @@ -128,4 +129,14 @@ public void afterClass() { safeDeleteDatabase(createdDatabase); safeClose(client); } + + private static InternalObjectNode getDocumentDefinition() { + String uuid = UUID.randomUUID().toString(); + InternalObjectNode doc = new InternalObjectNode(String.format("{ " + + "\"id\": \"%s\", " + + "\"mypk\": \"%s\", " + + "}" + , uuid, uuid)); + return doc; + } } diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java index dead021f8e7e9..a5e0e0682e933 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java @@ -516,12 +516,16 @@ private static CosmosAsyncContainer safeCreateCollection(CosmosAsyncClient clien } static protected CosmosContainerProperties getCollectionDefinition() { + return getCollectionDefinition(UUID.randomUUID().toString()); + } + + static protected CosmosContainerProperties getCollectionDefinition(String collectionId) { PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); + ArrayList paths = new ArrayList<>(); paths.add("/mypk"); partitionKeyDef.setPaths(paths); - CosmosContainerProperties collectionDefinition = new CosmosContainerProperties(UUID.randomUUID().toString(), partitionKeyDef); + CosmosContainerProperties collectionDefinition = new CosmosContainerProperties(collectionId, partitionKeyDef); return collectionDefinition; } diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/Contributing.md b/sdk/cosmos/azure-spring-data-cosmosdb/Contributing.md new file mode 100644 index 0000000000000..b22da7d47c965 --- /dev/null +++ b/sdk/cosmos/azure-spring-data-cosmosdb/Contributing.md @@ -0,0 +1,62 @@ +# Contributing +This instruction is guideline for building and code contribution. + +## Prequisites +- JDK 1.8 and above +- [Maven](http://maven.apache.org/) 3.0 and above + +## Build from source +To build the project, run maven commands. + +```bash +git clone https://github.com/Azure/azure-sdk-for-java.git +cd sdk/cosmos/azure-spring-data-cosmosdb +mvnw clean install +``` + +## Test +There're integration tests on azure and on emulator to trigger integration test execution against Azure Cosmos DB and against [Azure Cosmos DB Emulator](https://docs.microsoft.com/azure/cosmos-db/local-emulator), you need to follow the link to setup emulator before test execution. + +- Run unit tests +```bash +mvnw clean install +``` + +- Run integration tests + - on Azure + >**NOTE** Please note that integration test against Azure requires Azure Cosmos DB Document API and will automatically create a Cosmos database in your Azure subscription, then there will be **Azure usage fee.** + + Integration tests will require a Azure Subscription. If you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits](https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/) or sign up for a [free Azure account](https://azure.microsoft.com/free/). + + 1. Create an Azure Cosmos DB on Azure. + - Go to [Azure portal](https://portal.azure.com/) and click +New. + - Click Databases, and then click Azure Cosmos DB to create your database. + - Navigate to the database you have created, and click Access keys and copy your URI and access keys for your database. + + 2. Set environment variables ACCOUNT_HOST, ACCOUNT_KEY and SECONDARY_ACCOUNT_KEY, where value of them are Cosmos account URI, primary key and secondary key. + 3. Run maven command with `integration-test-azure` profile. + + ```bash + set ACCOUNT_HOST=your-cosmos-account-uri + set ACCOUNT_KEY=your-cosmos-account-primary-key + set SECONDARY_ACCOUNT_KEY=your-cosmos-account-secondary-key + mvnw -P integration-test-azure clean install + ``` + - on Emulator + + Setup Azure Cosmos DB Emulator by following [this instruction](https://docs.microsoft.com/azure/cosmos-db/local-emulator), and set associated environment variables. Then run test with: + ```bash + mvnw -P integration-test-emulator install + ``` + + +- Skip tests execution +```bash +mvnw clean install -DskipTests +``` + +## Version management +Developing version naming convention is like `0.1.2-beta.1`. Release version naming convention is like `0.1.2`. + +## Contribute to code +Contribution is welcome. Please follow [this instruction](https://github.com/Azure/azure-sdk-for-java/blob/master/CONTRIBUTING.md) to contribute code. diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/README.md b/sdk/cosmos/azure-spring-data-cosmosdb/README.md index c181d5b5ff53b..c6e8f26a27727 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/README.md +++ b/sdk/cosmos/azure-spring-data-cosmosdb/README.md @@ -1,342 +1,25 @@ -[![Travis CI](https://travis-ci.org/Microsoft/spring-data-cosmosdb.svg?branch=master)](https://travis-ci.org/Microsoft/spring-data-cosmosdb) -[![codecov](https://codecov.io/gh/Microsoft/spring-data-cosmosdb/branch/master/graph/badge.svg)](https://codecov.io/gh/Microsoft/spring-data-cosmosdb) -[![MIT License](http://img.shields.io/badge/license-MIT-green.svg) ](https://github.com/Microsoft/spring-data-cosmosdb/blob/master/LICENSE) - - #Azure Cosmos DB client library for Java ## Getting started -[Azure Cosmos DB](https://docs.microsoft.com/en-us/azure/cosmos-db/introduction) is a globally-distributed database service that allows developers to work with data using a variety of standard APIs, such as SQL, MongoDB, Cassandra, Graph, and Table. - -**Spring Data Azure Cosmos DB** provides initial Spring Data support for Azure Cosmos DB using the [SQL API](https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-introduction), based on Spring Data framework. Currently it only supports SQL API, the other APIs are in the plan. ## TOC -* [Examples](#Examples) -* [Spring data version support](#spring-data-version-support) -* [Feature List](#feature-list) -* [Quick Start](#quick-start) -* [Query Partitioned Collection](QueryPartitionedCollection.md) -* [Snapshots](#snapshots) -* [Troubleshooting](#Troubleshooting) -* [Contributing](#Contributing) -* [Code of Conduct](#code-of-conduct) -* [Key concepts](#Key concepts) -* [Next steps](#Next steps) - ## Examples -Please refer to [sample project here](./samplecode). ## Spring Data Version Support -Version mapping between spring boot and spring-data-cosmosdb: - -| Spring boot version | spring-data-cosmosdb version | -| :----------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| -| ![version](https://img.shields.io/badge/version-2.3.x-blue) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/spring-data-cosmosdb/2.3.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:spring-data-cosmosdb%20AND%20v:2.3.*) | -| ![version](https://img.shields.io/badge/version-2.2.x-blue) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/spring-data-cosmosdb/2.2.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:spring-data-cosmosdb%20AND%20v:2.2.*) | -| ![version](https://img.shields.io/badge/version-2.1.x-blue) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/spring-data-cosmosdb/2.1.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:spring-data-cosmosdb%20AND%20v:2.1.*) | -| ![version](https://img.shields.io/badge/version-2.0.x-blue) | [![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/spring-data-cosmosdb/2.0.svg)](https://search.maven.org/search?q=g:com.microsoft.azure%20AND%20a:spring-data-cosmosdb%20AND%20v:2.0.*) | ## Feature List -- Spring Data ReactiveCrudRepository CrudRepository basic CRUD functionality - - save - - findAll - - findOne by Id - - deleteAll - - delete by Id - - delete entity -- Spring Data [@Id](https://github.com/spring-projects/spring-data-commons/blob/db62390de90c93a78743c97cc2cc9ccd964994a5/src/main/java/org/springframework/data/annotation/Id.java) annotation. - There're 2 ways to map a field in domain class to `id` field of Azure Cosmos DB document. - - annotate a field in domain class with `@Id`, this field will be mapped to document `id` in Cosmos DB. - - set name of this field to `id`, this field will be mapped to document `id` in Azure Cosmos DB. -- Custom collection Name. - By default, collection name will be class name of user domain class. To customize it, add the `@Document(collection="myCustomCollectionName")` annotation to the domain class. The collection field also supports SpEL expressions (eg. `collection = "${dynamic.collection.name}"` or `collection = "#{@someBean.getContainerName()}"`) in order to provide collection names programmatically/via configuration properties. -- Custom IndexingPolicy - By default, IndexingPolicy will be set by azure service. To customize it add annotation `@DocumentIndexingPolicy` to domain class. This annotation has 4 attributes to customize, see following: -```java - boolean automatic; // Indicate if indexing policy use automatic or not - IndexingMode mode; // Indexing policy mode, option Consistent|Lazy|None. - String[] includePaths; // Included paths for indexing - String[] excludePaths; // Excluded paths for indexing -``` -- Supports Optimistic Locking for specific collections, which means upserts/deletes by document will fail with an exception in case the document was modified by another process in the meanwhile. To enable Optimistic Locking for a collection, just create a string `_etag` field and mark it with the `@Version` annotation. See the following: - -```java -@Document(collection = "myCollection") -class MyDocument { - String id; - String data; - @Version - String _etag; -} -``` -- Supports [Azure Cosmos DB partition](https://docs.microsoft.com/en-us/azure/cosmos-db/partition-data). To specify a field of domain class to be partition key field, just annotate it with `@PartitionKey`. When you do CRUD operation, pls specify your partition value. For more sample on partition CRUD, pls refer to [test here](./src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/AddressRepositoryIT.java) -- Supports [Spring Data custom query](https://docs.spring.io/spring-data/commons/docs/current/reference/html/#repositories.query-methods.details) find operation, e.g., `findByAFieldAndBField` -- Supports [Spring Data pagable and sort](https://docs.spring.io/spring-data/commons/docs/current/reference/html/#repositories.special-parameters). - - Based on available RUs on the database account, cosmosDB can return documents less than or equal to the requested size. - - Due to this variable number of returned documents in every iteration, user should not rely on the totalPageSize, and instead iterating over pageable should be done in this way. -```java - final CosmosPageRequest pageRequest = new CosmosPageRequest(0, pageSize, null); - Page page = tRepository.findAll(pageRequest); - List pageContent = page.getContent(); - while(page.hasNext()) { - Pageable nextPageable = page.nextPageable(); - page = repository.findAll(nextPageable); - pageContent = page.getContent(); - } -``` -- Supports [spring-boot-starter-data-rest](https://projects.spring.io/spring-data-rest/). -- Supports List and nested type in domain class. -- Configurable ObjectMapper bean with unique name `cosmosdbObjectMapper`, only configure customized ObjectMapper if you really need to. e.g., -```java - @Bean(name = "cosmosdbObjectMapper") - public ObjectMapper objectMapper() { - return new ObjectMapper(); // Do configuration to the ObjectMapper if required - } -``` ## Quick Start -### Add the dependency -`spring-data-cosmosdb` is published on Maven Central Repository. -If you are using Maven, add the following dependency. - -```xml - - com.microsoft.azure - spring-data-cosmosdb - 2.2.4 - -``` - -### Setup Configuration -Setup configuration class. - -CosmosKeyCredential feature provides capability to rotate keys on the fly. You can switch keys using switchToSecondaryKey(). -For more information on this, see the Sample Application code. - -### Sync and Reactive Repository support -2.2.x supports both sync and reactive repository support. - -Use `@EnableCosmosRepositories` to enable sync repository support. - -For reactive repository support, use `@EnableReactiveCosmosRepositories` - -### Response Diagnostics String and Query Metrics -2.2.x supports Response Diagnostics String and Query Metrics. -Set `populateQueryMetrics` flag to true in application.properties to enable query metrics. -In addition to setting the flag, implement `ResponseDiagnosticsProcessor` to log diagnostics information. - -```java -@Configuration -@EnableCosmosRepositories -@Slf4j -public class AppConfiguration extends AbstractCosmosConfiguration { - - @Value("${azure.cosmosdb.uri}") - private String uri; - - @Value("${azure.cosmosdb.key}") - private String key; - - @Value("${azure.cosmosdb.secondaryKey}") - private String secondaryKey; - - @Value("${azure.cosmosdb.database}") - private String dbName; - - @Value("${azure.cosmosdb.populateQueryMetrics}") - private boolean populateQueryMetrics; - - private CosmosKeyCredential cosmosKeyCredential; - - public CosmosDBConfig getConfig() { - this.cosmosKeyCredential = new CosmosKeyCredential(key); - CosmosDbConfig cosmosdbConfig = CosmosDBConfig.builder(uri, - this.cosmosKeyCredential, dbName).build(); - cosmosdbConfig.setPopulateQueryMetrics(populateQueryMetrics); - cosmosdbConfig.setResponseDiagnosticsProcessor(new ResponseDiagnosticsProcessorImplementation()); - return cosmosdbConfig; - } - - public void switchToSecondaryKey() { - this.cosmosKeyCredential.key(secondaryKey); - } - - private static class ResponseDiagnosticsProcessorImplementation implements ResponseDiagnosticsProcessor { - - @Override - public void processResponseDiagnostics(@Nullable ResponseDiagnostics responseDiagnostics) { - log.info("Response Diagnostics {}", responseDiagnostics); - } - } - -} -``` -Or if you want to customize your config: -```java -public CosmosDBConfig getConfig() { - this.cosmosKeyCredential = new CosmosKeyCredential(key); - CosmosDBConfig cosmosDbConfig = CosmosDBConfig.builder(uri, this.cosmosKeyCredential, dbName).build(); - cosmosDbConfig.getConnectionPolicy().setConnectionMode(ConnectionMode.DIRECT); - cosmosDbConfig.getConnectionPolicy().setMaxPoolSize(1000); - return cosmosDbConfig; -} -``` -By default, `@EnableCosmosRepositories` will scan the current package for any interfaces that extend one of Spring Data's repository interfaces. Using it to annotate your Configuration class to scan a different root package by type if your project layout has multiple projects and it's not finding your repositories. -```java -@Configuration -@EnableCosmosRepositories(basePackageClass=UserRepository.class) -public class AppConfiguration extends AbstractCosmosConfiguration { - // configuration code -} -``` - - -### Define an entity -Define a simple entity as Document in Azure Cosmos DB. - -You can define entities by adding the `@Document` annotation and specifying properties related to the container, such as the container name, request units (RUs), time to live, and auto-create container. - -Containers are created automatically unless you don't want them to: Set `autoCreateCollection` to false in `@Document` annotation to disable auto creation of containers. - -Note: By default request units assigned to newly created containers is 4000. Specify different ru value to customize request units for container created by the SDK (minimum RU value is 400). - -```java -@Document(collection = "myCollection", ru = "400") -public class User { - private String id; - private String firstName; - - @PartitionKey - private String lastName; - - ... // setters and getters - - public User() { - // If you do not want to create a default constructor, - // use annotation @JsonCreator and @JsonProperty in the full args constructor - } - - public User(String id, String firstName, String lastName) { - this.id = id; - this.firstName = firstName; - this.lastName = lastName; - } - - @Override - public String toString() { - return String.format("User: %s %s, %s", firstName, lastName, id); - } -} -``` -`id` field will be used as document id in Azure Cosmos DB. If you want use another field like `emailAddress` as document `id`, just annotate that field with `@Id` annotation. - -Annotation `@Document(collection="mycollection")` is used to specify collection name in Azure Cosmos DB. -Annotation `@PartitionKey` on `lastName` field is used to specify this field be partition key in Azure Cosmos DB. - -```java -@Document(collection = "mycollection") -public class User { - @Id - private String emailAddress; - - ... -} -``` - -### Create repositories -Extends CosmosRepository interface, which provides Spring Data repository support. - -```java -import CosmosRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface UserRepository extends CosmosRepository { - List findByFirstName(String firstName); -} -``` - -`findByFirstName` method is custom query method, it will find documents per FirstName. - -### Create an Application class -Here create an application class with all the components - -```java -@SpringBootApplication -public class SampleApplication implements CommandLineRunner { - - @Autowired - private UserRepository repository; - - @Autowired - private ApplicationContext applicationContext; - - public static void main(String[] args) { - SpringApplication.run(SampleApplication.class, args); - } - - public void run(String... var1) throws Exception { - - final User testUser = new User("testId", "testFirstName", "testLastName"); - - repository.deleteAll(); - repository.save(testUser); - - // to find by Id, please specify partition key value if collection is partitioned - final User result = repository.findOne(testUser.getId(), testUser.getLastName); - // if emailAddress is mapped to id, then - // final User result = respository.findOne(testUser.getEmailAddress(), testUser.getLastName()); - - // Switch to secondary key - UserRepositoryConfiguration bean = - applicationContext.getBean(UserRepositoryConfiguration.class); - bean.switchToSecondaryKey(); - - // Now repository will use secondary key - repository.save(testUser); - - } -} -``` -Autowired UserRepository interface, then can do save, delete and find operations. Spring Data Azure Cosmos DB uses the CosmosTemplate to execute the queries behind *find*, *save* methods. You can use the template yourself for more complex queries. - ## Snapshots -[![Nexus OSS](https://img.shields.io/nexus/snapshots/https/oss.sonatype.org/com.microsoft.azure/spring-data-cosmosdb.svg)](https://oss.sonatype.org/content/repositories/snapshots/com/microsoft/azure/spring-data-cosmosdb/) - -Snapshots built from `master` branch are available, add [maven repositories](https://maven.apache.org/settings.html#Repositories) configuration to your pom file as below. -```xml - - - nexus-snapshots - https://oss.sonatype.org/content/repositories/snapshots/ - - true - always - - - -``` ## Troubleshooting -If you encounter any bug, please file an issue [here](https://github.com/Microsoft/spring-data-cosmosdb/issues/new). - -To suggest a new feature or changes that could be made, file an issue the same way you would for a bug. - ## Contributing -Contribution is welcome. Please follow [this instruction](https://github.com/Azure/azure-sdk-for-java/blob/master/CONTRIBUTING.md) to contribute code. - ## Code of Conduct -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. - -### Data/Telemetry - - This project collects usage data and sends it to Microsoft to help improve our products and services. Read our [privacy](https://privacy.microsoft.com/en-us/privacystatement) statement to learn more. - ## Key concepts ## Next steps diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/pom.xml b/sdk/cosmos/azure-spring-data-cosmosdb/pom.xml index c173ad25dd9a9..bd96baf15b134 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/pom.xml +++ b/sdk/cosmos/azure-spring-data-cosmosdb/pom.xml @@ -13,7 +13,7 @@ com.microsoft.azure spring-data-cosmosdb 2.3.1-beta.1 - + jar Spring Data for Azure Cosmos DB SQL API Spring Data for Azure Cosmos DB SQL API https://github.com/Microsoft/spring-data-cosmosdb @@ -213,29 +213,6 @@ - - org.codehaus.mojo - cobertura-maven-plugin - 2.7 - - - html - xml - - - true - 65 - 65 - - - - com/microsoft/azure/**/GetHashMac.class - com/microsoft/azure/**/Constants.class - - - - - org.apache.maven.plugins maven-failsafe-plugin @@ -254,22 +231,72 @@ + org.apache.maven.plugins maven-javadoc-plugin 3.1.1 - private - - BasicCosmosPersistentProperty.java - + com/microsoft/azure/spring/data/cosmosdb/core/mapping/BasicCosmosPersistentProperty.java - ${basedir}/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/ + + + org.projectlombok + lombok + 1.18.6 + + - + + + dev + + true + + + dev + true + false + false + + + + integration-test-azure + + integration-test-azure + false + true + false + + + + integration-test-emulator + + integration-test-emulator + false + false + true + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.22.0 + + + + **/PageablePersonRepositoryIT.java + + + + + + + diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/Constants.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/Constants.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/Constants.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/Constants.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/CosmosDbFactory.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/CosmosDbFactory.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/CosmosDbFactory.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/CosmosDbFactory.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/CosmosdbUtils.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/CosmosdbUtils.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/CosmosdbUtils.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/CosmosdbUtils.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/ExpressionResolver.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/ExpressionResolver.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/ExpressionResolver.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/ExpressionResolver.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/MacAddress.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/MacAddress.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/MacAddress.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/MacAddress.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/Memoizer.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/Memoizer.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/Memoizer.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/Memoizer.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/PropertyLoader.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/PropertyLoader.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/PropertyLoader.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/PropertyLoader.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/TelemetryEventData.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/TelemetryEventData.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/TelemetryEventData.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/TelemetryEventData.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/TelemetrySender.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/TelemetrySender.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/TelemetrySender.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/TelemetrySender.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/common/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/config/AbstractCosmosConfiguration.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/config/AbstractCosmosConfiguration.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/config/AbstractCosmosConfiguration.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/config/AbstractCosmosConfiguration.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/config/CosmosConfigurationSupport.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/config/CosmosConfigurationSupport.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/config/CosmosConfigurationSupport.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/config/CosmosConfigurationSupport.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/config/CosmosDBConfig.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/config/CosmosDBConfig.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/config/CosmosDBConfig.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/config/CosmosDBConfig.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/config/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/config/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/config/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/config/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosOperations.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosOperations.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosOperations.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosOperations.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplate.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplate.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplate.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplate.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosOperations.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosOperations.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosOperations.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosOperations.java index 64bf11e918778..e2320fd6c6792 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosOperations.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosOperations.java @@ -28,7 +28,7 @@ public interface ReactiveCosmosOperations { * Use createContainerIfNotExists() instead * @param information cosmos entity information * @return Mono of cosmos container response - * @deprecated use createContainerIfNotExists(CosmosEntityInformation) instead. + * @deprecated use {@link #createContainerIfNotExists(CosmosEntityInformation)} instead. */ @Deprecated Mono createCollectionIfNotExists(CosmosEntityInformation information); diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosTemplate.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosTemplate.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosTemplate.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosTemplate.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/ResponseDiagnostics.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/ResponseDiagnostics.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/ResponseDiagnostics.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/ResponseDiagnostics.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/ResponseDiagnosticsProcessor.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/ResponseDiagnosticsProcessor.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/ResponseDiagnosticsProcessor.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/ResponseDiagnosticsProcessor.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/convert/MappingCosmosConverter.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/convert/MappingCosmosConverter.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/convert/MappingCosmosConverter.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/convert/MappingCosmosConverter.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/convert/ObjectMapperFactory.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/convert/ObjectMapperFactory.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/convert/ObjectMapperFactory.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/convert/ObjectMapperFactory.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/convert/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/convert/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/convert/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/convert/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/generator/AbstractQueryGenerator.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/generator/AbstractQueryGenerator.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/generator/AbstractQueryGenerator.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/generator/AbstractQueryGenerator.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/generator/CountQueryGenerator.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/generator/CountQueryGenerator.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/generator/CountQueryGenerator.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/generator/CountQueryGenerator.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/generator/FindQuerySpecGenerator.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/generator/FindQuerySpecGenerator.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/generator/FindQuerySpecGenerator.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/generator/FindQuerySpecGenerator.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/generator/QuerySpecGenerator.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/generator/QuerySpecGenerator.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/generator/QuerySpecGenerator.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/generator/QuerySpecGenerator.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/generator/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/generator/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/generator/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/generator/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/BasicCosmosPersistentEntity.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/BasicCosmosPersistentEntity.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/BasicCosmosPersistentEntity.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/BasicCosmosPersistentEntity.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/BasicCosmosPersistentProperty.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/BasicCosmosPersistentProperty.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/BasicCosmosPersistentProperty.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/BasicCosmosPersistentProperty.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/CosmosMappingContext.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/CosmosMappingContext.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/CosmosMappingContext.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/CosmosMappingContext.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/CosmosPersistentEntity.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/CosmosPersistentEntity.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/CosmosPersistentEntity.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/CosmosPersistentEntity.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/CosmosPersistentProperty.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/CosmosPersistentProperty.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/CosmosPersistentProperty.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/CosmosPersistentProperty.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/Document.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/Document.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/Document.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/Document.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/DocumentIndexingPolicy.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/DocumentIndexingPolicy.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/DocumentIndexingPolicy.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/DocumentIndexingPolicy.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/PartitionKey.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/PartitionKey.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/PartitionKey.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/PartitionKey.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/CosmosPageImpl.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/CosmosPageImpl.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/CosmosPageImpl.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/CosmosPageImpl.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/CosmosPageRequest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/CosmosPageRequest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/CosmosPageRequest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/CosmosPageRequest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/Criteria.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/Criteria.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/Criteria.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/Criteria.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/CriteriaType.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/CriteriaType.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/CriteriaType.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/CriteriaType.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/DocumentQuery.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/DocumentQuery.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/DocumentQuery.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/DocumentQuery.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/core/query/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/core/query/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/ConfigurationException.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/ConfigurationException.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/ConfigurationException.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/ConfigurationException.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/CosmosDBAccessException.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/CosmosDBAccessException.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/CosmosDBAccessException.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/CosmosDBAccessException.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/CosmosDBExceptionUtils.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/CosmosDBExceptionUtils.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/CosmosDBExceptionUtils.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/CosmosDBExceptionUtils.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/DatabaseCreationException.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/DatabaseCreationException.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/DatabaseCreationException.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/DatabaseCreationException.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/IllegalCollectionException.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/IllegalCollectionException.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/IllegalCollectionException.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/IllegalCollectionException.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/IllegalQueryException.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/IllegalQueryException.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/IllegalQueryException.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/IllegalQueryException.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/exception/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/exception/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/CosmosRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/CosmosRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/CosmosRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/CosmosRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/ReactiveCosmosRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/ReactiveCosmosRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/ReactiveCosmosRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/ReactiveCosmosRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/CosmosRepositoriesRegistrar.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/CosmosRepositoriesRegistrar.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/CosmosRepositoriesRegistrar.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/CosmosRepositoriesRegistrar.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/CosmosRepositoryConfigurationExtension.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/CosmosRepositoryConfigurationExtension.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/CosmosRepositoryConfigurationExtension.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/CosmosRepositoryConfigurationExtension.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/EnableCosmosRepositories.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/EnableCosmosRepositories.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/EnableCosmosRepositories.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/EnableCosmosRepositories.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/EnableReactiveCosmosRepositories.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/EnableReactiveCosmosRepositories.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/EnableReactiveCosmosRepositories.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/EnableReactiveCosmosRepositories.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/ReactiveCosmosRepositoriesRegistrar.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/ReactiveCosmosRepositoriesRegistrar.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/ReactiveCosmosRepositoriesRegistrar.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/ReactiveCosmosRepositoriesRegistrar.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/ReactiveCosmosRepositoryConfigurationExtension.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/ReactiveCosmosRepositoryConfigurationExtension.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/ReactiveCosmosRepositoryConfigurationExtension.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/ReactiveCosmosRepositoryConfigurationExtension.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/AbstractCosmosQuery.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/AbstractCosmosQuery.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/AbstractCosmosQuery.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/AbstractCosmosQuery.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/AbstractReactiveCosmosQuery.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/AbstractReactiveCosmosQuery.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/AbstractReactiveCosmosQuery.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/AbstractReactiveCosmosQuery.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosEntityMetadata.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosEntityMetadata.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosEntityMetadata.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosEntityMetadata.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosParameter.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosParameter.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosParameter.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosParameter.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosParameterAccessor.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosParameterAccessor.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosParameterAccessor.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosParameterAccessor.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosParameterParameterAccessor.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosParameterParameterAccessor.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosParameterParameterAccessor.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosParameterParameterAccessor.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosParameters.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosParameters.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosParameters.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosParameters.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosQueryCreator.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosQueryCreator.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosQueryCreator.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosQueryCreator.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosQueryExecution.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosQueryExecution.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosQueryExecution.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosQueryExecution.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosQueryMethod.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosQueryMethod.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/CosmosQueryMethod.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/CosmosQueryMethod.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/PartTreeCosmosQuery.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/PartTreeCosmosQuery.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/PartTreeCosmosQuery.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/PartTreeCosmosQuery.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/PartTreeReactiveCosmosQuery.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/PartTreeReactiveCosmosQuery.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/PartTreeReactiveCosmosQuery.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/PartTreeReactiveCosmosQuery.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosEntityMetadata.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosEntityMetadata.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosEntityMetadata.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosEntityMetadata.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosParameterAccessor.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosParameterAccessor.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosParameterAccessor.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosParameterAccessor.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosParameterParameterAccessor.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosParameterParameterAccessor.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosParameterParameterAccessor.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosParameterParameterAccessor.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosQueryCreator.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosQueryCreator.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosQueryCreator.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosQueryCreator.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosQueryExecution.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosQueryExecution.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosQueryExecution.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosQueryExecution.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosQueryMethod.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosQueryMethod.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/ReactiveCosmosQueryMethod.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/ReactiveCosmosQueryMethod.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/SimpleCosmosEntityMetadata.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/SimpleCosmosEntityMetadata.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/SimpleCosmosEntityMetadata.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/SimpleCosmosEntityMetadata.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/SimpleReactiveCosmosEntityMetadata.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/SimpleReactiveCosmosEntityMetadata.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/SimpleReactiveCosmosEntityMetadata.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/SimpleReactiveCosmosEntityMetadata.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/query/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/query/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosEntityInformation.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosEntityInformation.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosEntityInformation.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosEntityInformation.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosRepositoryFactory.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosRepositoryFactory.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosRepositoryFactory.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosRepositoryFactory.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosRepositoryFactoryBean.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosRepositoryFactoryBean.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosRepositoryFactoryBean.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosRepositoryFactoryBean.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/ReactiveCosmosRepositoryFactory.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/ReactiveCosmosRepositoryFactory.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/ReactiveCosmosRepositoryFactory.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/ReactiveCosmosRepositoryFactory.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/ReactiveCosmosRepositoryFactoryBean.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/ReactiveCosmosRepositoryFactoryBean.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/ReactiveCosmosRepositoryFactoryBean.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/ReactiveCosmosRepositoryFactoryBean.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/SimpleCosmosRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/SimpleCosmosRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/SimpleCosmosRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/SimpleCosmosRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/SimpleReactiveCosmosRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/SimpleReactiveCosmosRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/SimpleReactiveCosmosRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/SimpleReactiveCosmosRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/package-info.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/package-info.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/package-info.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/main/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/package-info.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/CosmosDbFactoryTestIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/CosmosDbFactoryTestIT.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/CosmosDbFactoryTestIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/CosmosDbFactoryTestIT.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/UserAgentTestIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/UserAgentTestIT.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/UserAgentTestIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/UserAgentTestIT.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/DynamicContainer.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/DynamicContainer.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/DynamicContainer.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/DynamicContainer.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/ExpressionResolverUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/ExpressionResolverUnitTest.java similarity index 99% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/ExpressionResolverUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/ExpressionResolverUnitTest.java index ccb3160225cad..ee4821faabf8f 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/ExpressionResolverUnitTest.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/ExpressionResolverUnitTest.java @@ -3,7 +3,6 @@ package com.microsoft.azure.spring.data.cosmosdb.common; import org.junit.Test; - import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/MemoizerUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/MemoizerUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/MemoizerUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/MemoizerUnitTest.java index 0da9f66b63ffc..05f3cbb9e588c 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/MemoizerUnitTest.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/MemoizerUnitTest.java @@ -5,14 +5,14 @@ import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; - import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import java.util.stream.IntStream; +import static org.junit.Assert.assertEquals; + /** * * @author Domenico Sibilio diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/PageTestUtils.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/PageTestUtils.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/PageTestUtils.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/PageTestUtils.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/PropertyLoaderUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/PropertyLoaderUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/PropertyLoaderUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/PropertyLoaderUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/ResponseDiagnosticsTestUtils.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/ResponseDiagnosticsTestUtils.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/ResponseDiagnosticsTestUtils.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/ResponseDiagnosticsTestUtils.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/TestConstants.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/TestConstants.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/TestConstants.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/TestConstants.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/TestUtils.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/TestUtils.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/common/TestUtils.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/common/TestUtils.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/config/AbstractCosmosConfigurationIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/config/AbstractCosmosConfigurationIT.java similarity index 99% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/config/AbstractCosmosConfigurationIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/config/AbstractCosmosConfigurationIT.java index a3fdd33fc4ef9..231c587837f5a 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/config/AbstractCosmosConfigurationIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/config/AbstractCosmosConfigurationIT.java @@ -16,7 +16,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mock; - import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplateIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplateIT.java similarity index 94% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplateIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplateIT.java index 289a2e4d33ea3..14da8e2515431 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplateIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplateIT.java @@ -39,20 +39,7 @@ import static com.microsoft.azure.spring.data.cosmosdb.common.PageTestUtils.validateLastPage; import static com.microsoft.azure.spring.data.cosmosdb.common.PageTestUtils.validateNonLastPage; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.ADDRESSES; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.FIRST_NAME; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.HOBBIES; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.ID_1; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.ID_2; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.ID_3; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.LAST_NAME; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.NEW_FIRST_NAME; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.NEW_LAST_NAME; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.NOT_EXIST_ID; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.PAGE_SIZE_1; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.PAGE_SIZE_2; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.PAGE_SIZE_3; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.UPDATED_FIRST_NAME; +import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.*; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplateIllegalTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplateIllegalTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplateIllegalTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplateIllegalTest.java index 0c63ef1c49e92..4b2ad4354ec25 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplateIllegalTest.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplateIllegalTest.java @@ -15,12 +15,12 @@ import org.mockito.junit.MockitoJUnitRunner; import org.springframework.util.Assert; -import static com.microsoft.azure.spring.data.cosmosdb.core.query.CriteriaType.IS_EQUAL; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; +import static com.microsoft.azure.spring.data.cosmosdb.core.query.CriteriaType.IS_EQUAL; + @SuppressWarnings("unchecked") @RunWith(MockitoJUnitRunner.class) public class CosmosTemplateIllegalTest { diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplatePartitionIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplatePartitionIT.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplatePartitionIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplatePartitionIT.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplateUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplateUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/CosmosTemplateUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/CosmosTemplateUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosTemplateIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosTemplateIT.java similarity index 99% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosTemplateIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosTemplateIT.java index 37395f876c36a..d2442de406c37 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosTemplateIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosTemplateIT.java @@ -19,11 +19,7 @@ import com.microsoft.azure.spring.data.cosmosdb.repository.TestRepositoryConfig; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; import io.reactivex.subscribers.TestSubscriber; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosTemplatePartitionIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosTemplatePartitionIT.java similarity index 90% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosTemplatePartitionIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosTemplatePartitionIT.java index fce527da71b08..124a85d651725 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/ReactiveCosmosTemplatePartitionIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/ReactiveCosmosTemplatePartitionIT.java @@ -12,11 +12,7 @@ import com.microsoft.azure.spring.data.cosmosdb.domain.PartitionPerson; import com.microsoft.azure.spring.data.cosmosdb.repository.TestRepositoryConfig; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScanner; @@ -31,16 +27,7 @@ import java.util.Arrays; import java.util.UUID; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.ADDRESSES; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.FIRST_NAME; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.HOBBIES; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.ID_1; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.ID_2; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.LAST_NAME; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.NEW_FIRST_NAME; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.NEW_LAST_NAME; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.PROPERTY_LAST_NAME; -import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.UPDATED_FIRST_NAME; +import static com.microsoft.azure.spring.data.cosmosdb.common.TestConstants.*; import static com.microsoft.azure.spring.data.cosmosdb.core.query.CriteriaType.IS_EQUAL; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/convert/ZonedDateTimeDeserializerTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/convert/ZonedDateTimeDeserializerTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/convert/ZonedDateTimeDeserializerTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/convert/ZonedDateTimeDeserializerTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/converter/MappingCosmosConverterUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/converter/MappingCosmosConverterUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/converter/MappingCosmosConverterUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/converter/MappingCosmosConverterUnitTest.java index c0d3c93947ae7..5b52d9f14a48a 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/converter/MappingCosmosConverterUnitTest.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/converter/MappingCosmosConverterUnitTest.java @@ -8,8 +8,8 @@ import com.microsoft.azure.spring.data.cosmosdb.core.convert.MappingCosmosConverter; import com.microsoft.azure.spring.data.cosmosdb.core.mapping.CosmosMappingContext; import com.microsoft.azure.spring.data.cosmosdb.domain.Address; -import com.microsoft.azure.spring.data.cosmosdb.domain.Memo; import com.microsoft.azure.spring.data.cosmosdb.domain.Importance; +import com.microsoft.azure.spring.data.cosmosdb.domain.Memo; import org.json.JSONObject; import org.junit.Before; import org.junit.Test; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/BasicCosmosPersistentEntityUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/BasicCosmosPersistentEntityUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/BasicCosmosPersistentEntityUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/BasicCosmosPersistentEntityUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/CosmosMappingContextUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/CosmosMappingContextUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/mapping/CosmosMappingContextUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/mapping/CosmosMappingContextUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/query/CriteriaUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/query/CriteriaUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/query/CriteriaUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/query/CriteriaUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/query/DocumentQueryUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/query/DocumentQueryUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/core/query/DocumentQueryUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/core/query/DocumentQueryUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Address.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Address.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Address.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Address.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Contact.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Contact.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Contact.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Contact.java index 3c2bfc9c5dd4a..6770f1c528da9 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Contact.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Contact.java @@ -14,6 +14,9 @@ public class Contact { private String title; + public Contact() { + } + public Contact(String logicId, String title) { this.logicId = logicId; this.title = title; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Course.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Course.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Course.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Course.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Customer.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Customer.java similarity index 97% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Customer.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Customer.java index e79d5a49b6966..d31168f085500 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Customer.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Customer.java @@ -15,6 +15,9 @@ public class Customer { private User user; + public Customer() { + } + public Customer(String id, Long level, User user) { this.id = id; this.level = level; @@ -83,6 +86,9 @@ public static class User { private Long age; + public User() { + } + public User(String name, Long age) { this.name = name; this.age = age; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Importance.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Importance.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Importance.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Importance.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/IntegerIdDomain.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/IntegerIdDomain.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/IntegerIdDomain.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/IntegerIdDomain.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Memo.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Memo.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Memo.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Memo.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/NoDBAnnotationPerson.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/NoDBAnnotationPerson.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/NoDBAnnotationPerson.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/NoDBAnnotationPerson.java index ef76b39d97c28..bc5eab89003ad 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/NoDBAnnotationPerson.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/NoDBAnnotationPerson.java @@ -14,6 +14,9 @@ public class NoDBAnnotationPerson { private List hobbies; private List
shippingAddresses; + public NoDBAnnotationPerson() { + } + public NoDBAnnotationPerson(String id, String firstName, String lastName, List hobbies, List
shippingAddresses) { this.id = id; this.firstName = firstName; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PageableAddress.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PageableAddress.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PageableAddress.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PageableAddress.java index 947b30baf43cc..7b644336eead9 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PageableAddress.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PageableAddress.java @@ -35,6 +35,9 @@ public int hashCode() { return Objects.hash(postalCode, street, city); } + public PageableAddress() { + } + public PageableAddress(String postalCode, String street, String city) { this.postalCode = postalCode; this.street = street; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PageableMemo.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PageableMemo.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PageableMemo.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PageableMemo.java index 5796f18e8af7f..d1425e5c357c1 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PageableMemo.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PageableMemo.java @@ -17,6 +17,9 @@ public class PageableMemo { private Date date; private Importance importance; + public PageableMemo() { + } + public PageableMemo(String id, String message, Date date, Importance importance) { this.id = id; this.message = message; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PageablePerson.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PageablePerson.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PageablePerson.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PageablePerson.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PartitionPerson.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PartitionPerson.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PartitionPerson.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PartitionPerson.java index fefe9b080a9df..0285512b18345 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/PartitionPerson.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/PartitionPerson.java @@ -22,6 +22,9 @@ public class PartitionPerson { private List
shippingAddresses; + public PartitionPerson() { + } + public PartitionPerson(String id, String firstName, String lastName, List hobbies, List
shippingAddresses) { this.id = id; this.firstName = firstName; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Person.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Person.java similarity index 99% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Person.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Person.java index 8038c1826df0a..481617488a38b 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Person.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Person.java @@ -3,16 +3,15 @@ package com.microsoft.azure.spring.data.cosmosdb.domain; -import java.util.List; -import java.util.Objects; - import com.microsoft.azure.spring.data.cosmosdb.common.TestConstants; import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document; import com.microsoft.azure.spring.data.cosmosdb.core.mapping.DocumentIndexingPolicy; import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey; - import org.springframework.data.annotation.Version; +import java.util.List; +import java.util.Objects; + @Document() @DocumentIndexingPolicy(includePaths = TestConstants.ORDER_BY_STRING_PATH) public class Person { diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Project.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Project.java similarity index 99% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Project.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Project.java index 436b040198faf..334cba0bad9da 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Project.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Project.java @@ -28,6 +28,9 @@ public class Project { private Long forkCount; + public Project() { + } + public Project(String id, String name, String creator, Boolean hasReleased, Long starCount, Long forkCount) { this.id = id; this.name = name; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Question.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Question.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Question.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Question.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Role.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Role.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Role.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Role.java index 6bc7ca4233d03..542885fe92549 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Role.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Role.java @@ -34,6 +34,9 @@ public class Role { String level; + public Role() { + } + public Role(String id, String name, String level) { this.id = id; this.name = name; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/SortedProject.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/SortedProject.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/SortedProject.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/SortedProject.java index 38437509175d4..f8def0da26bda 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/SortedProject.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/SortedProject.java @@ -28,6 +28,9 @@ public class SortedProject { private Long forkCount; + public SortedProject() { + } + public SortedProject(String id, String name, String creator, Boolean hasReleased, Long starCount, Long forkCount) { this.id = id; this.name = name; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/SpELBeanStudent.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/SpELBeanStudent.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/SpELBeanStudent.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/SpELBeanStudent.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/SpELPropertyStudent.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/SpELPropertyStudent.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/SpELPropertyStudent.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/SpELPropertyStudent.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Student.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Student.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Student.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Student.java index 6e80572759169..c531cf58ca45b 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/Student.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Student.java @@ -14,6 +14,9 @@ public class Student { private String firstName; private String lastName; + public Student() { + } + public Student(String id, String firstName, String lastName) { this.id = id; this.firstName = firstName; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/TimeToLiveSample.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/TimeToLiveSample.java similarity index 93% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/TimeToLiveSample.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/TimeToLiveSample.java index 3a6093ec6b6f0..9e1455317e6b6 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/TimeToLiveSample.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/TimeToLiveSample.java @@ -9,6 +9,9 @@ public class TimeToLiveSample { private String id; + public TimeToLiveSample() { + } + public TimeToLiveSample(String id) { this.id = id; } diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/inheritance/Shape.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/inheritance/Shape.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/inheritance/Shape.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/inheritance/Shape.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/inheritance/Square.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/inheritance/Square.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/domain/inheritance/Square.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/inheritance/Square.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/PerfConfiguration.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/PerfConfiguration.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/PerfConfiguration.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/PerfConfiguration.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/PerformanceCompare.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/PerformanceCompare.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/PerformanceCompare.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/PerformanceCompare.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/PerformanceReport.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/PerformanceReport.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/PerformanceReport.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/PerformanceReport.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/domain/PerfPerson.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/domain/PerfPerson.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/domain/PerfPerson.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/domain/PerfPerson.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/repository/PerfPersonRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/repository/PerfPersonRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/repository/PerfPersonRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/repository/PerfPersonRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/service/SdkService.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/service/SdkService.java similarity index 96% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/service/SdkService.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/service/SdkService.java index bf5462d42c1a2..4b37ac7db7207 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/service/SdkService.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/service/SdkService.java @@ -2,13 +2,7 @@ // Licensed under the MIT License. package com.microsoft.azure.spring.data.cosmosdb.performance.service; -import com.azure.data.cosmos.CosmosClient; -import com.azure.data.cosmos.CosmosClientException; -import com.azure.data.cosmos.CosmosItemProperties; -import com.azure.data.cosmos.CosmosItemRequestOptions; -import com.azure.data.cosmos.FeedOptions; -import com.azure.data.cosmos.FeedResponse; -import com.azure.data.cosmos.PartitionKey; +import com.azure.data.cosmos.*; import com.azure.data.cosmos.sync.CosmosSyncClient; import com.google.gson.Gson; import com.microsoft.azure.spring.data.cosmosdb.performance.domain.PerfPerson; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/utils/Constants.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/utils/Constants.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/utils/Constants.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/utils/Constants.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/utils/DatabaseUtils.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/utils/DatabaseUtils.java similarity index 90% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/utils/DatabaseUtils.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/utils/DatabaseUtils.java index 061e6a97e4d56..8c7be5c489857 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/utils/DatabaseUtils.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/utils/DatabaseUtils.java @@ -2,11 +2,7 @@ // Licensed under the MIT License. package com.microsoft.azure.spring.data.cosmosdb.performance.utils; -import com.azure.data.cosmos.CosmosClientException; -import com.azure.data.cosmos.CosmosContainerProperties; -import com.azure.data.cosmos.IncludedPath; -import com.azure.data.cosmos.IndexingPolicy; -import com.azure.data.cosmos.PartitionKeyDefinition; +import com.azure.data.cosmos.*; import com.azure.data.cosmos.internal.RequestOptions; import com.azure.data.cosmos.sync.CosmosSyncClient; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/utils/FunctionUtils.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/utils/FunctionUtils.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/utils/FunctionUtils.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/utils/FunctionUtils.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/utils/PerfDataProvider.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/utils/PerfDataProvider.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/performance/utils/PerfDataProvider.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/performance/utils/PerfDataProvider.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/CosmosAnnotationUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/CosmosAnnotationUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/CosmosAnnotationUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/CosmosAnnotationUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/SimpleCosmosRepositoryIllegalTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/SimpleCosmosRepositoryIllegalTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/SimpleCosmosRepositoryIllegalTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/SimpleCosmosRepositoryIllegalTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/SimpleCosmosRepositoryUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/SimpleCosmosRepositoryUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/SimpleCosmosRepositoryUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/SimpleCosmosRepositoryUnitTest.java index 6ec48cb66bc3e..ca3bd62d503f4 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/SimpleCosmosRepositoryUnitTest.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/SimpleCosmosRepositoryUnitTest.java @@ -22,8 +22,8 @@ import java.util.List; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/TestRepositoryConfig.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/TestRepositoryConfig.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/TestRepositoryConfig.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/TestRepositoryConfig.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/CosmosRepositoryConfigurationExtensionUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/CosmosRepositoryConfigurationExtensionUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/CosmosRepositoryConfigurationExtensionUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/CosmosRepositoryConfigurationExtensionUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/ReactiveCosmosRepositoryConfigurationExtensionUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/ReactiveCosmosRepositoryConfigurationExtensionUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/config/ReactiveCosmosRepositoryConfigurationExtensionUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/config/ReactiveCosmosRepositoryConfigurationExtensionUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/AddressRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/AddressRepositoryIT.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/AddressRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/AddressRepositoryIT.java index 78526ac34dd6c..90c73e73ab298 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/AddressRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/AddressRepositoryIT.java @@ -11,12 +11,7 @@ import com.microsoft.azure.spring.data.cosmosdb.repository.repository.AddressRepository; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; import org.assertj.core.util.Lists; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ContactRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ContactRepositoryIT.java similarity index 97% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ContactRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ContactRepositoryIT.java index ca4368e987c09..3a7b23df07af3 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ContactRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ContactRepositoryIT.java @@ -9,12 +9,7 @@ import com.microsoft.azure.spring.data.cosmosdb.repository.repository.ContactRepository; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; import org.assertj.core.util.Lists; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/CosmosAnnotationIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/CosmosAnnotationIT.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/CosmosAnnotationIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/CosmosAnnotationIT.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/CustomerRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/CustomerRepositoryIT.java similarity index 96% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/CustomerRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/CustomerRepositoryIT.java index c476c4a57d0e7..aade6e404ee21 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/CustomerRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/CustomerRepositoryIT.java @@ -7,11 +7,7 @@ import com.microsoft.azure.spring.data.cosmosdb.repository.TestRepositoryConfig; import com.microsoft.azure.spring.data.cosmosdb.repository.repository.CustomerRepository; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.lang.NonNull; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/IntegerIdDomainRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/IntegerIdDomainRepositoryIT.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/IntegerIdDomainRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/IntegerIdDomainRepositoryIT.java index 67573dd759f6f..4b8cd3b8a4725 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/IntegerIdDomainRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/IntegerIdDomainRepositoryIT.java @@ -9,12 +9,7 @@ import com.microsoft.azure.spring.data.cosmosdb.repository.TestRepositoryConfig; import com.microsoft.azure.spring.data.cosmosdb.repository.repository.IntegerIdDomainRepository; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -215,6 +210,9 @@ private static class InvalidDomain { private String location; + InvalidDomain() { + } + InvalidDomain(int count, String location) { this.count = count; this.location = location; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/MemoRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/MemoRepositoryIT.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/MemoRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/MemoRepositoryIT.java index 4fa4053db39b7..71ce123073bf2 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/MemoRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/MemoRepositoryIT.java @@ -11,13 +11,7 @@ import com.microsoft.azure.spring.data.cosmosdb.repository.TestRepositoryConfig; import com.microsoft.azure.spring.data.cosmosdb.repository.repository.MemoRepository; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/PageableAddressRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/PageableAddressRepositoryIT.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/PageableAddressRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/PageableAddressRepositoryIT.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/PageableMemoRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/PageableMemoRepositoryIT.java similarity index 97% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/PageableMemoRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/PageableMemoRepositoryIT.java index 35e4a60ee5195..c8c254f7ad2bc 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/PageableMemoRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/PageableMemoRepositoryIT.java @@ -27,13 +27,7 @@ import reactor.core.publisher.Flux; import reactor.test.StepVerifier; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.UUID; +import java.util.*; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/PageablePersonRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/PageablePersonRepositoryIT.java similarity index 97% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/PageablePersonRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/PageablePersonRepositoryIT.java index bea46dbc742ed..f3720b6e78b4d 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/PageablePersonRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/PageablePersonRepositoryIT.java @@ -21,11 +21,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; +import java.util.*; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/PersonRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/PersonRepositoryIT.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/PersonRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/PersonRepositoryIT.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ProjectRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ProjectRepositoryIT.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ProjectRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ProjectRepositoryIT.java index 1e0475d9257d5..64ee38ccc15ea 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ProjectRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ProjectRepositoryIT.java @@ -9,22 +9,14 @@ import com.microsoft.azure.spring.data.cosmosdb.repository.TestRepositoryConfig; import com.microsoft.azure.spring.data.cosmosdb.repository.repository.ProjectRepository; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.lang.NonNull; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; +import java.util.*; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ProjectRepositorySortIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ProjectRepositorySortIT.java similarity index 98% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ProjectRepositorySortIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ProjectRepositorySortIT.java index dd952e74dc53d..4da352b4589d9 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ProjectRepositorySortIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ProjectRepositorySortIT.java @@ -10,11 +10,7 @@ import com.microsoft.azure.spring.data.cosmosdb.repository.repository.SortedProjectRepository; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; import org.assertj.core.util.Lists; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/QuestionRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/QuestionRepositoryIT.java similarity index 96% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/QuestionRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/QuestionRepositoryIT.java index deba6ec4e6266..61b24a271e360 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/QuestionRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/QuestionRepositoryIT.java @@ -9,11 +9,7 @@ import com.microsoft.azure.spring.data.cosmosdb.repository.repository.QuestionRepository; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; import org.assertj.core.util.Lists; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ReactiveCourseRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ReactiveCourseRepositoryIT.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/ReactiveCourseRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/ReactiveCourseRepositoryIT.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/SpELCosmosDBAnnotationIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/SpELCosmosDBAnnotationIT.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/SpELCosmosDBAnnotationIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/SpELCosmosDBAnnotationIT.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/SquareRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/SquareRepositoryIT.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/SquareRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/SquareRepositoryIT.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/StudentRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/StudentRepositoryIT.java similarity index 97% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/StudentRepositoryIT.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/StudentRepositoryIT.java index 9b0058e7f9056..45e25aa3cac7d 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/integration/StudentRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/integration/StudentRepositoryIT.java @@ -7,11 +7,7 @@ import com.microsoft.azure.spring.data.cosmosdb.repository.TestRepositoryConfig; import com.microsoft.azure.spring.data.cosmosdb.repository.repository.StudentRepository; import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosEntityInformation; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/AddressRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/AddressRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/AddressRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/AddressRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/ContactRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/ContactRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/ContactRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/ContactRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/CustomerRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/CustomerRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/CustomerRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/CustomerRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/IntegerIdDomainRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/IntegerIdDomainRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/IntegerIdDomainRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/IntegerIdDomainRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/MemoRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/MemoRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/MemoRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/MemoRepository.java index f6544d0462c4d..8718388d42a66 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/MemoRepository.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/MemoRepository.java @@ -2,8 +2,8 @@ // Licensed under the MIT License. package com.microsoft.azure.spring.data.cosmosdb.repository.repository; -import com.microsoft.azure.spring.data.cosmosdb.domain.Memo; import com.microsoft.azure.spring.data.cosmosdb.domain.Importance; +import com.microsoft.azure.spring.data.cosmosdb.domain.Memo; import com.microsoft.azure.spring.data.cosmosdb.repository.CosmosRepository; import org.springframework.stereotype.Repository; diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/PageableAddressRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/PageableAddressRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/PageableAddressRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/PageableAddressRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/PageableMemoRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/PageableMemoRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/PageableMemoRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/PageableMemoRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/PageablePersonRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/PageablePersonRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/PageablePersonRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/PageablePersonRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/PartitionPersonRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/PartitionPersonRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/PartitionPersonRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/PartitionPersonRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/PersonRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/PersonRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/PersonRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/PersonRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/ProjectRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/ProjectRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/ProjectRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/ProjectRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/QuestionRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/QuestionRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/QuestionRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/QuestionRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/ReactiveCourseRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/ReactiveCourseRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/ReactiveCourseRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/ReactiveCourseRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/SortedProjectRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/SortedProjectRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/SortedProjectRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/SortedProjectRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/SquareRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/SquareRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/SquareRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/SquareRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/StudentRepository.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/StudentRepository.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/repository/StudentRepository.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/repository/StudentRepository.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosEntityInformationUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosEntityInformationUnitTest.java similarity index 99% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosEntityInformationUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosEntityInformationUnitTest.java index 598f0359d8c77..e22e573c6d5ac 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosEntityInformationUnitTest.java +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosEntityInformationUnitTest.java @@ -2,9 +2,6 @@ // Licensed under the MIT License. package com.microsoft.azure.spring.data.cosmosdb.repository.support; -import java.util.List; -import java.util.Objects; - import com.microsoft.azure.spring.data.cosmosdb.common.TestConstants; import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document; import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey; @@ -12,9 +9,11 @@ import com.microsoft.azure.spring.data.cosmosdb.domain.Person; import com.microsoft.azure.spring.data.cosmosdb.domain.Student; import org.junit.Test; - import org.springframework.data.annotation.Version; +import java.util.List; +import java.util.Objects; + import static org.assertj.core.api.Assertions.assertThat; public class CosmosEntityInformationUnitTest { diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosRepositoryFactoryBeanUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosRepositoryFactoryBeanUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosRepositoryFactoryBeanUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosRepositoryFactoryBeanUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosRepositoryFactoryUnitTest.java b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosRepositoryFactoryUnitTest.java similarity index 100% rename from sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com.microsoft.azure.spring.data.cosmosdb/repository/support/CosmosRepositoryFactoryUnitTest.java rename to sdk/cosmos/azure-spring-data-cosmosdb/src/test/java/com/microsoft/azure/spring/data/cosmosdb/repository/support/CosmosRepositoryFactoryUnitTest.java diff --git a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/resources/application.properties b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/resources/application.properties index 85ff3ddb4a407..12b7c8f46f80b 100644 --- a/sdk/cosmos/azure-spring-data-cosmosdb/src/test/resources/application.properties +++ b/sdk/cosmos/azure-spring-data-cosmosdb/src/test/resources/application.properties @@ -1,6 +1,6 @@ -cosmosdb.uri=${DOCUMENTDB_URI} -cosmosdb.key=${DOCUMENTDB_KEY} -cosmosdb.secondaryKey=${COSMOSDB_SECONDARY_KEY} +cosmosdb.uri=${ACCOUNT_HOST} +cosmosdb.key=${ACCOUNT_KEY} +cosmosdb.secondaryKey=${SECONDARY_ACCOUNT_KEY} #You can also use connection string instead of uri and key to connect to cosmos DB #cosmosdb.connection-string=${DOCUMENTDB_CONNECTION_STRING} diff --git a/sdk/cosmos/test-resources.json b/sdk/cosmos/test-resources.json index 5ff266717f1bb..447dd5729a440 100644 --- a/sdk/cosmos/test-resources.json +++ b/sdk/cosmos/test-resources.json @@ -95,4 +95,4 @@ "value": "[listKeys(variables('resourceId'), variables('apiVersion')).secondaryMasterKey]" } } -} \ No newline at end of file +} diff --git a/sdk/cosmos/tests.yml b/sdk/cosmos/tests.yml index ecddcf4d81e79..41881477a7f93 100644 --- a/sdk/cosmos/tests.yml +++ b/sdk/cosmos/tests.yml @@ -244,4 +244,33 @@ jobs: goals: verify options: '$(ProfileFlag) -Dgpg.skip $(AdditionalArgs) -pl $(ProjectList)' - TestResultsFiles: '**/junitreports/TEST-*.xml' \ No newline at end of file + TestResultsFiles: '**/junitreports/TEST-*.xml' + + - template: ../../eng/pipelines/templates/jobs/archetype-sdk-tests.yml + parameters: + TestName: Integration_Test_Spring_Data_Cosmosdb + ServiceDirectory: cosmos + Artifacts: + - name: spring-data-cosmosdb + groupId: com.microsoft.azure + safeName: springdatacosmosdb + TimeoutInMinutes: 90 + Matrix: + Session_Integration: + ArmTemplateParameters: "@{ enableMultipleWriteLocations = $false; defaultConsistencyLevel = 'Session' }" + DisplayName: Session Integration + OSVmImage: 'ubuntu-18.04' + ProfileFlag: '-P integration-test-azure' + Strong_Integration: + ArmTemplateParameters: "@{ enableMultipleWriteLocations = $false; defaultConsistencyLevel = 'Strong' }" + DisplayName: Strong Integration + OSVmImage: 'ubuntu-18.04' + ProfileFlag: '-P integration-test-azure' + + EnvVars: + AZURE_TEST_MODE: LIVE + PreRunSteps: + - template: /eng/pipelines/templates/steps/install-reporting-tools.yml + TestStepMavenInputs: + goals: verify + options: '$(ProfileFlag) -Dgpg.skip -Dmaven.wagon.http.pool=false $(DefaultOptions) -Dmaven.javadoc.skip=true -Drevapi.skip=true -pl $(ProjectList)' diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md index 162ff520b38fa..3cb44caee64fd 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md +++ b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md @@ -2,6 +2,9 @@ ## 1.0.0-beta.4 (Unreleased) ### Breaking Changes +- `beginRecognizeReceipt` APIs now return a `RecognizedForm` model instead of a `RecognizedReceipt`. See +[this](https://github.com/Azure/azure-sdk-for-java/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/StronglyTypedRecognizedFormUSReceipt.java) +suggested approach for extracting information from receipts. - Methods returning `textContent` have been renamed to `fieldElements` on `FieldData` and `FormTableCell` - Renamed `FormContent` to `FormElement` - Renamed `FieldText` to `FieldData` diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/README.md b/sdk/formrecognizer/azure-ai-formrecognizer/README.md index 1ba2bd54919b9..6fef4de94f21e 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/README.md +++ b/sdk/formrecognizer/azure-ai-formrecognizer/README.md @@ -177,7 +177,7 @@ followed by polling the service at intervals to determine whether the operation succeeded, to get the result. Methods that train models or recognize values from forms are modeled as long-running operations. The client exposes -a `begin` method that returns a `SyncPoller` or `PollerFlux` instance. +a `begin` method that returns a `SyncPoller` or `PollerFlux` instance. Callers should wait for the operation to completed by calling `getFinalResult()` on the returned operation from the `begin` method. Sample code snippets are provided to illustrate using long-running operations [below](#Examples). @@ -195,7 +195,7 @@ The following section provides several code snippets covering some of the most c ### Recognize Forms Using a Custom Model Recognize name/value pairs and table data from forms. These models are trained with your own data, so they're tailored to your forms. You should only recognize forms of the same form type that the custom model was trained on. - + ```java String formUrl = "{form_url}"; String modelId = "{custom_trained_model_id}"; @@ -206,20 +206,19 @@ List recognizedForms = recognizeFormPoller.getFinalResult(); for (int i = 0; i < recognizedForms.size(); i++) { RecognizedForm form = recognizedForms.get(i); - System.out.printf("----------- Recognized Form %d-----------%n", i); + System.out.printf("----------- Recognized Form %d -----------%n", i); System.out.printf("Form type: %s%n", form.getFormType()); - form.getFields().forEach((label, formField) -> { + form.getFields().forEach((label, formField) -> System.out.printf("Field %s has value %s with confidence score of %f.%n", label, formField.getValueData().getText(), - formField.getConfidence()); - }); - System.out.print("-----------------------------------"); + formField.getConfidence()) + ); } ``` ### Recognize Content Recognize text and table structures, along with their bounding box coordinates, from documents. - + ```java // recognize form content using file input stream File form = new File("local/file_path/filename.png"); @@ -233,7 +232,7 @@ List contentPageResults = recognizeContentPoller.getFinalResult(); for (int i = 0; i < contentPageResults.size(); i++) { FormPage formPage = contentPageResults.get(i); - System.out.printf("----Recognizing content for page %d----%n", i); + System.out.printf("----Recognizing content for page %d ----%n", i); // Table information System.out.printf("Has width: %f and height: %f, measured with unit: %s.%n", formPage.getWidth(), formPage.getHeight(), @@ -241,64 +240,75 @@ for (int i = 0; i < contentPageResults.size(); i++) { formPage.getTables().forEach(formTable -> { System.out.printf("Table has %d rows and %d columns.%n", formTable.getRowCount(), formTable.getColumnCount()); - formTable.getCells().forEach(formTableCell -> { - System.out.printf("Cell has text %s.%n", formTableCell.getText()); - }); - System.out.println(); + formTable.getCells().forEach(formTableCell -> + System.out.printf("Cell has text %s.%n", formTableCell.getText())); }); } ``` ### Recognize receipts -Recognize data from a USA sales receipts using a prebuilt model. [Here][service_recognize_receipt] are the fields the -service returns for a recognized receipt. - +Recognize data from a USA sales receipts using a prebuilt model. [Here][service_recognize_receipt] are the fields the service returns for a recognized receipt. See [StronglyTypedRecognizedForm.java][strongly_typed_sample] for a suggested approach to extract +information from receipts. + + ```java String receiptUrl = "https://docs.microsoft.com/en-us/azure/cognitive-services/form-recognizer/media" + "/contoso-allinone.jpg"; -SyncPoller> syncPoller = +SyncPoller> syncPoller = formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl); -List receiptPageResults = syncPoller.getFinalResult(); +List receiptPageResults = syncPoller.getFinalResult(); for (int i = 0; i < receiptPageResults.size(); i++) { - RecognizedReceipt recognizedReceipt = receiptPageResults.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); + RecognizedForm recognizedForm = receiptPageResults.get(i); + Map> recognizedFields = recognizedForm.getFields(); System.out.printf("----------- Recognized Receipt page %d -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Name")) { - if (formField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Name: %s, confidence: %.2fs%n", - formField.getFieldValue().asString(), - formField.getConfidence()); - } - } - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %d, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } + } + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %f, confidence: %.2f%n", + quantity, formField.getConfidence()); + } } - } - }); - } - }); + }); + } + }); + } } } ``` @@ -307,7 +317,7 @@ for (int i = 0; i < receiptPageResults.size(); i++) { Train a machine-learned model on your own form type. The resulting model will be able to recognize values from the types of forms it was trained on. Provide a container SAS url to your Azure Storage Blob container where you're storing the training documents. See details on setting this up in the [service quickstart documentation][quickstart_training]. - + ```java String trainingFilesUrl = "{SAS-URL-of-your-container-in-blob-storage}"; SyncPoller trainingPoller = @@ -334,7 +344,7 @@ customFormModel.getSubmodels().forEach(customFormSubmodel -> { ### Manage your models Manage the custom models attached to your account. - + ```java AtomicReference modelId = new AtomicReference<>(); // First, we see how many custom models we have, and what our limit is @@ -376,7 +386,7 @@ to provide an invalid file source URL an `HttpResponseException` would be raised In the following code snippet, the error is handled gracefully by catching the exception and display the additional information about the error. - + ```java try { formRecognizerClient.beginRecognizeContentFromUrl("invalidSourceUrl"); @@ -414,7 +424,7 @@ These code samples show common scenario operations with the Azure Form Recognize #### Async APIs All the examples shown so far have been using synchronous APIs, but we provide full support for async APIs as well. You'll need to use `FormRecognizerAsyncClient` - + ```java FormRecognizerAsyncClient formRecognizerAsyncClient = new FormRecognizerClientBuilder() .credential(new AzureKeyCredential("{key}")) @@ -498,7 +508,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m [service_access]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows [service_doc_train_unlabeled]: https://docs.microsoft.com/azure/cognitive-services/form-recognizer/overview#train-without-labels [service_doc_train_labeled]: https://docs.microsoft.com/azure/cognitive-services/form-recognizer/overview#train-with-labels -[service_recognize_receipt]: https://westus2.dev.cognitive.microsoft.com/docs/services/form-recognizer-api-v2-preview/operations/GetAnalyzeReceiptResult +[service_recognize_receipt]: https://aka.ms/azsdk/python/formrecognizer/receiptfields +[strongly_typed_sample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/StronglyTypedRecognizedForm.java [source_code]: src [quickstart_training]: https://docs.microsoft.com/azure/cognitive-services/form-recognizer/quickstarts/curl-train-extract#train-a-form-recognizer-model [wiki_identity]: https://github.com/Azure/azure-sdk-for-java/wiki/Identity-and-Authentication 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 6f35bf31af369..6e9dc5a0a9629 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 @@ -16,7 +16,6 @@ import com.azure.ai.formrecognizer.models.OperationResult; import com.azure.ai.formrecognizer.models.RecognizeOptions; import com.azure.ai.formrecognizer.models.RecognizedForm; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; @@ -38,7 +37,6 @@ import java.util.UUID; import java.util.function.Function; -import static com.azure.ai.formrecognizer.Transforms.toReceipt; import static com.azure.ai.formrecognizer.Transforms.toRecognizedForm; import static com.azure.ai.formrecognizer.Transforms.toRecognizedLayout; import static com.azure.ai.formrecognizer.implementation.Utility.detectContentType; @@ -339,13 +337,13 @@ public PollerFlux> beginRecognizeContent(Flux> + public PollerFlux> beginRecognizeReceiptsFromUrl(String receiptUrl) { return beginRecognizeReceiptsFromUrl(receiptUrl, null); } @@ -364,17 +362,17 @@ public PollerFlux> beginRecognizeContent(Flux> + public PollerFlux> beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeOptions recognizeOptions) { try { recognizeOptions = getRecognizeOptionsProperties(recognizeOptions); - return new PollerFlux>( + return new PollerFlux>( recognizeOptions.getPollInterval(), receiptAnalyzeActivationOperation(receiptUrl, recognizeOptions.isIncludeFieldElements()), extractReceiptPollOperation(), @@ -403,13 +401,13 @@ public PollerFlux> beginRecognizeContent(Flux> beginRecognizeReceipts( + public PollerFlux> beginRecognizeReceipts( Flux receipt, long length) { return beginRecognizeReceipts(receipt, length, null); } @@ -433,13 +431,13 @@ public PollerFlux> beginRecognizeReceip * analyzing a receipt. * * @return A {@link PollerFlux} that polls the recognize receipt operation until it has completed, has failed, - * or has been cancelled. The completed operation returns a List of {@link RecognizedReceipt}. + * 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}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PollerFlux> + public PollerFlux> beginRecognizeReceipts(Flux receipt, long length, RecognizeOptions recognizeOptions) { try { recognizeOptions = getRecognizeOptionsProperties(recognizeOptions); @@ -514,7 +512,7 @@ private Function, Mono> receipt }; } - private Function, Mono>> + private Function, Mono>> fetchExtractReceiptResult(boolean includeFieldElements) { return (pollingContext) -> { try { @@ -522,7 +520,8 @@ private Function, Mono> receipt return service.getAnalyzeReceiptResultWithResponseAsync(resultUid) .map(modelSimpleResponse -> { throwIfAnalyzeStatusInvalid(modelSimpleResponse.getValue()); - return toReceipt(modelSimpleResponse.getValue().getAnalyzeResult(), includeFieldElements); + return toRecognizedForm(modelSimpleResponse.getValue().getAnalyzeResult(), + includeFieldElements); }) .onErrorMap(Utility::mapToHttpResponseExceptionIfExist); } catch (RuntimeException ex) { 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 2d0fcb6f8d425..be8c2332fc80e 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 @@ -11,7 +11,6 @@ import com.azure.ai.formrecognizer.models.OperationResult; import com.azure.ai.formrecognizer.models.RecognizeOptions; import com.azure.ai.formrecognizer.models.RecognizedForm; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; @@ -257,13 +256,13 @@ public SyncPoller> beginRecognizeContent(InputSt * @param receiptUrl The URL of the receipt to analyze. * * @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 RecognizedReceipt}. + * 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 receiptUrl} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public SyncPoller> beginRecognizeReceiptsFromUrl(String receiptUrl) { + public SyncPoller> beginRecognizeReceiptsFromUrl(String receiptUrl) { return beginRecognizeReceiptsFromUrl(receiptUrl, null); } @@ -281,13 +280,13 @@ public SyncPoller> beginRecognizeReceip * analyzing a receipt. Include text lines and element references in the result. * * @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 RecognizedReceipt}. + * 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 receiptUrl} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public SyncPoller> + public SyncPoller> beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeOptions recognizeOptions) { return client.beginRecognizeReceiptsFromUrl(receiptUrl, recognizeOptions).getSyncPoller(); } @@ -306,13 +305,13 @@ public SyncPoller> beginRecognizeReceip * @param length The exact length of the data. * * @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 RecognizedReceipt}. + * 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 receipt} is {@code null}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public SyncPoller> + public SyncPoller> beginRecognizeReceipts(InputStream receipt, long length) { return beginRecognizeReceipts(receipt, length, null); } @@ -333,13 +332,13 @@ public SyncPoller> beginRecognizeReceip * analyzing a receipt. * * @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 RecognizedReceipt}. + * 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}. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public SyncPoller> + public SyncPoller> beginRecognizeReceipts(InputStream receipt, long length, RecognizeOptions recognizeOptions) { Flux buffer = Utility.toFluxByteBuffer(receipt); return client.beginRecognizeReceipts(buffer, length, recognizeOptions).getSyncPoller(); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java index 156c0a8f28aba..9ddbefa914a1d 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java @@ -25,7 +25,6 @@ import com.azure.ai.formrecognizer.models.LengthUnit; import com.azure.ai.formrecognizer.models.Point; import com.azure.ai.formrecognizer.models.RecognizedForm; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; import com.azure.core.util.CoreUtils; import com.azure.core.util.logging.ClientLogger; @@ -80,7 +79,7 @@ static List toRecognizedForm(AnalyzeResult analyzeResult, boolea formPageRange = new FormPageRange(1, 1); } - Map extractedFieldMap = getUnlabeledFieldMap(documentResultItem, readResults, + Map> extractedFieldMap = getUnlabeledFieldMap(documentResultItem, readResults, includeFieldElements); extractedFormList.add(new RecognizedForm( extractedFieldMap, @@ -97,7 +96,7 @@ static List toRecognizedForm(AnalyzeResult analyzeResult, boolea if (clusterId != null) { formType.append(clusterId); } - Map extractedFieldMap = getLabeledFieldMap(includeFieldElements, readResults, + Map> extractedFieldMap = getLabeledFieldMap(includeFieldElements, readResults, pageResultItem, pageNumber); extractedFormList.add(new RecognizedForm( @@ -110,21 +109,6 @@ static List toRecognizedForm(AnalyzeResult analyzeResult, boolea return extractedFormList; } - /** - * Helper method to transform the service returned {@link AnalyzeResult} to SDK model {@link RecognizedReceipt}. - * - * @param analyzeResult The service returned result for analyze receipts. - * @param includeFieldElements Boolean to indicate if to set reference elements data on fields. - * - * @return The List of {@code RecognizedReceipt}. - */ - static List toReceipt(AnalyzeResult analyzeResult, boolean includeFieldElements) { - return toRecognizedForm(analyzeResult, includeFieldElements) - .stream() - .map(recognizedForm -> new RecognizedReceipt(recognizedForm)) - .collect(Collectors.toList()); - } - /** * Helper method to transform the service returned {@link AnalyzeResult} to SDK model {@link FormPage}. * @@ -213,9 +197,9 @@ static List getReadResultFormLines(ReadResult readResultItem) { * * @return The {@code RecognizedForm#getFields}. */ - private static Map getUnlabeledFieldMap(DocumentResult documentResultItem, + private static Map> getUnlabeledFieldMap(DocumentResult documentResultItem, List readResults, boolean includeFieldElements) { - Map extractedFieldMap = new TreeMap<>(); + Map> extractedFieldMap = new TreeMap<>(); // add receipt fields if (!CoreUtils.isNullOrEmpty(documentResultItem.getFields())) { documentResultItem.getFields().forEach((key, fieldValue) -> { @@ -233,8 +217,8 @@ private static Map getUnlabeledFieldMap(DocumentResult docume readResults)); } else { FieldData labelText = new FieldData(key, null, null, null); - extractedFieldMap.put(key, new FormField(DEFAULT_CONFIDENCE_VALUE, labelText, - key, null, null)); + extractedFieldMap.put(key, new FormField<>(DEFAULT_CONFIDENCE_VALUE, labelText, + key, null, null, null)); } }); } @@ -254,52 +238,44 @@ private static Map getUnlabeledFieldMap(DocumentResult docume * * @return The strongly typed {@link FormField} for the field input. */ - private static FormField setFormField(FieldData labelText, String key, FieldValue fieldValue, + private static FormField setFormField(FieldData labelText, String key, FieldValue fieldValue, FieldData valueText, Integer pageNumber, List readResults) { - FormField value; + FormField value; switch (fieldValue.getType()) { case PHONE_NUMBER: - value = new FormField(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, - key, new com.azure.ai.formrecognizer.models.FieldValue(FieldValueType.PHONE_NUMBER). - setFormFieldPhoneNumber(fieldValue.getValuePhoneNumber()), valueText); + value = new FormField<>(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, + key, fieldValue.getValuePhoneNumber(), valueText, FieldValueType.PHONE_NUMBER); break; case STRING: - value = new FormField(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, - key, new com.azure.ai.formrecognizer.models.FieldValue(FieldValueType.STRING) - .setFormFieldString(fieldValue.getValueString()), valueText); + value = new FormField<>(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, + key, fieldValue.getValueString(), valueText, FieldValueType.STRING); break; case TIME: LocalTime fieldTime = fieldValue.getValueTime() == null ? null : LocalTime .parse(fieldValue.getValueTime(), DateTimeFormatter.ofPattern("HH:mm:ss")); - value = new FormField(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, - key, new com.azure.ai.formrecognizer.models.FieldValue(FieldValueType.TIME) - .setFormFieldTime(fieldTime), valueText); + value = new FormField<>(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, + key, fieldTime, valueText, FieldValueType.TIME); break; case DATE: - value = new FormField(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, - key, new com.azure.ai.formrecognizer.models.FieldValue(FieldValueType.DATE) - .setFormFieldDate(fieldValue.getValueDate()), valueText); + value = new FormField<>(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, + key, fieldValue.getValueDate(), valueText, FieldValueType.DATE); break; case INTEGER: - value = new FormField(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, - key, new com.azure.ai.formrecognizer.models.FieldValue(FieldValueType.INTEGER) - .setFormFieldInteger(fieldValue.getValueInteger()), valueText); + value = new FormField<>(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, + key, fieldValue.getValueInteger(), valueText, FieldValueType.LONG); break; case NUMBER: - value = new FormField(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, - key, new com.azure.ai.formrecognizer.models.FieldValue(FieldValueType.FLOAT) - .setFormFieldFloat(fieldValue.getValueNumber()), valueText); + value = new FormField<>(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, + key, fieldValue.getValueNumber(), valueText, FieldValueType.DOUBLE); break; case ARRAY: - value = new FormField(setDefaultConfidenceValue(fieldValue.getConfidence()), null, key, - new com.azure.ai.formrecognizer.models.FieldValue(FieldValueType.LIST) - .setFormFieldList(toFormFieldArray(fieldValue.getValueArray(), readResults)), null); + value = new FormField<>(setDefaultConfidenceValue(fieldValue.getConfidence()), null, key, + toFormFieldArray(fieldValue.getValueArray(), readResults), null, FieldValueType.LIST); break; case OBJECT: - value = new FormField(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, - key, new com.azure.ai.formrecognizer.models.FieldValue(FieldValueType.MAP) - .setFormFieldMap(toFormFieldObject(fieldValue.getValueObject(), pageNumber, readResults)), valueText - ); + value = new FormField<>(setDefaultConfidenceValue(fieldValue.getConfidence()), labelText, + key, toFormFieldObject(fieldValue.getValueObject(), pageNumber, readResults), valueText, + FieldValueType.MAP); break; default: throw LOGGER.logExceptionAsError(new RuntimeException("FieldValue Type not supported")); @@ -327,9 +303,9 @@ private static float setDefaultConfidenceValue(Float confidence) { * * @return The Map of {@link FormField}. */ - private static Map toFormFieldObject(Map valueObject, + private static Map> toFormFieldObject(Map valueObject, Integer pageNumber, List readResults) { - Map fieldValueObjectMap = new TreeMap<>(); + Map> fieldValueObjectMap = new TreeMap<>(); valueObject.forEach((key, fieldValue) -> fieldValueObjectMap.put(key, setFormField(null, key, fieldValue, new FieldData(fieldValue.getText(), @@ -350,7 +326,7 @@ private static Map toFormFieldObject(Map * * @return The List of {@link FormField}. */ - private static List toFormFieldArray(List valueArray, List readResults) { + private static List> toFormFieldArray(List valueArray, List readResults) { return valueArray.stream() .map(fieldValue -> setFormField(null, null, fieldValue, null, fieldValue.getPage(), readResults)) .collect(Collectors.toList()); @@ -388,10 +364,10 @@ private static FormPage getFormPage(ReadResult readResultItem, List p * * @return The fields populated on {@link RecognizedForm#getFields() fields}. */ - private static Map getLabeledFieldMap(boolean includeFieldElements, + private static Map> getLabeledFieldMap(boolean includeFieldElements, List readResults, PageResult pageResultItem, Integer pageNumber) { - Map formFieldMap = new TreeMap<>(); + Map> formFieldMap = new TreeMap<>(); List keyValuePairs = pageResultItem.getKeyValuePairs(); forEachWithIndex(keyValuePairs, ((index, keyValuePair) -> { List formKeyContentList = null; @@ -407,10 +383,8 @@ private static Map getLabeledFieldMap(boolean includeFieldEle toBoundingBox(keyValuePair.getValue().getBoundingBox()), pageNumber, formValueContentList); String fieldName = "field-" + index; - FormField formField = new FormField(setDefaultConfidenceValue(keyValuePair.getConfidence()), - labelFieldData, fieldName, - new com.azure.ai.formrecognizer.models.FieldValue(FieldValueType.STRING) - .setFormFieldString(keyValuePair.getValue().getText()), valueText); + FormField formField = new FormField<>(setDefaultConfidenceValue(keyValuePair.getConfidence()), + labelFieldData, fieldName, keyValuePair.getValue().getText(), valueText, FieldValueType.STRING); formFieldMap.put(fieldName, formField); })); return formFieldMap; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldValue.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldValue.java deleted file mode 100644 index 688930ce24399..0000000000000 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldValue.java +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.ai.formrecognizer.models; - -import com.azure.core.annotation.Fluent; - -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * The FieldValue model. - */ -@Fluent -public final class FieldValue { - private final FieldValueType type; - private Map formFieldMap; - private List formFieldList; - private Float formFieldFloat; - private Integer formFieldInteger; - private LocalDate formFieldDate; - private LocalTime formFieldTime; - private String formFieldString; - private String formFieldPhoneNumber; - - /** - * Constructs a FieldValue object - * - * @param type The type of the field. - */ - public FieldValue(final FieldValueType type) { - this.type = type; - } - - /** - * Set the map value of the field. - * - * @param formFieldMap the map value of the field. - * - * @return the FieldValue object itself. - */ - public FieldValue setFormFieldMap(final Map formFieldMap) { - this.formFieldMap = formFieldMap == null ? null : Collections.unmodifiableMap(formFieldMap); - return this; - } - - /** - * Set the list value of the field. - * - * @param formFieldList the list of the field. - * - * @return the FieldValue object itself. - */ - public FieldValue setFormFieldList(final List formFieldList) { - this.formFieldList = formFieldList == null ? null - : Collections.unmodifiableList(formFieldList); - return this; - } - - /** - * Set the float value of the field. - * - * @param formFieldFloat the float value of the field. - * - * @return the FieldValue object itself. - */ - public FieldValue setFormFieldFloat(final Float formFieldFloat) { - this.formFieldFloat = formFieldFloat; - return this; - } - - /** - * Set the integer value of the field. - * - * @param formFieldInteger the integer value of the field. - * - * @return the FieldValue object itself. - */ - public FieldValue setFormFieldInteger(final Integer formFieldInteger) { - this.formFieldInteger = formFieldInteger; - return this; - } - - /** - * Set the date value of the field. - * - * @param formFieldDate the date value of the field. - * - * @return the FieldValue object itself. - */ - public FieldValue setFormFieldDate(final LocalDate formFieldDate) { - this.formFieldDate = formFieldDate; - return this; - } - - /** - * Set the time value of the field. - * - * @param formFieldTime the time value of the field. - * - * @return the FieldValue object itself. - */ - public FieldValue setFormFieldTime(final LocalTime formFieldTime) { - this.formFieldTime = formFieldTime; - return this; - } - - /** - * Set the string value of the field. - * - * @param formFieldString the string value of the field. - * - * @return the FieldValue object itself. - */ - public FieldValue setFormFieldString(final String formFieldString) { - this.formFieldString = formFieldString; - return this; - } - - /** - * Set the phone number value of the field. - * - * @param formFieldPhoneNumber the phone number value of the field. - * - * @return the FieldValue object itself. - */ - public FieldValue setFormFieldPhoneNumber(final String formFieldPhoneNumber) { - this.formFieldPhoneNumber = formFieldPhoneNumber; - return this; - } - - /** - * Gets the type of the value of the field. - * - * @return the {@link FieldValueType type} of the field. - */ - public FieldValueType getType() { - return type; - } - - /** - * Gets the value of the field as a {@link String}. - * - * @return the value of the field as a {@link String}. - */ - public String asString() { - return this.formFieldString; - } - - /** - * Gets the value of the field as a {@link Integer}. - * - * @return the value of the field as a {@link Integer}. - */ - public Integer asInteger() { - return this.formFieldInteger; - } - - /** - * Gets the value of the field as a {@link Float}. - * - * @return the value of the field as a {@link Float}. - */ - public Float asFloat() { - return this.formFieldFloat; - } - - /** - * Gets the value of the field as a {@link LocalDate}. - * - * @return the value of the field as a {@link LocalDate}. - */ - public LocalDate asDate() { - return this.formFieldDate; - } - - /** - * Gets the value of the field as a {@link LocalTime}. - * - * @return the value of the field as a {@link LocalTime}. - */ - public LocalTime asTime() { - return this.formFieldTime; - } - - /** - * Gets the value of the field as a phone number. - * - * @return the value of the field as a phone number. - */ - public String asPhoneNumber() { - return this.formFieldPhoneNumber; - } - - /** - * Gets the value of the field as a {@link List}. - * - * @return the value of the field as an unmodifiable {@link List}. - */ - public List asList() { - return this.formFieldList; - } - - /** - * Gets the value of the field as a {@link Map}. - * - * @return the value of the field as an unmodifiable {@link Map}. - */ - public Map asMap() { - return this.formFieldMap; - } -} diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldValueType.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldValueType.java index 93e5f7dda8b03..975c61ae89c43 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldValueType.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FieldValueType.java @@ -3,62 +3,179 @@ package com.azure.ai.formrecognizer.models; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; +import com.azure.core.util.logging.ClientLogger; -/** Defines values for FieldValueType. */ +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.util.Objects; + +/** + * Define enum values for FieldValue types. + */ +@SuppressWarnings("unchecked") public enum FieldValueType { - /** Enum value string. */ - STRING("string"), + /** + * Static value string for FieldValueType. + */ + STRING { + @Override + public T cast(FormField formField) { + if (isFieldValueNull(formField)) { + return null; + } + return (T) String.valueOf(formField.getValue()); + } + }, - /** Enum value date. */ - DATE("date"), + /** + * Static value date for FieldValueType. + */ + DATE { + @Override + public T cast(FormField formField) { + if (isFieldValueNull(formField)) { + return null; + } + if (this == formField.getValueType()) { + return (T) formField.getValue(); + } else if (STRING == formField.getValueType()) { + return (T) LocalDate.parse(formField.getValue().toString(), DateTimeFormatter.ofPattern("yyyy/MM/dd")); + } else { + throw LOGGER.logExceptionAsError(new UnsupportedOperationException(String.format("Cannot cast from " + + "field value of type %s to type %s", formField.getValueType(), DATE))); + } + } + }, - /** Enum value time. */ - TIME("time"), + /** + * Static value time for FieldValueType. + */ + TIME { + @Override + public T cast(FormField formField) { + if (isFieldValueNull(formField)) { + return null; + } + if (this == formField.getValueType()) { + return (T) formField.getValue(); + } else if (STRING == formField.getValueType()) { + return (T) LocalTime.parse(formField.getValue().toString(), DateTimeFormatter.ofPattern("HH:mm:ss")); + } else { + throw LOGGER.logExceptionAsError(new UnsupportedOperationException(String.format("Cannot cast from " + + "field value of type %s to type %s", formField.getValueType(), TIME))); + } + } + }, - /** Enum value phoneNumber. */ - PHONE_NUMBER("phoneNumber"), + /** + * Static value phone number for FieldValueType. + */ + PHONE_NUMBER { + @Override + public T cast(FormField formField) { + if (isFieldValueNull(formField)) { + return null; + } + if (this == formField.getValueType()) { + return (T) formField.getValue(); + } else if (STRING == formField.getValueType()) { + return (T) formField.getValue(); + } else { + throw LOGGER.logExceptionAsError(new UnsupportedOperationException(String.format("Cannot cast from " + + "field value of type %s to type %s", formField.getValueType(), PHONE_NUMBER))); + } + } + }, - /** Enum value number. */ - FLOAT("float"), + /** + * Static value double for FieldValueType. + */ + DOUBLE { + @Override + public T cast(FormField formField) { + if (isFieldValueNull(formField)) { + return null; + } + if (this == formField.getValueType()) { + return (T) formField.getValue(); + } else if (STRING == formField.getValueType()) { + return (T) Double.valueOf(formField.getValue().toString()); + } else { + throw LOGGER.logExceptionAsError(new UnsupportedOperationException(String.format("Cannot cast from " + + "field value of type %s to type %s", formField.getValueType(), DOUBLE))); + } + } + }, - /** Enum value integer. */ - INTEGER("integer"), + /** + * Static value long for FieldValueType. + */ + LONG { + @Override + public T cast(FormField formField) { + if (isFieldValueNull(formField)) { + return null; + } + if (this == formField.getValueType()) { + return (T) formField.getValue(); + } else if (STRING == formField.getValueType()) { + return (T) Long.valueOf(formField.getValue().toString()); + } else { + throw LOGGER.logExceptionAsError(new UnsupportedOperationException(String.format("Cannot cast from " + + "field value of type %s to type %s", formField.getValueType(), LONG))); + } + } + }, - /** Enum value array. */ - LIST("list"), + /** + * Static value list for FieldValueType. + */ + LIST { + @Override + public T cast(FormField formField) { + return getCollectionTypeCast(formField); + } + }, - /** Enum value object. */ - MAP("map"); + /** + * Static value map for FieldValueType. + */ + MAP { + @Override + public T cast(FormField formField) { + return getCollectionTypeCast(formField); + } + }; - /** The actual serialized value for a FieldValueType instance. */ - private final String value; + static boolean isFieldValueNull(FormField formField) { + Objects.requireNonNull(formField, "'formField' cannot be null"); + return formField.getValue() == null; + } - FieldValueType(String value) { - this.value = value; + T getCollectionTypeCast(FormField formField) { + if (isFieldValueNull(formField)) { + return null; + } + if (this == formField.getValueType()) { + return (T) formField.getValue(); + } else { + throw LOGGER.logExceptionAsError(new UnsupportedOperationException(String.format("Cannot cast from " + + "field value of type %s to type %s", formField.getValueType(), this))); + } } + private static final ClientLogger LOGGER = new ClientLogger(FieldValueType.class); + /** - * Parses a serialized value to a FieldValueType instance. + * Converts the form field value to a specific enum type. + * + * @param formField The recognized field value that needs to be converted. + * @param the class of the field. * - * @param value the serialized value to parse. - * @return the parsed FieldValueType object, or null if unable to parse. + * @return the converted value of the recognized field. + * @throws UnsupportedOperationException if the {@code formField} type does not match the casting value type. + * @throws NullPointerException if {@code formField} is {@code null} */ - @JsonCreator - public static FieldValueType fromString(String value) { - FieldValueType[] items = FieldValueType.values(); - for (FieldValueType item : items) { - if (item.toString().equalsIgnoreCase(value)) { - return item; - } - } - return null; - } - - @JsonValue - @Override - public String toString() { - return this.value; - } + public abstract T cast(FormField formField); } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormField.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormField.java index 036bfbef2db2e..6eef6b1912568 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormField.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/FormField.java @@ -9,13 +9,14 @@ * The FormField model. */ @Immutable -public final class FormField { +public final class FormField { private final float confidence; private final FieldData labelData; private final String name; - private final FieldValue fieldValue; private final FieldData valueData; + private final T value; + private final FieldValueType valueType; /** * Constructs a FormField object. @@ -23,16 +24,18 @@ public final class FormField { * @param confidence The confidence of the recognized field. * @param labelData The text, bounding box, and field elements for the field label. * @param name The name the field or label. - * @param fieldValue The value of the recognized field. + * @param value The value of the recognized field. * @param valueData The text, bounding box, and field elements for the field value. + * @param valueType The type of the value of the recognized field. */ - public FormField(final float confidence, final FieldData labelData, final String name, final FieldValue fieldValue, - final FieldData valueData) { + public FormField(final float confidence, final FieldData labelData, final String name, final T value, + final FieldData valueData, FieldValueType valueType) { this.confidence = confidence; this.labelData = labelData; this.name = name; - this.fieldValue = fieldValue; + this.value = value; this.valueData = valueData; + this.valueType = valueType; } /** @@ -65,14 +68,25 @@ public String getName() { /** * Get the value of the recognized field. * - * @return Value of the recognized field. + * @return the value of the recognized field. */ - public FieldValue getFieldValue() { - return this.fieldValue; + public T getValue() { + return this.value; } /** - * Get the text, bounding box, and field elements for the field value. + * The type of the value of the recognized field. + * Possible types include: 'String', + * 'LocalDate', 'LocalTime', 'Long', 'Double', 'Map', or 'List'. + * + * @return the type of the value of the field. + */ + public FieldValueType getValueType() { + return valueType; + } + + /** + * Get the text, bounding box, and text content of the field value. * * @return the text, bounding box, and field elements for the field value. */ diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedForm.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedForm.java index 5a8c11011ca7e..9b775763a9f4b 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedForm.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedForm.java @@ -20,7 +20,7 @@ public final class RecognizedForm { * For models trained with labels, this is the training-time label of the field. For models trained with forms * only, a unique name is generated for each field. */ - private final Map fields; + private final Map> fields; /* * Form type. @@ -45,7 +45,7 @@ public final class RecognizedForm { * @param formPageRange First and last page number where the document is found. * @param pages List of extracted pages from the form. */ - public RecognizedForm(final Map fields, final String formType, + public RecognizedForm(final Map> fields, final String formType, final FormPageRange formPageRange, final List pages) { this.fields = fields == null ? null : Collections.unmodifiableMap(fields); this.formType = formType; @@ -60,7 +60,7 @@ public RecognizedForm(final Map fields, final String formType * * @return the unmodifiable map of recognized fields. */ - public Map getFields() { + public Map> getFields() { return this.fields; } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedReceipt.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedReceipt.java deleted file mode 100644 index 2f16596dfaca8..0000000000000 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedReceipt.java +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.ai.formrecognizer.models; - -import com.azure.core.annotation.Immutable; - -/** - * The RecognizedReceipt model. - */ -@Immutable -public class RecognizedReceipt { - - /** - * The recognized form. - */ - private final RecognizedForm recognizedForm; - - /** - * Constructs a RecognizedReceipt object. - * - * @param recognizedForm The recognized form. - */ - public RecognizedReceipt(final RecognizedForm recognizedForm) { - this.recognizedForm = recognizedForm; - } - - /** - * Get the extracted field information form for the provided document. - * - * @return The extracted field information form for the provided document. - */ - public RecognizedForm getRecognizedForm() { - return this.recognizedForm; - } -} 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 e380fce535a96..b3a96dd6c8955 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 @@ -78,7 +78,7 @@ public static void main(String[] args) throws IOException { } System.out.printf("Field %s has value %s based on %s within bounding box %s with a confidence score " + "of %.2f.%n", - label, formField.getFieldValue(), formField.getValueData().getText(), boundingBoxStr, + label, formField.getValue(), formField.getValueData().getText(), boundingBoxStr, formField.getConfidence()); // Find the value of a specific labeled field. @@ -120,7 +120,7 @@ public static void main(String[] args) throws IOException { System.out.printf("Field %s has value %s based on %s within bounding box %s with a confidence score " + "of %.2f.%n", - label, formField.getFieldValue(), formField.getValueData().getText(), boundingBoxStr, + label, formField.getValue(), formField.getValueData().getText(), boundingBoxStr, formField.getConfidence()); // Find the value of a specific unlabeled field. The specific key "Vendor Name:" provided in the example diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/AdvancedDiffLabeledUnlabeledDataAsync.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/AdvancedDiffLabeledUnlabeledDataAsync.java index f5e14b6167076..24b783a515d1a 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/AdvancedDiffLabeledUnlabeledDataAsync.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/AdvancedDiffLabeledUnlabeledDataAsync.java @@ -108,7 +108,7 @@ public static void main(String[] args) throws IOException { } System.out.printf("Field %s has value %s based on %s within bounding box %s with a confidence score " + "of %.2f.%n", - label, formField.getFieldValue(), formField.getValueData().getText(), boundingBoxStr, + label, formField.getValue(), formField.getValueData().getText(), boundingBoxStr, formField.getConfidence()); // Find the value of a specific labeled field. @@ -157,7 +157,7 @@ public static void main(String[] args) throws IOException { System.out.printf("Field %s has value %s based on %s within bounding box %s with a confidence " + "score of %.2f.%n", - label, formField.getFieldValue(), formField.getValueData().getText(), boundingBoxStr, + label, formField.getValue(), formField.getValueData().getText(), boundingBoxStr, formField.getConfidence()); // Find the value of a specific unlabeled field. The specific key "Vendor Name:" provided in the diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/Authentication.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/Authentication.java index a8ddc6396270a..121fa1b04037c 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/Authentication.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/Authentication.java @@ -7,21 +7,21 @@ import com.azure.ai.formrecognizer.models.FieldValueType; import com.azure.ai.formrecognizer.models.FormField; import com.azure.ai.formrecognizer.models.OperationResult; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.ai.formrecognizer.training.FormTrainingClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.util.polling.SyncPoller; import com.azure.identity.DefaultAzureCredentialBuilder; -import java.io.IOException; +import java.time.LocalDate; import java.util.List; import java.util.Map; /** * Samples for two supported methods of authentication in Form Recognizer and Form Training clients: - * 1) Use a Form Recognizer API key with AzureKeyCredential from azure.core.credentials - * 2) Use a token credential from azure-identity to authenticate with Azure Active Directory + * 1) Use a Form Recognizer API key with AzureKeyCredential from azure.core.credentials + * 2) Use a token credential from azure-identity to authenticate with Azure Active Directory */ public class Authentication { /** @@ -29,16 +29,15 @@ public class Authentication { * * @param args Unused arguments to the program. * - * @throws IOException Exception thrown when there is an error in reading all the bytes from the File. */ public static void main(String[] args) { - /* - Set the environment variables with your own values before running the sample: + /** + * Set the environment variables with your own values before running the sample: + * AZURE_CLIENT_ID - the client ID of your active directory application. + * AZURE_TENANT_ID - the tenant ID of your active directory application. + * AZURE_CLIENT_SECRET - the secret of your active directory application. + */ - 1) AZURE_CLIENT_ID - the client ID of your active directory application. - 2) AZURE_TENANT_ID - the tenant ID of your active directory application. - 3) AZURE_CLIENT_SECRET - the secret of your active directory application. - */ // Form recognizer client: Key credential authenticationWithKeyCredentialFormRecognizerClient(); // Form recognizer client: Azure Active Directory @@ -82,52 +81,72 @@ private static void authenticationWithAzureActiveDirectoryFormTrainingClient() { } private static void beginRecognizeCustomFormsFromUrl(FormRecognizerClient formRecognizerClient) { - String receiptUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/sample-forms/receipts/contoso-allinone.jpg"; + String receiptUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/sdk/formrecognizer" + + "/azure-ai-formrecognizer/src/samples/java/sample-forms/receipts/contoso-allinone.jpg"; - SyncPoller> recognizeReceiptPoller = + SyncPoller> recognizeReceiptPoller = formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl); - List receiptPageResults = recognizeReceiptPoller.getFinalResult(); + List receiptPageResults = recognizeReceiptPoller.getFinalResult(); for (int i = 0; i < receiptPageResults.size(); i++) { - RecognizedReceipt recognizedReceipt = receiptPageResults.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); + RecognizedForm recognizedForm = receiptPageResults.get(i); + Map> recognizedFields = recognizedForm.getFields(); System.out.printf("----------- Recognized Receipt page %d -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } + } + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Name")) { - if (formField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Name: %s, confidence: %.2fs%n", - formField.getFieldValue().asString(), - formField.getConfidence()); + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Name".equals(key)) { + if (FieldValueType.STRING.equals(formField.getValueType())) { + String name = FieldValueType.STRING.cast(formField); + System.out.printf("Name: %s, confidence: %.2fs%n", + name, formField.getConfidence()); + } } - } - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %s, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %f, confidence: %.2f%n", + quantity, formField.getConfidence()); + } } - } - }); - } - }); + }); + } + }); + } } System.out.print("-----------------------------------"); } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientJavaDocCodeSnippets.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientJavaDocCodeSnippets.java index ab23ef74d3c29..3ac36fa322436 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientJavaDocCodeSnippets.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientJavaDocCodeSnippets.java @@ -7,7 +7,7 @@ import com.azure.ai.formrecognizer.models.FormContentType; import com.azure.ai.formrecognizer.models.FormField; import com.azure.ai.formrecognizer.models.RecognizeOptions; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; @@ -19,6 +19,7 @@ import java.nio.ByteBuffer; import java.nio.file.Files; import java.time.Duration; +import java.time.LocalDate; import java.util.List; import java.util.Map; @@ -76,7 +77,7 @@ public void beginRecognizeCustomFormsFromUrl() { recognizedForms.forEach(recognizedForm -> { recognizedForm.getFields().forEach((fieldText, fieldValue) -> { System.out.printf("Field text: %s%n", fieldText); - System.out.printf("Field value: %s%n", fieldValue.getFieldValue()); + System.out.printf("Field value: %s%n", fieldValue.getValue()); System.out.printf("Confidence score: %.2f%n", fieldValue.getConfidence()); }); })); @@ -103,7 +104,7 @@ public void beginRecognizeCustomFormsFromUrlWithOptions() { recognizedForms.forEach(recognizedForm -> { recognizedForm.getFields().forEach((fieldText, fieldValue) -> { System.out.printf("Field text: %s%n", fieldText); - System.out.printf("Field value: %s%n", fieldValue.getFieldValue()); + System.out.printf("Field value: %s%n", fieldValue.getValue()); System.out.printf("Confidence score: %.2f%n", fieldValue.getConfidence()); }); })); @@ -129,7 +130,7 @@ public void beginRecognizeCustomForms() throws IOException { recognizedForms.forEach(recognizedForm -> { recognizedForm.getFields().forEach((fieldText, fieldValue) -> { System.out.printf("Field text: %s%n", fieldText); - System.out.printf("Field value: %s%n", fieldValue.getFieldValue()); + System.out.printf("Field value: %s%n", fieldValue.getValue()); System.out.printf("Confidence score: %.2f%n", fieldValue.getConfidence()); }); })); @@ -162,7 +163,7 @@ public void beginRecognizeCustomFormsWithOptions() throws IOException { recognizedForms.forEach(recognizedForm -> { recognizedForm.getFields().forEach((fieldText, fieldValue) -> { System.out.printf("Field text: %s%n", fieldText); - System.out.printf("Field value: %s%n", fieldValue.getFieldValue()); + System.out.printf("Field value: %s%n", fieldValue.getValue()); System.out.printf("Confidence score: %.2f%n", fieldValue.getConfidence()); }); })); @@ -289,37 +290,57 @@ public void beginRecognizeReceiptsFromUrl() { recognizePollingOperation.getFinalResult()) .subscribe(recognizedReceipts -> { for (int i = 0; i < recognizedReceipts.size(); i++) { - RecognizedReceipt recognizedReceipt = recognizedReceipts.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); + RecognizedForm recognizedForm = recognizedReceipts.get(i); + Map> recognizedFields = recognizedForm.getFields(); System.out.printf("----------- Recognized Receipt page %d -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } + } + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %s, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %f, confidence: %.2f%n", + quantity, formField.getConfidence()); + } } - } - }); - } - }); + }); + } + }); + } } } }); @@ -342,37 +363,57 @@ public void beginRecognizeReceiptsFromUrlWithOptions() { recognizePollingOperation.getFinalResult()) .subscribe(recognizedReceipts -> { for (int i = 0; i < recognizedReceipts.size(); i++) { - RecognizedReceipt recognizedReceipt = recognizedReceipts.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); - System.out.printf("----------- Recognized Receipt page %s -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + RecognizedForm recognizedReceipt = recognizedReceipts.get(i); + Map> recognizedFields = recognizedReceipt.getFields(); + System.out.printf("----------- Recognized Receipt page %d -----------%n", i); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %s, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } + } + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %f, confidence: %.2f%n", + quantity, formField.getConfidence()); + } } - } - }); - } - }); + }); + } + }); + } } } }); @@ -389,45 +430,64 @@ public void beginRecognizeReceipts() throws IOException { File receipt = new File("{file_source_url}"); Flux buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(receipt.toPath()))); formRecognizerAsyncClient.beginRecognizeReceipts(buffer, receipt.length()) - .flatMap(recognizePollingOperation -> + .subscribe(recognizePollingOperation -> // if training polling operation completed, retrieve the final result. - recognizePollingOperation.getFinalResult()) - .subscribe(recognizedReceipts -> { - for (int i = 0; i < recognizedReceipts.size(); i++) { - RecognizedReceipt recognizedReceipt = recognizedReceipts.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); - System.out.printf("----------- Recognized Receipt page %s -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); - } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); - } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %s, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); - } + recognizePollingOperation.getFinalResult().subscribe(recognizedReceipts -> { + for (int i = 0; i < recognizedReceipts.size(); i++) { + RecognizedForm recognizedForm = recognizedReceipts.get(i); + Map> recognizedFields = recognizedForm.getFields(); + System.out.printf("----------- Recognized Receipt page %d -----------%n", i); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } + } + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } + } + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } + } + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %f, confidence: %.2f%n", + quantity, formField.getConfidence()); + } + } + }); } }); } - }); + } } - } - }); + })); // END: com.azure.ai.formrecognizer.FormRecognizerAsyncClient.beginRecognizeReceipts#Flux-long } @@ -448,45 +508,65 @@ public void beginRecognizeReceiptsWithOptions() throws IOException { .setContentType(FormContentType.IMAGE_JPEG) .setIncludeFieldElements(includeFieldElements) .setPollInterval(Duration.ofSeconds(5))) - .flatMap(recognizePollingOperation -> + .subscribe(recognizePollingOperation -> // if training polling operation completed, retrieve the final result. - recognizePollingOperation.getFinalResult()) - .subscribe(recognizedReceipts -> { - for (int i = 0; i < recognizedReceipts.size(); i++) { - RecognizedReceipt recognizedReceipt = recognizedReceipts.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); - System.out.printf("----------- Recognized Receipt page %s -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); - } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); - } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %s, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); - } + recognizePollingOperation.getFinalResult().subscribe(recognizedReceipts -> { + for (int i = 0; i < recognizedReceipts.size(); i++) { + RecognizedForm recognizedForm = recognizedReceipts.get(i); + Map> recognizedFields = recognizedForm.getFields(); + System.out.printf("----------- Recognized Receipt page %d -----------%n", i); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } + } + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } + } + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } + } + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %f, confidence: %.2f%n", + quantity, formField.getConfidence()); + } + } + }); } }); } - }); + } } - } - }); + })); + // END: com.azure.ai.formrecognizer.FormRecognizerAsyncClient.beginRecognizeReceipts#Flux-long-recognizeOptions } } 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 f1aa02207094a..3e88ff23d154f 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 @@ -17,6 +17,7 @@ import java.io.InputStream; import java.nio.file.Files; import java.time.Duration; +import java.time.LocalDate; import java.util.List; import java.util.Map; @@ -67,13 +68,12 @@ public void beginRecognizeCustomFormsFromUrl() { String modelId = "{custom_trained_model_id}"; formRecognizerClient.beginRecognizeCustomFormsFromUrl(formUrl, modelId).getFinalResult() - .forEach(recognizedForm -> { + .forEach(recognizedForm -> recognizedForm.getFields().forEach((fieldText, fieldValue) -> { System.out.printf("Field text: %s%n", fieldText); - System.out.printf("Field value: %s%n", fieldValue.getFieldValue()); + System.out.printf("Field value: %s%n", fieldValue.getValue()); System.out.printf("Confidence score: %.2f%n", fieldValue.getConfidence()); - }); - }); + })); // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomFormsFromUrl#string-string } @@ -94,7 +94,7 @@ public void beginRecognizeCustomFormsFromUrlWithOptions() { .getFinalResult() .forEach(recognizedForm -> recognizedForm.getFields().forEach((fieldText, fieldValue) -> { System.out.printf("Field text: %s%n", fieldText); - System.out.printf("Field value: %s%n", fieldValue.getFieldValue()); + System.out.printf("Field value: %s%n", fieldValue.getValue()); System.out.printf("Confidence score: %.2f%n", fieldValue.getConfidence()); })); // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomFormsFromUrl#string-string-recognizeOptions @@ -116,7 +116,7 @@ public void beginRecognizeCustomForms() throws IOException { formRecognizerClient.beginRecognizeCustomForms(targetStream, form.length(), modelId).getFinalResult() .forEach(recognizedForm -> recognizedForm.getFields().forEach((fieldText, fieldValue) -> { System.out.printf("Field text: %s%n", fieldText); - System.out.printf("Field value: %s%n", fieldValue.getFieldValue()); + System.out.printf("Field value: %s%n", fieldValue.getValue()); System.out.printf("Confidence score: %.2f%n", fieldValue.getConfidence()); })); // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomForms#InputStream-long-string @@ -145,7 +145,7 @@ public void beginRecognizeCustomFormsWithOptions() throws IOException { .getFinalResult() .forEach(recognizedForm -> recognizedForm.getFields().forEach((fieldText, fieldValue) -> { System.out.printf("Field text: %s%n", fieldText); - System.out.printf("Field value: %s%n", fieldValue.getFieldValue()); + System.out.printf("Field value: %s%n", fieldValue.getValue()); System.out.printf("Confidence score: %.2f%n", fieldValue.getConfidence()); })); // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeCustomForms#InputStream-long-string-recognizeOptions @@ -250,35 +250,54 @@ public void beginRecognizeReceiptsFromUrl() { String receiptUrl = "{file_source_url}"; formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl).getFinalResult() .forEach(recognizedReceipt -> { - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + Map> recognizedFields = recognizedReceipt.getFields(); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } + } + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %s, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %d, confidence: %.2f%n", + quantity, formField.getConfidence()); + } } - } - }); - } - }); + }); + } + }); + } } }); // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceiptsFromUrl#string @@ -289,38 +308,57 @@ public void beginRecognizeReceiptsFromUrl() { */ public void beginRecognizeReceiptsFromUrlWithOptions() { // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceiptsFromUrl#string-recognizeOptions - String receiptUrl = "{file_source_url}"; + String receiptUrl = "{receipt_url}"; formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl).getFinalResult() .forEach(recognizedReceipt -> { - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + Map> recognizedFields = recognizedReceipt.getFields(); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } + } + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %s, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %d, confidence: %.2f%n", + quantity, formField.getConfidence()); + } } - } - }); - } - }); + }); + } + }); + } } }); // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceiptsFromUrl#string-recognizeOptions @@ -333,41 +371,60 @@ public void beginRecognizeReceiptsFromUrlWithOptions() { */ public void beginRecognizeReceipts() throws IOException { // BEGIN: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceipts#InputStream-long - File receipt = new File("{file_source_url}"); + File receipt = new File("{receipt_url}"); byte[] fileContent = Files.readAllBytes(receipt.toPath()); InputStream targetStream = new ByteArrayInputStream(fileContent); formRecognizerClient.beginRecognizeReceipts(targetStream, receipt.length()) .getFinalResult().forEach(recognizedReceipt -> { - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + Map> recognizedFields = recognizedReceipt.getFields(); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %d, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } + } + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %d, confidence: %.2f%n", + quantity, formField.getConfidence()); + } } - } - }); - } - }); + }); + } + }); + } } }); // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceipts#InputStream-long @@ -392,35 +449,54 @@ public void beginRecognizeReceiptsWithOptions() throws IOException { .setIncludeFieldElements(includeFieldElements) .setPollInterval(Duration.ofSeconds(5))) .getFinalResult().forEach(recognizedReceipt -> { - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + Map> recognizedFields = recognizedReceipt.getFields(); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } + } + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %d, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %d, confidence: %.2f%n", + quantity, formField.getConfidence()); + } } - } - }); - } - }); + }); + } + }); + } } }); // END: com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceipts#InputStream-long-recognizeOptions 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 ed281654cad82..f6f72e2d9c951 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 @@ -50,7 +50,7 @@ public static void main(String[] args) { recognizedForm.getFields().forEach((fieldText, fieldValue) -> System.out.printf("Field %s has value %s " + "based on %s with a confidence score " + "of %.2f.%n", - fieldText, fieldValue.getFieldValue(), fieldValue.getValueData().getText(), + fieldText, fieldValue.getValue(), fieldValue.getValueData().getText(), fieldValue.getConfidence())); // Page Information diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxesAsync.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxesAsync.java index c8931c16ab2ac..ebfad4bdc35f7 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxesAsync.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/GetBoundingBoxesAsync.java @@ -63,7 +63,7 @@ public static void main(String[] args) { recognizedForm.getFields().forEach((fieldText, fieldValue) -> { System.out.printf("Field %s has value %s based on %s with a confidence score " + "of %.2f.%n", - fieldText, fieldValue.getFieldValue(), fieldValue.getValueData().getText(), + fieldText, fieldValue.getValue(), fieldValue.getValueData().getText(), fieldValue.getConfidence()); }); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ReadmeSamples.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ReadmeSamples.java index d58e884434b32..e1851afe0cd48 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ReadmeSamples.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ReadmeSamples.java @@ -11,7 +11,6 @@ import com.azure.ai.formrecognizer.models.FormPage; import com.azure.ai.formrecognizer.models.OperationResult; import com.azure.ai.formrecognizer.models.RecognizedForm; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.ai.formrecognizer.training.FormTrainingClientBuilder; import com.azure.core.credential.AzureKeyCredential; @@ -26,6 +25,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import java.time.LocalDate; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -95,14 +95,13 @@ public void recognizeCustomForm() { for (int i = 0; i < recognizedForms.size(); i++) { RecognizedForm form = recognizedForms.get(i); - System.out.printf("----------- Recognized Form %d-----------%n", i); + System.out.printf("----------- Recognized Form %d -----------%n", i); System.out.printf("Form type: %s%n", form.getFormType()); - form.getFields().forEach((label, formField) -> { + form.getFields().forEach((label, formField) -> System.out.printf("Field %s has value %s with confidence score of %f.%n", label, formField.getValueData().getText(), - formField.getConfidence()); - }); - System.out.print("-----------------------------------"); + formField.getConfidence()) + ); } } @@ -124,7 +123,7 @@ public void recognizeContent() throws IOException { for (int i = 0; i < contentPageResults.size(); i++) { FormPage formPage = contentPageResults.get(i); - System.out.printf("----Recognizing content for page %d----%n", i); + System.out.printf("----Recognizing content for page %d ----%n", i); // Table information System.out.printf("Has width: %f and height: %f, measured with unit: %s.%n", formPage.getWidth(), formPage.getHeight(), @@ -132,10 +131,8 @@ public void recognizeContent() throws IOException { formPage.getTables().forEach(formTable -> { System.out.printf("Table has %d rows and %d columns.%n", formTable.getRowCount(), formTable.getColumnCount()); - formTable.getCells().forEach(formTableCell -> { - System.out.printf("Cell has text %s.%n", formTableCell.getText()); - }); - System.out.println(); + formTable.getCells().forEach(formTableCell -> + System.out.printf("Cell has text %s.%n", formTableCell.getText())); }); } } @@ -143,49 +140,61 @@ public void recognizeContent() throws IOException { public void recognizeReceipt() { String receiptUrl = "https://docs.microsoft.com/en-us/azure/cognitive-services/form-recognizer/media" + "/contoso-allinone.jpg"; - SyncPoller> syncPoller = + SyncPoller> syncPoller = formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl); - List receiptPageResults = syncPoller.getFinalResult(); + List receiptPageResults = syncPoller.getFinalResult(); for (int i = 0; i < receiptPageResults.size(); i++) { - RecognizedReceipt recognizedReceipt = receiptPageResults.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); + RecognizedForm recognizedForm = receiptPageResults.get(i); + Map> recognizedFields = recognizedForm.getFields(); System.out.printf("----------- Recognized Receipt page %d -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + FormField merchantNameField = recognizedFields.get("MerchantName"); + if (merchantNameField != null) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", + merchantName, merchantNameField.getConfidence()); + } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { - System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } } - FormField receiptItemsField = recognizedFields.get("Items"); - System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); - receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Name")) { - if (formField.getFieldValue().getType() == FieldValueType.STRING) { - System.out.printf("Name: %s, confidence: %.2fs%n", - formField.getFieldValue().asString(), - formField.getConfidence()); - } - } - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %d, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + + FormField transactionDateField = recognizedFields.get("TransactionDate"); + if (transactionDateField != null) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + transactionDate, transactionDateField.getConfidence()); + } + } + + FormField receiptItemsField = recognizedFields.get("Items"); + if (receiptItemsField != null) { + System.out.printf("Receipt Items: %n"); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); + receiptItems.forEach(receiptItem -> { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %f, confidence: %.2f%n", + quantity, formField.getConfidence()); + } } - } - }); - } - }); + }); + } + }); + } } } } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/Receipt.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/Receipt.java new file mode 100644 index 0000000000000..f174d8f2ff629 --- /dev/null +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/Receipt.java @@ -0,0 +1,360 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.ai.formrecognizer; + +import com.azure.ai.formrecognizer.models.FormField; +import com.azure.ai.formrecognizer.models.RecognizedForm; +import com.azure.core.annotation.Immutable; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * The Receipt model. + */ +public final class Receipt { + + /** + * List of recognized field items. + */ + private List receiptItems; + + /** + * Recognized receipt type information. + */ + private ReceiptType receiptType; + + /** + * Recognized field merchant name. + */ + private FormField merchantName; + + /** + * Recognized field merchant address. + */ + private FormField merchantAddress; + + /** + * Recognized field merchant phone number. + */ + private FormField merchantPhoneNumber; + + /** + * Recognized field subtotal. + */ + private FormField subtotal; + + /** + * Recognized field tax. + */ + private FormField tax; + + /** + * Recognized field tip. + */ + private FormField tip; + + /** + * Recognized field total. + */ + private FormField total; + + /** + * Recognized field transaction date. + */ + private FormField transactionDate; + + /** + * Recognized field transaction time. + */ + private FormField transactionTime; + + @SuppressWarnings("unchecked") + public Receipt(RecognizedForm recognizedForm) { + for (Map.Entry> entry : recognizedForm.getFields().entrySet()) { + String key = entry.getKey(); + FormField fieldValue = entry.getValue(); + switch (key) { + case "ReceiptType": + receiptType = new ReceiptType(((FormField) fieldValue).getValue(), + fieldValue.getConfidence()); + break; + case "MerchantName": + merchantName = (FormField) fieldValue; + break; + case "MerchantAddress": + merchantAddress = (FormField) fieldValue; + break; + case "MerchantPhoneNumber": + merchantPhoneNumber = (FormField) fieldValue; + break; + case "Subtotal": + subtotal = (FormField) fieldValue; + break; + case "Tax": + tax = (FormField) fieldValue; + break; + case "Tip": + tip = (FormField) fieldValue; + break; + case "Total": + total = (FormField) fieldValue; + break; + case "TransactionDate": + transactionDate = (FormField) fieldValue; + break; + case "TransactionTime": + transactionTime = (FormField) fieldValue; + break; + case "Items": + receiptItems = Collections.unmodifiableList(toReceiptItems(fieldValue)); + break; + default: + break; + } + } + } + + /** + * Get the itemized fields in the Recognized Receipt. + * + * @return the unmodifiable list of itemized fields on the receipt. + */ + public List getReceiptItems() { + return this.receiptItems; + } + + /** + * Get the type of Recognized Receipt. + * + * @return the type of Recognized Receipt. + */ + public ReceiptType getReceiptType() { + return this.receiptType; + } + + /** + * Get the merchant name field. + * + * @return the merchantName value. + */ + public FormField getMerchantName() { + return this.merchantName; + } + + /** + * Get the merchant address field. + * + * @return the merchantAddress value. + */ + public FormField getMerchantAddress() { + return this.merchantAddress; + } + + /** + * Get the merchant Phone number field. + * + * @return the merchantPhoneNumber value. + */ + public FormField getMerchantPhoneNumber() { + return this.merchantPhoneNumber; + } + + /** + * Get the subtotal field. + * + * @return the subtotal value. + */ + public FormField getSubtotal() { + return this.subtotal; + } + + /** + * Get the tax field. + * + * @return the tax value. + */ + public FormField getTax() { + return this.tax; + } + + /** + * Get the tip field. + * + * @return the tip value. + */ + public FormField getTip() { + return this.tip; + } + + /** + * Get the Total field. + * + * @return the total value. + */ + public FormField getTotal() { + return this.total; + } + + /** + * Get the Transaction date field. + * + * @return the transactionDate value. + */ + public FormField getTransactionDate() { + return this.transactionDate; + } + + /** + * Get the transaction time field. + * + * @return the transactionTime value. + */ + public FormField getTransactionTime() { + return this.transactionTime; + } + + /** + * Helper method to convert the service level + * {@link com.azure.ai.formrecognizer.implementation.models.FieldValue#getValueArray() value items} + * to SDK level {@link ReceiptItem receipt items}. + * + * @param fieldValueItems The strongly typed field values. + * b + * + * @return An unmodifiable list of {@link ReceiptItem}. + */ + @SuppressWarnings("unchecked") + private static List toReceiptItems(FormField fieldValueItems) { + List> fieldValueArray = (List>) fieldValueItems.getValue(); + List receiptItemList = new ArrayList<>(); + + for (FormField eachFieldValue : fieldValueArray) { + Map> objectValue = ((Map>) (eachFieldValue.getValue())); + FormField name = null; + FormField quantity = null; + FormField price = null; + FormField totalPrice = null; + for (Map.Entry> entry : objectValue.entrySet()) { + String key = entry.getKey(); + if ("Quantity".equals(key)) { + quantity = (FormField) entry.getValue(); + } else if ("Name".equals(key)) { + name = (FormField) entry.getValue(); + } else if ("Price".equals(key)) { + price = (FormField) entry.getValue(); + } else if ("Total Price".equals(key)) { + totalPrice = (FormField) entry.getValue(); + } + } + receiptItemList.add(new ReceiptItem(name, quantity, price, totalPrice)); + } + return Collections.unmodifiableList(receiptItemList); + } + + /** + * The USReceiptType model. + */ + @Immutable + public static final class ReceiptType { + private final String type; + private final float confidence; + + /** + * Constructs a Receipt Type. + * + * @param type The type of the receipt. + * @param confidence The confidence score. + */ + public ReceiptType(final String type, final float confidence) { + this.type = type; + this.confidence = confidence; + } + + /** + * Gets the type of the receipt. + * + * @return The type of the receipt. + */ + public String getType() { + return this.type; + } + + /** + * Gets the confidence score of the detected type of the receipt. + * + * @return The confidence score of the detected type of the receipt. + */ + public float getConfidence() { + return this.confidence; + } + } + + /** + * The ReceiptItem model. + */ + @Immutable + public static final class ReceiptItem { + private final FormField name; + private final FormField quantity; + private final FormField price; + private final FormField totalPrice; + + /** + * Constructs a ReceiptItem object. + * + * @param name Name of the field value. + * @param quantity quantity of the field value. + * @param price price of the field value. + * @param totalPrice Total price of the field value. + */ + public ReceiptItem(final FormField name, final FormField quantity, final FormField price, + final FormField totalPrice) { + this.name = name; + this.quantity = quantity; + this.price = price; + this.totalPrice = totalPrice; + } + + /** + * Gets the name of the field value. + * + * @return The name of the field value. + */ + public FormField getName() { + return name; + } + + /** + * Gets the quantity of the Receipt Item. + * + * @return the quantity of Receipt Item. + */ + public FormField getQuantity() { + return quantity; + } + + /** + * Gets the price of the Receipt Item. + * + * @return The total Price. + */ + public FormField getPrice() { + return price; + } + + /** + * Gets the total price of the Receipt Item. + * + * @return The total Price. + */ + public FormField getTotalPrice() { + return totalPrice; + } + } +} diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceipts.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceipts.java index da6871ca95b87..cd612e70d4a65 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceipts.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceipts.java @@ -6,7 +6,7 @@ import com.azure.ai.formrecognizer.models.FieldValueType; import com.azure.ai.formrecognizer.models.FormField; import com.azure.ai.formrecognizer.models.OperationResult; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.util.polling.SyncPoller; @@ -15,11 +15,15 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import java.time.LocalDate; import java.util.List; import java.util.Map; /** - * Sample for recognizing US receipt information using file source URL. + * Sample for recognizing commonly found US receipt fields from a local file input stream. + * For a suggested approach to extracting information from receipts, see StronglyTypedRecognizedForm.java. + * See fields found on a receipt here: + * https://aka.ms/azsdk/python/formrecognizer/receiptfields */ public class RecognizeReceipts { @@ -42,72 +46,86 @@ public static void main(final String[] args) throws IOException { byte[] fileContent = Files.readAllBytes(sourceFile.toPath()); InputStream targetStream = new ByteArrayInputStream(fileContent); - SyncPoller> analyzeReceiptPoller = + SyncPoller> analyzeReceiptPoller = client.beginRecognizeReceipts(targetStream, sourceFile.length()); - List receiptPageResults = analyzeReceiptPoller.getFinalResult(); + List receiptPageResults = analyzeReceiptPoller.getFinalResult(); for (int i = 0; i < receiptPageResults.size(); i++) { - RecognizedReceipt recognizedReceipt = receiptPageResults.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); + RecognizedForm recognizedForm = receiptPageResults.get(i); + Map> recognizedFields = recognizedForm.getFields(); System.out.printf("----------- Recognized Receipt page %d -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); + FormField merchantNameField = recognizedFields.get("MerchantName"); if (merchantNameField != null) { - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + merchantName, merchantNameField.getConfidence()); } } - FormField merchantAddressField = recognizedFields.get("MerchantAddress"); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } + } + + FormField merchantAddressField = recognizedFields.get("MerchantAddress"); if (merchantAddressField != null) { - if (merchantAddressField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.STRING.cast(merchantAddressField); System.out.printf("Merchant Address: %s, confidence: %.2f%n", - merchantAddressField.getFieldValue().asString(), - merchantAddressField.getConfidence()); + merchantAddress, merchantAddressField.getConfidence()); } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); + + FormField transactionDateField = recognizedFields.get("TransactionDate"); if (transactionDateField != null) { - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + transactionDate, transactionDateField.getConfidence()); } } - FormField receiptItemsField = recognizedFields.get("Items"); + + FormField receiptItemsField = recognizedFields.get("Items"); if (receiptItemsField != null) { System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Name")) { - if (formField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Name".equals(key)) { + if (FieldValueType.STRING.equals(formField.getValueType())) { + String name = FieldValueType.STRING.cast(formField); System.out.printf("Name: %s, confidence: %.2fs%n", - formField.getFieldValue().asString(), - formField.getConfidence()); + name, formField.getConfidence()); } } - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %d, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %f, confidence: %.2f%n", + quantity, formField.getConfidence()); } } - if (key.equals("Price")) { - if (formField.getFieldValue().getType() == FieldValueType.FLOAT) { + if ("Price".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float price = FieldValueType.DOUBLE.cast(formField); System.out.printf("Price: %f, confidence: %.2f%n", - formField.getFieldValue().asFloat(), - formField.getConfidence()); + price, formField.getConfidence()); } } - if (key.equals("TotalPrice")) { - if (formField.getFieldValue().getType() == FieldValueType.FLOAT) { + if ("TotalPrice".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float totalPrice = FieldValueType.DOUBLE.cast(formField); System.out.printf("Total Price: %f, confidence: %.2f%n", - formField.getFieldValue().asFloat(), - formField.getConfidence()); + totalPrice, formField.getConfidence()); } } }); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsAsync.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsAsync.java index f59aeb97cb60e..d9c1b3849187c 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsAsync.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsAsync.java @@ -6,7 +6,7 @@ import com.azure.ai.formrecognizer.models.FieldValueType; import com.azure.ai.formrecognizer.models.FormField; import com.azure.ai.formrecognizer.models.OperationResult; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.util.polling.PollerFlux; import reactor.core.publisher.Mono; @@ -16,6 +16,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import java.time.LocalDate; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -23,7 +24,10 @@ import static com.azure.ai.formrecognizer.implementation.Utility.toFluxByteBuffer; /** - * Async sample for recognizing US receipt information from a local file. + * Async sample for recognizing commonly found US receipt fields from a local file input stream. + * For a suggested approach to extracting information from receipts, see StronglyTypedRecognizedForm.java. + * See fields found on a receipt here: + * https://aka.ms/azsdk/python/formrecognizer/receiptfields */ public class RecognizeReceiptsAsync { @@ -31,6 +35,7 @@ public class RecognizeReceiptsAsync { * Main method to invoke this demo. * * @param args Unused. Arguments to the program. + * * @throws IOException Exception thrown when there is an error in reading all the bytes from the File. */ public static void main(final String[] args) throws IOException { @@ -45,11 +50,11 @@ public static void main(final String[] args) throws IOException { byte[] fileContent = Files.readAllBytes(sourceFile.toPath()); InputStream targetStream = new ByteArrayInputStream(fileContent); - PollerFlux> analyzeReceiptPoller = + PollerFlux> analyzeReceiptPoller = client.beginRecognizeReceipts(toFluxByteBuffer(targetStream), sourceFile.length()); - Mono> receiptPageResultsMono = analyzeReceiptPoller + Mono> receiptPageResultsMono = analyzeReceiptPoller .last() .flatMap(recognizeReceiptPollOperation -> { if (recognizeReceiptPollOperation.getStatus().isComplete()) { @@ -64,66 +69,80 @@ public static void main(final String[] args) throws IOException { receiptPageResultsMono.subscribe(receiptPageResults -> { for (int i = 0; i < receiptPageResults.size(); i++) { - RecognizedReceipt recognizedReceipt = receiptPageResults.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); + RecognizedForm recognizedForm = receiptPageResults.get(i); + Map> recognizedFields = recognizedForm.getFields(); System.out.printf("----------- Recognized Receipt page %d -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); + FormField merchantNameField = recognizedFields.get("MerchantName"); if (merchantNameField != null) { - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + merchantName, merchantNameField.getConfidence()); + } + } + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); } } - FormField merchantAddressField = recognizedFields.get("MerchantAddress"); + + FormField merchantAddressField = recognizedFields.get("MerchantAddress"); if (merchantAddressField != null) { - if (merchantAddressField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.STRING.cast(merchantAddressField); System.out.printf("Merchant Address: %s, confidence: %.2f%n", - merchantAddressField.getFieldValue().asString(), - merchantAddressField.getConfidence()); + merchantAddress, merchantAddressField.getConfidence()); } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); + + FormField transactionDateField = recognizedFields.get("TransactionDate"); if (transactionDateField != null) { - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + transactionDate, transactionDateField.getConfidence()); } } - FormField receiptItemsField = recognizedFields.get("Items"); + + FormField receiptItemsField = recognizedFields.get("Items"); if (receiptItemsField != null) { System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Name")) { - if (formField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Name".equals(key)) { + if (FieldValueType.STRING.equals(formField.getValueType())) { + String name = FieldValueType.STRING.cast(formField); System.out.printf("Name: %s, confidence: %.2fs%n", - formField.getFieldValue().asString(), - formField.getConfidence()); + name, formField.getConfidence()); } } - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %d, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %f, confidence: %.2f%n", + quantity, formField.getConfidence()); } } - if (key.equals("Price")) { - if (formField.getFieldValue().getType() == FieldValueType.FLOAT) { + if ("Price".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float price = FieldValueType.DOUBLE.cast(formField); System.out.printf("Price: %f, confidence: %.2f%n", - formField.getFieldValue().asFloat(), - formField.getConfidence()); + price, formField.getConfidence()); } } - if (key.equals("TotalPrice")) { - if (formField.getFieldValue().getType() == FieldValueType.FLOAT) { + if ("TotalPrice".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float totalPrice = FieldValueType.DOUBLE.cast(formField); System.out.printf("Total Price: %f, confidence: %.2f%n", - formField.getFieldValue().asFloat(), - formField.getConfidence()); + totalPrice, formField.getConfidence()); } } }); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrl.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrl.java index 8e7239f00dc0a..df9c21ca7d093 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrl.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrl.java @@ -6,15 +6,19 @@ import com.azure.ai.formrecognizer.models.FieldValueType; import com.azure.ai.formrecognizer.models.FormField; import com.azure.ai.formrecognizer.models.OperationResult; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.util.polling.SyncPoller; +import java.time.LocalDate; import java.util.List; import java.util.Map; /** - * Sample for recognizing US receipt information using file source URL. + * Sample for recognizing commonly found US receipt fields from a file source URL. For a suggested approach to + * extracting information from receipts, see StronglyTypedRecognizedForm.java. + * See fields found on a receipt here: + * https://aka.ms/azsdk/python/formrecognizer/receiptfields */ public class RecognizeReceiptsFromUrl { @@ -30,73 +34,88 @@ public static void main(final String[] args) { .endpoint("https://{endpoint}.cognitiveservices.azure.com/") .buildClient(); - String receiptUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/sample-forms/receipts/contoso-allinone.jpg"; - SyncPoller> recognizeReceiptPoller = + String receiptUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/sdk/formrecognizer" + + "/azure-ai-formrecognizer/src/samples/java/sample-forms/receipts/contoso-allinone.jpg"; + SyncPoller> recognizeReceiptPoller = client.beginRecognizeReceiptsFromUrl(receiptUrl); - List receiptPageResults = recognizeReceiptPoller.getFinalResult(); + List receiptPageResults = recognizeReceiptPoller.getFinalResult(); for (int i = 0; i < receiptPageResults.size(); i++) { - RecognizedReceipt recognizedReceipt = receiptPageResults.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); + RecognizedForm recognizedForm = receiptPageResults.get(i); + Map> recognizedFields = recognizedForm.getFields(); System.out.printf("----------- Recognized Receipt page %d -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); + FormField merchantNameField = recognizedFields.get("MerchantName"); if (merchantNameField != null) { - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + merchantName, merchantNameField.getConfidence()); } } - FormField merchantAddressField = recognizedFields.get("MerchantAddress"); + + FormField merchantAddressField = recognizedFields.get("MerchantAddress"); if (merchantAddressField != null) { - if (merchantAddressField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.STRING.cast(merchantAddressField); System.out.printf("Merchant Address: %s, confidence: %.2f%n", - merchantAddressField.getFieldValue().asString(), - merchantAddressField.getConfidence()); + merchantAddress, merchantAddressField.getConfidence()); + } + } + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Phone number: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); + + FormField transactionDateField = recognizedFields.get("TransactionDate"); if (transactionDateField != null) { - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + transactionDate, transactionDateField.getConfidence()); } } - FormField receiptItemsField = recognizedFields.get("Items"); + + FormField receiptItemsField = recognizedFields.get("Items"); if (receiptItemsField != null) { System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Name")) { - if (formField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Name".equals(key)) { + if (FieldValueType.STRING.equals(formField.getValueType())) { + String name = FieldValueType.STRING.cast(formField); System.out.printf("Name: %s, confidence: %.2fs%n", - formField.getFieldValue().asString(), - formField.getConfidence()); + name, formField.getConfidence()); } } - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { - System.out.printf("Quantity: %d, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); + System.out.printf("Quantity: %f, confidence: %.2f%n", + quantity, formField.getConfidence()); } } - if (key.equals("Price")) { - if (formField.getFieldValue().getType() == FieldValueType.FLOAT) { + if ("Price".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float price = FieldValueType.DOUBLE.cast(formField); System.out.printf("Price: %f, confidence: %.2f%n", - formField.getFieldValue().asFloat(), - formField.getConfidence()); + price, formField.getConfidence()); } } - if (key.equals("TotalPrice")) { - if (formField.getFieldValue().getType() == FieldValueType.FLOAT) { + if ("TotalPrice".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float totalPrice = FieldValueType.DOUBLE.cast(formField); System.out.printf("Total Price: %f, confidence: %.2f%n", - formField.getFieldValue().asFloat(), - formField.getConfidence()); + totalPrice, formField.getConfidence()); } } }); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrlAsync.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrlAsync.java index e6148c58664a2..4df763056b81d 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrlAsync.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrlAsync.java @@ -6,17 +6,21 @@ import com.azure.ai.formrecognizer.models.FieldValueType; import com.azure.ai.formrecognizer.models.FormField; import com.azure.ai.formrecognizer.models.OperationResult; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.util.polling.PollerFlux; import reactor.core.publisher.Mono; +import java.time.LocalDate; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; /** - * Async sample for recognizing US receipt information using file source URL. + * Async sample for recognizing commonly found US receipt fields from a file source URL. For a suggested approach to + * extracting information from receipts, see StronglyTypedRecognizedForm.java. + * See fields found on a receipt here: + * https://aka.ms/azsdk/python/formrecognizer/receiptfields */ public class RecognizeReceiptsFromUrlAsync { @@ -32,11 +36,12 @@ public static void main(final String[] args) { .endpoint("https://{endpoint}.cognitiveservices.azure.com/") .buildAsyncClient(); - String receiptUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/sample-forms/receipts/contoso-allinone.jpg"; - PollerFlux> recognizeReceiptPoller = + String receiptUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/sdk/formrecognizer" + + "/azure-ai-formrecognizer/src/samples/java/sample-forms/receipts/contoso-allinone.jpg"; + PollerFlux> recognizeReceiptPoller = client.beginRecognizeReceiptsFromUrl(receiptUrl); - Mono> receiptPageResults = recognizeReceiptPoller + Mono> receiptPageResults = recognizeReceiptPoller .last() .flatMap(trainingOperationResponse -> { if (trainingOperationResponse.getStatus().isComplete()) { @@ -51,66 +56,81 @@ public static void main(final String[] args) { receiptPageResults.subscribe(recognizedReceipts -> { for (int i = 0; i < recognizedReceipts.size(); i++) { - RecognizedReceipt recognizedReceipt = recognizedReceipts.get(i); - Map recognizedFields = recognizedReceipt.getRecognizedForm().getFields(); + RecognizedForm recognizedForm = recognizedReceipts.get(i); + Map> recognizedFields = recognizedForm.getFields(); System.out.printf("----------- Recognized Receipt page %d -----------%n", i); - FormField merchantNameField = recognizedFields.get("MerchantName"); + FormField merchantNameField = recognizedFields.get("MerchantName"); if (merchantNameField != null) { - if (merchantNameField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantName = FieldValueType.STRING.cast(merchantNameField); System.out.printf("Merchant Name: %s, confidence: %.2f%n", - merchantNameField.getFieldValue().asString(), - merchantNameField.getConfidence()); + merchantName, merchantNameField.getConfidence()); } } - FormField merchantAddressField = recognizedFields.get("MerchantAddress"); + + FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber"); + if (merchantPhoneNumberField != null) { + if (FieldValueType.PHONE_NUMBER.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.PHONE_NUMBER.cast(merchantPhoneNumberField); + System.out.printf("Merchant Address: %s, confidence: %.2f%n", + merchantAddress, merchantPhoneNumberField.getConfidence()); + } + } + + FormField merchantAddressField = recognizedFields.get("MerchantAddress"); if (merchantAddressField != null) { - if (merchantAddressField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.STRING.equals(merchantNameField.getValueType())) { + String merchantAddress = FieldValueType.STRING.cast(merchantAddressField); System.out.printf("Merchant Address: %s, confidence: %.2f%n", - merchantAddressField.getFieldValue().asString(), - merchantAddressField.getConfidence()); + merchantAddress, merchantAddressField.getConfidence()); } } - FormField transactionDateField = recognizedFields.get("TransactionDate"); + + FormField transactionDateField = recognizedFields.get("TransactionDate"); if (transactionDateField != null) { - if (transactionDateField.getFieldValue().getType() == FieldValueType.DATE) { + if (FieldValueType.DATE.equals(transactionDateField.getValueType())) { + LocalDate transactionDate = FieldValueType.DATE.cast(transactionDateField); System.out.printf("Transaction Date: %s, confidence: %.2f%n", - transactionDateField.getFieldValue().asDate(), - transactionDateField.getConfidence()); + transactionDate, transactionDateField.getConfidence()); } } - FormField receiptItemsField = recognizedFields.get("Items"); + + FormField receiptItemsField = recognizedFields.get("Items"); if (receiptItemsField != null) { System.out.printf("Receipt Items: %n"); - if (receiptItemsField.getFieldValue().getType() == FieldValueType.LIST) { - List receiptItems = receiptItemsField.getFieldValue().asList(); + if (FieldValueType.LIST.equals(receiptItemsField.getValueType())) { + List> receiptItems = FieldValueType.LIST.cast(receiptItemsField); receiptItems.forEach(receiptItem -> { - if (receiptItem.getFieldValue().getType() == FieldValueType.MAP) { - receiptItem.getFieldValue().asMap().forEach((key, formField) -> { - if (key.equals("Name")) { - if (formField.getFieldValue().getType() == FieldValueType.STRING) { + if (FieldValueType.MAP.equals(receiptItem.getValueType())) { + // we still have to cast or assign + Map> formFieldMap = FieldValueType.MAP.cast(receiptItem); + formFieldMap.forEach((key, formField) -> { + if ("Name".equals(key)) { + if (FieldValueType.STRING.equals(formField.getValueType())) { + String name = FieldValueType.STRING.cast(formField); System.out.printf("Name: %s, confidence: %.2fs%n", - formField.getFieldValue().asString(), - formField.getConfidence()); + name, formField.getConfidence()); } } - if (key.equals("Quantity")) { - if (formField.getFieldValue().getType() == FieldValueType.INTEGER) { + if ("Quantity".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float quantity = FieldValueType.DOUBLE.cast(formField); System.out.printf("Quantity: %f, confidence: %.2f%n", - formField.getFieldValue().asInteger(), formField.getConfidence()); + quantity, formField.getConfidence()); } } - if (key.equals("Price")) { - if (formField.getFieldValue().getType() == FieldValueType.FLOAT) { + if ("Price".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float price = FieldValueType.DOUBLE.cast(formField); System.out.printf("Price: %f, confidence: %.2f%n", - formField.getFieldValue().asFloat(), - formField.getConfidence()); + price, formField.getConfidence()); } } - if (key.equals("TotalPrice")) { - if (formField.getFieldValue().getType() == FieldValueType.FLOAT) { + if ("TotalPrice".equals(key)) { + if (FieldValueType.DOUBLE.equals(formField.getValueType())) { + Float totalPrice = FieldValueType.DOUBLE.cast(formField); System.out.printf("Total Price: %f, confidence: %.2f%n", - formField.getFieldValue().asFloat(), - formField.getConfidence()); + totalPrice, formField.getConfidence()); } } }); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/StronglyTypedRecognizedForm.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/StronglyTypedRecognizedForm.java new file mode 100644 index 0000000000000..f0144fdc9a565 --- /dev/null +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/StronglyTypedRecognizedForm.java @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.ai.formrecognizer; + +import com.azure.ai.formrecognizer.models.OperationResult; +import com.azure.ai.formrecognizer.models.RecognizedForm; +import com.azure.core.credential.AzureKeyCredential; +import com.azure.core.util.polling.SyncPoller; + +import java.util.List; + +/** + * Sample demonstrating converting recognized form fields to strongly typed US receipt field values. + * See + * + * for information on the strongly typed fields returned by service when recognizing receipts. + */ +public class StronglyTypedRecognizedForm { + + /** + * Main method to invoke this demo. + * + * @param args Unused. Arguments to the program. + */ + public static void main(final String[] args) { + // Instantiate a client that will be used to call the service. + FormRecognizerClient client = new FormRecognizerClientBuilder() + .credential(new AzureKeyCredential("{api_Key}")) + .endpoint("https://{endpoint}.cognitiveservices.azure.com/") + .buildClient(); + + String receiptUrl = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/sdk/formrecognizer" + + "/azure-ai-formrecognizer/src/samples/java/sample-forms/receipts/contoso-allinone.jpg"; + SyncPoller> recognizeReceiptPoller = + client.beginRecognizeReceiptsFromUrl(receiptUrl); + + List receiptPageResults = recognizeReceiptPoller.getFinalResult(); + + for (int i = 0; i < receiptPageResults.size(); i++) { + final RecognizedForm recognizedForm = receiptPageResults.get(i); + System.out.printf("----------- Recognized Receipt page %d -----------%n", i); + // Use Receipt model transform the recognized form to strongly typed US receipt fields + Receipt usReceipt = new Receipt(recognizedForm); + System.out.printf("Merchant Name: %s, confidence: %.2f%n", usReceipt.getMerchantName().getValue(), + usReceipt.getMerchantName().getConfidence()); + System.out.printf("Merchant Address: %s, confidence: %.2f%n", + usReceipt.getMerchantAddress().getValue(), + usReceipt.getMerchantAddress().getConfidence()); + System.out.printf("Merchant Phone Number %s, confidence: %.2f%n", + usReceipt.getMerchantPhoneNumber().getValue(), usReceipt.getMerchantPhoneNumber().getConfidence()); + System.out.printf("Total: %s confidence: %.2f%n", usReceipt.getTotal().getValue(), + usReceipt.getTotal().getConfidence()); + System.out.printf("Transaction Date: %s, confidence: %.2f%n", + usReceipt.getTransactionDate().getValue(), usReceipt.getTransactionDate().getConfidence()); + System.out.printf("Transaction Time: %s, confidence: %.2f%n", + usReceipt.getTransactionTime().getValue(), usReceipt.getTransactionTime().getConfidence()); + System.out.printf("Receipt Items: %n"); + usReceipt.getReceiptItems().forEach(receiptItem -> { + if (receiptItem.getName() != null) { + System.out.printf("Name: %s, confidence: %.2f%n", receiptItem.getName().getValue(), + receiptItem.getName().getConfidence()); + } + if (receiptItem.getQuantity() != null) { + System.out.printf("Quantity: %f, confidence: %.2f%n", receiptItem.getQuantity().getValue(), + receiptItem.getQuantity().getConfidence()); + } + if (receiptItem.getPrice() != null) { + System.out.printf("Price: %f, confidence: %.2f%n", receiptItem.getPrice().getValue(), + receiptItem.getPrice().getConfidence()); + } + if (receiptItem.getTotalPrice() != null) { + System.out.printf("Total Price: %f, confidence: %.2f%n", + receiptItem.getTotalPrice().getValue(), receiptItem.getTotalPrice().getConfidence()); + } + }); + System.out.print("-----------------------------------"); + } + } +} diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FieldValueTypeCastTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FieldValueTypeCastTest.java new file mode 100644 index 0000000000000..1c74acbfcb934 --- /dev/null +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FieldValueTypeCastTest.java @@ -0,0 +1,429 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.ai.formrecognizer; + +import com.azure.ai.formrecognizer.models.FieldValueType; +import com.azure.ai.formrecognizer.models.FormField; +import org.junit.jupiter.api.Test; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class FieldValueTypeCastTest { + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to Date. + */ + @Test + public void toDateFromDate() { + LocalDate inputDate = LocalDate.of(2006, 6, 6); + LocalDate actualDate = FieldValueType.DATE.cast(new FormField<>(0, null, null, + inputDate, null, FieldValueType.DATE)); + assertEquals(inputDate, actualDate); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to Date from String. + */ + @Test + public void toDateFromString() { + String inputDateString = "2006/06/06"; + LocalDate inputDate = LocalDate.parse(inputDateString, DateTimeFormatter.ofPattern("yyyy/MM/dd")); + LocalDate actualDate = FieldValueType.DATE.cast(new FormField<>(0, null, null, + inputDateString, null, FieldValueType.STRING)); + assertEquals(inputDate, actualDate); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to Date from null field value. + */ + @Test + public void toDateFromNull() { + assertNull(FieldValueType.DATE.cast(new FormField<>(0, null, null, + null, null, FieldValueType.STRING))); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to Date from any other + * FieldValueType except for String. + */ + @Test + public void toDateFromPhoneNumber() { + final UnsupportedOperationException unsupportedOperationException = + assertThrows(UnsupportedOperationException.class, () -> + FieldValueType.DATE.cast(new FormField<>(0, null, null, + "19876543210", null, FieldValueType.PHONE_NUMBER))); + assertEquals(unsupportedOperationException.getMessage(), "Cannot cast from field value of " + + "type PHONE_NUMBER to type DATE"); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to TIME. + */ + @Test + public void toTimeFromTime() { + LocalTime inputTime = LocalTime.parse("13:59:00", DateTimeFormatter.ofPattern("HH:mm:ss")); + LocalTime actualTime = FieldValueType.TIME.cast(new FormField<>(0, null, null, + inputTime, null, FieldValueType.TIME)); + assertEquals(inputTime, actualTime); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to TIME from String. + */ + @Test + public void toTimeFromString() { + String inputTimeString = "13:59:00"; + LocalTime inputTime = LocalTime.parse(inputTimeString, DateTimeFormatter.ofPattern("HH:mm:ss")); + LocalTime actualTime = FieldValueType.TIME.cast(new FormField<>(0, null, null, + inputTimeString, null, FieldValueType.STRING)); + assertEquals(inputTime, actualTime); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to TIME from null field value. + */ + @Test + public void toTimeFromNull() { + assertNull(FieldValueType.TIME.cast(new FormField<>(0, null, null, + null, null, FieldValueType.TIME))); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to TIME from any other + * FieldValueType except for String. + */ + @Test + public void toTimeFromPhoneNumber() { + final UnsupportedOperationException unsupportedOperationException = + assertThrows(UnsupportedOperationException.class, () -> + FieldValueType.TIME.cast(new FormField<>(0, null, null, + "19876543210", null, FieldValueType.PHONE_NUMBER))); + assertEquals(unsupportedOperationException.getMessage(), "Cannot cast from field value of " + + "type PHONE_NUMBER to type TIME"); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to list. + */ + @Test + public void toListFromList() { + List inputList = new ArrayList<>(Arrays.asList("1")); + List actualList = FieldValueType.LIST.cast(new FormField<>(0, null, null, + inputList, null, FieldValueType.LIST)); + assertEquals(inputList, actualList); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to list from String. + */ + @Test + public void toListFromString() { + String listString = "1"; + final UnsupportedOperationException unsupportedOperationException = + assertThrows(UnsupportedOperationException.class, () -> + FieldValueType.LIST.cast(new FormField<>(0, null, null, + listString, null, FieldValueType.STRING))); + assertEquals(unsupportedOperationException.getMessage(), "Cannot cast from field value of " + + "type STRING to type LIST"); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to list from null field value. + */ + @Test + public void toListFromNull() { + assertNull(FieldValueType.LIST.cast(new FormField<>(0, null, null, + null, null, FieldValueType.LIST))); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to list from any other + * FieldValueType except for String. + */ + @Test + public void toListFromTime() { + LocalTime inputTime = LocalTime.parse("13:59:00", DateTimeFormatter.ofPattern("HH:mm:ss")); + final UnsupportedOperationException unsupportedOperationException = + assertThrows(UnsupportedOperationException.class, () -> + FieldValueType.LIST.cast(new FormField<>(0, null, null, + inputTime, null, FieldValueType.TIME))); + assertEquals(unsupportedOperationException.getMessage(), "Cannot cast from field value of " + + "type TIME to type LIST"); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to phone number. + */ + @Test + public void toPhoneNumberFromPhoneNumber() { + String phoneNumber = "19876543210"; + String actualPhoneNumber = FieldValueType.PHONE_NUMBER.cast(new FormField<>(0, null, null, + phoneNumber, null, FieldValueType.PHONE_NUMBER)); + assertEquals(phoneNumber, actualPhoneNumber); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to phone number from String. + */ + @Test + public void toPhoneNumberFromString() { + String phoneNumber = "19876543210"; + String actualPhoneNumber = FieldValueType.PHONE_NUMBER.cast(new FormField<>(0, null, null, + phoneNumber, null, FieldValueType.STRING)); + assertEquals(phoneNumber, actualPhoneNumber); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to phone number from null field value. + */ + @Test + public void toPhoneNumberFromNull() { + assertNull(FieldValueType.PHONE_NUMBER.cast(new FormField<>(0, null, null, + null, null, FieldValueType.PHONE_NUMBER))); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to phone number from any other + * FieldValueType except for String. + */ + @Test + public void toPhoneNumberFromTime() { + LocalTime inputTime = LocalTime.parse("13:59:00", DateTimeFormatter.ofPattern("HH:mm:ss")); + final UnsupportedOperationException unsupportedOperationException = + assertThrows(UnsupportedOperationException.class, () -> + FieldValueType.PHONE_NUMBER.cast(new FormField<>(0, null, null, + inputTime, null, FieldValueType.TIME))); + assertEquals(unsupportedOperationException.getMessage(), "Cannot cast from field value of " + + "type TIME to type PHONE_NUMBER"); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to map. + */ + @Test + public void toMapFromMap() { + Map inputMap = Collections.singletonMap("key", "value"); + Map actualList = FieldValueType.MAP.cast(new FormField<>(0, null, null, + inputMap, null, FieldValueType.MAP)); + assertEquals(inputMap, actualList); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to map from String. + */ + @Test + public void toMapFromString() { + String listString = "1"; + final UnsupportedOperationException unsupportedOperationException = + assertThrows(UnsupportedOperationException.class, () -> + FieldValueType.MAP.cast(new FormField<>(0, null, null, + listString, null, FieldValueType.STRING))); + assertEquals(unsupportedOperationException.getMessage(), "Cannot cast from field value of " + + "type STRING to type MAP"); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to map from null field value. + */ + @Test + public void toMapFromNull() { + assertNull(FieldValueType.MAP.cast(new FormField<>(0, null, null, + null, null, FieldValueType.MAP))); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to map from any other + * FieldValueType except for String. + */ + @Test + public void toMapFromTime() { + LocalTime inputTime = LocalTime.parse("13:59:00", DateTimeFormatter.ofPattern("HH:mm:ss")); + final UnsupportedOperationException unsupportedOperationException = + assertThrows(UnsupportedOperationException.class, () -> + FieldValueType.MAP.cast(new FormField<>(0, null, null, + inputTime, null, FieldValueType.TIME))); + assertEquals(unsupportedOperationException.getMessage(), "Cannot cast from field value of " + + "type TIME to type MAP"); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to double. + */ + @Test + public void toDoubleFromDouble() { + Double inputDouble = 2.2; + Double actualDoubleValue = FieldValueType.DOUBLE.cast(new FormField<>(0, null, null, + inputDouble, null, FieldValueType.DOUBLE)); + assertEquals(inputDouble, actualDoubleValue); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to double from String. + */ + @Test + public void toDoubleFromString() { + String doubleString = "2.2"; + Double actualDouble = FieldValueType.DOUBLE.cast(new FormField<>(0, null, null, + doubleString, null, FieldValueType.STRING)); + assertEquals(Double.valueOf(doubleString), actualDouble); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to double from null field value. + */ + @Test + public void toDoubleFromNull() { + assertNull(FieldValueType.DOUBLE.cast(new FormField<>(0, null, null, + null, null, FieldValueType.DOUBLE))); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to double from any other + * FieldValueType except for String. + */ + @Test + public void toDoubleFromTime() { + LocalTime inputTime = LocalTime.parse("13:59:00", DateTimeFormatter.ofPattern("HH:mm:ss")); + final UnsupportedOperationException unsupportedOperationException = + assertThrows(UnsupportedOperationException.class, () -> + FieldValueType.DOUBLE.cast(new FormField<>(0, null, null, + inputTime, null, FieldValueType.TIME))); + assertEquals(unsupportedOperationException.getMessage(), "Cannot cast from field value of " + + "type TIME to type DOUBLE"); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to long. + */ + @Test + public void toLongFromLong() { + long inputDouble = 22; + Long actualLongValue = FieldValueType.LONG.cast(new FormField<>(0, null, null, + inputDouble, null, FieldValueType.LONG)); + assertEquals(inputDouble, actualLongValue); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to long from String. + */ + @Test + public void toLongFromString() { + String inputDoubleString = "22"; + Long actualLongValue = FieldValueType.LONG.cast(new FormField<>(0, null, null, + inputDoubleString, null, FieldValueType.STRING)); + assertEquals(Long.valueOf(inputDoubleString), actualLongValue); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to long from null field value. + */ + @Test + public void toLongFromNull() { + assertNull(FieldValueType.LONG.cast(new FormField<>(0, null, null, + null, null, FieldValueType.LONG))); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to long from any other + * FieldValueType except for String. + */ + @Test + public void toLongFromTime() { + LocalTime inputTime = LocalTime.parse("13:59:00", DateTimeFormatter.ofPattern("HH:mm:ss")); + final UnsupportedOperationException unsupportedOperationException = + assertThrows(UnsupportedOperationException.class, () -> + FieldValueType.LONG.cast(new FormField<>(0, null, null, + inputTime, null, FieldValueType.TIME))); + assertEquals(unsupportedOperationException.getMessage(), "Cannot cast from field value of " + + "type TIME to type LONG"); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to String from TIME. + */ + @Test + public void toStringFromTime() { + LocalTime inputTime = LocalTime.parse("13:59:00", DateTimeFormatter.ofPattern("HH:mm:ss")); + String localTimeString = FieldValueType.STRING.cast(new FormField<>(0, null, null, + inputTime, null, FieldValueType.TIME)); + assertEquals(inputTime.toString(), localTimeString); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to String from String. + */ + @Test + public void toStringFromString() { + String stringValue = "String value"; + String actualStringValue = FieldValueType.STRING.cast(new FormField<>(0, null, null, + stringValue, null, FieldValueType.STRING)); + assertEquals(stringValue, actualStringValue); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to String from double. + */ + @Test + public void toStringFromDouble() { + Double doubleValue = 2.2; + String actualDouble = FieldValueType.STRING.cast(new FormField<>(0, null, null, + doubleValue, null, FieldValueType.DOUBLE)); + assertEquals(String.valueOf(doubleValue), actualDouble); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to long from String. + */ + @Test + public void toStringFromLong() { + Long inputLong = 22L; + String actualLongValue = FieldValueType.STRING.cast(new FormField<>(0, null, null, + inputLong, null, FieldValueType.LONG)); + assertEquals(String.valueOf(inputLong), actualLongValue); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to String from Map. + */ + @Test + public void toStringFromMap() { + Map inputMap = Collections.singletonMap("key", "value"); + String stringMap = FieldValueType.STRING.cast(new FormField<>(0, null, null, + inputMap, null, FieldValueType.MAP)); + assertEquals(inputMap.toString(), stringMap); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to String from Phone number. + */ + @Test + public void toStringFromPhoneNumber() { + String phoneNumber = "19876543210"; + String actualPhoneNumber = FieldValueType.STRING.cast(new FormField<>(0, null, null, + phoneNumber, null, FieldValueType.PHONE_NUMBER)); + assertEquals(phoneNumber, actualPhoneNumber); + } + + /** + * Test for {@link com.azure.ai.formrecognizer.models.FieldValueType#cast(FormField)} to String from List. + */ + @Test + public void toStringFromList() { + List inputList = Collections.singletonList("1"); + String actualStringList = FieldValueType.STRING.cast(new FormField<>(0, null, null, + inputList, null, FieldValueType.LIST)); + assertEquals(inputList.toString(), actualStringList); + } +} diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java index 4a63846663ef5..5aa35327f249c 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java @@ -11,7 +11,6 @@ import com.azure.ai.formrecognizer.models.OperationResult; import com.azure.ai.formrecognizer.models.RecognizeOptions; import com.azure.ai.formrecognizer.models.RecognizedForm; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; import com.azure.ai.formrecognizer.training.FormTrainingAsyncClient; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpClient; @@ -78,7 +77,7 @@ private FormTrainingAsyncClient getFormTrainingAsyncClient(HttpClient httpClient public void recognizeReceiptData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); receiptDataRunner((data, dataLength) -> { - SyncPoller> syncPoller = + SyncPoller> syncPoller = client.beginRecognizeReceipts(toFluxByteBuffer(data), dataLength, new RecognizeOptions() .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode)) .getSyncPoller(); @@ -108,7 +107,7 @@ public void recognizeReceiptDataWithContentTypeAutoDetection(HttpClient httpClie FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); - SyncPoller> syncPoller = client.beginRecognizeReceipts( + SyncPoller> syncPoller = client.beginRecognizeReceipts( getReplayableBufferData(RECEIPT_LOCAL_URL), RECEIPT_FILE_LENGTH, new RecognizeOptions() .setPollInterval(durationTestMode)).getSyncPoller(); @@ -124,7 +123,7 @@ public void recognizeReceiptDataWithContentTypeAutoDetection(HttpClient httpClie public void recognizeReceiptDataIncludeFieldElements(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); receiptDataRunnerFieldElements((data, includeFieldElements) -> { - SyncPoller> syncPoller = client.beginRecognizeReceipts( + SyncPoller> syncPoller = client.beginRecognizeReceipts( toFluxByteBuffer(data), RECEIPT_FILE_LENGTH, new RecognizeOptions() .setContentType(FormContentType.IMAGE_JPEG).setIncludeFieldElements(includeFieldElements) .setPollInterval(durationTestMode)).getSyncPoller(); @@ -142,7 +141,7 @@ public void recognizeReceiptDataWithPngFile(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); receiptPngDataRunnerFieldElements((data, includeFieldElements) -> { - SyncPoller> syncPoller = + SyncPoller> syncPoller = client.beginRecognizeReceipts(toFluxByteBuffer(data), RECEIPT_PNG_FILE_LENGTH, new RecognizeOptions() .setContentType(FormContentType.IMAGE_PNG).setIncludeFieldElements(includeFieldElements) .setPollInterval(durationTestMode)).getSyncPoller(); @@ -160,7 +159,7 @@ public void recognizeReceiptDataWithBlankPdf(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); blankPdfDataRunner((data, dataLength) -> { - SyncPoller> syncPoller = + SyncPoller> syncPoller = client.beginRecognizeReceipts(toFluxByteBuffer(data), dataLength, new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)) .getSyncPoller(); @@ -174,7 +173,7 @@ public void recognizeReceiptDataWithBlankPdf(HttpClient httpClient, public void recognizeReceiptFromDataMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); multipageFromDataRunner((data, dataLength) -> { - SyncPoller> syncPoller = client.beginRecognizeReceipts( + SyncPoller> syncPoller = client.beginRecognizeReceipts( toFluxByteBuffer(data), dataLength, new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)) .getSyncPoller(); @@ -193,7 +192,7 @@ public void recognizeReceiptFromDataMultiPage(HttpClient httpClient, FormRecogni public void recognizeReceiptSourceUrl(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); receiptSourceUrlRunner(sourceUrl -> { - SyncPoller> syncPoller = + SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl(sourceUrl).getSyncPoller(); syncPoller.waitForCompletion(); validateReceiptResultData(syncPoller.getFinalResult(), false); @@ -227,7 +226,7 @@ public void recognizeReceiptFromUrlIncludeFieldElements(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); receiptSourceUrlRunnerFieldElements((sourceUrl, includeFieldElements) -> { - SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( + SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( sourceUrl, new RecognizeOptions().setIncludeFieldElements(includeFieldElements) .setPollInterval(durationTestMode)).getSyncPoller(); syncPoller.waitForCompletion(); @@ -245,7 +244,7 @@ public void recognizeReceiptSourceUrlWithPngFile(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); receiptPngSourceUrlRunnerFieldElements((sourceUrl, includeFieldElements) -> { - SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( + SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( sourceUrl, new RecognizeOptions().setIncludeFieldElements(includeFieldElements) .setPollInterval(durationTestMode)) .getSyncPoller(); @@ -259,7 +258,7 @@ sourceUrl, new RecognizeOptions().setIncludeFieldElements(includeFieldElements) public void recognizeReceiptFromUrlMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); multipageFromUrlRunner(fileUrl -> { - SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( + SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( fileUrl, new RecognizeOptions().setPollInterval(durationTestMode)).getSyncPoller(); syncPoller.waitForCompletion(); validateMultipageReceiptData(syncPoller.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 860e06541abfb..ca8741c86814d 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 @@ -11,7 +11,6 @@ import com.azure.ai.formrecognizer.models.OperationResult; import com.azure.ai.formrecognizer.models.RecognizeOptions; import com.azure.ai.formrecognizer.models.RecognizedForm; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpClient; @@ -63,7 +62,7 @@ private FormTrainingClient getFormTrainingClient(HttpClient httpClient, public void recognizeReceiptData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); receiptDataRunner((data, dataLength) -> { - SyncPoller> syncPoller = + SyncPoller> syncPoller = client.beginRecognizeReceipts(data, dataLength, new RecognizeOptions() .setContentType(FormContentType.IMAGE_JPEG).setPollInterval(durationTestMode)); syncPoller.waitForCompletion(); @@ -91,7 +90,7 @@ public void recognizeReceiptDataNullData(HttpClient httpClient, public void recognizeReceiptDataWithContentTypeAutoDetection(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); - SyncPoller> syncPoller = client.beginRecognizeReceipts( + SyncPoller> syncPoller = client.beginRecognizeReceipts( getContentDetectionFileData(RECEIPT_LOCAL_URL), RECEIPT_FILE_LENGTH, new RecognizeOptions() .setPollInterval(durationTestMode)); syncPoller.waitForCompletion(); @@ -107,7 +106,7 @@ public void recognizeReceiptDataWithContentTypeAutoDetection(HttpClient httpClie public void recognizeReceiptDataIncludeFieldElements(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); receiptDataRunnerFieldElements((data, includeFieldElements) -> { - SyncPoller> syncPoller = client.beginRecognizeReceipts( + SyncPoller> syncPoller = client.beginRecognizeReceipts( data, RECEIPT_FILE_LENGTH, new RecognizeOptions().setContentType(FormContentType.IMAGE_JPEG) .setIncludeFieldElements(includeFieldElements).setPollInterval(durationTestMode)); syncPoller.waitForCompletion(); @@ -124,7 +123,7 @@ public void recognizeReceiptDataWithPngFile(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); receiptPngDataRunnerFieldElements((data, includeFieldElements) -> { - SyncPoller> syncPoller = + SyncPoller> syncPoller = client.beginRecognizeReceipts(data, RECEIPT_PNG_FILE_LENGTH, new RecognizeOptions().setContentType( FormContentType.IMAGE_PNG).setIncludeFieldElements(includeFieldElements) .setPollInterval(durationTestMode)); @@ -142,7 +141,7 @@ public void recognizeReceiptDataWithBlankPdf(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); blankPdfDataRunner((data, dataLength) -> { - SyncPoller> syncPoller = client.beginRecognizeReceipts( + SyncPoller> syncPoller = client.beginRecognizeReceipts( data, dataLength, new RecognizeOptions().setContentType(FormContentType.APPLICATION_PDF) .setPollInterval(durationTestMode)); syncPoller.waitForCompletion(); @@ -155,7 +154,7 @@ data, dataLength, new RecognizeOptions().setContentType(FormContentType.APPLICAT public void recognizeReceiptFromDataMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); multipageFromDataRunner((data, dataLength) -> { - SyncPoller> syncPoller = client.beginRecognizeReceipts( + SyncPoller> syncPoller = client.beginRecognizeReceipts( data, dataLength, new RecognizeOptions().setContentType(FormContentType.APPLICATION_PDF) .setPollInterval(durationTestMode)); syncPoller.waitForCompletion(); @@ -173,7 +172,7 @@ data, dataLength, new RecognizeOptions().setContentType(FormContentType.APPLICAT public void recognizeReceiptSourceUrl(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); receiptSourceUrlRunner((sourceUrl) -> { - SyncPoller> syncPoller = + SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl(sourceUrl); syncPoller.waitForCompletion(); validateReceiptResultData(syncPoller.getFinalResult(), false); @@ -202,7 +201,7 @@ public void recognizeReceiptFromUrlIncludeFieldElements(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); receiptSourceUrlRunnerFieldElements((sourceUrl, includeFieldElements) -> { - SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( + SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( sourceUrl, new RecognizeOptions().setIncludeFieldElements(includeFieldElements) .setPollInterval(durationTestMode)); syncPoller.waitForCompletion(); @@ -220,7 +219,7 @@ public void recognizeReceiptSourceUrlWithPngFile(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); receiptPngSourceUrlRunnerFieldElements((sourceUrl, includeFieldElements) -> { - SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( + SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( sourceUrl, new RecognizeOptions().setIncludeFieldElements(includeFieldElements) .setPollInterval(durationTestMode)); @@ -234,7 +233,7 @@ public void recognizeReceiptSourceUrlWithPngFile(HttpClient httpClient, public void recognizeReceiptFromUrlMultiPage(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); multipageFromUrlRunner(receiptUrl -> { - SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( + SyncPoller> syncPoller = client.beginRecognizeReceiptsFromUrl( receiptUrl, new RecognizeOptions().setPollInterval(durationTestMode)); syncPoller.waitForCompletion(); validateMultipageReceiptData(syncPoller.getFinalResult()); @@ -411,7 +410,7 @@ public void recognizeCustomFormLabeledDataWithJpgContentType(HttpClient httpClie beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = getFormTrainingClient(httpClient, serviceVersion).beginTraining(trainingFilesUrl, useTrainingLabels, - null, durationTestMode); + null, durationTestMode); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = client.beginRecognizeCustomForms( diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTestBase.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTestBase.java index 31c0cf01d6330..4fa322aff7449 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTestBase.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTestBase.java @@ -16,6 +16,7 @@ import com.azure.ai.formrecognizer.implementation.models.TextLine; import com.azure.ai.formrecognizer.implementation.models.TextWord; import com.azure.ai.formrecognizer.models.BoundingBox; +import com.azure.ai.formrecognizer.models.FieldValueType; import com.azure.ai.formrecognizer.models.FormElement; import com.azure.ai.formrecognizer.models.FormField; import com.azure.ai.formrecognizer.models.FormLine; @@ -26,7 +27,6 @@ import com.azure.ai.formrecognizer.models.FormWord; import com.azure.ai.formrecognizer.models.Point; import com.azure.ai.formrecognizer.models.RecognizedForm; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; import com.azure.ai.formrecognizer.training.FormTrainingClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.HttpClient; @@ -253,7 +253,8 @@ private static void validateBoundingBoxData(List expectedBoundingBox, Bou } } - private static void validateFieldValueTransforms(FieldValue expectedFieldValue, FormField actualFormField, + @SuppressWarnings("unchecked") + private static void validateFieldValueTransforms(FieldValue expectedFieldValue, FormField actualFormField, List readResults, boolean includeFieldElements) { if (expectedFieldValue != null) { if (expectedFieldValue.getBoundingBox() != null) { @@ -266,35 +267,35 @@ private static void validateFieldValueTransforms(FieldValue expectedFieldValue, } switch (expectedFieldValue.getType()) { case NUMBER: - assertEquals(expectedFieldValue.getValueNumber(), actualFormField.getFieldValue().asFloat()); + assertEquals(expectedFieldValue.getValueNumber(), FieldValueType.DOUBLE.cast(actualFormField)); break; case DATE: - assertEquals(expectedFieldValue.getValueDate(), actualFormField.getFieldValue().asDate()); + assertEquals(expectedFieldValue.getValueDate(), FieldValueType.DATE.cast(actualFormField)); break; case TIME: assertEquals(LocalTime.parse(expectedFieldValue.getValueTime(), - DateTimeFormatter.ofPattern("HH:mm:ss")), actualFormField.getFieldValue().asTime()); + DateTimeFormatter.ofPattern("HH:mm:ss")), FieldValueType.TIME.cast(actualFormField)); break; case STRING: - assertEquals(expectedFieldValue.getValueString(), actualFormField.getFieldValue().asString()); + assertEquals(expectedFieldValue.getValueString(), FieldValueType.STRING.cast(actualFormField)); break; case INTEGER: - assertEquals(expectedFieldValue.getValueInteger(), actualFormField.getFieldValue().asInteger()); + assertEquals(expectedFieldValue.getValueInteger(), FieldValueType.LONG.cast(actualFormField)); break; case PHONE_NUMBER: - assertEquals(expectedFieldValue.getValuePhoneNumber(), actualFormField.getFieldValue().asPhoneNumber()); + assertEquals(expectedFieldValue.getValuePhoneNumber(), FieldValueType.PHONE_NUMBER.cast(actualFormField)); break; case OBJECT: expectedFieldValue.getValueObject().forEach((key, fieldValue) -> { - FormField actualFormFieldValue = actualFormField.getFieldValue().asMap().get(key); + FormField actualFormFieldValue = ((Map>) actualFormField.getValue()).get(key); validateFieldValueTransforms(fieldValue, actualFormFieldValue, readResults, includeFieldElements); }); break; case ARRAY: - assertEquals(expectedFieldValue.getValueArray().size(), actualFormField.getFieldValue().asList().size()); + assertEquals(expectedFieldValue.getValueArray().size(), ((List>) actualFormField.getValue()).size()); for (int i = 0; i < expectedFieldValue.getValueArray().size(); i++) { FieldValue expectedReceiptItem = expectedFieldValue.getValueArray().get(i); - FormField actualReceiptItem = actualFormField.getFieldValue().asList().get(i); + FormField actualReceiptItem = ((List>) actualFormField.getValue()).get(i); validateFieldValueTransforms(expectedReceiptItem, actualReceiptItem, readResults, includeFieldElements); } break; @@ -492,14 +493,14 @@ abstract void recognizeCustomFormUrlMultiPageLabeled(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion); // Receipt - void validateReceiptDataFields(Map actualRecognizedReceiptFields, boolean includeFieldElements) { + void validateReceiptDataFields(Map> actualRecognizedReceiptFields, boolean includeFieldElements) { final AnalyzeResult analyzeResult = getAnalyzeRawResponse().getAnalyzeResult(); List readResults = analyzeResult.getReadResults(); DocumentResult documentResult = analyzeResult.getDocumentResults().get(0); Map expectedReceiptFields = documentResult.getFields(); assertEquals(expectedReceiptFields.get("ReceiptType").getValueString(), - actualRecognizedReceiptFields.get("ReceiptType").getFieldValue().asString()); + FieldValueType.STRING.cast(actualRecognizedReceiptFields.get("ReceiptType"))); assertEquals(expectedReceiptFields.get("ReceiptType").getConfidence(), actualRecognizedReceiptFields.get("ReceiptType").getConfidence()); validateFieldValueTransforms(expectedReceiptFields.get("MerchantName"), @@ -547,20 +548,20 @@ void validateContentResultData(List actualFormPageList, boolean includ } } - void validateReceiptResultData(List actualReceiptList, boolean includeFieldElements) { + void validateReceiptResultData(List actualReceiptList, boolean includeFieldElements) { final AnalyzeResult rawResponse = getAnalyzeRawResponse().getAnalyzeResult(); for (int i = 0; i < actualReceiptList.size(); i++) { - final RecognizedReceipt actualReceipt = actualReceiptList.get(i); - validateLabeledData(actualReceipt.getRecognizedForm(), includeFieldElements, rawResponse.getReadResults(), + final RecognizedForm actualReceipt = actualReceiptList.get(i); + validateLabeledData(actualReceipt, includeFieldElements, rawResponse.getReadResults(), rawResponse.getDocumentResults().get(i)); - validateReceiptDataFields(actualReceipt.getRecognizedForm().getFields(), includeFieldElements); + validateReceiptDataFields(actualReceipt.getFields(), includeFieldElements); } } - void validateBlankPdfResultData(List actualReceiptList) { + void validateBlankPdfResultData(List actualReceiptList) { assertEquals(1, actualReceiptList.size()); - final RecognizedReceipt actualReceipt = actualReceiptList.get(0); - assertTrue(actualReceipt.getRecognizedForm().getFields().isEmpty()); + final RecognizedForm actualReceipt = actualReceiptList.get(0); + assertTrue(actualReceipt.getFields().isEmpty()); } void validateRecognizedResult(List actualFormList, boolean includeFieldElements, @@ -697,7 +698,7 @@ private void validateUnLabeledResult(RecognizedForm actualForm, boolean includeF validatePageRangeData(expectedPage.getPage(), actualForm.getFormPageRange()); for (int i = 0; i < expectedPage.getKeyValuePairs().size(); i++) { final KeyValuePair expectedFormField = expectedPage.getKeyValuePairs().get(i); - final FormField actualFormField = actualForm.getFields().get("field-" + i); + final FormField actualFormField = actualForm.getFields().get("field-" + i); assertEquals(expectedFormField.getConfidence(), actualFormField.getConfidence()); assertEquals(expectedFormField.getKey().getText(), actualFormField.getLabelData().getText()); validateBoundingBoxData(expectedFormField.getKey().getBoundingBox(), @@ -720,7 +721,7 @@ private void validateLabeledData(RecognizedForm actualForm, boolean includeField assertEquals(documentResult.getPageRange().get(0), actualForm.getFormPageRange().getFirstPageNumber()); assertEquals(documentResult.getPageRange().get(1), actualForm.getFormPageRange().getLastPageNumber()); documentResult.getFields().forEach((label, expectedFieldValue) -> { - final FormField actualFormField = actualForm.getFields().get(label); + final FormField actualFormField = actualForm.getFields().get(label); assertEquals(label, actualFormField.getName()); if (expectedFieldValue != null) { if (expectedFieldValue.getConfidence() != null) { @@ -741,7 +742,7 @@ static void validateMultiPageDataLabeled(List actualRecognizedFo assertEquals(3, recognizedForm.getPages().size()); recognizedForm.getFields().forEach((label, formField) -> { assertNotNull(formField.getName()); - assertNotNull(formField.getFieldValue()); + assertNotNull(formField.getValue()); assertNotNull(formField.getValueData().getText()); assertNotNull(formField.getLabelData().getText()); }); @@ -751,34 +752,35 @@ static void validateMultiPageDataLabeled(List actualRecognizedFo static void validateMultiPageDataUnlabeled(List actualRecognizedFormsList) { actualRecognizedFormsList.forEach(recognizedForm -> { assertNotNull(recognizedForm.getFormType()); - assertEquals(1, recognizedForm.getPages().stream().count()); + assertEquals(1, (long) recognizedForm.getPages().size()); recognizedForm.getFields().forEach((label, formField) -> { assertNotNull(formField.getName()); - assertNotNull(formField.getFieldValue()); + assertNotNull(formField.getValue()); assertNotNull(formField.getValueData().getText()); assertNotNull(formField.getLabelData().getText()); + }); }); } - static void validateMultipageReceiptData(List recognizedReceipts) { + static void validateMultipageReceiptData(List recognizedReceipts) { assertEquals(3, recognizedReceipts.size()); - RecognizedForm receiptPage1 = recognizedReceipts.get(0).getRecognizedForm(); - RecognizedForm receiptPage2 = recognizedReceipts.get(1).getRecognizedForm(); - RecognizedForm receiptPage3 = recognizedReceipts.get(2).getRecognizedForm(); + RecognizedForm receiptPage1 = recognizedReceipts.get(0); + RecognizedForm receiptPage2 = recognizedReceipts.get(1); + RecognizedForm receiptPage3 = recognizedReceipts.get(2); assertEquals(1, receiptPage1.getFormPageRange().getFirstPageNumber()); assertEquals(1, receiptPage1.getFormPageRange().getLastPageNumber()); - Map receiptPage1Fields = receiptPage1.getFields(); + Map> receiptPage1Fields = receiptPage1.getFields(); assertEquals(EXPECTED_MULTIPAGE_ADDRESS_VALUE, receiptPage1Fields.get("MerchantAddress") - .getFieldValue().asString()); + .getValue()); assertEquals("Bilbo Baggins", receiptPage1Fields.get("MerchantName") - .getFieldValue().asString()); + .getValue()); assertEquals(EXPECTED_MULTIPAGE_PHONE_NUMBER_VALUE, receiptPage1Fields.get("MerchantPhoneNumber") - .getFieldValue().asPhoneNumber()); - assertNotNull(receiptPage1Fields.get("Total").getFieldValue().asFloat()); + .getValue()); + assertNotNull(receiptPage1Fields.get("Total").getValue()); assertNotNull(receiptPage1.getPages()); - assertEquals(ITEMIZED_RECEIPT_VALUE, receiptPage1Fields.get("ReceiptType").getFieldValue().asString()); + assertEquals(ITEMIZED_RECEIPT_VALUE, receiptPage1Fields.get("ReceiptType").getValue()); // Assert no fields, tables and lines on second page assertEquals(0, receiptPage2.getFields().size()); @@ -791,18 +793,15 @@ static void validateMultipageReceiptData(List recognizedRecei assertEquals(3, receiptPage3.getFormPageRange().getFirstPageNumber()); assertEquals(3, receiptPage3.getFormPageRange().getLastPageNumber()); - Map receiptPage3Fields = receiptPage3.getFields(); - assertEquals(EXPECTED_MULTIPAGE_ADDRESS_VALUE, receiptPage3Fields.get("MerchantAddress") - .getFieldValue().asString()); - assertEquals("Frodo Baggins", receiptPage3Fields.get("MerchantName") - .getFieldValue().asString()); - assertEquals(EXPECTED_MULTIPAGE_PHONE_NUMBER_VALUE, receiptPage3Fields.get("MerchantPhoneNumber") - .getFieldValue().asPhoneNumber()); - assertNotNull(receiptPage3Fields.get("Total").getFieldValue().asFloat()); + Map> receiptPage3Fields = receiptPage3.getFields(); + assertEquals(EXPECTED_MULTIPAGE_ADDRESS_VALUE, FieldValueType.STRING.cast(receiptPage3Fields.get("MerchantAddress"))); + assertEquals("Frodo Baggins", FieldValueType.STRING.cast(receiptPage3Fields.get("MerchantName"))); + assertEquals(EXPECTED_MULTIPAGE_PHONE_NUMBER_VALUE, FieldValueType.PHONE_NUMBER.cast(receiptPage3Fields.get("MerchantPhoneNumber"))); + assertNotNull(receiptPage3Fields.get("Total").getValue()); // why isn't tip returned by service? // total value 1000 returned by service but should be 4300, service bug - assertEquals(3000.0f, receiptPage3Fields.get("Subtotal").getFieldValue().asFloat()); - assertEquals(ITEMIZED_RECEIPT_VALUE, receiptPage3Fields.get("ReceiptType").getFieldValue().asString()); + assertEquals(3000.0f, (Float) receiptPage3Fields.get("Subtotal").getValue()); + assertEquals(ITEMIZED_RECEIPT_VALUE, FieldValueType.STRING.cast(receiptPage3Fields.get("ReceiptType"))); } protected String getEndpoint() { diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java index 7d660cffb838b..804537d907f11 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java @@ -12,7 +12,7 @@ import com.azure.ai.formrecognizer.models.FormRecognizerException; import com.azure.ai.formrecognizer.models.OperationResult; import com.azure.ai.formrecognizer.models.RecognizeOptions; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.ai.formrecognizer.models.TrainingFileFilter; import com.azure.ai.formrecognizer.training.FormTrainingAsyncClient; import com.azure.core.exception.HttpResponseException; @@ -70,7 +70,7 @@ void getFormRecognizerClientAndValidate(HttpClient httpClient, FormRecognizerSer FormRecognizerAsyncClient formRecognizerClient = getFormTrainingAsyncClient(httpClient, serviceVersion) .getFormRecognizerAsyncClient(); blankPdfDataRunner(data -> { - SyncPoller> syncPoller = + SyncPoller> syncPoller = formRecognizerClient.beginRecognizeReceipts(toFluxByteBuffer(data), BLANK_FORM_FILE_LENGTH, new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF) 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 beb6aa4bd0fd6..340889097b86c 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 @@ -13,7 +13,7 @@ import com.azure.ai.formrecognizer.models.FormRecognizerException; import com.azure.ai.formrecognizer.models.OperationResult; import com.azure.ai.formrecognizer.models.RecognizeOptions; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.ai.formrecognizer.models.TrainingFileFilter; import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.core.exception.HttpResponseException; @@ -55,7 +55,7 @@ public void getFormRecognizerClientAndValidate(HttpClient httpClient, FormRecogn FormRecognizerClient formRecognizerClient = getFormTrainingClient(httpClient, serviceVersion) .getFormRecognizerClient(); blankPdfDataRunner(data -> { - SyncPoller> syncPoller = + SyncPoller> syncPoller = formRecognizerClient.beginRecognizeReceipts(data, BLANK_FORM_FILE_LENGTH, new RecognizeOptions() .setContentType(FormContentType.APPLICATION_PDF).setPollInterval(durationTestMode)); syncPoller.waitForCompletion(); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java index cc3ed0e43fd8e..3ce2fd70e2a59 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java @@ -12,7 +12,7 @@ import com.azure.ai.formrecognizer.models.CustomFormSubmodel; import com.azure.ai.formrecognizer.models.ErrorInformation; import com.azure.ai.formrecognizer.models.FormRecognizerError; -import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.ai.formrecognizer.models.TrainingDocumentInfo; import com.azure.ai.formrecognizer.training.FormTrainingClientBuilder; import com.azure.core.credential.AzureKeyCredential; @@ -348,10 +348,10 @@ String getEndpoint() { : Configuration.getGlobalConfiguration().get(AZURE_FORM_RECOGNIZER_ENDPOINT); } - void validateBlankPdfResultData(List actualReceiptList) { + void validateBlankPdfResultData(List actualReceiptList) { assertEquals(1, actualReceiptList.size()); - final RecognizedReceipt actualReceipt = actualReceiptList.get(0); - assertTrue(actualReceipt.getRecognizedForm().getFields().isEmpty()); + final RecognizedForm actualReceipt = actualReceiptList.get(0); + assertTrue(actualReceipt.getFields().isEmpty()); } void blankPdfDataRunner(Consumer testRunner) { diff --git a/sdk/management/README.md b/sdk/management/README.md index 58b701bf42106..874c196e932ac 100644 --- a/sdk/management/README.md +++ b/sdk/management/README.md @@ -4,7 +4,7 @@ The Azure Management Libraries for Java is a higher-level, object-oriented API f that is optimized for ease of use, succinctness and consistency. - [API reference documentation][docs] -- [Code snippets and samples][sample] +- **[Code snippets and samples][sample]** ## Getting started diff --git a/sdk/management/azure/pom.xml b/sdk/management/azure/pom.xml index 0fc16e5a2556e..47f5898756970 100644 --- a/sdk/management/azure/pom.xml +++ b/sdk/management/azure/pom.xml @@ -16,7 +16,7 @@ jar Microsoft Azure SDK - This package contains Microsoft Azure SDK. + This package contains Microsoft Azure SDK. For documentation on how to use this package, please see https://aka.ms/azure-sdk-java-mgmt https://github.com/Azure/azure-sdk-for-java diff --git a/sdk/management/docs/AUTH.md b/sdk/management/docs/AUTH.md index eaea25c97a46d..6207ef90c2ba7 100644 --- a/sdk/management/docs/AUTH.md +++ b/sdk/management/docs/AUTH.md @@ -61,13 +61,13 @@ AzureProfile profile = new AzureProfile("", " invokeTaskAsync(TaskGroup.InvocationContext context) { .doOnNext(createdExternalChild -> externalChild.setPendingOperation(PendingOperation.None)) .map(updatedExternalChild -> updatedExternalChild); case ToBeRemoved: - // With 2.0 runtime, deleteResourceAsync() will be - // returning 'Completable' then use below code instead - // - // return this.externalChild.deleteResourceAsync().doOnCompleted(new Action0() { - // @Override - // public void call() { - // externalChild.setPendingOperation(PendingOperation.None); - // } - // }).andThen(voidObservable()); - // - // TODO: Fix void mono result. return this.externalChild.deleteResourceAsync() .doOnSuccess(aVoid -> externalChild.setPendingOperation(PendingOperation.None)) .map(aVoid -> voidIndexable()); diff --git a/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/policy/ProviderRegistrationPolicy.java b/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/policy/ProviderRegistrationPolicy.java index 1943e854e7e41..ac8386bbaf5ea 100644 --- a/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/policy/ProviderRegistrationPolicy.java +++ b/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/policy/ProviderRegistrationPolicy.java @@ -66,7 +66,6 @@ public Mono process(HttpPipelineCallContext context, HttpPipelineN } if (cloudError != null && MISSING_SUBSCRIPTION_REGISTRATION.equals(cloudError.getCode())) { - // TODO: add proxy in rest client ResourceManager resourceManager = ResourceManager.authenticate(credential, profile) .withDefaultSubscription(); Pattern providerPattern = Pattern.compile(".*'(.*)'"); diff --git a/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/utils/Utils.java b/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/utils/Utils.java index 665ccaf4e6b03..3f33fafeabf40 100644 --- a/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/utils/Utils.java +++ b/sdk/resources/mgmt/src/main/java/com/azure/resourcemanager/resources/fluentcore/utils/Utils.java @@ -4,19 +4,27 @@ package com.azure.resourcemanager.resources.fluentcore.utils; import com.azure.core.annotation.Get; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.ServiceInterface; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpRequest; -import com.azure.core.http.HttpResponse; import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.RestProxy; +import com.azure.core.http.rest.SimpleResponse; import com.azure.core.management.AzureEnvironment; +import com.azure.core.util.FluxUtil; import com.azure.core.util.logging.ClientLogger; import com.azure.resourcemanager.resources.fluentcore.arm.ResourceId; import com.azure.resourcemanager.resources.fluentcore.model.Indexable; import com.azure.resourcemanager.resources.models.Subscription; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -115,20 +123,48 @@ public static Mono rootResource(Mono stream) * Download a file asynchronously. * * @param url the URL pointing to the file - * @param retrofit the retrofit client + * @param httpPipeline the http pipeline * @return an Observable pointing to the content of the file */ + public static Mono downloadFileAsync(String url, HttpPipeline httpPipeline) { + FileService service = RestProxy.create(FileService.class, httpPipeline); + try { + return service.download(getHost(url), getPathAndQuery(url)) + .flatMap(response -> FluxUtil.collectBytesInByteBufferStream(response.getValue())); + } catch (MalformedURLException ex) { + return Mono.error(() -> ex); + } + } + /** - * Download a file asynchronously. + * Get host from url. * - * @param url the URL pointing to the file - * @param retrofit the retrofit client - * @return an Observable pointing to the content of the file + * @param urlString the url string + * @return the host + * @throws MalformedURLException when url is invalid format */ - public static Mono downloadFileAsync(String url, HttpPipeline retrofit) { - FileService service = RestProxy.create(FileService.class, retrofit); - Mono response = service.download(url); - return response.flatMap(httpResponse -> httpResponse.getBodyAsByteArray()); + public static String getHost(String urlString) throws MalformedURLException { + URL url = new URL(urlString); + String protocol = url.getProtocol(); + String host = url.getAuthority(); + return protocol + "://" + host; + } + + /** + * Get path from url. + * + * @param urlString the url string + * @return the path + * @throws MalformedURLException when the url is invalid format + */ + public static String getPathAndQuery(String urlString) throws MalformedURLException { + URL url = new URL(urlString); + String path = url.getPath(); + String query = url.getQuery(); + if (query != null && !query.isEmpty()) { + path = path + "?" + query; + } + return path; } /** @@ -185,9 +221,12 @@ public static String resourceGroupId(String id) { /** * A Retrofit service used to download a file. */ + @Host("{$host}") + @ServiceInterface(name = "FileService") private interface FileService { - @Get("{url}") - Mono download(@PathParam("url") String url); + @Get("{path}") + Mono>> download( + @HostParam("$host") String host, @PathParam(value = "path", encoded = true) String path); } /** diff --git a/sdk/resources/mgmt/src/test/java/com/azure/resourcemanager/resources/ResourceUtilsTests.java b/sdk/resources/mgmt/src/test/java/com/azure/resourcemanager/resources/ResourceUtilsTests.java index 677803cd12336..651898b9150dc 100644 --- a/sdk/resources/mgmt/src/test/java/com/azure/resourcemanager/resources/ResourceUtilsTests.java +++ b/sdk/resources/mgmt/src/test/java/com/azure/resourcemanager/resources/ResourceUtilsTests.java @@ -3,12 +3,20 @@ package com.azure.resourcemanager.resources; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.RetryPolicy; import com.azure.core.management.AzureEnvironment; import com.azure.resourcemanager.resources.fluentcore.arm.ResourceUtils; import com.azure.resourcemanager.resources.fluentcore.utils.Utils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.time.temporal.ChronoUnit; + public class ResourceUtilsTests { @Test public void canExtractGroupFromId() throws Exception { @@ -39,11 +47,16 @@ public void canExtractRelativePathFromId() throws Exception { @Test public void canDownloadFile() throws Exception { - // TODO(not known): Fix this -// RestProxy retrofit = new RestProxyBuilder().baseUrl("http://microsoft.com").addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build(); -// byte[] content = Utils.downloadFileAsync("http://google.com/humans.txt", retrofit).toBlocking().single(); -// String contentString = new String(content); -// Assertions.assertNotNull(contentString); + HttpPipeline httpPipeline = new HttpPipelineBuilder() + .policies( + new HttpLoggingPolicy(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)), + new RetryPolicy("Retry-After", ChronoUnit.SECONDS) + ) + .build(); + byte[] content = Utils.downloadFileAsync("https://www.google.com/humans.txt", httpPipeline).block(); + String contentString = new String(content); + Assertions.assertNotNull(contentString); + Assertions.assertTrue(contentString.startsWith("Google is built by a large team of engineers,")); } @Test diff --git a/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClient.java b/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClient.java index b75f2e01523f3..5206e8ab6c0ed 100644 --- a/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClient.java +++ b/sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClient.java @@ -56,10 +56,6 @@ * other terminal scenarios. See {@link #receiveMessages()} for more information.

* {@codesnippet com.azure.messaging.servicebus.servicebusasyncreceiverclient.receive#all} * - *

Receive a maximum number of messages or until max a Duration

- *

This receives at most 15 messages, or until a duration of 30 seconds elapses. Whichever occurs first.

- * {@codesnippet com.azure.messaging.servicebus.servicebusasyncreceiverclient.receive#int-duration} - * *

Receive messages in {@link ReceiveMode#RECEIVE_AND_DELETE} mode from Service Bus resource

* {@codesnippet com.azure.messaging.servicebus.servicebusasyncreceiverclient.receiveWithReceiveAndDeleteMode} * @@ -886,30 +882,6 @@ public Flux receiveMessages() { } } - /** - * Receives a bounded stream of {@link ServiceBusReceivedMessage messages} from the Service Bus entity. This stream - * receives either {@code maxNumberOfMessages} are received or the {@code maxWaitTime} has elapsed. - * - * @param maxNumberOfMessages Maximum number of messages to receive. - * @param maxWaitTime Maximum time to wait. - * - * @return A bounded {@link Flux} of messages. - * @throws NullPointerException if {@code maxWaitTime} is null. - * @throws IllegalArgumentException if {@code maxNumberOfMessages} is less than 1. {@code maxWaitTime} is zero - * or a negative duration. - */ - public Flux receiveMessages(int maxNumberOfMessages, Duration maxWaitTime) { - if (maxNumberOfMessages < 1) { - return fluxError(logger, new IllegalArgumentException("'maxNumberOfMessages' cannot be less than 1.")); - } else if (maxWaitTime == null) { - return fluxError(logger, new NullPointerException("'maxWaitTime' cannot be null.")); - } else if (maxWaitTime.isNegative() || maxWaitTime.isZero()) { - return fluxError(logger, new NullPointerException("'maxWaitTime' cannot be negative or zero.")); - } - - return receiveMessages().take(maxNumberOfMessages).take(maxWaitTime); - } - /** * Receives a deferred {@link ServiceBusReceivedMessage message}. Deferred messages can only be received by using * sequence number. diff --git a/sdk/servicebus/azure-messaging-servicebus/src/samples/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClientJavaDocCodeSamples.java b/sdk/servicebus/azure-messaging-servicebus/src/samples/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClientJavaDocCodeSamples.java index 7dde0409d038c..4fa81a2c8c40d 100644 --- a/sdk/servicebus/azure-messaging-servicebus/src/samples/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClientJavaDocCodeSamples.java +++ b/sdk/servicebus/azure-messaging-servicebus/src/samples/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClientJavaDocCodeSamples.java @@ -11,7 +11,6 @@ import reactor.core.publisher.Mono; import java.util.Map; -import java.time.Duration; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -140,35 +139,6 @@ public void receiveAll() { // END: com.azure.messaging.servicebus.servicebusasyncreceiverclient.receive#all } - /** - * Receives messages up to a time or duration. - */ - public void receiveMaxTimeDuration() { - ServiceBusReceiverAsyncClient receiver = new ServiceBusClientBuilder() - .connectionString("fake-string") - .receiver() - .queueName("<< QUEUE NAME >>") - .buildAsyncClient(); - - // BEGIN: com.azure.messaging.servicebus.servicebusasyncreceiverclient.receive#int-duration - Disposable subscription = receiver.receiveMessages(15, Duration.ofSeconds(30)) - .flatMap(context -> { - ServiceBusReceivedMessage message = context.getMessage(); - System.out.printf("Received message id: %s%n", message.getMessageId()); - System.out.printf("Contents of message as string: %s%n", new String(message.getBody(), UTF_8)); - return receiver.complete(message.getLockToken()); - }).subscribe(aVoid -> System.out.println("Processed message."), - error -> System.out.println("Error occurred: " + error)); - - // subscribe is a non-blocking call and program flow will continue before messages are fetched. - // END: com.azure.messaging.servicebus.servicebusasyncreceiverclient.receive#int-duration - - // When program ends, or you're done receiving all messages. - subscription.dispose(); - - receiver.close(); - } - /** * Demonstrates how to create a session receiver for a single, first available session. */ diff --git a/sdk/servicebus/azure-messaging-servicebus/src/test/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClientIntegrationTest.java b/sdk/servicebus/azure-messaging-servicebus/src/test/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClientIntegrationTest.java index 9a5fcf5c67fff..823605ce32972 100644 --- a/sdk/servicebus/azure-messaging-servicebus/src/test/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClientIntegrationTest.java +++ b/sdk/servicebus/azure-messaging-servicebus/src/test/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClientIntegrationTest.java @@ -933,44 +933,6 @@ void setAndGetSessionState(MessagingEntityType entityType) { messagesPending.decrementAndGet(); } - @MethodSource("com.azure.messaging.servicebus.IntegrationTestBase#messagingEntityProvider") - @ParameterizedTest - void receivesByNumber(MessagingEntityType entityType) { - // Arrange - setSenderAndReceiver(entityType, TestUtils.USE_CASE_RECEIVE_BY_NUMBER, false); - - final String messageId = UUID.randomUUID().toString(); - final int number = 10; - final List messages = TestUtils.getServiceBusMessages(number, messageId, CONTENTS_BYTES); - - sendMessage(messages).block(Duration.ofSeconds(10)); - - // Act & Assert - StepVerifier.create(receiveAndDeleteReceiver.receiveMessages(messages.size(), Duration.ofSeconds(15)) - .doOnNext(next -> messagesPending.decrementAndGet())) - .expectNextCount(number) - .verifyComplete(); - } - - @MethodSource("com.azure.messaging.servicebus.IntegrationTestBase#messagingEntityProvider") - @ParameterizedTest - void receivesByTime(MessagingEntityType entityType) { - // Arrange - - setSenderAndReceiver(entityType, TestUtils.USE_CASE_RECEIVE_BY_TIME, false); - final String messageId = UUID.randomUUID().toString(); - final int number = 10; - final List messages = TestUtils.getServiceBusMessages(number, messageId, CONTENTS_BYTES); - - sendMessage(messages).block(Duration.ofSeconds(15)); - - // Act & Assert - StepVerifier.create(receiveAndDeleteReceiver.receiveMessages(number + 10, Duration.ofSeconds(15)) - .doOnNext(next -> messagesPending.decrementAndGet())) - .expectNextCount(number) - .verifyComplete(); - } - /** * Verifies that we can receive a message from dead letter queue. */ diff --git a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/PayloadSizeGate.java b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/PayloadSizeGate.java index ba8be907702cc..806fa97e54967 100644 --- a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/PayloadSizeGate.java +++ b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/PayloadSizeGate.java @@ -66,7 +66,8 @@ Flux write(ByteBuffer buf) { */ Flux flush() { if (byteBuffers != null) { - Flux result = dequeuingFlux(byteBuffers); + // We return Flux from iterable in this case to support retries on single upload. + Flux result = Flux.fromIterable(byteBuffers); byteBuffers = null; return result; } else { diff --git a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java index 96222f808bd7f..b4590afc123ec 100644 --- a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java +++ b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java @@ -112,10 +112,11 @@ public Flux write(ByteBuffer buf) { // We will overflow the current buffer and require another one. // Duplicate and adjust the window of buf so that we fill up currentBuf without going out of bounds. ByteBuffer duplicate = buf.duplicate(); - duplicate.limit(buf.position() + (int) this.currentBuf.remainingCapacity()); + int newLimit = buf.position() + (int) this.currentBuf.remainingCapacity(); + duplicate.limit(newLimit); this.currentBuf.append(duplicate); // Adjust the window of original buffer to represent remaining part. - buf.position(buf.position() + (int) this.currentBuf.remainingCapacity()); + buf.position(newLimit); result = Flux.just(this.currentBuf); diff --git a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadUtils.java b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadUtils.java index 6c0611d3363b9..6c97ce64d2f0c 100644 --- a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadUtils.java +++ b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadUtils.java @@ -44,14 +44,18 @@ public static Mono> uploadFullOrChunked(final Flux d .filter(ByteBuffer::hasRemaining) // The gate buffers data until threshold is breached. .concatMap(gate::write) - .concatWith(Flux.defer(gate::flush)) // First buffer is emitted after threshold is breached or there's no more data. // Therefore we can make a decision how to upload data on first element. .switchOnFirst((signal, flux) -> { if (gate.isThresholdBreached()) { - return uploadInChunks.apply(flux); + // In this case we can pass a flux that can have just one subscriber because + // the chunked upload is going to cache the data downstream before sending chunks over the wire. + return uploadInChunks.apply(flux.concatWith(Flux.defer(gate::flush))); } else { - return uploadFull.apply(flux, gate.size()); + // In this case gate contains all the data cached. + // The flux passed to this lambda allows only one subscriber. Therefore we substitute it + // with flux coming from gate which is based of iterable and can be subscribed again. + return uploadFull.apply(gate.flush(), gate.size()); } }) .next()