dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #16867
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6536: Impl json result for notifications
------------------------------------------------------------
revno: 6536
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-04-10 22:15:18 +0200
message:
Impl json result for notifications
added:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonNotifications.vm
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/Notifier.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementGroups.vm
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetNotificationsAction.java
dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataMart.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java 2012-04-10 19:37:24 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java 2012-04-10 20:15:18 +0000
@@ -76,19 +76,11 @@
}
@Override
- public List<Notification> getNotifications( int max )
- {
- max = max > notifications.size() ? notifications.size() : max;
-
- return notifications.subList( 0, max );
- }
-
- @Override
public List<Notification> getNotifications( NotificationCategory category, int max )
{
List<Notification> list = new ArrayList<Notification>();
- if ( category != null && max > 0 )
+ if ( category != null )
{
for ( Notification notification : notifications )
{
@@ -106,6 +98,30 @@
return list;
}
+
+ @Override
+ public List<Notification> getNotifications( NotificationCategory category, String lastUid )
+ {
+ List<Notification> list = new ArrayList<Notification>();
+
+ if ( category != null )
+ {
+ for ( Notification notification : notifications )
+ {
+ if ( lastUid != null && lastUid.equals( notification.getUid() ) )
+ {
+ break;
+ }
+
+ if ( category.equals( notification.getCategory() ) )
+ {
+ list.add( notification );
+ }
+ }
+ }
+
+ return list;
+ }
@Override
public Notifier clear( NotificationCategory category )
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/Notifier.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/Notifier.java 2012-04-10 19:37:24 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/Notifier.java 2012-04-10 20:15:18 +0000
@@ -38,9 +38,9 @@
Notifier notify( NotificationLevel level, NotificationCategory category, String message, boolean completed );
- List<Notification> getNotifications( int max );
-
List<Notification> getNotifications( NotificationCategory category, int max );
+ List<Notification> getNotifications( NotificationCategory category, String lastUid );
+
Notifier clear( NotificationCategory category );
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementGroups.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementGroups.vm 2012-01-22 11:28:12 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementGroups.vm 2012-04-10 20:15:18 +0000
@@ -2,7 +2,7 @@
{ "dataElementGroups": [
#foreach( $dataElementGroup in $dataElementGroups )
{
- "id": ${dataElementGroup.id} ,
+ "id": ${dataElementGroup.id} ,
"name": "$!encoder.jsonEncode( ${dataElementGroup.displayName} )"
}#if( $velocityCount < $size ),#end
#end
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonNotifications.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonNotifications.vm 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonNotifications.vm 2012-04-10 20:15:18 +0000
@@ -0,0 +1,13 @@
+#set( $size = $notifications.size() )
+{ "notifications": [
+#foreach( $notification in $notifications )
+ {
+ "uid": "${notification.uid}",
+ "level": "${notification.level}",
+ "category": "${notification.category}",
+ "time": "${format.formatDate( $notification.time )}",
+ "message": "${notification.message}",
+ "completed": "${notification.completed}"
+ }#if( $velocityCount < $size ),#end
+#end
+] }
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetNotificationsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetNotificationsAction.java 2012-02-12 19:23:31 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetNotificationsAction.java 2012-04-10 20:15:18 +0000
@@ -64,6 +64,13 @@
this.category = category;
}
+ private String lastUid;
+
+ public void setLastUid( String lastUid )
+ {
+ this.lastUid = lastUid;
+ }
+
private Integer max;
public void setMax( Integer max )
@@ -90,17 +97,18 @@
public String execute()
throws Exception
{
- max = max != null ? max : 20;
-
if ( category != null )
{
NotificationCategory notificationCategory = NotificationCategory.valueOf( category.toUpperCase() );
-
- notifications = notifier.getNotifications( notificationCategory, max );
- }
- else
- {
- notifications = notifier.getNotifications( max );
+
+ if ( max != null )
+ {
+ notifications = notifier.getNotifications( notificationCategory, max );
+ }
+ else
+ {
+ notifications = notifier.getNotifications( notificationCategory, lastUid );
+ }
}
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml 2012-04-05 13:13:13 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml 2012-04-10 20:15:18 +0000
@@ -318,11 +318,6 @@
<package name="dhis-web-commons-ajax" extends="dhis-web-commons" namespace="/dhis-web-commons-ajax">
- <action name="getNotifications" class="org.hisp.dhis.commons.action.GetNotificationsAction">
- <result name="success" type="velocity">/dhis-web-commons/ajax/htmlNotifications.vm</result>
- <param name="onExceptionReturn">plainTextError</param>
- </action>
-
<action name="getCategoryOptionCombos" class="org.hisp.dhis.commons.action.GetCategoryOptionCombosAction">
<result name="success" type="velocity-xml">
/dhis-web-commons/ajax/xmlCategoryOptionCombos.vm
@@ -462,6 +457,11 @@
<package name="dhis-web-commons-ajax-html" extends="dhis-web-commons" namespace="/dhis-web-commons-ajax-html">
+ <action name="getNotifications" class="org.hisp.dhis.commons.action.GetNotificationsAction">
+ <result name="success" type="velocity">/dhis-web-commons/ajax/htmlNotifications.vm</result>
+ <param name="onExceptionReturn">plainTextError</param>
+ </action>
+
<action name="getUser" class="org.hisp.dhis.commons.action.GetUserAction">
<result name="success" type="velocity">
/dhis-web-commons/ajax/htmlUser.vm
@@ -474,6 +474,11 @@
<!-- Common actions JSON -->
<package name="dhis-web-commons-ajax-json" extends="dhis-web-commons" namespace="/dhis-web-commons-ajax-json">
+
+ <action name="getNotifications" class="org.hisp.dhis.commons.action.GetNotificationsAction">
+ <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonNotifications.vm</result>
+ <param name="onExceptionReturn">plainTextError</param>
+ </action>
<action name="getUser" class="org.hisp.dhis.commons.action.GetUserAction">
<result name="success" type="velocity-json">
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataMart.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataMart.js 2012-02-12 19:23:31 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataMart.js 2012-04-10 20:15:18 +0000
@@ -20,7 +20,7 @@
function pingNotifications()
{
- $( '#notificationDiv' ).load( '../dhis-web-commons-ajax/getNotifications.action?category=DATAMART' );
+ $( '#notificationDiv' ).load( '../dhis-web-commons-ajax-html/getNotifications.action?category=DATAMART&max=20' );
}
function pingNotificationsTimeout()