diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryTermRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryTermRepository.java index 8f468a583de..e134033c94e 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryTermRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryTermRepository.java @@ -90,6 +90,7 @@ import org.openmetadata.service.util.EntityUtil; import org.openmetadata.service.util.EntityUtil.Fields; import org.openmetadata.service.util.FullyQualifiedName; import org.openmetadata.service.util.JsonUtils; +import org.openmetadata.service.util.NotificationHandler; @Slf4j public class GlossaryTermRepository extends EntityRepository { @@ -653,6 +654,9 @@ public class GlossaryTermRepository extends EntityRepository { .withUpdatedAt(System.currentTimeMillis()); FeedRepository feedRepository = Entity.getFeedRepository(); feedRepository.create(thread); + + // Send WebSocket Notification + NotificationHandler.handleTaskNotification(thread); } private void closeApprovalTask(GlossaryTerm entity, String comment) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/NotificationHandler.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/NotificationHandler.java index 6f25c72c136..7401fcf1b0f 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/NotificationHandler.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/NotificationHandler.java @@ -17,13 +17,12 @@ import static org.openmetadata.service.Entity.TEAM; import static org.openmetadata.service.Entity.USER; import static org.openmetadata.service.util.EmailUtil.getSmtpSettings; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import freemarker.template.TemplateException; import java.io.IOException; import java.time.Instant; import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.UUID; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -45,11 +44,9 @@ import org.openmetadata.service.socket.WebSocketManager; @Slf4j public class NotificationHandler { - private final ObjectMapper mapper; private final ExecutorService threadScheduler; public NotificationHandler() { - this.mapper = new ObjectMapper(); this.threadScheduler = Executors.newFixedThreadPool(1); } @@ -57,33 +54,29 @@ public class NotificationHandler { threadScheduler.submit( () -> { try { - CollectionDAO collectionDAO = Entity.getCollectionDAO(); - handleNotifications(responseContext, collectionDAO); + handleNotifications(responseContext); } catch (Exception ex) { LOG.error("[NotificationHandler] Failed to use mapper in converting to Json", ex); } }); } - private void handleNotifications( - ContainerResponseContext responseContext, CollectionDAO collectionDAO) - throws JsonProcessingException { + private void handleNotifications(ContainerResponseContext responseContext) { int responseCode = responseContext.getStatus(); if (responseCode == Response.Status.CREATED.getStatusCode() && responseContext.getEntity() != null && responseContext.getEntity().getClass().equals(Thread.class)) { Thread thread = (Thread) responseContext.getEntity(); switch (thread.getType()) { - case Task -> handleTaskNotification(thread, collectionDAO); - case Conversation -> handleConversationNotification(thread, collectionDAO); + case Task -> handleTaskNotification(thread); + case Conversation -> handleConversationNotification(thread); case Announcement -> handleAnnouncementNotification(thread); } } } - private void handleTaskNotification(Thread thread, CollectionDAO collectionDAO) - throws JsonProcessingException { - String jsonThread = mapper.writeValueAsString(thread); + public static void handleTaskNotification(Thread thread) { + String jsonThread = JsonUtils.pojoToJson(thread); if (thread.getPostsCount() == 0) { List assignees = thread.getTask().getAssignees(); HashSet receiversList = new HashSet<>(); @@ -94,7 +87,7 @@ public class NotificationHandler { } else if (Entity.TEAM.equals(e.getType())) { // fetch all that are there in the team List records = - collectionDAO + Entity.getCollectionDAO() .relationshipDAO() .findTo(e.getId(), TEAM, Relationship.HAS.ordinal(), Entity.USER); records.forEach(eRecord -> receiversList.add(eRecord.getId())); @@ -111,8 +104,8 @@ public class NotificationHandler { } } - private void handleAnnouncementNotification(Thread thread) throws JsonProcessingException { - String jsonThread = mapper.writeValueAsString(thread); + private void handleAnnouncementNotification(Thread thread) { + String jsonThread = JsonUtils.pojoToJson(thread); AnnouncementDetails announcementDetails = thread.getAnnouncement(); Long currentTimestamp = Instant.now().getEpochSecond(); if (announcementDetails.getStartTime() <= currentTimestamp @@ -122,9 +115,8 @@ public class NotificationHandler { } } - private void handleConversationNotification(Thread thread, CollectionDAO collectionDAO) - throws JsonProcessingException { - String jsonThread = mapper.writeValueAsString(thread); + private void handleConversationNotification(Thread thread) { + String jsonThread = JsonUtils.pojoToJson(thread); WebSocketManager.getInstance() .broadCastMessageToAll(WebSocketManager.FEED_BROADCAST_CHANNEL, jsonThread); List mentions; @@ -138,14 +130,14 @@ public class NotificationHandler { entityLink -> { String fqn = entityLink.getEntityFQN(); if (USER.equals(entityLink.getEntityType())) { - User user = collectionDAO.userDAO().findEntityByName(fqn); + User user = Entity.getCollectionDAO().userDAO().findEntityByName(fqn); WebSocketManager.getInstance() .sendToOne(user.getId(), WebSocketManager.MENTION_CHANNEL, jsonThread); } else if (TEAM.equals(entityLink.getEntityType())) { - Team team = collectionDAO.teamDAO().findEntityByName(fqn); + Team team = Entity.getCollectionDAO().teamDAO().findEntityByName(fqn); // fetch all that are there in the team List records = - collectionDAO + Entity.getCollectionDAO() .relationshipDAO() .findTo(team.getId(), TEAM, Relationship.HAS.ordinal(), USER); // Notify on WebSocket for Realtime @@ -155,7 +147,7 @@ public class NotificationHandler { }); } - private void handleEmailNotifications(HashSet userList, Thread thread) { + public static void handleEmailNotifications(Set userList, Thread thread) { UserRepository repository = (UserRepository) Entity.getEntityRepository(USER); userList.forEach( id -> {