Skip to content

Commit

Permalink
Merge pull request #44 from ldclakmal/dev
Browse files Browse the repository at this point in the history
Replace hard coded native package version
  • Loading branch information
ldclakmal authored Dec 23, 2020
2 parents b606f68 + 52e1260 commit 5f7bfe2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 14 deletions.
25 changes: 25 additions & 0 deletions ldap-ballerina/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/java;

isolated function init() {
setModule();
}

isolated function setModule() = @java:Method {
'class: "org.ballerinalang.stdlib.ldap.nativeimpl.ModuleUtils"
} external;
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,12 @@

package org.ballerinalang.stdlib.ldap;

import io.ballerina.runtime.api.Module;

import static io.ballerina.runtime.api.constants.RuntimeConstants.BALLERINA_BUILTIN_PKG_PREFIX;

/**
* Constants to be used in LDAP user stores.
*
* @since 0.983.0
*/
public class LdapConstants {

// Name of the Ballerina ldap module, used to create struct instances.
public static final String PACKAGE_NAME = "ldap";
public static final Module LDAP_PACKAGE_ID = new Module(BALLERINA_BUILTIN_PKG_PREFIX, PACKAGE_NAME, "1.0.5");

// Record used to reference to a LDAP connection.
public static final String LDAP_CONNECTION = "LdapConnection";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static Object initLdapConnectionContext(BMap<BString, Object> authProvide
DirContext dirContext = connectionSource.getContext();

BMap<BString, Object> ldapConnectionRecord = ValueCreator.
createRecordValue(LdapConstants.LDAP_PACKAGE_ID, LdapConstants.LDAP_CONNECTION);
createRecordValue(ModuleUtils.getModule(), LdapConstants.LDAP_CONNECTION);
ldapConnectionRecord.addNativeData(LdapConstants.LDAP_CONFIGURATION, commonLdapConfiguration);
ldapConnectionRecord.addNativeData(LdapConstants.LDAP_CONNECTION_SOURCE, connectionSource);
ldapConnectionRecord.addNativeData(LdapConstants.LDAP_CONNECTION_CONTEXT, dirContext);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.
*/

package org.ballerinalang.stdlib.ldap.nativeimpl;

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

/**
* Utility functions relevant to module operations.
*
* @since 2.0.0
*/
public class ModuleUtils {

private static Module ldapModule;

private ModuleUtils() {}

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

public static Module getModule() {
return ldapModule;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.values.BError;
import org.ballerinalang.stdlib.ldap.CommonLdapConfiguration;
import org.ballerinalang.stdlib.ldap.LdapConstants;
import org.ballerinalang.stdlib.ldap.nativeimpl.ModuleUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,9 +38,6 @@
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;

import static org.ballerinalang.stdlib.ldap.LdapConstants.LDAP_ERROR_TYPE;
import static org.ballerinalang.stdlib.ldap.LdapConstants.LDAP_PACKAGE_ID;

/**
* Utility class for LDAP related common operations.
*
Expand Down Expand Up @@ -258,6 +257,7 @@ public static void removeServiceName() {
}

public static BError createError(String errMsg) {
return ErrorCreator.createDistinctError(LDAP_ERROR_TYPE, LDAP_PACKAGE_ID, StringUtils.fromString(errMsg));
return ErrorCreator.createDistinctError(LdapConstants.LDAP_ERROR_TYPE, ModuleUtils.getModule(),
StringUtils.fromString(errMsg));
}
}

0 comments on commit 5f7bfe2

Please sign in to comment.