Add Announcement Count to Feed Count API (#19600)

* Add Announcement Count to Feed Count API

* add inactive and active announcement count
This commit is contained in:
sonika-shah 2025-03-24 17:37:44 +05:30 committed by GitHub
parent d0f4080e37
commit 3684a2661b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 64 additions and 0 deletions

View File

@ -1699,6 +1699,26 @@ public interface CollectionDAO {
parts = {":toType", ".%"})
String toType);
@ConnectionAwareSqlQuery(
value =
"SELECT COUNT(te.id) AS count "
+ "FROM thread_entity te "
+ "WHERE te.type = 'Announcement' "
+ " AND te.entityLink = :entityLink "
+ " AND CAST(JSON_EXTRACT(te.json, '$.announcement.startTime') AS UNSIGNED) <= UNIX_TIMESTAMP()*1000 "
+ " AND CAST(JSON_EXTRACT(te.json, '$.announcement.endTime') AS UNSIGNED) >= UNIX_TIMESTAMP()*1000",
connectionType = MYSQL)
@ConnectionAwareSqlQuery(
value =
"SELECT COUNT(te.id) AS count "
+ "FROM thread_entity te "
+ "WHERE te.type = 'Announcement' "
+ " AND te.entityLink = :entityLink "
+ " AND (te.json->'announcement'->>'startTime')::numeric <= EXTRACT(EPOCH FROM NOW()) * 1000 "
+ " AND (te.json->'announcement'->>'endTime')::numeric >= EXTRACT(EPOCH FROM NOW()) * 1000",
connectionType = POSTGRES)
int countActiveAnnouncement(@Bind("entityLink") String entityLink);
@ConnectionAwareSqlQuery(
value =
"SELECT combined.type, combined.taskStatus, COUNT(combined.id) AS count "

View File

@ -660,6 +660,12 @@ public class FeedRepository {
} else if (taskStatus.equals("Closed")) {
threadCount.setClosedTaskCount(count);
}
} else if (type.equalsIgnoreCase("Announcement")) {
// announcements are set at entity level will be called only once
threadCount.setTotalAnnouncementCount(count);
int activeCount = (count > 0) ? dao.feedDAO().countActiveAnnouncement(eLink) : 0;
threadCount.setActiveAnnouncementCount(activeCount);
threadCount.setInactiveAnnouncementCount(count - activeCount);
}
computeTotalTaskCount(threadCount);
threadCounts.add(threadCount);

View File

@ -532,6 +532,17 @@ public class FeedResourceTest extends OpenMetadataApplicationTest {
announcements = listAnnouncements(about, null, false, ADMIN_AUTH_HEADERS);
assertEquals(totalAnnouncementCount + 3, announcements.getPaging().getTotal());
assertEquals(totalAnnouncementCount + 3, announcements.getData().size());
// verify the announcement counts in the feed count API
FeedResource.ThreadCountList threadCounts = listThreadsCount(about, ADMIN_AUTH_HEADERS);
for (ThreadCount threadCount : threadCounts.getData()) {
if (threadCount.getEntityLink().equals(about)
&& threadCount.getTotalAnnouncementCount() != null) {
assertEquals(totalAnnouncementCount + 4, threadCount.getTotalAnnouncementCount());
assertEquals(1, threadCount.getActiveAnnouncementCount());
assertEquals(totalAnnouncementCount + 3, threadCount.getInactiveAnnouncementCount());
}
}
}
@Test

View File

@ -31,6 +31,21 @@
"type": "integer",
"minimum": 0
},
"totalAnnouncementCount": {
"description": "Total count of all the announcements associated with the entity.",
"type": "integer",
"minimum": 0
},
"activeAnnouncementCount": {
"description": "Total count of all the active announcements associated with the entity.",
"type": "integer",
"minimum": 0
},
"inactiveAnnouncementCount": {
"description": "Total count of all the inactive announcements associated with the entity.",
"type": "integer",
"minimum": 0
},
"entityLink": {
"$ref": "../../type/basic.json#/definitions/entityLink"
}

View File

@ -14,6 +14,10 @@
* This schema defines the type for reporting the count of threads related to an entity.
*/
export interface ThreadCount {
/**
* Total count of all the active announcements associated with the entity.
*/
activeAnnouncementCount?: number;
/**
* Total count of all the tasks.
*/
@ -23,6 +27,10 @@ export interface ThreadCount {
*/
conversationCount?: number;
entityLink?: string;
/**
* Total count of all the inactive announcements associated with the entity.
*/
inactiveAnnouncementCount?: number;
/**
* Total count of all the mentions of a user.
*/
@ -31,6 +39,10 @@ export interface ThreadCount {
* Total count of all the open tasks.
*/
openTaskCount?: number;
/**
* Total count of all the announcements associated with the entity.
*/
totalAnnouncementCount?: number;
/**
* Total count of all the tasks.
*/