diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsService.java b/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsService.java index 84507b1..bd9726a 100644 --- a/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsService.java +++ b/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsService.java @@ -18,4 +18,6 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; public interface NotificationsService extends RemoteService { UserInfo getUserInfo(); HashMap> getUserNotifications(); + + boolean setAllUserNotificationsRead(); } diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsServiceAsync.java b/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsServiceAsync.java index 0ffd07b..2d9a351 100644 --- a/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsServiceAsync.java @@ -16,6 +16,8 @@ public interface NotificationsServiceAsync { void getUserNotifications( AsyncCallback>> callback); + void setAllUserNotificationsRead(AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationsPanel.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationsPanel.java index f145b29..67ae68a 100644 --- a/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationsPanel.java +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationsPanel.java @@ -1,8 +1,11 @@ package org.gcube.portlets.user.notifications.client.view; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; +import java.util.SortedSet; +import java.util.TreeSet; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.UserInfo; @@ -12,6 +15,7 @@ import org.gcube.portlets.user.notifications.client.view.templates.DayWrapper; import org.gcube.portlets.user.notifications.client.view.templates.SingleNotificationView; import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; @@ -78,12 +82,16 @@ public class NotificationsPanel extends Composite { mainPanel.setHeight(""); mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT); mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP); - for (Date day : notificationsPerDay.keySet()) { + + ArrayList sortedKeys=new ArrayList(notificationsPerDay.keySet()); + Collections.sort(sortedKeys, Collections.reverseOrder()); + + for (Date day : sortedKeys) { mainPanel.add(new DayWrapper(day)); for (Notification notif : notificationsPerDay.get(day)) mainPanel.add(new SingleNotificationView(notif)); } - + setNotificationsRead(); } } else @@ -99,4 +107,23 @@ public class NotificationsPanel extends Composite { mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); mainPanel.add(loadingImage); } + + Timer t; + private void setNotificationsRead() { + t = new Timer() { + + @Override + public void run() { + notificationService.setAllUserNotificationsRead(new AsyncCallback() { + public void onFailure(Throwable caught) { + } + public void onSuccess(Boolean result) { + } + }); + + } + }; + + t.schedule(3000); + } } diff --git a/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java b/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java index f1bc703..c253df5 100644 --- a/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java @@ -14,6 +14,9 @@ import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DatabookStore; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.UserInfo; +import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException; +import org.gcube.portal.databook.shared.ex.NotificationIDNotFoundException; +import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException; import org.gcube.portlets.user.notifications.client.NotificationsService; import com.google.gwt.user.server.rpc.RemoteServiceServlet; @@ -137,7 +140,7 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No private Date removeTimePart(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); - + // Set time fields to zero cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); @@ -146,4 +149,18 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No return cal.getTime(); } + /** + * this set all the notifications for this user read + */ + public boolean setAllUserNotificationsRead() { + try { + for (Notification notification :store.getUnreadNotificationsByUser(getASLSession().getUsername()) ) { + store.setNotificationRead(notification.getKey()); + } + } catch (Exception e) { + _log.error("While trying to set User notifications Read"); + e.printStackTrace(); + } + return false; + } }