Skip to content

Commit

Permalink
[refactor] transform abstract if-hell
Browse files Browse the repository at this point in the history
  • Loading branch information
tuancamtbtx committed Dec 13, 2023
1 parent ae425fd commit 88fb8cb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
19 changes: 9 additions & 10 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,27 @@ public R apply(R record) {

protected Map<String, Object> processDataNestedWithSchemaless(String field, Map<String, Object> updatedValue, String providerClass) {
Optional<String> rootField = TransformUtils.getRootField(field);
if (rootField.isPresent()) {
Optional<String> pathChildField = TransformUtils.getPathChildField(field);
if (pathChildField.isPresent()) {
Object rootValue = updatedValue.get(rootField.get().trim());
Optional<Object> valueNeedEncrypt = TransformUtils.getValueFromJsonObject(rootValue, pathChildField.get());
try {
if (valueNeedEncrypt.isPresent()) {
Object encrypted = this.encryptByDataType(providerClass, valueNeedEncrypt.get());
if (rootValue instanceof String) {
String encryptedStr = JsonPath.parse(rootValue.toString()).set(pathChildField.get(), encrypted).jsonString();
updatedValue.put(rootField.get(), encryptedStr);
} else {
JsonPath.parse(rootValue).set(pathChildField.get(), encrypted);
}
}
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
if (rootField.isEmpty()) {
return updatedValue;
}
Optional<String> pathChildField = TransformUtils.getPathChildField(field);
if (pathChildField.isEmpty()) {
return updatedValue;
}
Object rootValue = updatedValue.get(rootField.get().trim());
Optional<Object> valueNeedEncrypt = TransformUtils.getValueFromJsonObject(rootValue, pathChildField.get());
try {
if (valueNeedEncrypt.isPresent()) {
Object encrypted = this.encryptByDataType(providerClass, valueNeedEncrypt.get());
if (rootValue instanceof String) {
String encryptedStr = JsonPath.parse(rootValue.toString()).set(pathChildField.get(), encrypted).jsonString();
updatedValue.put(rootField.get(), encryptedStr);
} else {
JsonPath.parse(rootValue).set(pathChildField.get(), encrypted);
}
} else {
log.info("path child field is empty");
}
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
}
return updatedValue;
}
Expand Down

0 comments on commit 88fb8cb

Please sign in to comment.