Skip to content

Commit 78bb7de

Browse files
SK-2200: update java sdk with latest detect changes
1 parent 88cb2d6 commit 78bb7de

5 files changed

Lines changed: 45 additions & 13 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ protected DeidentifyPdfRequest getDeidentifyPdfRequest(DeidentifyFileRequest req
539539
return DeidentifyPdfRequest.builder()
540540
.vaultId(vaultId)
541541
.file(file)
542-
.density(Double.valueOf(request.getPixelDensity() != null ? request.getPixelDensity().intValue() : null))
543-
.maxResolution(Double.valueOf(request.getMaxResolution() != null ? request.getMaxResolution().intValue() : null))
542+
.density(request.getPixelDensity() != null ? request.getPixelDensity().doubleValue() : null)
543+
.maxResolution(request.getMaxResolution() != null ? request.getMaxResolution().doubleValue() : null)
544544
.entityTypes(mappedEntityTypes)
545545
.tokenType(tokenType)
546546
.allowRegex(allowRegex)

src/main/java/com/skyflow/enums/DeidentifyFileStatus.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
public enum DeidentifyFileStatus {
44
IN_PROGRESS("IN_PROGRESS"),
5-
SUCCESS("SUCCESS");
5+
FAILED("FAILED"),
6+
SUCCESS("SUCCESS"),
7+
UNKNOWN("UNKNOWN");
68

79
private final String value;
810

src/main/java/com/skyflow/enums/DetectEntities.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ public enum DetectEntities {
1313
CREDIT_CARD_EXPIRATION("credit_card_expiration"),
1414
CVV("cvv"),
1515
DATE("date"),
16+
DAY("day"),
1617
DATE_INTERVAL("date_interval"),
1718
DOB("dob"),
1819
DOSE("dose"),
1920
DRIVER_LICENSE("driver_license"),
2021
DRUG("drug"),
2122
DURATION("duration"),
23+
EFFECT("effect"),
2224
EMAIL_ADDRESS("email_address"),
2325
EVENT("event"),
2426
FILENAME("filename"),
2527
FINANCIAL_METRIC("financial_metric"),
26-
GENDER_SEXUALITY("gender_sexuality"),
28+
GENDER("gender"),
2729
HEALTHCARE_NUMBER("healthcare_number"),
2830
INJURY("injury"),
2931
IP_ADDRESS("ip_address"),
@@ -40,30 +42,35 @@ public enum DetectEntities {
4042
MEDICAL_CODE("medical_code"),
4143
MEDICAL_PROCESS("medical_process"),
4244
MONEY("money"),
45+
MONTH("month"),
4346
NAME("name"),
4447
NAME_FAMILY("name_family"),
4548
NAME_GIVEN("name_given"),
4649
NAME_MEDICAL_PROFESSIONAL("name_medical_professional"),
4750
NUMERICAL_PII("numerical_pii"),
4851
OCCUPATION("occupation"),
4952
ORGANIZATION("organization"),
53+
ORGANIZATION_ID("organization_id"),
5054
ORGANIZATION_MEDICAL_FACILITY("organization_medical_facility"),
5155
ORIGIN("origin"),
5256
PASSPORT_NUMBER("passport_number"),
5357
PASSWORD("password"),
5458
PHONE_NUMBER("phone_number"),
59+
PROJECT("project"),
5560
PHYSICAL_ATTRIBUTE("physical_attribute"),
5661
POLITICAL_AFFILIATION("political_affiliation"),
5762
PRODUCT("product"),
5863
RELIGION("religion"),
5964
ROUTING_NUMBER("routing_number"),
65+
SEXUALITY("sexuality"),
6066
SSN("ssn"),
6167
STATISTICS("statistics"),
6268
TIME("time"),
6369
TREND("trend"),
6470
URL("url"),
6571
USERNAME("username"),
6672
VEHICLE_ID("vehicle_id"),
73+
YEAR("year"),
6774
ZODIAC_SIGN("zodiac_sign");
6875

6976
private final String detectEntities;

src/main/java/com/skyflow/utils/validations/Validations.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ public static void validateDeidentifyFileRequest(DeidentifyFileRequest request)
789789
}
790790

791791
TokenFormat tokenFormat = request.getTokenFormat();
792-
if (tokenFormat != null && !tokenFormat.getVaultToken().isEmpty()) {
792+
if (tokenFormat.getVaultToken() != null && !tokenFormat.getVaultToken().isEmpty()) {
793793
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.VaultTokenFormatIsNotAllowedForFiles.getMessage());
794794
}
795795

@@ -847,9 +847,6 @@ public static void validateDeidentifyFileRequest(DeidentifyFileRequest request)
847847
));
848848
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRequestBody.getMessage());
849849
}
850-
if (request.getBleep().getGain() == null) {
851-
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRequestBody.getMessage());
852-
}
853850
if (request.getBleep().getStartPadding() == null || request.getBleep().getStartPadding() < 0) {
854851
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidRequestBody.getMessage());
855852
}

