From 5df24aff925d61a60ae92843630d6962fa7eff0a Mon Sep 17 00:00:00 2001 From: Chuhaa Date: Wed, 15 Jun 2022 08:44:28 +0530 Subject: [PATCH 1/2] Fix record type in stream response --- .../ballerinax/cosmosdb/RecordIteratorUtils.java | 14 +++++++++----- cosmosdb/iterator.bal | 6 ++++-- cosmosdb/tests/test.bal | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cosmosdb-native/src/main/java/io/ballerinax/cosmosdb/RecordIteratorUtils.java b/cosmosdb-native/src/main/java/io/ballerinax/cosmosdb/RecordIteratorUtils.java index 2467942b..3e350348 100644 --- a/cosmosdb-native/src/main/java/io/ballerinax/cosmosdb/RecordIteratorUtils.java +++ b/cosmosdb-native/src/main/java/io/ballerinax/cosmosdb/RecordIteratorUtils.java @@ -19,15 +19,15 @@ package io.ballerinax.cosmosdb; import com.azure.cosmos.models.CosmosStoredProcedureProperties; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; -import io.ballerina.runtime.api.types.MapType; import io.ballerina.runtime.api.types.RecordType; +import io.ballerina.runtime.api.types.UnionType; import io.ballerina.runtime.api.values.BObject; -import io.ballerina.runtime.internal.JsonParser; +import io.ballerina.runtime.api.values.BTypedesc; +import org.ballerinalang.langlib.value.FromJsonStringWithType; import java.util.HashMap; import java.util.Iterator; @@ -57,10 +57,14 @@ public static Object nextResult(BObject recordIterator) { return null; } else { Iterator results = (Iterator) recordIterator.getNativeData(Constants.OBJECT_ITERATOR); - ObjectMapper mapper = new ObjectMapper(); if (results.hasNext()) { try { - return JsonParser.parse(mapper.writeValueAsString(results.next())); + String result = new ObjectMapper().writeValueAsString(results.next()); + RecordType recordType = (RecordType) recordIterator.getNativeData(Constants.RECORD_TYPE); + UnionType responseType = TypeCreator.createUnionType(recordType, PredefinedTypes.TYPE_ERROR, + PredefinedTypes.TYPE_NULL); + BTypedesc responseTypedescValue = ValueCreator.createTypedescValue(responseType); + return FromJsonStringWithType.fromJsonStringWithType(fromString(result), responseTypedescValue); } catch (Exception e) { return BallerinaErrorGenerator.createBallerinaDatabaseError(e); } diff --git a/cosmosdb/iterator.bal b/cosmosdb/iterator.bal index d93a483f..f5e94ee4 100644 --- a/cosmosdb/iterator.bal +++ b/cosmosdb/iterator.bal @@ -28,14 +28,16 @@ public class ResultIterator { public isolated function next() returns record {|record {} value;|}|Error? { record {}|Error? result; result = nextResult(self); - if (result is record {}) { + if result is record {} { record {| record {} value; |} streamRecord = {value: result}; return streamRecord; - } else { + } else if result is Error { self.err = result; return self.err; + } else { + return result; } } } diff --git a/cosmosdb/tests/test.bal b/cosmosdb/tests/test.bal index c2b4fb05..60def3a7 100644 --- a/cosmosdb/tests/test.bal +++ b/cosmosdb/tests/test.bal @@ -484,9 +484,9 @@ function testGetDocumentList() returns error? { stream result = check azureCosmosClient->getDocumentList(databaseId, containerId, valueOfPartitionKey); check result.forEach(isolated function(Person queryResult) { + test:assertTrue(queryResult is Person); test:assertEquals(1234, queryResult.AccountNumber); }); - } @test:Config { From 684ee3abceb2a739d7cd07e1576ead1cdac786ef Mon Sep 17 00:00:00 2001 From: Chuhaa Date: Tue, 28 Jun 2022 11:59:39 +0530 Subject: [PATCH 2/2] Upgrade bal version --- .github/workflows/dev-stg-release.yml | 6 ++--- .github/workflows/release.yml | 4 ++-- cosmosdb/Ballerina.toml | 6 ++--- cosmosdb/Dependencies.toml | 33 ++++++++++++++------------- cosmosdb/Package.md | 2 +- gradle.properties | 2 +- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/.github/workflows/dev-stg-release.yml b/.github/workflows/dev-stg-release.yml index 373e7aec..c545034f 100644 --- a/.github/workflows/dev-stg-release.yml +++ b/.github/workflows/dev-stg-release.yml @@ -32,7 +32,7 @@ jobs: run: | ./gradlew build - name: Ballerina Build - uses: ballerina-platform/ballerina-action@master + uses: ballerina-platform/ballerina-action@2201.1.0 with: args: pack ./cosmosdb @@ -41,7 +41,7 @@ jobs: - name: Push to Staging if: github.event.inputs.bal_central_environment == 'STAGE' - uses: ballerina-platform/ballerina-action@master + uses: ballerina-platform/ballerina-action@2201.1.0 with: args: push @@ -52,7 +52,7 @@ jobs: - name: Push to Dev if: github.event.inputs.bal_central_environment == 'DEV' - uses: ballerina-platform/ballerina-action@master + uses: ballerina-platform/ballerina-action@2201.1.0 with: args: push diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 752c5a21..d56a9fe0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,7 +25,7 @@ jobs: run: | ./gradlew build - name: Ballerina Build - uses: ballerina-platform/ballerina-action/@master + uses: ballerina-platform/ballerina-action/@2201.1.0 with: args: pack ./cosmosdb @@ -34,7 +34,7 @@ jobs: MASTER_OR_RESOURCE_TOKEN: ${{ secrets.MASTER_OR_RESOURCE_TOKEN }} JAVA_HOME: /usr/lib/jvm/default-jvm - name: Ballerina Push - uses: ballerina-platform/ballerina-action/@master + uses: ballerina-platform/ballerina-action/@2201.1.0 with: args: push diff --git a/cosmosdb/Ballerina.toml b/cosmosdb/Ballerina.toml index 0afc80d9..693749c2 100644 --- a/cosmosdb/Ballerina.toml +++ b/cosmosdb/Ballerina.toml @@ -1,5 +1,5 @@ [package] -distribution = "2201.0.0" +distribution = "2201.1.0" org= "ballerinax" name= "azure_cosmosdb" version= "3.0.1" @@ -21,9 +21,9 @@ version = "3.0.1" [[platform.java11.dependency]] groupId = "io.netty" artifactId = "netty-resolver-dns" -version = "4.1.71.Final" +version = "4.1.77.Final" [[platform.java11.dependency]] groupId = "io.netty" artifactId = "netty-handler" -version = "4.1.71.Final" +version = "4.1.77.Final" diff --git a/cosmosdb/Dependencies.toml b/cosmosdb/Dependencies.toml index 50e66c7b..41a24e66 100644 --- a/cosmosdb/Dependencies.toml +++ b/cosmosdb/Dependencies.toml @@ -9,7 +9,7 @@ dependencies-toml-version = "2" [[package]] org = "ballerina" name = "auth" -version = "2.2.0" +version = "2.2.1" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, @@ -22,7 +22,7 @@ dependencies = [ [[package]] org = "ballerina" name = "cache" -version = "3.2.0" +version = "3.2.2" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "task"}, @@ -32,7 +32,7 @@ dependencies = [ [[package]] org = "ballerina" name = "crypto" -version = "2.2.0" +version = "2.2.2" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} @@ -44,8 +44,9 @@ modules = [ [[package]] org = "ballerina" name = "file" -version = "1.2.0" +version = "1.2.2" dependencies = [ + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"}, {org = "ballerina", name = "os"}, @@ -56,7 +57,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.2.0" +version = "2.2.2" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -86,7 +87,7 @@ modules = [ [[package]] org = "ballerina" name = "io" -version = "1.2.0" +version = "1.2.2" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} @@ -103,7 +104,7 @@ modules = [ [[package]] org = "ballerina" name = "jwt" -version = "2.2.0" +version = "2.2.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -190,7 +191,7 @@ dependencies = [ [[package]] org = "ballerina" name = "log" -version = "2.2.0" +version = "2.2.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -204,7 +205,7 @@ modules = [ [[package]] org = "ballerina" name = "mime" -version = "2.2.0" +version = "2.2.2" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -214,7 +215,7 @@ dependencies = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.2.0" +version = "2.2.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -226,7 +227,7 @@ dependencies = [ [[package]] org = "ballerina" name = "observe" -version = "1.0.1" +version = "1.0.5" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -234,7 +235,7 @@ dependencies = [ [[package]] org = "ballerina" name = "os" -version = "1.2.0" +version = "1.2.1" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -245,7 +246,7 @@ modules = [ [[package]] org = "ballerina" name = "regex" -version = "1.2.0" +version = "1.2.1" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -256,7 +257,7 @@ modules = [ [[package]] org = "ballerina" name = "task" -version = "2.2.0" +version = "2.2.2" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} @@ -277,7 +278,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.2.0" +version = "2.2.2" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -288,7 +289,7 @@ modules = [ [[package]] org = "ballerina" name = "url" -version = "2.2.0" +version = "2.2.2" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] diff --git a/cosmosdb/Package.md b/cosmosdb/Package.md index 3139283b..a81f5829 100644 --- a/cosmosdb/Package.md +++ b/cosmosdb/Package.md @@ -6,7 +6,7 @@ The `azure_cosmosdb` is a [Ballerina](https://ballerina.io/) connector for Azure ### Compatibility | | Version | |----------------------|-------------------------------| -| Ballerina Language | Ballerina Swan Lake 2201.0.0 | +| Ballerina Language | Ballerina Swan Lake 2201.1.0 | | Cosmos DB (SQL)API | 2018-12-31 | ## Report issues diff --git a/gradle.properties b/gradle.properties index eb476d16..866bcc2e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.caching=true group=org.ballerinalang.azure_cosmosdb version=3.0.1 -ballerinaLangVersion=2201.0.3 +ballerinaLangVersion=2201.1.0 azureCosmosVersion=4.21.1