Skip to content

Commit

Permalink
SAK-47863 Dashboard / Future release date announcements displayed (sa…
Browse files Browse the repository at this point in the history
  • Loading branch information
austin48 authored Sep 7, 2023
1 parent c3bbd1a commit 2b68130
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,6 @@ public AnnouncementChannelEdit addAnnouncementChannel(String ref) throws IdUsedE
public List getMessages(String channelReference, Filter filter, boolean ascending, boolean merged) throws IdUnusedException, PermissionException, NullPointerException;

public Map<String, List<AnnouncementMessage>> getViewableAnnouncementsForCurrentUser(Integer maxAgeInDays);

public List<AnnouncementMessage> getViewableAnnouncementsForSite(String channelRef, Integer maxAgeInDays);
}
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,20 @@ public Map<String, List<AnnouncementMessage>> getViewableAnnouncementsForCurrent

return allAnnouncements;
}

public List<AnnouncementMessage> getViewableAnnouncementsForSite(String channelRef, Integer maxAgeInDays) {

try {
ViewableFilter viewableFilter = new ViewableFilter(null, null, Integer.MAX_VALUE, this);
if (maxAgeInDays != null) {
long now = Instant.now().toEpochMilli();
Time afterDate = m_timeService.newTime(now - (maxAgeInDays * 24 * 60 * 60 * 1000));
viewableFilter.setFilter(new MessageSelectionFilter(afterDate, null, false));
}
return (List<AnnouncementMessage>) getMessages(channelRef, viewableFilter, false, true);
} catch (Exception e) {
log.warn("Failed to add announcements from site {}", channelRef, e);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ public List<AnnouncementRestBean> getSiteAnnouncements(@PathVariable String site
try {
Site site = siteService.getSite(siteId);
String channelRef = announcementService.channelReference(siteId, "main");
return ((List<AnnouncementMessage>) announcementService.getMessages(channelRef, null, false, true))
return ((List<AnnouncementMessage>) announcementService.getViewableAnnouncementsForSite(channelRef, 10))
.stream()
.map(am -> {
Optional<String> optionalUrl = entityManager.getUrl(am.getReference(), Entity.UrlType.PORTAL);
return new AnnouncementRestBean(site, am, optionalUrl.get());
}).collect(Collectors.toList());
} catch (IdUnusedException idue) {
log.error("No announcements for id {}", siteId);
} catch (PermissionException pe) {
log.warn("The current user does not have permission to get announcements for this site {}", siteId);
} catch (Exception ex) {
log.warn("Error getting announcements for this site {}", siteId, ex);
}

return Collections.EMPTY_LIST;
Expand Down

0 comments on commit 2b68130

Please sign in to comment.