-
Notifications
You must be signed in to change notification settings - Fork 32
Add JSON Resource endpoints for emergencies and normal messages #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ | |
| import javax.xml.bind.annotation.XmlRootElement; | ||
| import javax.xml.bind.annotation.XmlTransient; | ||
| import javax.xml.bind.annotation.XmlType; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import org.jasig.portlet.announcements.xml.Namespaces; | ||
|
|
||
| /** @author Erik A. Olsson ([email protected]) */ | ||
|
|
@@ -95,6 +97,7 @@ public void setId(Long id) { | |
| } | ||
|
|
||
| /** @return the parent */ | ||
| @JsonIgnore | ||
| @XmlElement(name = "parent") | ||
| public Topic getParent() { | ||
| return parent; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,21 +18,25 @@ | |
| */ | ||
| package org.jasig.portlet.announcements.mvc.portlet.display; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import javax.portlet.EventRequest; | ||
| import javax.portlet.EventResponse; | ||
| import javax.portlet.PortletException; | ||
| import javax.portlet.PortletPreferences; | ||
| import javax.portlet.PortletRequest; | ||
| import javax.portlet.RenderRequest; | ||
| import javax.portlet.ResourceRequest; | ||
| import javax.portlet.ResourceResponse; | ||
| import javax.xml.namespace.QName; | ||
| import net.sf.ehcache.Cache; | ||
| import net.sf.ehcache.Element; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.apache.log4j.Logger; | ||
| import org.jasig.portlet.announcements.UnauthorizedException; | ||
| import org.jasig.portlet.announcements.model.Announcement; | ||
|
|
@@ -51,8 +55,6 @@ | |
| import org.jasig.portlet.notice.NotificationQuery; | ||
| import org.jasig.portlet.notice.NotificationResponse; | ||
| import org.jasig.portlet.notice.NotificationResult; | ||
| import org.springframework.beans.factory.BeanCreationException; | ||
| import org.springframework.beans.factory.InitializingBean; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.cache.ehcache.EhCacheCacheManager; | ||
| import org.springframework.stereotype.Controller; | ||
|
|
@@ -62,6 +64,7 @@ | |
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.portlet.bind.annotation.EventMapping; | ||
| import org.springframework.web.portlet.bind.annotation.RenderMapping; | ||
| import org.springframework.web.portlet.bind.annotation.ResourceMapping; | ||
|
|
||
| /** @author eolsson */ | ||
| @Controller | ||
|
|
@@ -114,6 +117,8 @@ public class AnnouncementsViewController { | |
|
|
||
| @Autowired private UserIdService userIdService; | ||
|
|
||
| private final ObjectMapper mapper = new ObjectMapper(); | ||
|
|
||
| private final Logger logger = Logger.getLogger(getClass()); | ||
|
|
||
| /** | ||
|
|
@@ -142,27 +147,10 @@ public String mainView( | |
|
|
||
| final PortletPreferences prefs = request.getPreferences(); | ||
|
|
||
| List<Announcement> announcements; | ||
| List<Announcement> emergencyAnnouncements; | ||
|
|
||
| final String userId = userIdService.getUserId(request); | ||
|
|
||
| // create a new announcement list | ||
| announcements = new ArrayList<>(); | ||
| emergencyAnnouncements = new ArrayList<>(); | ||
| List[] lists = getLists(request); | ||
|
|
||
| // fetch the user's topic subscription from the database | ||
| List<TopicSubscription> myTopics = tss.getTopicSubscription(request); | ||
|
|
||
| // add all the published announcements of each subscribed topic to the announcement list | ||
| // to emergency announcements into their own list | ||
| for (TopicSubscription ts : myTopics) { | ||
| if (ts.getSubscribed() && ts.getTopic().getSubscriptionMethod() != Topic.EMERGENCY) { | ||
| announcements.addAll(ts.getTopic().getPublishedAnnouncements()); | ||
| } else if (ts.getSubscribed() && ts.getTopic().getSubscriptionMethod() == Topic.EMERGENCY) { | ||
| emergencyAnnouncements.addAll(ts.getTopic().getPublishedAnnouncements()); | ||
| } | ||
| } | ||
| List<Announcement> announcements = lists[0]; | ||
| List<Announcement> emergencyAnnouncements = lists[1]; | ||
|
|
||
| // sort the list (since they are not sorted from the database) | ||
| Comparator<Announcement> sortStrategy = | ||
|
|
@@ -190,6 +178,46 @@ public String mainView( | |
| return viewNameSelector.select(request, "displayAnnouncements"); | ||
| } | ||
|
|
||
| private List[] getLists(PortletRequest request) throws PortletException { | ||
| final String userId = userIdService.getUserId(request); | ||
|
|
||
| // create a new announcement list | ||
| List<Announcement> announcements1 = new ArrayList<>(); | ||
| List<Announcement> emergencyAnnouncements1 = new ArrayList<>(); | ||
|
|
||
| // fetch the user's topic subscription from the database | ||
| List<TopicSubscription> myTopics = tss.getTopicSubscription(request); | ||
|
|
||
| // add all the published announcements of each subscribed topic to the announcement list | ||
| // to emergency announcements into their own list | ||
| for (TopicSubscription ts : myTopics) { | ||
| if (ts.getSubscribed() && ts.getTopic().getSubscriptionMethod() != Topic.EMERGENCY) { | ||
| announcements1.addAll(ts.getTopic().getPublishedAnnouncements()); | ||
|
||
| } else if (ts.getSubscribed() && ts.getTopic().getSubscriptionMethod() == Topic.EMERGENCY) { | ||
| emergencyAnnouncements1.addAll(ts.getTopic().getPublishedAnnouncements()); | ||
| } | ||
| } | ||
| return new List[]{announcements1, emergencyAnnouncements1}; | ||
| } | ||
|
|
||
| @ResourceMapping(value = "emergencies") | ||
| public void emergenciesResource(ResourceRequest request, ResourceResponse response) | ||
| throws IOException, PortletException { | ||
| logger.debug("Processing AJAX resource request for emergency alerts"); | ||
| List[] lists = getLists(request); | ||
| final String json = mapper.writeValueAsString(lists[1]); | ||
| response.getWriter().write(json); | ||
| } | ||
|
|
||
| @ResourceMapping(value = "announcements") | ||
| public void announcementsResource(ResourceRequest request, ResourceResponse response) | ||
| throws IOException, PortletException { | ||
| logger.debug("Processing AJAX resource request for announcements"); | ||
| List[] lists = getLists(request); | ||
| final String json = mapper.writeValueAsString(lists[0]); | ||
| response.getWriter().write(json); | ||
| } | ||
|
|
||
| @RenderMapping(params = "action=" + ACTION_DISPLAY_FULL_ANNOUNCEMENT) | ||
| public String displayFullAnnouncement( | ||
| Model model, RenderRequest request, @RequestParam("announcementId") String announcementId) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to see lombok being used.
Is it being used?