-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGetExample.java
More file actions
74 lines (58 loc) · 2.48 KB
/
GetExample.java
File metadata and controls
74 lines (58 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.example;
import com.skyflow.entities.RedactionType;
import com.skyflow.entities.ResponseToken;
import com.skyflow.entities.SkyflowConfiguration;
import com.skyflow.entities.TokenProvider;
import com.skyflow.errors.SkyflowException;
import com.skyflow.serviceaccount.util.Token;
import com.skyflow.vault.Skyflow;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class GetExample {
public static void main(String[] args) {
try {
SkyflowConfiguration config = new SkyflowConfiguration("<your_vaultID>",
"<your_vaultURL>", new DemoTokenProvider());
Skyflow skyflowClient = Skyflow.init(config);
JSONObject records = new JSONObject();
JSONArray recordsArray = new JSONArray();
JSONObject firstRecord = new JSONObject();
JSONArray ids = new JSONArray();
ids.add("<your_skyflowId>");
firstRecord.put("ids", ids);
firstRecord.put("table", "<your_table_name>");
firstRecord.put("redaction", RedactionType.PLAIN_TEXT.toString());
JSONObject secondRecord = new JSONObject();
JSONArray valuesArray = new JSONArray();
valuesArray.add("<your_column_value>");
secondRecord.put("table", "<your_table_name>");
secondRecord.put("columnName", "<unique_column_name>");
secondRecord.put("columnValues", valuesArray);
secondRecord.put("redaction", RedactionType.PLAIN_TEXT.toString());
recordsArray.add(firstRecord);
recordsArray.add(secondRecord);
records.put("records", recordsArray);
JSONObject response = skyflowClient.get(records);
} catch (SkyflowException e) {
e.printStackTrace();
System.out.println(e.getData());
}
}
static class DemoTokenProvider implements TokenProvider {
private String bearerToken = null;
@Override
public String getBearerToken() throws Exception {
ResponseToken response = null;
try {
String filePath = "<YOUR_CREDENTIALS_FILE_PATH>";
if (Token.isExpired(bearerToken)) {
response = Token.generateBearerToken(filePath);
bearerToken = response.getAccessToken();
}
} catch (SkyflowException e) {
e.printStackTrace();
}
return bearerToken;
}
}
}