Skip to content

Commit

Permalink
SAK-46774 WCAnnouncements: release date ordering fix (sakaiproject#10255
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored Feb 11, 2022
1 parent d93113a commit 038dc27
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public AnnouncementChannelEdit addAnnouncementChannel(String ref) throws IdUsedE
* Channel's reference String
* @param filter
* A filtering object to accept messages, or null if no filtering is desired.
* @param order
* @param ascending
* Order of messages, ascending if true, descending if false
* @param merged
* flag to include merged channel messages, true returns ALL messages including merged sites/channels
Expand All @@ -197,7 +197,7 @@ public AnnouncementChannelEdit addAnnouncementChannel(String ref) throws IdUsedE
* if the user does not have read permission to the channel.
* @exception NullPointerException
*/
public List getMessages(String channelReference, Filter filter, boolean order, boolean merged) throws IdUnusedException, PermissionException, NullPointerException;
public List getMessages(String channelReference, Filter filter, boolean ascending, boolean merged) throws IdUnusedException, PermissionException, NullPointerException;

public Map<String, List<AnnouncementMessage>> getViewableAnnouncementsForCurrentUser(Integer maxAgeInDays);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ public AnnouncementChannelEdit addAnnouncementChannel(String ref) throws IdUsedE
* Channel's reference String
* @param filter
* A filtering object to accept messages, or null if no filtering is desired.
* @param order
* @param ascending
* Order of messages, ascending if true, descending if false
* @param merged
* flag to include merged channel messages, true returns ALL messages including merged sites/channels
Expand All @@ -1057,7 +1057,7 @@ public AnnouncementChannelEdit addAnnouncementChannel(String ref) throws IdUsedE
* if the user does not have read permission to the channel.
* @exception NullPointerException
*/
public List getMessages(String channelReference,Filter filter, boolean order, boolean merged) throws IdUnusedException, PermissionException, NullPointerException
public List getMessages(String channelReference,Filter filter, boolean ascending, boolean merged) throws IdUnusedException, PermissionException, NullPointerException
{
List<Message> messageList = new Vector();
filter = new PrivacyFilter(filter); // filter out drafts this user cannot see
Expand Down Expand Up @@ -1089,14 +1089,14 @@ public List getMessages(String channelReference,Filter filter, boolean order, bo
//merged flag = true then add all channel's messages
//merged flag = false only add the calling channel's messages
if(merged || siteChannel.getContext().equals(site.getId()))
messageList.addAll(siteChannel.getMessages(filter,order));
messageList.addAll(siteChannel.getMessages(filter, ascending));
}
}
}

//sort messages
Collections.sort(messageList);
if (!order)
if (!ascending)
{
Collections.reverse(messageList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import org.sakaiproject.announcement.api.AnnouncementMessage;
import org.sakaiproject.announcement.api.AnnouncementService;
import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
import org.sakaiproject.entity.api.EntityPropertyTypeException;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.site.api.Site;

Expand Down Expand Up @@ -42,8 +44,9 @@ public AnnouncementRestBean(Site site, AnnouncementMessage am, String url) {
author = am.getAnnouncementHeader().getFrom().getDisplayName();
date = am.getAnnouncementHeader().getInstant().toEpochMilli();
ResourceProperties props = am.getProperties();
String release = props.getProperty(AnnouncementService.RELEASE_DATE);
if (release != null) date = Long.parseLong(release);
try {
date = props.getInstantProperty(AnnouncementService.RELEASE_DATE).toEpochMilli();
} catch (EntityPropertyTypeException|EntityPropertyNotDefinedException e) { /*No action needed*/ }
this.url = url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ 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, true, true))
return ((List<AnnouncementMessage>) announcementService.getMessages(channelRef, null, false, true))
.stream()
.map(am -> {
Optional<String> optionalUrl = entityManager.getUrl(am.getReference(), Entity.UrlType.PORTAL);
Expand Down

0 comments on commit 038dc27

Please sign in to comment.