From 690c2ebcdc3fbeaf878d948ea2fa1172cd3e7893 Mon Sep 17 00:00:00 2001 From: Sriharsha Chintalapani Date: Mon, 25 Dec 2023 12:49:18 -0800 Subject: [PATCH 1/2] Fix #13982: Fix userFQN encoding while creating mentions --- bootstrap/sql/migrations/native/1.2.4/mysql/schemaChanges.sql | 3 +++ .../sql/migrations/native/1.2.4/postgres/schemaChanges.sql | 3 +++ .../java/org/openmetadata/service/jdbi3/FeedRepository.java | 4 ++-- 3 files changed, 8 insertions(+), 2 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/jdbi3/FeedRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java index ba7c024a14ee..7007a42aa83f 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java @@ -417,9 +417,9 @@ private void storeMentions(Thread thread, String message) { mention -> dao.fieldRelationshipDAO() .insert( - mention.getFullyQualifiedFieldValue(), + FullyQualifiedName.quoteName(mention.getFullyQualifiedFieldValue()), thread.getId().toString(), - mention.getFullyQualifiedFieldValue(), + FullyQualifiedName.quoteName(mention.getFullyQualifiedFieldValue()), thread.getId().toString(), mention.getFullyQualifiedFieldType(), Entity.THREAD, From 2a29a4fb5e07e85498a04c7b5a961eeeabfc4322 Mon Sep 17 00:00:00 2001 From: Sriharsha Chintalapani Date: Mon, 25 Dec 2023 16:16:05 -0800 Subject: [PATCH 2/2] quote only teams or users --- .../openmetadata/service/jdbi3/FeedRepository.java | 4 ++-- .../service/resources/feeds/MessageParser.java | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java index 7007a42aa83f..ba7c024a14ee 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java @@ -417,9 +417,9 @@ private void storeMentions(Thread thread, String message) { mention -> dao.fieldRelationshipDAO() .insert( - FullyQualifiedName.quoteName(mention.getFullyQualifiedFieldValue()), + mention.getFullyQualifiedFieldValue(), thread.getId().toString(), - FullyQualifiedName.quoteName(mention.getFullyQualifiedFieldValue()), + mention.getFullyQualifiedFieldValue(), thread.getId().toString(), mention.getFullyQualifiedFieldType(), Entity.THREAD, 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); }