mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-27 18:36:08 +00:00
fix(change-summary): minor issues (#20095)
- deep copy previous change summary so that it doesnt get modified - handle multiple fields during consolidation
This commit is contained in:
parent
2704ed1900
commit
242e85a797
@ -56,7 +56,10 @@ public class ChangeSummarizer<T extends EntityInterface> {
|
||||
new ChangeSummary()
|
||||
.withChangeSource(changeSource)
|
||||
.withChangedAt(changedAt)
|
||||
.withChangedBy(changedBy)));
|
||||
.withChangedBy(changedBy),
|
||||
// If its a consolidation, we might have multiple changes for the same field.
|
||||
// Since we are only interested in the field name, we can just take whichever.
|
||||
(existing, replacement) -> existing));
|
||||
}
|
||||
|
||||
private boolean isFieldTracked(String fieldName) {
|
||||
|
@ -2993,6 +2993,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
ChangeSummaryMap current =
|
||||
Optional.ofNullable(original.getChangeDescription())
|
||||
.map(ChangeDescription::getChangeSummary)
|
||||
.map(changeSummaryMap -> JsonUtils.deepCopy(changeSummaryMap, ChangeSummaryMap.class))
|
||||
.orElse(new ChangeSummaryMap());
|
||||
|
||||
Map<String, ChangeSummary> addedSummaries =
|
||||
|
@ -42,6 +42,26 @@ public class ChangeSummarizerTest {
|
||||
assert result.size() == 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_duplicateEntriesConsolidation() {
|
||||
String fieldName = "description";
|
||||
ChangeSource changeSource = ChangeSource.MANUAL;
|
||||
long updatedAt = System.currentTimeMillis();
|
||||
String updatedBy = "testUser";
|
||||
List<FieldChange> changes =
|
||||
List.of(new FieldChange().withName(fieldName), new FieldChange().withName(fieldName));
|
||||
|
||||
Map<String, ChangeSummary> result =
|
||||
changeSummarizer.summarizeChanges(Map.of(), changes, changeSource, updatedBy, updatedAt);
|
||||
assert result.size() == 1;
|
||||
Assertions.assertTrue(result.containsKey(fieldName));
|
||||
|
||||
result =
|
||||
changeSummarizer.summarizeChanges(
|
||||
result, changes, ChangeSource.AUTOMATED, "older-change", updatedAt - 100);
|
||||
assert result.size() == 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_columnDescription() {
|
||||
String fieldName = "columns.column1.description";
|
||||
|
Loading…
x
Reference in New Issue
Block a user