Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions common/src/main/java/com/skyflow/errors/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ public enum ErrorMessage {
EmptyTokenInDetokenizeData("%s0 Validation error. Invalid data tokens. Specify a valid data token."),
TokensSizeExceedError("%s0 Maximum number of tokens exceeded. The limit is 10000."),

// Delete
DeleteRequestNull("%s0 Validation error. DeleteRequest object is null. Specify a valid DeleteRequest object."),

// Delete Tokens
DeleteTokensRequestNull("%s0 Validation error. DeleteTokensRequest object is null. Specify a valid DeleteTokensRequest object."),
EmptyDeleteTokensData("%s0 Validation error. Tokens list is empty. Specify at least one token to delete."),
EmptyTokenInDeleteTokensData("%s0 Validation error. Invalid token in delete tokens request. Specify a valid token."),
DeleteTokensSizeExceedError("%s0 Maximum number of tokens exceeded. The limit is 10000."),

// Get
GetRequestNull("%s0 Validation error. GetRequest object is null. Specify a valid GetRequest object."),
IdsKeyError("%s0 Validation error. 'ids' key is missing from the payload. Specify an 'ids' key."),
EmptyIds("%s0 Validation error. 'ids' can't be empty. Specify at least one id."),
EmptyIdInIds("%s0 Validation error. Invalid id in 'ids'. Specify a valid id."),
Expand Down Expand Up @@ -141,8 +145,13 @@ public enum ErrorMessage {
SkyflowIdKeyError("%s0 Validation error. 'skyflow_id' is missing from the data payload. Specify a 'skyflow_id'."),
InvalidSkyflowIdType("%s0 Validation error. Invalid type for 'skyflow_id' in data payload. Specify 'skyflow_id' as a string."),
EmptySkyflowId("%s0 Validation error. 'skyflow_id' can't be empty. Specify a skyflow id."),
UpdateRequestNull("%s0 Validation error. UpdateRequest object is null. Specify a valid UpdateRequest object."),
UpdateRecordNull("%s0 Validation error. UpdateRequestRecord object in the list is null. Specify a valid UpdateRequestRecord object."),
RecordSkyflowIdKeyError("%s0 Validation error. 'skyflowId' key is missing from the record. Specify a 'skyflowId' key."),
EmptySkyflowIdInRecord("%s0 Validation error. 'skyflowId' can't be empty in the record. Specify a valid skyflow ID."),

// Query
QueryRequestNull("%s0 Validation error. QueryRequest object is null. Specify a valid QueryRequest object."),
QueryKeyError("%s0 Validation error. 'query' key is missing from the payload. Specify a 'query' key."),
EmptyQuery("%s0 Validation error. 'query' can't be empty. Specify a query"),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.example.vault;

import com.skyflow.Skyflow;
import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.Env;
import com.skyflow.enums.LogLevel;
import com.skyflow.errors.SkyflowException;
import com.skyflow.vault.data.DeleteRequest;
import com.skyflow.vault.data.DeleteResponse;
import com.skyflow.vault.data.DeleteResponseRecord;

import java.util.ArrayList;
import java.util.List;

/**
* This sample demonstrates the Skyflow Java SDK's unary delete operation — deleting records by
* skyflowId or unique value. This makes exactly one API call per invocation: there is no internal
* batching or concurrency to configure.
*
* Distinct from deleteTokens/bulkDeleteTokens, which remove tokens only and leave the underlying
* record in place.
*/
public class DeleteExample {

public static void main(String[] args) {
try {
// Step 1: Initialize credentials with the path to your service account key file
// String filePath = "<YOUR_CREDENTIALS_FILE_PATH>";
Credentials credentials = new Credentials();
credentials.setToken("<YOUR_BEARER_TOKEN>");

// Step 2: Configure the vault with required parameters
VaultConfig vaultConfig = new VaultConfig();
vaultConfig.setVaultId("<YOUR_VAULT_ID>");
vaultConfig.setClusterId("<YOUR_CLUSTER_ID>");
vaultConfig.setEnv(Env.PROD);
vaultConfig.setCredentials(credentials);

// Step 3: Create Skyflow client instance with error logging
Skyflow skyflowClient = Skyflow.builder()
.setLogLevel(LogLevel.ERROR)
.addVaultConfig(vaultConfig)
.build();

// Step 4: Prepare the skyflow IDs to delete.
// Either ids or uniqueValues is required; specifying both fails validation.
List<String> ids = new ArrayList<>();
ids.add("<YOUR_SKYFLOW_ID>");

// Step 5: Build and execute the delete request
DeleteRequest request = DeleteRequest.builder()
.table("<YOUR_TABLE_NAME>")
.ids(ids)
.build();

DeleteResponse response = skyflowClient.vault().delete(request);

// Step 6: Read the outcome. A record succeeded when its error is null.
for (DeleteResponseRecord record : response.getRecords()) {
if (record.getError() == null) {
System.out.printf("delete: skyflowId=%s removed%n", record.getSkyflowId());
} else {
System.out.printf("delete failed (%d): %s%n", record.getHttpCode(), record.getError());
}
}
} catch (SkyflowException e) {
// Step 7: Handle any errors that occur during the process
System.err.println("Error in delete operation:\t" + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.example.vault;

import com.skyflow.Skyflow;
import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.Env;
import com.skyflow.enums.LogLevel;
import com.skyflow.errors.SkyflowException;
import com.skyflow.vault.data.DetokenizeRequest;
import com.skyflow.vault.data.DetokenizeResponse;
import com.skyflow.vault.data.DetokenizeResponseRecord;
import com.skyflow.vault.data.TokenGroupRedactions;

import java.util.ArrayList;
import java.util.List;

/**
* This sample demonstrates the Skyflow Java SDK's unary detokenize operation. Unlike
* bulkDetokenize, this makes exactly one API call per invocation: there is no internal batching
* or concurrency to configure.
*/
public class DetokenizeExample {

public static void main(String[] args) {
try {
// Step 1: Initialize credentials with the path to your service account key file
// String filePath = "<YOUR_CREDENTIALS_FILE_PATH>";
Credentials credentials = new Credentials();
credentials.setToken("<YOUR_BEARER_TOKEN>");

// Step 2: Configure the vault with required parameters
VaultConfig vaultConfig = new VaultConfig();
vaultConfig.setVaultId("<YOUR_VAULT_ID>");
vaultConfig.setClusterId("<YOUR_CLUSTER_ID>");
vaultConfig.setEnv(Env.PROD);
vaultConfig.setCredentials(credentials);

// Step 3: Create Skyflow client instance with error logging
Skyflow skyflowClient = Skyflow.builder()
.setLogLevel(LogLevel.ERROR)
.addVaultConfig(vaultConfig)
.build();

// Step 4: Prepare the tokens to detokenize and any per-group redactions
List<String> tokens = new ArrayList<>();
tokens.add("<YOUR_TOKEN>");

List<TokenGroupRedactions> tokenGroupRedactions = new ArrayList<>();
tokenGroupRedactions.add(TokenGroupRedactions.builder()
.tokenGroupName("<YOUR_TOKEN_GROUP_NAME>")
.redaction("PLAIN_TEXT")
.build());

// Step 5: Build and execute the detokenize request
DetokenizeRequest request = DetokenizeRequest.builder()
.tokens(tokens)
.tokenGroupRedactions(tokenGroupRedactions)
.build();

DetokenizeResponse response = skyflowClient.vault().detokenize(request);

// Step 6: Read the outcome. A record succeeded when its error is null.
for (DetokenizeResponseRecord record : response.getRecords()) {
if (record.getError() == null) {
System.out.printf("detokenize: %s -> %s (tableName=%s)%n",
record.getToken(), record.getValue(), record.getMetadata().getTableName());
} else {
System.out.printf("detokenize failed (%d): %s%n", record.getHttpCode(), record.getError());
}
}
} catch (SkyflowException e) {
// Step 7: Handle any errors that occur during the process
System.err.println("Error in detokenize operation:\t" + e.getMessage());
}
}
}
83 changes: 83 additions & 0 deletions flowvault/samples/src/main/java/com/example/vault/GetExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.example.vault;

import com.skyflow.Skyflow;
import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.Env;
import com.skyflow.enums.LogLevel;
import com.skyflow.errors.SkyflowException;
import com.skyflow.vault.data.ColumnRedactions;
import com.skyflow.vault.data.GetRequest;
import com.skyflow.vault.data.GetResponse;
import com.skyflow.vault.data.GetResponseRecord;
import com.skyflow.vault.data.Token;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* This sample demonstrates the Skyflow Java SDK's unary get operation. This makes exactly one
* API call per invocation: there is no internal batching or concurrency to configure.
*
* A GetRequest works in one of two mutually exclusive modes: single-table (as shown here — a
* table plus ids or uniqueValues) or multi-table, via GetRequest#getRecords() (a list of
* GetRequestRecord, each specifying its own table).
*/
public class GetExample {

public static void main(String[] args) {
try {
// Step 1: Initialize credentials with the path to your service account key file
// String filePath = "<YOUR_CREDENTIALS_FILE_PATH>";
Credentials credentials = new Credentials();
credentials.setToken("<YOUR_BEARER_TOKEN>");

// Step 2: Configure the vault with required parameters
VaultConfig vaultConfig = new VaultConfig();
vaultConfig.setVaultId("<YOUR_VAULT_ID>");
vaultConfig.setClusterId("<YOUR_CLUSTER_ID>");
vaultConfig.setEnv(Env.PROD);
vaultConfig.setCredentials(credentials);

// Step 3: Create Skyflow client instance with error logging
Skyflow skyflowClient = Skyflow.builder()
.setLogLevel(LogLevel.ERROR)
.addVaultConfig(vaultConfig)
.build();

// Step 4: Prepare the skyflow IDs to fetch and any column redactions
ArrayList<String> ids = new ArrayList<>();
ids.add("<YOUR_SKYFLOW_ID>");

List<ColumnRedactions> columnRedactions = new ArrayList<>();
columnRedactions.add(ColumnRedactions.builder()
.columnName("<YOUR_COLUMN_NAME_1>")
.redaction("PLAIN_TEXT")
.build());

// Step 5: Build and execute the get request
GetRequest request = GetRequest.builder()
.table("<YOUR_TABLE_NAME>")
.ids(ids)
.columnRedactions(columnRedactions)
.build();

GetResponse response = skyflowClient.vault().get(request);

// Step 6: Read the fetched records
for (GetResponseRecord record : response.getRecords()) {
System.out.printf("get: %s -> skyflowId=%s%n", record.getTableName(), record.getSkyflowId());
for (Map.Entry<String, List<Token>> column : record.getTokens().entrySet()) {
for (Token token : column.getValue()) {
System.out.printf(" %s[%s] -> %s%n",
column.getKey(), token.getTokenGroupName(), token.getToken());
}
}
}
} catch (SkyflowException e) {
// Step 7: Handle any errors that occur during the process
System.err.println("Error in get operation:\t" + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.example.vault;

import com.skyflow.Skyflow;
import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.Env;
import com.skyflow.enums.LogLevel;
import com.skyflow.errors.SkyflowException;
import com.skyflow.vault.data.InsertRequest;
import com.skyflow.vault.data.InsertRequestRecord;
import com.skyflow.vault.data.InsertResponse;
import com.skyflow.vault.data.InsertResponseRecord;
import com.skyflow.vault.data.Token;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* This sample demonstrates the Skyflow Java SDK's unary insert operation. Unlike bulkInsert,
* this makes exactly one API call per invocation: there is no internal batching or concurrency
* to configure.
*/
public class InsertExample {

public static void main(String[] args) {
try {
// Step 1: Initialize credentials with the path to your service account key file
// String filePath = "<YOUR_CREDENTIALS_FILE_PATH>";
Credentials credentials = new Credentials();
credentials.setToken("<YOUR_BEARER_TOKEN>");

// Step 2: Configure the vault with required parameters
VaultConfig vaultConfig = new VaultConfig();
vaultConfig.setVaultId("<YOUR_VAULT_ID>");
vaultConfig.setClusterId("<YOUR_CLUSTER_ID>");
vaultConfig.setEnv(Env.PROD);
vaultConfig.setCredentials(credentials);

// Step 3: Create Skyflow client instance with error logging
Skyflow skyflowClient = Skyflow.builder()
.setLogLevel(LogLevel.ERROR)
.addVaultConfig(vaultConfig)
.build();

// Step 4: Prepare the record to insert
Map<String, Object> data = new HashMap<>();
data.put("<YOUR_COLUMN_NAME_1>", "<YOUR_VALUE_1>");

InsertRequestRecord record = InsertRequestRecord.builder()
.data(data)
.build();

List<InsertRequestRecord> records = new ArrayList<>();
records.add(record);

// Step 5: Build and execute the insert request
InsertRequest request = InsertRequest.builder()
.tableName("<YOUR_TABLE_NAME>")
.records(records)
.build();

InsertResponse response = skyflowClient.vault().insert(request);

// Step 6: Read the outcome. A record succeeded when its error is null.
for (InsertResponseRecord insertedRecord : response.getRecords()) {
if (insertedRecord.getError() == null) {
System.out.printf("insert: %s -> skyflowId=%s%n",
insertedRecord.getTableName(), insertedRecord.getSkyflowId());
for (Map.Entry<String, List<Token>> column : insertedRecord.getTokens().entrySet()) {
for (Token token : column.getValue()) {
System.out.printf(" %s[%s] -> %s%n",
column.getKey(), token.getTokenGroupName(), token.getToken());
}
}
} else {
System.out.printf("insert failed (%d): %s%n", insertedRecord.getHttpCode(), insertedRecord.getError());
}
}
} catch (SkyflowException e) {
// Step 7: Handle any errors that occur during the process
System.err.println("Error in insert operation:\t" + e.getMessage());
}
}
}
Loading
Loading