Skip to content

Commit

Permalink
feat: rename platformConnect/platformConnectPublic methods to connect…
Browse files Browse the repository at this point in the history
…/connectPublic (#8)

* feat: change platformConnect/platformConnectPublic method names to connect/connectPublic
Mark platformConnect/platformConnectPublic methods as deprecated

* docs: connection update

---------

Co-authored-by: fgrochowski <[email protected]>
  • Loading branch information
djenczewski and filipg43 authored Dec 6, 2024
1 parent fde9231 commit 0fd664e
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class BasicPrivmxEndpoint implements AutoCloseable {
*
* @param enableModule set of modules to initialize; should contain {@link Modules#THREAD }
* to enable Thread module or {@link Modules#STORE } to enable Store module
* @param platformUrl Platform's Endpoint URL
* @param bridgeUrl Bridge's Endpoint URL
* @param solutionId {@code SolutionId} of the current project
* @param userPrivateKey user private key used to authorize; generated from:
* {@link CryptoApi#generatePrivateKey} or
Expand All @@ -68,9 +68,9 @@ public BasicPrivmxEndpoint(
Set<Modules> enableModule,
String userPrivateKey,
String solutionId,
String platformUrl
String bridgeUrl
) throws IllegalStateException, PrivmxException, NativeException {
connection = Connection.platformConnect(userPrivateKey, solutionId, platformUrl);
connection = Connection.connect(userPrivateKey, solutionId, bridgeUrl);
storeApi = enableModule.contains(Modules.STORE) ? new StoreApi(connection) : null;
threadApi = enableModule.contains(Modules.THREAD) ? new ThreadApi(connection) : null;
inboxApi = enableModule.contains(Modules.INBOX) ? new InboxApi(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class PrivmxEndpoint extends BasicPrivmxEndpoint implements AutoCloseable
*
* @param enableModule set of modules to initialize; should contain {@link Modules#THREAD }
* to enable Thread module or {@link Modules#STORE } to enable Store module
* @param platformUrl Platform's Endpoint URL
* @param bridgeUrl Bridge's Endpoint URL
* @param solutionId {@code SolutionId} of the current project
* @param userPrivateKey user private key used to authorize; generated from:
* {@link CryptoApi#generatePrivateKey} or
Expand All @@ -57,9 +57,9 @@ public PrivmxEndpoint(
Set<Modules> enableModule,
String userPrivateKey,
String solutionId,
String platformUrl
String bridgeUrl
) throws IllegalStateException, PrivmxException, NativeException {
super(enableModule, userPrivateKey, solutionId, platformUrl);
super(enableModule, userPrivateKey, solutionId, bridgeUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void setCertsPath(String certsPath) throws IllegalArgumentException, Priv
* Creates a new connection.
*
* @param enableModule set of modules to initialize
* @param platformUrl Platform's Endpoint URL
* @param bridgeUrl Bridge's Endpoint URL
* @param solutionId {@code SolutionId} of the current project
* @param userPrivateKey user private key used to authorize; generated from:
* {@link CryptoApi#generatePrivateKey} or
Expand All @@ -128,14 +128,14 @@ public PrivmxEndpoint connect(
Set<Modules> enableModule,
String userPrivateKey,
String solutionId,
String platformUrl
String bridgeUrl
) throws IllegalStateException, PrivmxException, NativeException {
if (!isInitialized) throw new IllegalStateException("Certs path is not set");
PrivmxEndpoint privmxEndpoint = new PrivmxEndpoint(
enableModule,
userPrivateKey,
solutionId,
platformUrl
bridgeUrl
);
synchronized (privmxEndpoints) {
privmxEndpoints.put(privmxEndpoint.connection.getConnectionId(), privmxEndpoint);
Expand Down
111 changes: 56 additions & 55 deletions privmx-endpoint/src/main/cpp/modules/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,55 +47,6 @@ Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_deinit(JNIEnv *e
}
}

extern "C"
JNIEXPORT jobject JNICALL
Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_platformConnect(
JNIEnv *env,
jclass clazz,
jstring user_priv_key,
jstring solution_id,
jstring platform_url
) {
JniContextUtils ctx(env);
if (ctx.nullCheck(user_priv_key, "User Private Key") ||
ctx.nullCheck(solution_id, "Solution ID") ||
ctx.nullCheck(platform_url, "Platform URL")) {
return nullptr;
}
try {
jmethodID initMID = ctx->GetMethodID(clazz, "<init>", "(Ljava/lang/Long;Ljava/lang/Long;)V");
privmx::endpoint::core::Connection connection = privmx::endpoint::core::Connection::platformConnect(
ctx.jString2string(user_priv_key),
ctx.jString2string(solution_id),
ctx.jString2string(platform_url)
);
privmx::endpoint::core::Connection *api = new privmx::endpoint::core::Connection();
*api = connection;
jobject result = ctx->NewObject(
clazz,
initMID,
ctx.long2jLong((jlong) api),
ctx.long2jLong(api->getConnectionId())
);
return result;
} catch (const privmx::endpoint::core::Exception &e) {
env->Throw(ctx.coreException2jthrowable(e));
} catch (const std::exception &e) {
env->ThrowNew(
env->FindClass(
"com/simplito/java/privmx_endpoint/model/exceptions/NativeException"),
e.what()
);
} catch (...) {
env->ThrowNew(
env->FindClass(
"com/simplito/java/privmx_endpoint/model/exceptions/NativeException"),
"Unknown exception"
);
}
return nullptr;
}

extern "C"
JNIEXPORT jobject JNICALL
Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_listContexts(
Expand Down Expand Up @@ -236,22 +187,72 @@ Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_setCertsPath(

extern "C"
JNIEXPORT jobject JNICALL
Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_platformConnectPublic(
Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_connect(
JNIEnv *env,
jclass clazz,
jstring user_priv_key,
jstring solution_id,
jstring bridge_url
) {
JniContextUtils ctx(env);
if (ctx.nullCheck(user_priv_key, "User Private Key") ||
ctx.nullCheck(solution_id, "Solution ID") ||
ctx.nullCheck(bridge_url, "Bridge URL")) {
return nullptr;
}
try {
jmethodID initMID = ctx->GetMethodID(clazz, "<init>",
"(Ljava/lang/Long;Ljava/lang/Long;)V");
privmx::endpoint::core::Connection connection = privmx::endpoint::core::Connection::connect(
ctx.jString2string(user_priv_key),
ctx.jString2string(solution_id),
ctx.jString2string(bridge_url)
);
privmx::endpoint::core::Connection *api = new privmx::endpoint::core::Connection();
*api = connection;
jobject result = ctx->NewObject(
clazz,
initMID,
ctx.long2jLong((jlong) api),
ctx.long2jLong(api->getConnectionId())
);
return result;
} catch (const privmx::endpoint::core::Exception &e) {
env->Throw(ctx.coreException2jthrowable(e));
} catch (const std::exception &e) {
env->ThrowNew(
env->FindClass(
"com/simplito/java/privmx_endpoint/model/exceptions/NativeException"),
e.what()
);
} catch (...) {
env->ThrowNew(
env->FindClass(
"com/simplito/java/privmx_endpoint/model/exceptions/NativeException"),
"Unknown exception"
);
}
return nullptr;
}
extern "C"
JNIEXPORT jobject JNICALL
Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_connectPublic(
JNIEnv *env,
jclass clazz,
jstring solution_id,
jstring platform_url
jstring bridge_url
) {
JniContextUtils ctx(env);
if (ctx.nullCheck(solution_id, "Solution ID") ||
ctx.nullCheck(platform_url, "Platform URL")) {
ctx.nullCheck(bridge_url, "Bridge URL")) {
return nullptr;
}
try {
jmethodID initMID = ctx->GetMethodID(clazz, "<init>", "(Ljava/lang/Long;Ljava/lang/Long;)V");
privmx::endpoint::core::Connection connection = privmx::endpoint::core::Connection::platformConnectPublic(
jmethodID initMID = ctx->GetMethodID(clazz, "<init>",
"(Ljava/lang/Long;Ljava/lang/Long;)V");
privmx::endpoint::core::Connection connection = privmx::endpoint::core::Connection::connectPublic(
ctx.jString2string(solution_id),
ctx.jString2string(platform_url)
ctx.jString2string(bridge_url)
);
privmx::endpoint::core::Connection *api = new privmx::endpoint::core::Connection();
*api = connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private Connection(Long api, Long connectionId) {
public static native void setCertsPath(String certsPath) throws PrivmxException, NativeException;

/**
* Connects to the PrivMX Bridge server.
* Connects to PrivMX Bridge server.
*
* @param userPrivKey user's private key
* @param solutionId ID of the Solution
Expand All @@ -60,10 +60,28 @@ private Connection(Long api, Long connectionId) {
* channel: -
* payload: {@link Void}
*/
public static native Connection platformConnect(String userPrivKey, String solutionId, String platformUrl) throws PrivmxException, NativeException;
@Deprecated
public static Connection platformConnect(String userPrivKey, String solutionId, String platformUrl) throws PrivmxException, NativeException{
return connect(userPrivKey,solutionId,platformUrl);
}

/**
* Connects to PrivMX Bridge server.
*
* @param userPrivKey user's private key
* @param solutionId ID of the Solution
* @param bridgeUrl Bridge's Endpoint URL
* @return Connection object
* @throws PrivmxException thrown when method encounters an exception.
* @throws NativeException thrown when method encounters an unknown exception.
* @event type: libConnected
* channel: -
* payload: {@link Void}
*/
public static native Connection connect(String userPrivKey, String solutionId, String bridgeUrl) throws PrivmxException, NativeException;

/**
* Connects to the PrivMX Bridge server as a guest user.
* Connects to PrivMX Bridge server as a guest user.
*
* @param solutionId ID of the Solution
* @param platformUrl Platform's Endpoint URL
Expand All @@ -74,10 +92,27 @@ private Connection(Long api, Long connectionId) {
* channel: -
* payload: {@link Void}
*/
public static native Connection platformConnectPublic(String solutionId, String platformUrl) throws PrivmxException, NativeException;
@Deprecated
public static Connection platformConnectPublic(String solutionId, String platformUrl) throws PrivmxException, NativeException{
return connectPublic(solutionId,platformUrl);
}

/**
* Connects to PrivMX Bridge server as a guest user.
*
* @param solutionId ID of the Solution
* @param bridgeUrl Bridge's Endpoint URL
* @return Connection object
* @throws PrivmxException thrown when method encounters an exception.
* @throws NativeException thrown when method encounters an unknown exception.
* @event type: libConnected
* channel: -
* payload: {@link Void}
*/
public static native Connection connectPublic(String solutionId, String bridgeUrl) throws PrivmxException, NativeException;

/**
* Disconnects from the PrivMX Bridge server.
* Disconnects from PrivMX Bridge server.
*
* @throws IllegalStateException thrown when instance is not connected or closed.
* @throws PrivmxException thrown when method encounters an exception.
Expand Down Expand Up @@ -132,7 +167,7 @@ public Long getConnectionId() {


/**
* If there is an active connnection then it
* If there is an active connection then it
* disconnects from PrivMX Bridge and frees memory making this instance not reusable.
*/
@Override
Expand Down

0 comments on commit 0fd664e

Please sign in to comment.