From 4b7f4f43d66ded34a27bad44f4e609d20d537d62 Mon Sep 17 00:00:00 2001 From: Sriharsha Chintalapani Date: Mon, 25 Dec 2023 17:28:13 -0800 Subject: [PATCH] Fix #13982: Fix userFQN encoding while creating mentions (#14496) * Fix #13982: Fix userFQN encoding while creating mentions * quote only teams or users --- .../migrations/native/1.2.4/mysql/schemaChanges.sql | 3 +++ .../native/1.2.4/postgres/schemaChanges.sql | 3 +++ .../service/resources/feeds/MessageParser.java | 13 ++++++++----- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 bootstrap/sql/migrations/native/1.2.4/mysql/schemaChanges.sql create mode 100644 bootstrap/sql/migrations/native/1.2.4/postgres/schemaChanges.sql diff --git a/bootstrap/sql/migrations/native/1.2.4/mysql/schemaChanges.sql b/bootstrap/sql/migrations/native/1.2.4/mysql/schemaChanges.sql new file mode 100644 index 000000000000..b815213d6bd0 --- /dev/null +++ b/bootstrap/sql/migrations/native/1.2.4/mysql/schemaChanges.sql @@ -0,0 +1,3 @@ +update field_relationship fr INNER JOIN user_entity ue on fr.fromFQN=ue.name + set fr.fromFQNHASH=MD5(JSON_UNQUOTE(JSON_EXTRACT(ue.json, '$.fullyQualifiedName'))), + fr.fromFQN=JSON_UNQUOTE(JSON_EXTRACT(ue.json, '$.fullyQualifiedName')) where fr.fromType='user'; \ No newline at end of file diff --git a/bootstrap/sql/migrations/native/1.2.4/postgres/schemaChanges.sql b/bootstrap/sql/migrations/native/1.2.4/postgres/schemaChanges.sql new file mode 100644 index 000000000000..dbb1bf4249b4 --- /dev/null +++ b/bootstrap/sql/migrations/native/1.2.4/postgres/schemaChanges.sql @@ -0,0 +1,3 @@ +update field_relationship fr + set fromFQNHASH=MD5(ue.json->>'fullyQualifiedName'), + fromFQN=ue.json->>'fullyQualifiedName' from user_entity ue where fr.fromType='user' and fr.fromFQN=ue.name; \ No newline at end of file diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/feeds/MessageParser.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/feeds/MessageParser.java index 329e74cd905d..8d64378b0267 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/feeds/MessageParser.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/feeds/MessageParser.java @@ -23,6 +23,8 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.openmetadata.service.Entity; +import org.openmetadata.service.util.FullyQualifiedName; @Slf4j public final class MessageParser { @@ -167,18 +169,19 @@ public static EntityLink parse(String link) { EntityLink entityLink = null; while (matcher.find()) { if (entityLink == null) { + String entityType = matcher.group(1); String entityFQN = matcher.group(2); if (entityFQN == null) { throw new IllegalArgumentException( "Invalid Entity Link. Entity FQN is missing in " + link); } + if (entityType.equalsIgnoreCase(Entity.USER) + || entityType.equalsIgnoreCase(Entity.TEAM)) { + entityFQN = FullyQualifiedName.quoteName(entityFQN); + } entityLink = new EntityLink( - matcher.group(1), - entityFQN, - matcher.group(4), - matcher.group(6), - matcher.group(8)); + entityType, entityFQN, matcher.group(4), matcher.group(6), matcher.group(8)); } else { throw new IllegalArgumentException("Unexpected multiple entity links in " + link); }