src/main/java/com/skyflow/vault/controller/DetectController.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.skyflow.generated.rest.resources.files.requests.*;
1313
import com.skyflow.generated.rest.resources.strings.requests.DeidentifyStringRequest;
1414
import com.skyflow.generated.rest.resources.strings.requests.ReidentifyStringRequest;
15+
import com.skyflow.generated.rest.types.DeidentifyStatusResponseOutputType;
1516
import com.skyflow.generated.rest.types.*;
1617
import com.skyflow.logs.ErrorLogs;
1718
import com.skyflow.logs.InfoLogs;
@@ -239,6 +240,25 @@ private static synchronized DeidentifyFileResponse parseDeidentifyFileResponse(D
239240
String runId, String status) throws SkyflowException {
240241
DeidentifyFileOutput firstOutput = getFirstOutput(response);
241242

243+
if (firstOutput == null) {
244+
return new DeidentifyFileResponse(
245+
null,
246+
null,
247+
response.getOutputType().name(),
248+
null,
249+
null,
250+
null,
251+
response.getSize().orElse(null),
252+
response.getDuration().orElse(null),
253+
response.getPages().orElse(null),
254+
response.getSlides().orElse(null),
255+
getEntities(response),
256+
runId,
257+
response.getStatus().name(),
258+
null
259+
);
260+
}
261+
242262
Object wordCharObj = response.getAdditionalProperties().get("word_character_count");
243263
Integer wordCount = null;
244264
Integer charCount = null;
@@ -257,9 +277,8 @@ private static synchronized DeidentifyFileResponse parseDeidentifyFileResponse(D
257277

258278
File processedFileObject = null;
259279
FileInfo fileInfo = null;
260-
Optional<String> processedFileBase64 = firstOutput != null ? firstOutput.getProcessedFile() : Optional.empty();
261-
Optional<String> processedFileExtension = firstOutput != null ? firstOutput.getProcessedFileExtension() : Optional.empty();
262-
280+
Optional<String> processedFileBase64 = Optional.of(firstOutput).flatMap(DeidentifyFileOutput::getProcessedFile);
281+
Optional<String> processedFileExtension = Optional.of(firstOutput).flatMap(DeidentifyFileOutput::getProcessedFileExtension);
263282
if (processedFileBase64.isPresent() && processedFileExtension.isPresent()) {
264283
try {
265284
byte[] decodedBytes = Base64.getDecoder().decode(processedFileBase64.get());
@@ -274,11 +293,18 @@ private static synchronized DeidentifyFileResponse parseDeidentifyFileResponse(D
274293
}
275294
}
276295

296+
String processedFileType = firstOutput.getProcessedFileType()
297+
.map(Object::toString)
298+
.orElse(DeidentifyStatusResponseOutputType.UNKNOWN.toString());
299+
300+
String fileExtension = firstOutput.getProcessedFileExtension()
301+
.orElse(DeidentifyStatusResponseOutputType.UNKNOWN.toString());
302+
277303
return new DeidentifyFileResponse(
278304
fileInfo,
279305
firstOutput.getProcessedFile().orElse(null),
280-
firstOutput.getProcessedFileType().get().toString(),
281-
firstOutput.getProcessedFileExtension().get(),
306+
processedFileType,
307+
fileExtension,
282308
wordCount,
283309
charCount,
284310
response.getSize().orElse(null),

0 commit comments

Comments
 (0)