Skip to content

Commit

Permalink
Merge pull request #235 from chathuranga95/add-aggregation
Browse files Browse the repository at this point in the history
Add aggregation
  • Loading branch information
ThisaruGuruge authored Feb 12, 2024
2 parents e2dd509 + 5ab567d commit 1390e5b
Show file tree
Hide file tree
Showing 19 changed files with 318 additions and 176 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build-with-bal-test-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ jobs:
- 27012:27017

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
java-version: 17.0.7

- name: Set Up Ballerina
uses: ballerina-platform/[email protected]
Expand All @@ -50,7 +51,7 @@ jobs:
uses: graalvm/setup-graalvm@v1
with:
version: 'latest'
java-version: '11'
java-version: '17.0.7'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}

Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ jobs:
- 27012:27017

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Set up Java Environment
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
java-version: 17.0.7

# Setup Ballerina Environment
- name: Set Up Ballerina
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/daily-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ jobs:
- 27012:27017

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Set up Java Environment
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
java-version: 17.0.7

# Setup Ballerina Environment
- name: Set Up Ballerina
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/dev-stg-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ jobs:
BALLERINA_${{ github.event.inputs.bal_central_environment }}_CENTRAL: true

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Set up Java Environment
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
java-version: 17.0.7

# Setup Ballerina Environment
- name: Set Up Ballerina
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
- uses: actions/checkout@v3

# Set up Java Environment
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11
java-version: 17.0.7

# Setup Ballerina Environment
- name: Set Up Ballerina
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Set up Java Environment
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
java-version: 17.0.7

# Setup Ballerina Environment
- name: Set Up Ballerina
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
name: Build on Ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 11
java-version: 17.0.7

- name: Set Up Ballerina
uses: ballerina-platform/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ For more information, go to the module(s).

### Setting up the prerequisites

1. Download and install Java SE Development Kit (JDK) version 11. You can install either [OpenJDK](https://adoptopenjdk.net/) or [Oracle JDK](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html).
1. Download and install Java SE Development Kit (JDK) version 17. You can install either [OpenJDK](https://adoptopenjdk.net/) or [Oracle JDK](https://www.oracle.com/java/technologies/downloads/).

> **Note:** Set the JAVA_HOME environment variable to the path name of the directory into which you installed
JDK.
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
distribution = "2201.7.0"
org = "ballerinax"
name = "mongodb"
version = "4.3.0"
version = "4.4.0"
license= ["Apache-2.0"]
authors = ["Ballerina"]
keywords = ["IT Operations/Databases", "Cost/Freemium"]
Expand All @@ -13,10 +13,10 @@ repository = "https://github.com/ballerina-platform/module-ballerinax-mongodb"
graalvmCompatible = true

[[platform.java11.dependency]]
path = "../native/build/libs/mongodb-native-4.3.0.jar"
path = "../native/build/libs/mongodb-native-4.4.0.jar"
groupId = "org.ballerinalang"
artifactId = "mongodb-native"
version = "4.3.0"
version = "4.4.0"

[[platform.java11.dependency]]
groupId = "com.fasterxml.jackson.core"
Expand Down
19 changes: 15 additions & 4 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,21 @@ public isolated client class Client {
# + collectionName - Name of the collection
# + databaseName - Name of the database
# + filter - Filter for the count ($where & $near can be used)
# + pipeline - The aggregation pipeline for the count.
# + return - Count of the documents in the collection or else `mongodb:Error` if unable to reach the DB
@display {label: "Count Documents"}
remote isolated function countDocuments(@display {label: "Collection Name"} string collectionName,
@display {label: "Database Name"} string? databaseName = (),
@display {label: "Filter"} map<json>? filter = ())
@display {label: "Filter"} map<json>? filter = (),
@display {label: "Pipeline"} json[] pipeline = [])
returns @display {label: "Number of Documents"} int|Error {
handle collection = check getCollection(self, collectionName, databaseName);
if (filter is ()) {
return countDocuments(collection, ());
return countDocuments(collection, (), pipeline);
}
string filterString = filter.toJsonString();
return countDocuments(collection, java:fromString(filterString));
// string pipelineString = pipeline.toJsonString();
return countDocuments(collection, java:fromString(filterString), pipeline);
}

# Lists the indices associated with the collection.
Expand Down Expand Up @@ -193,6 +196,14 @@ public isolated client class Client {
'class: "org.ballerinalang.mongodb.MongoDBCollectionUtil"
} external;

remote isolated function aggregate(@display {label: "Collection Name"} string collectionName,
@display {label: "Database Name"} string? databaseName = (),
@display {label: "Pipeline"} json[] pipeline = [],
@display {label: "Record Type"} typedesc<record {}> rowType = <>)
returns stream<rowType, error?>|Error = @java:Method {
'class: "org.ballerinalang.mongodb.MongoDBCollectionUtil"
} external;

# Closes the client.
@display {label: "Close the Client"}
remote isolated function close() {
Expand Down Expand Up @@ -220,7 +231,7 @@ isolated function getCollection(Client mongoClient, string collectionName, strin
} external;

// Collection Client Java
isolated function countDocuments(handle collection, handle? filter) returns int|DatabaseError = @java:Method {
isolated function countDocuments(handle collection, handle? filter, json[] pipeline) returns int|DatabaseError = @java:Method {
'class: "org.ballerinalang.mongodb.MongoDBCollectionUtil"
} external;

Expand Down
6 changes: 3 additions & 3 deletions build-config/checkstyle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ plugins {
id "de.undercouch.download"
}

apply plugin: 'java'
apply plugin: 'java-library'

task downloadCheckstyleRuleFiles(type: Download) {
src([
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.3/checkstyle/checkstyle.xml',
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.3/checkstyle/suppressions.xml'
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/checkstyle.xml',
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/suppressions.xml'
])
overwrite false
onlyIfNewer true
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
org.gradle.caching=true
group=org.ballerinalang.mongodb
version=4.3.0
version=4.4.0

puppycrawlCheckstyleVersion=8.18
checkstyleToolVersion=7.8.2
githubSpotbugsVersion=4.0.5
githubJohnrengelmanShadowVersion=5.2.0
underCouchDownloadVersion=4.0.4
puppycrawlCheckstyleVersion=10.12.1
checkstyleToolVersion=10.12.1
githubSpotbugsVersion=5.0.14
githubJohnrengelmanShadowVersion=8.1.1
underCouchDownloadVersion=5.4.0
researchgateReleaseVersion=2.8.0
testngVersion=7.4.0
testngVersion=7.6.1

ballerinaLangVersion=2201.7.0
ballerinaLangVersion=2201.8.4
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 1390e5b

Please sign in to comment.