mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-29 17:49:14 +00:00
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:
parent
d0f4080e37
commit
3684a2661b
@ -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 "
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
}
|
||||
|
||||
@ -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.
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user