Skip to content

Commit

Permalink
Merge pull request #144 from SkNuwanTissera/slalpha5
Browse files Browse the repository at this point in the history
Remove hardcoded Module detail in java code
  • Loading branch information
SkNuwanTissera authored Oct 12, 2021
2 parents 1d24305 + 6b33b42 commit 0828c82
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mongo-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>module-mongo</artifactId>
<groupId>org.wso2.ei</groupId>
<version>2.0.9</version>
<version>2.0.10</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
44 changes: 44 additions & 0 deletions mongo-utils/src/main/java/org/wso2/mongo/ModuleUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.ballerinalang.mongodb;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.Module;

/**
* This class will hold module related utility functions.
*/
public class ModuleUtils {

/**
* MongoDB connector package ID.
*/
private static Module mongodbModule = null;

private ModuleUtils() {
}

public static void setModule(Environment env) {
mongodbModule = env.getCurrentModule();
}

public static Module getModule() {
return mongodbModule;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@

package org.wso2.mongo;

import io.ballerina.runtime.api.Module;

/**
* Constants used in the module-mongodb.
*/
public class MongoDBConstants {
public static final Module BAL_PACKAGE = new Module("ballerinax", "mongodb", "2.0.9");

/**
* Constants related to `mongodb:DatabaseError`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Map;

import static org.wso2.mongo.MongoDBConstants.APPLICATION_ERROR;
import static org.wso2.mongo.MongoDBConstants.BAL_PACKAGE;
import static org.wso2.mongo.MongoDBConstants.DatabaseError.DETAIL_FIELD_MONGODB_EXCEPTION;
import static org.wso2.mongo.MongoDBConstants.DatabaseError.DETAIL_RECORD_NAME;
import static org.wso2.mongo.MongoDBConstants.DatabaseError.NAME;
Expand All @@ -41,13 +40,14 @@ public static BError createBallerinaDatabaseError(Exception e) {
Map<String, Object> valueMap = new HashMap<>();
valueMap.put(DETAIL_FIELD_MONGODB_EXCEPTION, e.getClass().getSimpleName());
BMap<BString, Object> recordValue = ValueCreator
.createRecordValue(BAL_PACKAGE, DETAIL_RECORD_NAME, valueMap);
.createRecordValue(org.ballerinalang.mongodb.ModuleUtils.getModule(), DETAIL_RECORD_NAME, valueMap);

return ErrorCreator.createDistinctError(NAME, BAL_PACKAGE, StringUtils.fromString(e.getMessage()), recordValue);
return ErrorCreator.createDistinctError(NAME, org.ballerinalang.mongodb.ModuleUtils.getModule(),
StringUtils.fromString(e.getMessage()), recordValue);
}

public static BError createBallerinaApplicationError(Exception e) {
return ErrorCreator.createDistinctError(APPLICATION_ERROR, BAL_PACKAGE, StringUtils.fromString(e.getMessage()));
return ErrorCreator.createDistinctError(APPLICATION_ERROR, org.ballerinalang.mongodb.ModuleUtils.getModule(),
StringUtils.fromString(e.getMessage()));
}

}
4 changes: 2 additions & 2 deletions mongodb/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ keywords = ["MongoDB", "NoSQL"]
repository = "https://github.com/ballerina-platform/module-ballerinax-mongodb"

[[platform.java11.dependency]]
path = "../mongo-utils/target/mongo-utils-2.0.9.jar"
path = "../mongo-utils/target/mongo-utils-2.0.10.jar"
groupId = "org.wso2.ei"
artifactId = "mongo-utils"
version = "2.0.9"
version = "2.0.10"

25 changes: 25 additions & 0 deletions mongodb/init.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 Inc. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/jballerina.java;

function init() {
setModule();
}

function setModule() = @java:Method {
'class: "org.ballerinalang.mongodb.ModuleUtils"
} external;
2 changes: 1 addition & 1 deletion mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<artifactId>module-mongo</artifactId>
<groupId>org.wso2.ei</groupId>
<version>2.0.9</version>
<version>2.0.10</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<groupId>org.wso2.ei</groupId>
<artifactId>module-mongo</artifactId>
<packaging>pom</packaging>
<version>2.0.9</version>
<version>2.0.10</version>
<name>Ballerina MongoDB Module</name>

<modules>
Expand Down Expand Up @@ -81,7 +81,7 @@
<properties>
<project-home>${project.basedir}</project-home>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ballerina.version>2.0.0-alpha5</ballerina.version>
<ballerina.version>2.0.0-beta.3</ballerina.version>
<maven.checkstyleplugin.excludes>**/generated/**</maven.checkstyleplugin.excludes>
<maven.spotbugsplugin.exclude.file>spotbugs-exclude.xml</maven.spotbugsplugin.exclude.file>
<slf4j.version>1.7.21</slf4j.version>
Expand Down

0 comments on commit 0828c82

Please sign in to comment.