mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-04 07:08:09 +00:00
This commit is contained in:
parent
369b8c3b31
commit
170cb529ea
@ -257,6 +257,11 @@ public final class ChangeEventParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String getUpdateMessage(String updatedField, Object oldValue, Object newValue) {
|
private static String getUpdateMessage(String updatedField, Object oldValue, Object newValue) {
|
||||||
|
// New value should not be null in any case for an update
|
||||||
|
if (newValue == null) {
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
if (oldValue == null || oldValue.toString().isEmpty()) {
|
if (oldValue == null || oldValue.toString().isEmpty()) {
|
||||||
return String.format("Updated **%s** to %s", updatedField, getFieldValue(newValue));
|
return String.format("Updated **%s** to %s", updatedField, getFieldValue(newValue));
|
||||||
} else if (updatedField.contains("tags") || updatedField.contains("owner")) {
|
} else if (updatedField.contains("tags") || updatedField.contains("owner")) {
|
||||||
@ -265,37 +270,39 @@ public final class ChangeEventParser {
|
|||||||
// if old value is not empty, and is of type array or object, the updates can be across multiple keys
|
// if old value is not empty, and is of type array or object, the updates can be across multiple keys
|
||||||
// Example: [{name: "col1", dataType: "varchar", dataLength: "20"}]
|
// Example: [{name: "col1", dataType: "varchar", dataLength: "20"}]
|
||||||
|
|
||||||
try {
|
if (!newValue.toString().isEmpty()) {
|
||||||
// Check if field value is a json string
|
try {
|
||||||
JsonValue newJson = JsonUtils.readJson(newValue.toString());
|
// Check if field value is a json string
|
||||||
JsonValue oldJson = JsonUtils.readJson(oldValue.toString());
|
JsonValue newJson = JsonUtils.readJson(newValue.toString());
|
||||||
if (newJson.getValueType() == ValueType.ARRAY) {
|
JsonValue oldJson = JsonUtils.readJson(oldValue.toString());
|
||||||
JsonArray newJsonArray = newJson.asJsonArray();
|
if (newJson.getValueType() == ValueType.ARRAY) {
|
||||||
JsonArray oldJsonArray = oldJson.asJsonArray();
|
JsonArray newJsonArray = newJson.asJsonArray();
|
||||||
if (newJsonArray.size() == 1 && oldJsonArray.size() == 1) {
|
JsonArray oldJsonArray = oldJson.asJsonArray();
|
||||||
// if there is only one item in the array, it can be safely considered as an update
|
if (newJsonArray.size() == 1 && oldJsonArray.size() == 1) {
|
||||||
JsonValue newItem = newJsonArray.get(0);
|
// if there is only one item in the array, it can be safely considered as an update
|
||||||
JsonValue oldItem = oldJsonArray.get(0);
|
JsonValue newItem = newJsonArray.get(0);
|
||||||
if (newItem.getValueType() == ValueType.OBJECT) {
|
JsonValue oldItem = oldJsonArray.get(0);
|
||||||
JsonObject newJsonItem = newItem.asJsonObject();
|
if (newItem.getValueType() == ValueType.OBJECT) {
|
||||||
JsonObject oldJsonItem = oldItem.asJsonObject();
|
JsonObject newJsonItem = newItem.asJsonObject();
|
||||||
return getObjectUpdateMessage(updatedField, oldJsonItem, newJsonItem);
|
JsonObject oldJsonItem = oldItem.asJsonObject();
|
||||||
|
return getObjectUpdateMessage(updatedField, oldJsonItem, newJsonItem);
|
||||||
|
} else {
|
||||||
|
return getPlainTextUpdateMessage(updatedField, newItem.toString(), oldItem.toString());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return getPlainTextUpdateMessage(updatedField, newItem.toString(), oldItem.toString());
|
return getPlainTextUpdateMessage(updatedField, getFieldValue(oldValue), getFieldValue(newValue));
|
||||||
}
|
}
|
||||||
} else {
|
} else if (newJson.getValueType() == ValueType.OBJECT) {
|
||||||
return getPlainTextUpdateMessage(updatedField, getFieldValue(oldValue), getFieldValue(newValue));
|
JsonObject newJsonObject = newJson.asJsonObject();
|
||||||
|
JsonObject oldJsonObject = oldJson.asJsonObject();
|
||||||
|
return getObjectUpdateMessage(updatedField, oldJsonObject, newJsonObject);
|
||||||
}
|
}
|
||||||
} else if (newJson.getValueType() == ValueType.OBJECT) {
|
} catch (JsonParsingException ex) {
|
||||||
JsonObject newJsonObject = newJson.asJsonObject();
|
// update is of type String
|
||||||
JsonObject oldJsonObject = oldJson.asJsonObject();
|
// ignore this exception and process update message for plain text
|
||||||
return getObjectUpdateMessage(updatedField, oldJsonObject, newJsonObject);
|
|
||||||
}
|
}
|
||||||
} catch (JsonParsingException ex) {
|
|
||||||
// update is of String type
|
|
||||||
return getPlainTextUpdateMessage(updatedField, oldValue.toString(), newValue.toString());
|
|
||||||
}
|
}
|
||||||
return StringUtils.EMPTY;
|
return getPlainTextUpdateMessage(updatedField, oldValue.toString(), newValue.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPlaintextDiff(String oldValue, String newValue) {
|
private static String getPlaintextDiff(String oldValue, String newValue) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user