Skip to content

Commit 64f1baa

Browse files
Merge pull request #90 from skyflowapi/release/23.7.2
SK-897 Release/23.7.2
2 parents efc3323 + 378ce41 commit 64f1baa

File tree

12 files changed

+644
-2
lines changed

12 files changed

+644
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.skyflow</groupId>
88
<artifactId>skyflow-java</artifactId>
9-
<version>1.9.0</version>
9+
<version>1.10.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>${project.groupId}:${project.artifactId}</name>

src/main/java/com/skyflow/common/utils/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
public class Constants {
44

55
public static final String SDK_METRICS_HEADER_KEY = "sky-metadata";
6-
public static final String SDK_VERSION = "1.9.0";
6+
public static final String SDK_VERSION = "1.10.0";
77

88
}

src/main/java/com/skyflow/common/utils/Validators.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,17 @@ public static void validateGetRequestRecord(GetRecordInput record) throws Skyflo
134134
throw new SkyflowException(ErrorCode.MissingRecordColumnName);
135135
}
136136
}
137+
public static void validateDeleteBySkyflowId(DeleteRecordInput deleteRecordInput) throws SkyflowException{
138+
String table = deleteRecordInput.getTable();
139+
String id = deleteRecordInput.getId();
140+
if (table == null || table.trim().isEmpty()) {
141+
LogUtil.printErrorLog(ErrorLogs.InvalidTable.getLog());
142+
throw new SkyflowException(ErrorCode.InvalidTable);
143+
}
144+
if (id == null || id.trim().isEmpty()) {
145+
LogUtil.printErrorLog(ErrorLogs.InvalidId.getLog());
146+
throw new SkyflowException(ErrorCode.InvalidId);
147+
}
148+
149+
}
137150
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.skyflow.entities;
2+
3+
public class DeleteInput {
4+
private DeleteRecordInput[] records;
5+
6+
public DeleteRecordInput[] getRecords() {
7+
return records;
8+
}
9+
10+
public void setRecords(DeleteRecordInput[] records) {
11+
this.records = records;
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.skyflow.entities;
2+
3+
public class DeleteOptions {
4+
public DeleteOptions(){}
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.skyflow.entities;
2+
3+
public class DeleteRecordInput {
4+
private String id;
5+
private String table;
6+
7+
public String getId() {
8+
return id;
9+
}
10+
11+
public void setId(String id) {
12+
this.id = id;
13+
}
14+
15+
public String getTable() {
16+
return table;
17+
}
18+
19+
public void setTable(String table) {
20+
this.table = table;
21+
}
22+
}

src/main/java/com/skyflow/errors/ErrorCode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ public enum ErrorCode {
2020
BearerThrownException(400, "getBearer() thrown exception"),
2121
EmptyRecords(400, "Records cannot be empty"),
2222
InvalidTable(400, "Table name is missing"),
23+
InvalidId(400, "Skyflow id is missing"),
2324
InvalidFields(400, "Fields are missing"),
2425
InvalidSkyflowId(400, "Skyflow id are missing"),
2526
InvalidToken(400, "Token is empty"),
2627
InvalidDetokenizeInput(400, "Invalid Detokenize Input"),
2728
InvalidInsertInput(400, "Invalid insert input"),
2829
InvalidUpdateInput(400, "Invalid update input"),
30+
InvalidDeleteInput(400, "Invalid delete input"),
2931
InvalidGetByIdInput(400, "Invalid getById input"),
3032
InvalidGetInput(400, "Invalid get input"),
3133
MissingIdAndColumnName(400, "Provide either Ids or column name to get records."),

src/main/java/com/skyflow/logs/ErrorLogs.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public enum ErrorLogs {
99
InvalidTokenProvider("invalid TokenProvider. TokenProvider cannot be null"),
1010
InvalidInsertInput("invalid insert input"),
1111
InvalidUpdateInput("invalid update input"),
12+
InvalidDeleteInput("invalid delete input"),
1213
InvalidDetokenizeInput("invalid detokenize input"),
1314
ResponseParsingError("Unable to parse response in %s1 method"),
1415
ThreadInterruptedException("Thread was interrupted in %s1 method"),
@@ -38,6 +39,8 @@ public enum ErrorLogs {
3839
BearerThrownException("getBearer() thrown exception "),
3940
InvalidBearerToken("Invalid Bearer token"),
4041
InvalidTable("Table name is missing"),
42+
InvalidId("Skyflow id is missing"),
43+
4144
Server("Internal server error"),
4245
ServerReturnedErrors("Server returned errors, check SkyflowException.getData() for more"),
4346
InvalidUpsertOptionType("upsert options cannot be null, should be an non empty UpsertOption array."),

src/main/java/com/skyflow/logs/InfoLogs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public enum InfoLogs {
1313
ValidatingInvokeConnectionConfig("validating invoke connection configuration"),
1414
InsertMethodCalled("insert method has triggered"),
1515
UpdateMethodCalled("update method has triggered"),
16+
deleteMethodCalled("delete method has triggered"),
1617
ConstructInsertResponse("constructing insert response"),
1718
ConstructUpdateResponse("constructing update response"),
1819
DetokenizeMethodCalled("detokenize method has triggered"),
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.skyflow.vault;
2+
3+
import com.skyflow.common.utils.Helpers;
4+
import com.skyflow.common.utils.HttpUtility;
5+
import com.skyflow.common.utils.LogUtil;
6+
import com.skyflow.common.utils.Validators;
7+
import com.skyflow.entities.DeleteOptions;
8+
import com.skyflow.entities.DeleteRecordInput;
9+
import com.skyflow.errors.ErrorCode;
10+
import com.skyflow.errors.SkyflowException;
11+
import com.skyflow.logs.ErrorLogs;
12+
import org.json.simple.JSONArray;
13+
import org.json.simple.JSONObject;
14+
import org.json.simple.parser.JSONParser;
15+
import org.json.simple.parser.ParseException;
16+
17+
import java.io.IOException;
18+
import java.net.URL;
19+
import java.util.Map;
20+
import java.util.concurrent.Callable;
21+
22+
public class DeleteBySkyflowId implements Callable<String> {
23+
private final DeleteRecordInput recordInput;
24+
private final String vaultID;
25+
private final String vaultURL;
26+
private final Map<String, String> headers;
27+
private final DeleteOptions deleteOptions;
28+
29+
public DeleteBySkyflowId(DeleteRecordInput recordInput, String vaultID, String vaultURL, Map<String, String> headers, DeleteOptions deleteOptions) {
30+
this.recordInput = recordInput;
31+
this.vaultID = vaultID;
32+
this.vaultURL = vaultURL;
33+
this.headers = headers;
34+
this.deleteOptions = deleteOptions;
35+
}
36+
37+
38+
@Override
39+
public String call() throws SkyflowException {
40+
String response = null;
41+
try {
42+
Validators.validateDeleteBySkyflowId(recordInput);
43+
String url = vaultURL+ "/v1/vaults/"+ vaultID + "/" + recordInput.getTable() + "/" + recordInput.getId();
44+
response = HttpUtility.sendRequest("DELETE", new URL(url), null,headers);
45+
JSONObject formattedResponse = new JSONObject();
46+
JSONArray formattedRecords = new JSONArray();
47+
48+
JSONObject responseRecords = ((JSONObject) (new JSONParser().parse(response)));
49+
if (responseRecords != null && responseRecords.size() > 0) {
50+
String id = (String) responseRecords.get("skyflow_id");
51+
JSONObject formattedRecord = new JSONObject();
52+
formattedRecord.put("skyflow_id", responseRecords.get("skyflow_id"));
53+
formattedRecord.put("deleted", responseRecords.get("deleted"));
54+
formattedRecords.add(formattedRecord);
55+
}
56+
formattedResponse.put("records", formattedRecords);
57+
response = formattedResponse.toJSONString();
58+
59+
} catch (IOException e) {
60+
LogUtil.printErrorLog(ErrorLogs.Server.getLog());
61+
throw new SkyflowException(ErrorCode.Server, e);
62+
} catch (ParseException e) {
63+
LogUtil.printErrorLog(ErrorLogs.ResponseParsingError.getLog());
64+
throw new SkyflowException(ErrorCode.ResponseParsingError, e);
65+
} catch (SkyflowException e) {
66+
response = constructDeleteByIdErrorObject(e, recordInput.getId());
67+
}
68+
return response;
69+
}
70+
private String constructDeleteByIdErrorObject(SkyflowException skyflowException, String id){
71+
String deleteByIdResponse = null;
72+
JSONObject finalResponseError = new JSONObject();
73+
finalResponseError.put("id", id);
74+
try{
75+
JSONObject errorObject = (JSONObject) ((JSONObject) new JSONParser().parse(skyflowException.getMessage())).get("error");
76+
if (errorObject != null) {
77+
JSONObject responseError = new JSONObject();
78+
responseError.put("code", errorObject.get("http_code"));
79+
responseError.put("description", errorObject.get("message"));
80+
finalResponseError.put("error", responseError);
81+
82+
deleteByIdResponse = finalResponseError.toString();
83+
}
84+
85+
} catch (ParseException e){
86+
JSONObject responseError = new JSONObject();
87+
responseError.put("code", skyflowException.getCode());
88+
responseError.put("description", skyflowException.getMessage());
89+
finalResponseError.put("error", responseError);
90+
deleteByIdResponse = finalResponseError.toString();
91+
}
92+
return deleteByIdResponse;
93+
}
94+
}

0 commit comments

Comments
 (0)