Portlet Event Notification Service
Configuration to Turn On Events
Use the 'NotificationLifecycleController.doEvents' preference to turn on event processing for a portlet definition. This needs to be done in both Notifications Portlet and Notifications Icon.
Adding Support to A Portlet
The follow changes will need to be performed on the portlet that wishes to publish Notifications entries into the Notifications system.
Add dependency for the Notifications API
First off, the portlet will need to have access to the Notifications API artifacts. Include these in pom.xml
pom.xml
... <dependency> <groupId>org.jasig.portlet.notification</groupId> <artifactId>notification-portlet-api</artifactId> <version>3.0.0</version> </dependency> ... <dependency> <groupId>org.jasig.portlet.notification</groupId> <artifactId>notification-portlet-api</artifactId> </dependency>
Listen for Notification Events and Respond
Next, configure portlet.xml with the inter-portlet events to process and publish for each portlet.
portlet.xml
... </portlet-preferences> <supported-processing-event> <qname xmlns:x="https://source.jasig.org/schemas/portlet/notification">x:NotificationQuery</qname> </supported-processing-event> <supported-publishing-event> <qname xmlns:x="https://source.jasig.org/schemas/portlet/notification">x:NotificationResult</qname> </supported-publishing-event> </portlet>
And at the end of the file, add the event definitions.
... <event-definition> <qname xmlns:x="https://source.jasig.org/schemas/portlet/notification">x:NotificationQuery</qname> <value-type>org.jasig.portlet.notice.NotificationQuery</value-type> </event-definition> <event-definition> <qname xmlns:x="https://source.jasig.org/schemas/portlet/notification">x:NotificationResult</qname> <value-type>org.jasig.portlet.notice.NotificationResult</value-type> </event-definition> </portlet-app>
Example NotificationResult
Response Code
Use code like the following in a @Controller to respond to NotificationQuery
events and feed items to the NotificationPortlet.
Spring Portlet MVC Controller
@EventMapping(NOTIFICATION_QUERY_QNAME_STRING) public void echo(final EventRequest req, final EventResponse res) { final NotificationQuery query = (NotificationQuery) req.getEvent().getValue(); final NotificationEntry entry = new NotificationEntry(); entry.setSource("foo"); entry.setTitle("OMG WOOT!"); final NotificationCategory category = new NotificationCategory(); category.setTitle("MONKEY"); category.setEntries(Arrays.asList(new NotificationEntry[] { entry })); final NotificationResponse response = new NotificationResponse(); response.setCategories(Arrays.asList(new NotificationCategory[] { category })); final NotificationResult result = new NotificationResult(); result.setQueryWindowId(query.getQueryWindowId()); result.setResultWindowId(req.getWindowID()); result.setNotificationResponse(response); res.setEvent(NotificationLifecycleController.NOTIFICATION_RESULT_QNAME, result); }