Skip to content

Commit 00975cd

Browse files
authored
Release 2.2.0
Release 2.2.0
2 parents ea430f7 + 9066b48 commit 00975cd

File tree

40 files changed

+2607
-123
lines changed

40 files changed

+2607
-123
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ buildscript {
99
}
1010

1111
plugins {
12-
alias(libs.plugins.androidLibrary) apply false
12+
alias(libs.plugins.androidLibrary) apply false
13+
alias(libs.plugins.kotlin.jvm) apply false
1314
}
1415

examples/privmx-snippets/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
src/main/jniLibs

examples/privmx-snippets/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
alias(libs.plugins.kotlin.jvm)
3+
alias(libs.plugins.kotlinPluginSerialization)
4+
alias(libs.plugins.privmx.install.native)
5+
}
6+
7+
group = "com.simplito.privmx-endpoint-snippets"
8+
version = "2.2.0"
9+
10+
kotlin {
11+
jvmToolchain(21)
12+
}
13+
14+
privmxEndpointInstallJni {
15+
version = project.version
16+
}
17+
18+
dependencies {
19+
implementation(project(":privmx-endpoint-extra"))
20+
implementation(libs.gson)
21+
implementation(libs.kotlinx.serialization.json)
22+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package Stacks.JavaKotlin;
2+
3+
import com.simplito.java.privmx_endpoint_extra.lib.PrivmxEndpoint;
4+
import com.simplito.java.privmx_endpoint_extra.lib.PrivmxEndpointContainer;
5+
import com.simplito.java.privmx_endpoint_extra.model.Modules;
6+
7+
import java.util.Set;
8+
9+
public class PrivMXEndpointJava {
10+
PrivmxEndpointContainer endpointContainer;
11+
PrivmxEndpoint endpointSession;
12+
13+
// START: Initial assumption snippet
14+
/*
15+
All the values below like BRIDGE_URL, SOLUTION_ID, CONTEXT_ID
16+
should be replaced by the ones corresponding to your Bridge Server instance.
17+
18+
The private keys here are for demonstration purposes only.
19+
Normally, they should be kept separately by each user and stored in a safe place,
20+
or generated from a password (see the derivePrivateKey2() method in the Crypto API)
21+
*/
22+
23+
String bridgeUrl = "YOUR_BRIDGE_URL";
24+
String solutionId = "YOUR_SOLUTION_ID";
25+
String contextId = "YOUR_CONTEXT_ID";
26+
27+
String user1Id = "USER_ID_1";
28+
String user1PublicKey = "PUBLIC_KEY_1";
29+
String user1PrivateKey = "PRIVATE_KEY_1";
30+
31+
String user2Id = "USER_ID_2";
32+
String user2PublicKey = "PUBLIC_KEY_2";
33+
// END: Initial assumption snippet
34+
35+
void makeConnection(){
36+
// START: Make connection snippet
37+
String pathToCerts = "PATH_TO_CERTS"; // Path to .pem ssl certificate to connect with Privmx Bridge
38+
Set<Modules> initModules = Set.of(
39+
Modules.THREAD, // initializes ThreadApi to working with Threads
40+
Modules.STORE, // initializes StoreApi to working with Stores
41+
Modules.INBOX // initializes InboxApi to working with Inboxes
42+
); // set of modules to activate in new connection
43+
44+
PrivmxEndpointContainer endpointContainer = new PrivmxEndpointContainer();
45+
endpointContainer.setCertsPath(pathToCerts);
46+
47+
PrivmxEndpoint endpointSession = endpointContainer.connect(
48+
initModules,
49+
user1PrivateKey,
50+
solutionId,
51+
bridgeUrl
52+
);
53+
// END: Make connection snippet
54+
55+
this.endpointContainer = endpointContainer;
56+
this.endpointSession = endpointSession;
57+
}
58+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package Tools.Stores.UsingStores;
2+
3+
import com.simplito.java.privmx_endpoint_extra.storeFileStream.StoreFileStream;
4+
import com.simplito.java.privmx_endpoint_extra.storeFileStream.StoreFileStreamReader;
5+
6+
import java.io.FileOutputStream;
7+
import java.io.OutputStream;
8+
9+
public class DownloadingFiles extends ManagingStores {
10+
void downloadingFiles() {
11+
String fileId = "FILE_ID";
12+
StoreFileStream.Controller controller = new StoreFileStream.Controller() {
13+
@Override
14+
public void onChunkProcessed(Long processedBytes) {
15+
System.out.println("Downloaded bytes: " + processedBytes);
16+
}
17+
};
18+
19+
try (OutputStream outputStream = new FileOutputStream("PATH_TO_FILE")) {
20+
StoreFileStreamReader.openFile(
21+
endpointSession.storeApi,
22+
fileId,
23+
outputStream,
24+
controller
25+
);
26+
} catch (Exception e) {
27+
System.out.println("Cannot download file: " + e.getMessage());
28+
}
29+
}
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Tools.Stores.UsingStores;
2+
3+
import com.simplito.java.privmx_endpoint.model.File;
4+
import com.simplito.java.privmx_endpoint.model.PagingList;
5+
import com.simplito.java.privmx_endpoint_extra.model.SortOrder;
6+
7+
public class ManagingFiles extends ManagingStores{
8+
9+
void listingFiles() {
10+
String storeID = "STORE_ID";
11+
long limit = 30L;
12+
long skip = 0L;
13+
14+
PagingList<File> files = endpointSession.storeApi.listFiles(
15+
storeID,
16+
skip,
17+
limit,
18+
SortOrder.DESC
19+
);
20+
}
21+
22+
void deletingFiles() {
23+
String fileID = "FILE_ID";
24+
endpointSession.storeApi.deleteFile(fileID);
25+
}
26+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package Tools.Stores.UsingStores;
2+
3+
import com.simplito.java.privmx_endpoint.model.PagingList;
4+
import com.simplito.java.privmx_endpoint.model.Store;
5+
import com.simplito.java.privmx_endpoint.model.UserWithPubKey;
6+
import com.simplito.java.privmx_endpoint_extra.lib.PrivmxEndpoint;
7+
import com.simplito.java.privmx_endpoint_extra.lib.PrivmxEndpointContainer;
8+
import com.simplito.java.privmx_endpoint_extra.model.Modules;
9+
import com.simplito.java.privmx_endpoint_extra.model.SortOrder;
10+
11+
import java.nio.charset.StandardCharsets;
12+
import java.util.List;
13+
import java.util.Set;
14+
15+
public class ManagingStores {
16+
// START: Initial Assumptions Snippets
17+
/*
18+
All the values below like BRIDGE_URL, SOLUTION_ID, CONTEXT_ID
19+
should be replaced by the ones corresponding to your Bridge Server instance.
20+
21+
The private keys here are for demonstration purposes only.
22+
Normally, they should be kept separately by each user and stored in a safe place,
23+
or generated from a password (see the derivePrivateKey2() method in the Crypto API)
24+
*/
25+
26+
String bridgeUrl = "YOUR_BRIDGE_URL";
27+
String solutionId = "YOUR_SOLUTION_ID";
28+
String contextId = "YOUR_CONTEXT_ID";
29+
30+
String user1Id = "USER_ID_1";
31+
String user1PublicKey = "PUBLIC_KEY_1";
32+
String user1PrivateKey = "PRIVATE_KEY_1";
33+
34+
String user2Id = "USER_ID_2";
35+
String user2PublicKey = "PUBLIC_KEY_2";
36+
37+
String user3Id = "USER_ID_3";
38+
String user3PublicKey = "PUBLIC_KEY_3";
39+
40+
PrivmxEndpointContainer endpointContainer = new PrivmxEndpointContainer();
41+
42+
Set<Modules> initModules = Set.of(Modules.STORE);
43+
PrivmxEndpoint endpointSession = endpointContainer.connect(
44+
initModules,
45+
user1PrivateKey,
46+
solutionId,
47+
bridgeUrl
48+
);
49+
// END: Initial Assumptions Snippets
50+
51+
void creatingStores() {
52+
byte[] privateMeta = "My private data".getBytes(StandardCharsets.UTF_8);
53+
byte[] publicMeta = "My public data".getBytes(StandardCharsets.UTF_8);
54+
List<UserWithPubKey> users = List.of(
55+
new UserWithPubKey(user1Id, user1PublicKey),
56+
new UserWithPubKey(user2Id, user2PublicKey)
57+
);
58+
List<UserWithPubKey> managers = List.of(
59+
new UserWithPubKey(user1Id, user1PublicKey)
60+
);
61+
62+
String storeID = endpointSession.storeApi.createStore(
63+
contextId,
64+
users,
65+
managers,
66+
publicMeta,
67+
privateMeta
68+
);
69+
}
70+
71+
void listingStores() {
72+
long limit = 30L;
73+
long skip = 0L;
74+
75+
PagingList<Store> stores = endpointSession.storeApi.listStores(
76+
contextId,
77+
skip,
78+
limit,
79+
SortOrder.DESC
80+
);
81+
}
82+
83+
void modifyingStores() {
84+
String storeID = "STORE_ID";
85+
Store store = endpointSession.storeApi.getStore(storeID);
86+
List<UserWithPubKey> newUsers = List.of(
87+
new UserWithPubKey(user1Id, user1PublicKey),
88+
new UserWithPubKey(user2Id, user2PublicKey),
89+
new UserWithPubKey(user3Id, user3PublicKey)
90+
);
91+
List<UserWithPubKey> newManagers = List.of(
92+
new UserWithPubKey(user1Id, user1PublicKey),
93+
new UserWithPubKey(user2Id, user2PublicKey)
94+
);
95+
byte[] newPrivateMeta = "New store name".getBytes(StandardCharsets.UTF_8);
96+
97+
endpointSession.storeApi.updateStore(
98+
storeID,
99+
newUsers,
100+
newManagers,
101+
store.publicMeta,
102+
newPrivateMeta,
103+
store.version,
104+
false
105+
);
106+
}
107+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package Tools.Stores.UsingStores;
2+
3+
import com.simplito.java.privmx_endpoint_extra.events.EventType;
4+
5+
public class StoreEventsInRealTime extends ManagingStores{
6+
void handlingStoreEvents() {
7+
String callbacksID = "CALLBACK_ID";
8+
String storeID = "STORE_ID";
9+
10+
// Starting the Event Loop
11+
endpointContainer.startListening();
12+
13+
// Handling Store Events
14+
endpointSession.registerCallback(
15+
callbacksID,
16+
EventType.StoreCreatedEvent,
17+
newStore -> {
18+
System.out.println(newStore.storeId);
19+
}
20+
);
21+
22+
// Handling File Events
23+
endpointSession.registerCallback(
24+
callbacksID,
25+
EventType.StoreFileCreatedEvent(storeID),
26+
newFile -> {
27+
System.out.println(newFile.info.fileId);
28+
}
29+
);
30+
}
31+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package Tools.Stores.UsingStores;
2+
3+
import com.simplito.java.privmx_endpoint_extra.storeFileStream.StoreFileStream;
4+
import com.simplito.java.privmx_endpoint_extra.storeFileStream.StoreFileStreamWriter;
5+
6+
import java.io.FileInputStream;
7+
import java.io.InputStream;
8+
import java.nio.charset.StandardCharsets;
9+
10+
public class UploadingFiles extends ManagingStores{
11+
void uploadingSmallFiles(){
12+
String storeID = "STORE_ID";
13+
byte[] publicMeta = "File public meta".getBytes(StandardCharsets.UTF_8);
14+
byte[] privateMeta = "File private meta".getBytes(StandardCharsets.UTF_8);
15+
byte[] fileContent = "Text file content".getBytes(StandardCharsets.UTF_8);
16+
17+
try {
18+
Long fileHandle = endpointSession.storeApi.createFile(
19+
storeID,
20+
publicMeta,
21+
privateMeta,
22+
fileContent.length
23+
);
24+
endpointSession.storeApi.writeToFile(fileHandle,fileContent);
25+
endpointSession.storeApi.closeFile(fileHandle);
26+
}catch (Exception e){
27+
System.out.println("Cannot upload file: " + e.getMessage());
28+
}
29+
}
30+
31+
void uploadingFilesStream(){
32+
String storeID = "STORE_ID";
33+
byte[] publicMeta = "File public meta".getBytes(StandardCharsets.UTF_8);
34+
byte[] privateMeta = "File private meta".getBytes(StandardCharsets.UTF_8);
35+
StoreFileStream.Controller controller = new StoreFileStream.Controller(){
36+
@Override
37+
public void onChunkProcessed(Long processedBytes) {
38+
System.out.println("Uploaded bytes: " + processedBytes);
39+
}
40+
};
41+
42+
try(InputStream inputStream = new FileInputStream("PATH_TO_FILE")) {
43+
String fileId = StoreFileStreamWriter.createFile(
44+
endpointSession.storeApi,
45+
storeID,
46+
publicMeta,
47+
privateMeta,
48+
inputStream.available(),
49+
inputStream,
50+
controller
51+
);
52+
}catch (Exception e){
53+
System.out.println("Cannot upload file: " + e.getMessage());
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)