Skip to content

Commit 991a4fc

Browse files
SK-2071: add deidentify file interface
1 parent 21e94db commit 991a4fc

20 files changed

Lines changed: 1867 additions & 107 deletions

src/main/java/com/skyflow/VaultClient.java

Lines changed: 394 additions & 8 deletions
Large diffs are not rendered by default.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ public enum ErrorMessage {
129129
InvalidEmptyTextInDeIdentify("%s0 Validation error. The text field is required string and must not be empty string. Specify a valid text."),
130130
InvalidNullTextInReIdentify("%s0 Validation error. The text field is required string and must not be null. Specify a valid text."),
131131
InvalidEmptyTextInReIdentify("%s0 Validation error. The text field is required string and must not be empty string. Specify a valid text."),
132+
133+
//Detect Files
134+
InvalidNullFileInDeIdentifyFile("%s0 Validation error. The file field is required and must not be null. Specify a valid file object."),
135+
FileNotFoundToDeidentify("%s0 Validation error. The file to deidentify was not found at the specified path. Verify the file path and try again."),
136+
FileNotReadableToDeidentify("%s0 Validation error. The file to deidentify is not readable. Check the file permissions and try again."),
137+
InvalidPixelDensityToDeidentifyFile("%s0 Validation error. Should be a positive integer. Specify a valid pixel density."),
138+
InvalidMaxResolution("%s0 Validation error. Should be a positive integer. Specify a valid max resolution."),
139+
OutputDirectoryNotFound("%s0 Validation error. The output directory for deidentified files was not found at the specified path. Verify the output directory path and try again."),
140+
InvalidPermission("%s0 Validation error. The output directory for deidentified files is not writable. Check the directory permissions and try again."),
141+
InvalidWaitTime("%s0 Validation error. The wait time for deidentify file operation should be a positive integer. Specify a valid wait time."),
142+
WaitTimeExceedsLimit("%s0 Validation error. The wait time for deidentify file operation exceeds the maximum limit of 64 seconds. Specify a wait time less than or equal to 60 seconds."),
143+
InvalidOrEmptyRunId("%s0 Validation error. The run ID is invalid or empty. Specify a valid run ID."),
144+
FailedToEncodeFile("%s0 Validation error. Failed to encode the file. Ensure the file is in a supported format and try again."),
145+
PollingForResultsFailed("%s0 API error. Polling for results failed. Unable to retrieve the deidentified file"),
146+
FailedtoSaveProcessedFile("%s0 Validation error. Failed to save the processed file. Ensure the output directory is valid and writable."),
132147
;
133148
private final String message;
134149

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

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,37 @@ public SkyflowException(int httpCode, Throwable cause, Map<String, List<String>>
4141
super(cause);
4242
this.httpCode = httpCode;
4343
setRequestId(responseHeaders);
44-
setResponseBody(responseBody, responseHeaders);
44+
// Determine if responseBody is a JSON string with "error" key or a plain string
45+
if (isJsonWithErrorObject(responseBody)) {
46+
setResponseBodyFromJson(responseBody, responseHeaders);
47+
} else {
48+
this.message = responseBody;
49+
this.details = new JsonArray();
50+
}
4551
}
4652

47-
private void setResponseBody(String responseBody, Map<String, List<String>> responseHeaders) {
53+
// Helper to check if responseBody is a JSON string with "error" key
54+
private boolean isJsonWithErrorObject(String responseBody) {
55+
try {
56+
if (responseBody == null) return false;
57+
JsonObject obj = JsonParser.parseString(responseBody).getAsJsonObject();
58+
return obj.has("error");
59+
} catch (Exception e) {
60+
return false;
61+
}
62+
}
63+
64+
// Handles new error structure: {error={grpc_code=3, http_code=400, message=..., http_status=..., details=[]}}
65+
private void setResponseBodyFromJson(String responseBody, Map<String, List<String>> responseHeaders) {
4866
try {
4967
if (responseBody != null) {
5068
this.responseBody = JsonParser.parseString(responseBody).getAsJsonObject();
51-
if (this.responseBody.get("error") != null) {
52-
setGrpcCode();
53-
setHttpStatus();
54-
setMessage();
55-
setDetails(responseHeaders);
69+
if (this.responseBody.has("error")) {
70+
JsonObject errorObj = this.responseBody.getAsJsonObject("error");
71+
setGrpcCode(errorObj);
72+
setHttpStatus(errorObj);
73+
setMessage(errorObj);
74+
setDetails(errorObj, responseHeaders);
5675
}
5776
}
5877
} catch (JsonSyntaxException e) {
@@ -71,21 +90,43 @@ private void setRequestId(Map<String, List<String>> responseHeaders) {
7190
}
7291
}
7392

93+
// For legacy error structure
7494
private void setMessage() {
7595
JsonElement messageElement = ((JsonObject) responseBody.get("error")).get("message");
7696
this.message = messageElement == null ? null : messageElement.getAsString();
7797
}
7898

99+
// For new error structure
100+
private void setMessage(JsonObject errorObj) {
101+
JsonElement messageElement = errorObj.get("message");
102+
this.message = messageElement == null ? null : messageElement.getAsString();
103+
}
104+
105+
// For legacy error structure
79106
private void setGrpcCode() {
80107
JsonElement grpcElement = ((JsonObject) responseBody.get("error")).get("grpc_code");
81108
this.grpcCode = grpcElement == null ? null : grpcElement.getAsInt();
82109
}
83110

111+
// For new error structure
112+
private void setGrpcCode(JsonObject errorObj) {
113+
JsonElement grpcElement = errorObj.get("grpc_code");
114+
this.grpcCode = grpcElement == null ? null : grpcElement.getAsInt();
115+
}
116+
117+
// For legacy error structure
84118
private void setHttpStatus() {
85119
JsonElement statusElement = ((JsonObject) responseBody.get("error")).get("http_status");
86120
this.httpStatus = statusElement == null ? null : statusElement.getAsString();
87121
}
88122

123+
// For new error structure
124+
private void setHttpStatus(JsonObject errorObj) {
125+
JsonElement statusElement = errorObj.get("http_status");
126+
this.httpStatus = statusElement == null ? null : statusElement.getAsString();
127+
}
128+
129+
// For legacy error structure
89130
private void setDetails(Map<String, List<String>> responseHeaders) {
90131
JsonElement detailsElement = ((JsonObject) responseBody.get("error")).get("details");
91132
List<String> errorFromClientHeader = responseHeaders.get("error-from-client");
@@ -101,6 +142,22 @@ private void setDetails(Map<String, List<String>> responseHeaders) {
101142
}
102143
}
103144

145+
// For new error structure
146+
private void setDetails(JsonObject errorObj, Map<String, List<String>> responseHeaders) {
147+
JsonElement detailsElement = errorObj.get("details");
148+
List<String> errorFromClientHeader = responseHeaders.get("error-from-client");
149+
if (detailsElement != null && detailsElement.isJsonArray()) {
150+
this.details = detailsElement.getAsJsonArray();
151+
}
152+
if (errorFromClientHeader != null) {
153+
this.details = this.details == null ? new JsonArray() : this.details;
154+
String errorFromClient = errorFromClientHeader.get(0);
155+
JsonObject detailObject = new JsonObject();
156+
detailObject.addProperty("errorFromClient", errorFromClient);
157+
this.details.add(detailObject);
158+
}
159+
}
160+
104161
public int getHttpCode() {
105162
return httpCode;
106163
}

src/main/java/com/skyflow/generated/rest/core/ClientOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private ClientOptions(
3434
{
3535
put("X-Fern-Language", "JAVA");
3636
put("X-Fern-SDK-Name", "com.skyflow.fern:api-sdk");
37-
put("X-Fern-SDK-Version", "0.0.202");
37+
put("X-Fern-SDK-Version", "0.0.208");
3838
}
3939
});
4040
this.headerSuppliers = headerSuppliers;

src/main/java/com/skyflow/generated/rest/resources/files/types/DeidentifyImageRequestMaskingMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.fasterxml.jackson.annotation.JsonValue;
77

88
public enum DeidentifyImageRequestMaskingMethod {
9-
BLACKOUT("blackout"),
9+
BLACKBOX("blackbox"),
1010

1111
BLUR("blur");
1212

src/main/java/com/skyflow/generated/rest/types/DeidentifyStatusResponseOutputType.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import com.fasterxml.jackson.annotation.JsonValue;
77

88
public enum DeidentifyStatusResponseOutputType {
9-
BASE_64("base64"),
9+
BASE_64("BASE64"),
1010

11-
EFS_PATH("efs_path");
11+
EFS_PATH("EFS_PATH"),
12+
13+
UNKNOWN("UNKNOWN");
1214

1315
private final String value;
1416

src/main/java/com/skyflow/generated/rest/types/DeidentifyStatusResponseStatus.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import com.fasterxml.jackson.annotation.JsonValue;
77

88
public enum DeidentifyStatusResponseStatus {
9-
FAILED("failed"),
9+
FAILED("FAILED"),
1010

11-
IN_PROGRESS("in_progress"),
11+
IN_PROGRESS("IN_PROGRESS"),
1212

13-
SUCCESS("success");
13+
SUCCESS("SUCCESS");
1414

1515
private final String value;
1616

src/main/java/com/skyflow/generated/rest/types/ReidentifyStringResponse.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020
@JsonInclude(JsonInclude.Include.NON_ABSENT)
2121
@JsonDeserialize(builder = ReidentifyStringResponse.Builder.class)
2222
public final class ReidentifyStringResponse {
23-
private final Optional<String> processedText;
23+
private final Optional<String> text;
2424

2525
private final Map<String, Object> additionalProperties;
2626

27-
private ReidentifyStringResponse(Optional<String> processedText, Map<String, Object> additionalProperties) {
28-
this.processedText = processedText;
27+
private ReidentifyStringResponse(Optional<String> text, Map<String, Object> additionalProperties) {
28+
this.text = text;
2929
this.additionalProperties = additionalProperties;
3030
}
3131

3232
/**
3333
* @return Re-identified text.
3434
*/
35-
@JsonProperty("processed_text")
36-
public Optional<String> getProcessedText() {
37-
return processedText;
35+
@JsonProperty("text")
36+
public Optional<String> getText() {
37+
return text;
3838
}
3939

4040
@java.lang.Override
@@ -49,12 +49,12 @@ public Map<String, Object> getAdditionalProperties() {
4949
}
5050

5151
private boolean equalTo(ReidentifyStringResponse other) {
52-
return processedText.equals(other.processedText);
52+
return text.equals(other.text);
5353
}
5454

5555
@java.lang.Override
5656
public int hashCode() {
57-
return Objects.hash(this.processedText);
57+
return Objects.hash(this.text);
5858
}
5959

6060
@java.lang.Override
@@ -68,31 +68,31 @@ public static Builder builder() {
6868

6969
@JsonIgnoreProperties(ignoreUnknown = true)
7070
public static final class Builder {
71-
private Optional<String> processedText = Optional.empty();
71+
private Optional<String> text = Optional.empty();
7272

7373
@JsonAnySetter
7474
private Map<String, Object> additionalProperties = new HashMap<>();
7575

7676
private Builder() {}
7777

7878
public Builder from(ReidentifyStringResponse other) {
79-
processedText(other.getProcessedText());
79+
text(other.getText());
8080
return this;
8181
}
8282

83-
@JsonSetter(value = "processed_text", nulls = Nulls.SKIP)
84-
public Builder processedText(Optional<String> processedText) {
85-
this.processedText = processedText;
83+
@JsonSetter(value = "text", nulls = Nulls.SKIP)
84+
public Builder text(Optional<String> text) {
85+
this.text = text;
8686
return this;
8787
}
8888

89-
public Builder processedText(String processedText) {
90-
this.processedText = Optional.ofNullable(processedText);
89+
public Builder text(String text) {
90+
this.text = Optional.ofNullable(text);
9191
return this;
9292
}
9393

9494
public ReidentifyStringResponse build() {
95-
return new ReidentifyStringResponse(processedText, additionalProperties);
95+
return new ReidentifyStringResponse(text, additionalProperties);
9696
}
9797
}
9898
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,16 @@ public enum ErrorLogs {
117117
INVALID_NULL_TEXT_IN_REIDENTIFY("Invalid %s1 request. The text field is required string and must not be null. Specify a valid text."),
118118
INVALID_EMPTY_TEXT_IN_REIDENTIFY("Invalid %s1 request. The text field is required string and must not be empty string. Specify a valid text."),
119119
REIDENTIFY_TEXT_REQUEST_REJECTED("ReIdentify text request resulted in failure."),
120-
120+
DEIDENTIFY_FILE_REQUEST_REJECTED("DeIdentify file request resulted in failure."),
121+
GET_DETECT_RUN_REQUEST_REJECTED("Get detect run request resulted in failure."),
122+
INVALID_NULL_FILE_IN_DEIDENTIFY_FILE("Invalid %s1 request. The file field is required and must not be null. Specify a valid file."),
123+
FILE_NOT_FOUND_TO_DEIDENTIFY("Invalid %s1 request. The file field is required and must not be empty. Specify a valid file."),
124+
FILE_NOT_READABLE_TO_DEIDENTIFY("Invalid %s1 request. The file is not readable. Please check the file permissions or path."),
125+
INVALID_PIXEL_DENSITY_TO_DEIDENTIFY_FILE("Invalid %s1 request. Pixel density must be a positive integer greater than 0. Specify a valid pixel density."),
126+
INVALID_MAX_RESOLUTION("Invalid %s1 request. Max resolution must be a positive integer greater than 0. Specify a valid max resolution."),
127+
INVALID_BLEEP_TO_DEIDENTIFY_AUDIO("Invalid %s1 request. Specify a valid bleep as AudioBleep"),
128+
OUTPUT_DIRECTORY_NOT_FOUND("Invalid %s1 request. The output directory does not exist. Please specify a valid output directory."),
129+
INVALID_PERMISSIONS_FOR_OUTPUT_DIRECTORY("Invalid %s1 request. The output directory is not writable. Please check the permissions or specify a valid output directory."),
121130
;
122131

123132
private final String log;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ public enum InfoLogs {
8383
VALIDATE_REIDENTIFY_TEXT_REQUEST("Validating reidentify text request."),
8484
REIDENTIFY_TEXT_TRIGGERED("ReIdentify text method triggered."),
8585
REIDENTIFY_TEXT_REQUEST_RESOLVED("ReIdentify text request resolved."),
86+
DEIDENTIFY_FILE_TRIGGERED("DeIdentify file method triggered."),
87+
VALIDATE_DEIDENTIFY_FILE_REQUEST("Validating deidentify file request."),
88+
DEIDENTIFY_FILE_REQUEST_RESOLVED("DeIdentify file request resolved."),
89+
DEIDENTIFY_FILE_SUCCESS("File deidentified successfully."),
90+
GET_DETECT_RUN_TRIGGERED("Get detect run method triggered."),
91+
VALIDATE_GET_DETECT_RUN_REQUEST("Validating get detect run request."),
8692
REIDENTIFY_TEXT_SUCCESS("Text data re-identified."),
8793
;
8894

0 commit comments

Comments
 (0)