mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-03 23:26:54 +00:00
Solve issues related to actitivity feed (#9199)
* solved Activity feed related issue * solved Activity feed related issue * Addressing comments * test case related changes * test case related changes Co-authored-by: Himank Mehta <himankmehta@Himanks-MacBook-Air.local>
This commit is contained in:
parent
2cd5615136
commit
3053d57f79
@ -218,13 +218,6 @@
|
|||||||
<artifactId>flyway-mysql</artifactId>
|
<artifactId>flyway-mysql</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Diff util to compute diffs in plain text -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.java-diff-utils</groupId>
|
|
||||||
<artifactId>java-diff-utils</artifactId>
|
|
||||||
<version>4.12</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Dependencies for secret store manager providers -->
|
<!-- Dependencies for secret store manager providers -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>software.amazon.awssdk</groupId>
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
@ -412,6 +405,11 @@
|
|||||||
<artifactId>unboundid-ldapsdk</artifactId>
|
<artifactId>unboundid-ldapsdk</artifactId>
|
||||||
<version>${unboundsdk.version}</version>
|
<version>${unboundsdk.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bitbucket.cowwoc.diff-match-patch</groupId>
|
||||||
|
<artifactId>diff-match-patch</artifactId>
|
||||||
|
<version>${diffMatch.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -238,22 +238,21 @@ public class ChangeEventHandler implements EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EntityInterface entityInterface = (EntityInterface) entity;
|
EntityInterface entityInterface = (EntityInterface) entity;
|
||||||
|
if (RestUtil.ENTITY_SOFT_DELETED.equals(changeType)) {
|
||||||
|
String entityType = Entity.getEntityTypeFromClass(entity.getClass());
|
||||||
|
String message = String.format("Soft deleted **%s**: `%s`", entityType, entityInterface.getFullyQualifiedName());
|
||||||
|
EntityLink about = new EntityLink(entityType, entityInterface.getFullyQualifiedName(), null, null, null);
|
||||||
|
Thread thread = getThread(about.getLinkString(), message, loggedInUserName);
|
||||||
|
return List.of(thread);
|
||||||
|
}
|
||||||
if (RestUtil.ENTITY_DELETED.equals(changeType)) {
|
if (RestUtil.ENTITY_DELETED.equals(changeType)) {
|
||||||
String entityType = Entity.getEntityTypeFromClass(entity.getClass());
|
String entityType = Entity.getEntityTypeFromClass(entity.getClass());
|
||||||
// In this case, the entity itself got deleted
|
// In this case, the entity itself got deleted
|
||||||
// for which there will be no change description.
|
// for which there will be no change description.
|
||||||
String message = String.format("Deleted **%s**: `%s`", entityType, entityInterface.getFullyQualifiedName());
|
String message =
|
||||||
|
String.format("Permanently Deleted **%s**: `%s`", entityType, entityInterface.getFullyQualifiedName());
|
||||||
EntityLink about = new EntityLink(entityType, entityInterface.getFullyQualifiedName(), null, null, null);
|
EntityLink about = new EntityLink(entityType, entityInterface.getFullyQualifiedName(), null, null, null);
|
||||||
Thread thread =
|
Thread thread = getThread(about.getLinkString(), message, loggedInUserName);
|
||||||
new Thread()
|
|
||||||
.withId(UUID.randomUUID())
|
|
||||||
.withThreadTs(System.currentTimeMillis())
|
|
||||||
.withCreatedBy(entityInterface.getUpdatedBy())
|
|
||||||
.withAbout(about.getLinkString())
|
|
||||||
.withReactions(Collections.emptyList())
|
|
||||||
.withUpdatedBy(entityInterface.getUpdatedBy())
|
|
||||||
.withUpdatedAt(System.currentTimeMillis())
|
|
||||||
.withMessage(message);
|
|
||||||
return List.of(thread);
|
return List.of(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,12 +20,11 @@ import static org.openmetadata.service.Entity.FIELD_OWNER;
|
|||||||
import static org.openmetadata.service.Entity.KPI;
|
import static org.openmetadata.service.Entity.KPI;
|
||||||
import static org.openmetadata.service.Entity.TEST_CASE;
|
import static org.openmetadata.service.Entity.TEST_CASE;
|
||||||
|
|
||||||
import com.github.difflib.text.DiffRow;
|
|
||||||
import com.github.difflib.text.DiffRowGenerator;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -39,6 +38,7 @@ import javax.json.JsonValue;
|
|||||||
import javax.json.JsonValue.ValueType;
|
import javax.json.JsonValue.ValueType;
|
||||||
import javax.json.stream.JsonParsingException;
|
import javax.json.stream.JsonParsingException;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch;
|
||||||
import org.openmetadata.common.utils.CommonUtil;
|
import org.openmetadata.common.utils.CommonUtil;
|
||||||
import org.openmetadata.schema.EntityInterface;
|
import org.openmetadata.schema.EntityInterface;
|
||||||
import org.openmetadata.schema.dataInsight.kpi.Kpi;
|
import org.openmetadata.schema.dataInsight.kpi.Kpi;
|
||||||
@ -60,7 +60,7 @@ public final class ChangeEventParser {
|
|||||||
public static final String FEED_ADD_MARKER = "<!add>";
|
public static final String FEED_ADD_MARKER = "<!add>";
|
||||||
public static final String FEED_REMOVE_MARKER = "<!remove>";
|
public static final String FEED_REMOVE_MARKER = "<!remove>";
|
||||||
public static final String FEED_BOLD = "**%s**";
|
public static final String FEED_BOLD = "**%s**";
|
||||||
public static final String SLACK_BOLD = "*%s* ";
|
public static final String SLACK_BOLD = "*%s*";
|
||||||
public static final String FEED_SPAN_ADD = "<span class=\"diff-added\">";
|
public static final String FEED_SPAN_ADD = "<span class=\"diff-added\">";
|
||||||
public static final String FEED_SPAN_REMOVE = "<span class=\"diff-removed\">";
|
public static final String FEED_SPAN_REMOVE = "<span class=\"diff-removed\">";
|
||||||
public static final String FEED_SPAN_CLOSE = "</span>";
|
public static final String FEED_SPAN_CLOSE = "</span>";
|
||||||
@ -129,7 +129,7 @@ public final class ChangeEventParser {
|
|||||||
// TEAMS and FEED bold formatting is same
|
// TEAMS and FEED bold formatting is same
|
||||||
return "** ";
|
return "** ";
|
||||||
case SLACK:
|
case SLACK:
|
||||||
return "* ";
|
return "*";
|
||||||
default:
|
default:
|
||||||
return "INVALID";
|
return "INVALID";
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ public final class ChangeEventParser {
|
|||||||
// TEAMS and FEED bold formatting is same
|
// TEAMS and FEED bold formatting is same
|
||||||
return "~~ ";
|
return "~~ ";
|
||||||
case SLACK:
|
case SLACK:
|
||||||
return "~ ";
|
return "~";
|
||||||
default:
|
default:
|
||||||
return "INVALID";
|
return "INVALID";
|
||||||
}
|
}
|
||||||
@ -405,7 +405,9 @@ public final class ChangeEventParser {
|
|||||||
message =
|
message =
|
||||||
String.format(("Followed " + getBold(publishTo) + " `%s`"), link.getEntityType(), link.getEntityFQN());
|
String.format(("Followed " + getBold(publishTo) + " `%s`"), link.getEntityType(), link.getEntityFQN());
|
||||||
} else if (fieldValue != null && !fieldValue.isEmpty()) {
|
} else if (fieldValue != null && !fieldValue.isEmpty()) {
|
||||||
message = String.format(("Added " + getBold(publishTo) + ": `%s`"), updatedField, fieldValue);
|
message =
|
||||||
|
String.format(
|
||||||
|
("Added " + getBold(publishTo) + ": " + getBold(publishTo)), updatedField, fieldValue.trim());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
@ -416,7 +418,8 @@ public final class ChangeEventParser {
|
|||||||
message = String.format("Unfollowed %s `%s`", link.getEntityType(), link.getEntityFQN());
|
message = String.format("Unfollowed %s `%s`", link.getEntityType(), link.getEntityFQN());
|
||||||
} else {
|
} else {
|
||||||
message =
|
message =
|
||||||
String.format(("Deleted " + getBold(publishTo) + ": `%s`"), updatedField, getFieldValue(oldFieldValue));
|
String.format(
|
||||||
|
("Deleted " + getBold(publishTo) + ": `%s`"), updatedField, getFieldValue(oldFieldValue).trim());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -432,7 +435,7 @@ public final class ChangeEventParser {
|
|||||||
if (nullOrEmpty(diff)) {
|
if (nullOrEmpty(diff)) {
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
} else {
|
} else {
|
||||||
String field = String.format("Updated %s: %s", getBold(publishTo), diff);
|
String field = String.format("Updated %s : %s", getBold(publishTo), diff);
|
||||||
return String.format(field, updatedField);
|
return String.format(field, updatedField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -556,27 +559,23 @@ public final class ChangeEventParser {
|
|||||||
String addMarker = FEED_ADD_MARKER;
|
String addMarker = FEED_ADD_MARKER;
|
||||||
String removeMarker = FEED_REMOVE_MARKER;
|
String removeMarker = FEED_REMOVE_MARKER;
|
||||||
|
|
||||||
DiffRowGenerator generator =
|
DiffMatchPatch dmp = new DiffMatchPatch();
|
||||||
DiffRowGenerator.create()
|
LinkedList<DiffMatchPatch.Diff> diffs = dmp.diffMain(oldValue, newValue);
|
||||||
.showInlineDiffs(true)
|
dmp.diffCleanupSemantic(diffs);
|
||||||
.mergeOriginalRevised(true)
|
StringBuilder outputStr = new StringBuilder();
|
||||||
.inlineDiffByWord(true)
|
for (DiffMatchPatch.Diff d : diffs) {
|
||||||
.oldTag(f -> removeMarker) // introduce a tag to mark removals
|
if (DiffMatchPatch.Operation.EQUAL.equals(d.operation)) {
|
||||||
.newTag(f -> addMarker) // introduce a tag to mark new additions
|
// merging equal values of both string ..
|
||||||
.build();
|
outputStr.append(d.text.trim());
|
||||||
// compute the differences
|
} else if (DiffMatchPatch.Operation.INSERT.equals(d.operation)) {
|
||||||
List<DiffRow> rows = generator.generateDiffRows(List.of(oldValue), List.of(newValue));
|
// merging added values with addMarker before and after of new values added..
|
||||||
|
outputStr.append(addMarker).append(d.text.trim()).append(addMarker).append(" ");
|
||||||
// merge rows by %n for new line
|
|
||||||
String diff = null;
|
|
||||||
for (DiffRow row : rows) {
|
|
||||||
if (diff == null) {
|
|
||||||
diff = row.getOldLine();
|
|
||||||
} else {
|
} else {
|
||||||
diff = String.format("%s%n%s", diff, row.getOldLine());
|
// merging deleted values with removeMarker before and after of old value removed ..
|
||||||
|
outputStr.append(" ").append(removeMarker).append(d.text.trim()).append(removeMarker).append(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String diff = outputStr.toString().trim();
|
||||||
// The additions and removals will be wrapped by <!add> and <!remove> tags
|
// The additions and removals will be wrapped by <!add> and <!remove> tags
|
||||||
// Replace them with html tags to render nicely in the UI
|
// Replace them with html tags to render nicely in the UI
|
||||||
// Example: This is a test <!remove>sentence<!remove><!add>line<!add>
|
// Example: This is a test <!remove>sentence<!remove><!add>line<!add>
|
||||||
|
@ -103,7 +103,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest {
|
|||||||
ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, TABLE);
|
ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.FEED, changeDescription, TABLE);
|
||||||
assertEquals(1, messages.size());
|
assertEquals(1, messages.size());
|
||||||
|
|
||||||
assertEquals("Added **owner**: `User One`", messages.values().iterator().next());
|
assertEquals("Added **owner**: **User One**", messages.values().iterator().next());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -117,7 +117,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest {
|
|||||||
assertEquals(1, messages.size());
|
assertEquals(1, messages.size());
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Updated **description**: <span class=\"diff-removed\">old</span>"
|
"Updated **description** : <span class=\"diff-removed\">old</span> "
|
||||||
+ "<span class=\"diff-added\">new</span> description",
|
+ "<span class=\"diff-added\">new</span> description",
|
||||||
messages.values().iterator().next());
|
messages.values().iterator().next());
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest {
|
|||||||
assertEquals(1, messages.size());
|
assertEquals(1, messages.size());
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Updated **columns.lo_orderpriority**: <br/> name: <span class=\"diff-removed\">\"lo_order\"</span><span class=\"diff-added\">\"lo_orderpriority\"</span> <br/> displayName: <span class=\"diff-removed\">\"lo_order\"</span><span class=\"diff-added\">\"lo_orderpriority\"</span> <br/> fullyQualifiedName: \"local_mysql.sample_db.lineorder.<span class=\"diff-removed\">lo_order\"</span><span class=\"diff-added\">lo_orderpriority\"</span>",
|
"Updated **columns.lo_orderpriority**: <br/> name: \"lo_order<span class=\"diff-added\">priority</span> \" <br/> displayName: \"lo_order<span class=\"diff-added\">priority</span> \" <br/> fullyQualifiedName: \"local_mysql.sample_db.lineorder.lo_order<span class=\"diff-added\">priority</span> \"",
|
||||||
messages.values().iterator().next());
|
messages.values().iterator().next());
|
||||||
|
|
||||||
// Simulate a change of datatype change in column
|
// Simulate a change of datatype change in column
|
||||||
@ -198,7 +198,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest {
|
|||||||
assertEquals(1, messages.size());
|
assertEquals(1, messages.size());
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Updated **columns.lo_orderpriority**: <br/> dataType: <span class=\"diff-removed\">\"BLOB\"</span><span class=\"diff-added\">\"INT\"</span> <br/> dataTypeDisplay: <span class=\"diff-removed\">\"blob\"</span><span class=\"diff-added\">\"int\"</span>",
|
"Updated **columns.lo_orderpriority**: <br/> dataType: \" <span class=\"diff-removed\">BLOB</span> <span class=\"diff-added\">INT</span> \" <br/> dataTypeDisplay: \" <span class=\"diff-removed\">blob</span> <span class=\"diff-added\">int</span> \"",
|
||||||
messages.values().iterator().next());
|
messages.values().iterator().next());
|
||||||
|
|
||||||
// Simulate multiple changes to columns
|
// Simulate multiple changes to columns
|
||||||
@ -216,7 +216,7 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest {
|
|||||||
assertEquals(1, messages.size());
|
assertEquals(1, messages.size());
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Updated **columns**: lo_orderpriority<span class=\"diff-added\">, newColumn</span>",
|
"Updated **columns** : lo_orderpriority<span class=\"diff-added\">, newColumn</span>",
|
||||||
messages.values().iterator().next());
|
messages.values().iterator().next());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,10 +239,10 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest {
|
|||||||
assertEquals(1, messages.size());
|
assertEquals(1, messages.size());
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Updated *columns.lo_orderpriority* :\n"
|
"Updated *columns.lo_orderpriority*:\n"
|
||||||
+ "name: ~\"lo_order\"~ *\"lo_orderpriority\"* \n"
|
+ "name: \"lo_order*priority* \"\n"
|
||||||
+ "displayName: ~\"lo_order\"~ *\"lo_orderpriority\"* \n"
|
+ "displayName: \"lo_order*priority* \"\n"
|
||||||
+ "fullyQualifiedName: \"local_mysql.sample_db.lineorder.~lo_order\"~ *lo_orderpriority\"* ",
|
+ "fullyQualifiedName: \"local_mysql.sample_db.lineorder.lo_order*priority* \"",
|
||||||
messages.values().iterator().next());
|
messages.values().iterator().next());
|
||||||
|
|
||||||
// Simulate a change of datatype change in column
|
// Simulate a change of datatype change in column
|
||||||
@ -260,9 +260,9 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest {
|
|||||||
assertEquals(1, messages.size());
|
assertEquals(1, messages.size());
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Updated *columns.lo_orderpriority* :\n"
|
"Updated *columns.lo_orderpriority*:\n"
|
||||||
+ "dataType: ~\"BLOB\"~ *\"INT\"* \n"
|
+ "dataType: \" ~BLOB~ *INT* \"\n"
|
||||||
+ "dataTypeDisplay: ~\"blob\"~ *\"int\"* ",
|
+ "dataTypeDisplay: \" ~blob~ *int* \"",
|
||||||
messages.values().iterator().next());
|
messages.values().iterator().next());
|
||||||
|
|
||||||
// Simulate multiple changes to columns
|
// Simulate multiple changes to columns
|
||||||
@ -279,6 +279,6 @@ class ChangeEventParserResourceTest extends OpenMetadataApplicationTest {
|
|||||||
messages = ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.SLACK, changeDescription, TABLE);
|
messages = ChangeEventParser.getFormattedMessages(ChangeEventParser.PUBLISH_TO.SLACK, changeDescription, TABLE);
|
||||||
assertEquals(1, messages.size());
|
assertEquals(1, messages.size());
|
||||||
|
|
||||||
assertEquals("Updated *columns* : lo_orderpriority*, newColumn* ", messages.values().iterator().next());
|
assertEquals("Updated *columns* : lo_orderpriority*, newColumn*", messages.values().iterator().next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
pom.xml
1
pom.xml
@ -78,6 +78,7 @@
|
|||||||
<jackson.version>2.13.4</jackson.version>
|
<jackson.version>2.13.4</jackson.version>
|
||||||
<jackson-databind.version>2.13.4.1</jackson-databind.version>
|
<jackson-databind.version>2.13.4.1</jackson-databind.version>
|
||||||
<dropwizard.version>2.0.34</dropwizard.version>
|
<dropwizard.version>2.0.34</dropwizard.version>
|
||||||
|
<diffMatch.version>1.0</diffMatch.version>
|
||||||
<dropwizard-jdbi3.version>2.0.34</dropwizard-jdbi3.version>
|
<dropwizard-jdbi3.version>2.0.34</dropwizard-jdbi3.version>
|
||||||
<jersey-bom.version>2.35</jersey-bom.version>
|
<jersey-bom.version>2.35</jersey-bom.version>
|
||||||
<javax.ws.rs-api.version>2.1.1</javax.ws.rs-api.version>
|
<javax.ws.rs-api.version>2.1.1</javax.ws.rs-api.version>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user