git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/notifications@67318 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-01-08 17:24:40 +00:00
parent 1a3703b298
commit 54b4e94a0c
4 changed files with 51 additions and 3 deletions

View File

@ -18,4 +18,6 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
public interface NotificationsService extends RemoteService {
UserInfo getUserInfo();
HashMap<Date, ArrayList<Notification>> getUserNotifications();
boolean setAllUserNotificationsRead();
}

View File

@ -16,6 +16,8 @@ public interface NotificationsServiceAsync {
void getUserNotifications(
AsyncCallback<HashMap<Date, ArrayList<Notification>>> callback);
void setAllUserNotificationsRead(AsyncCallback<Boolean> callback);
}

View File

@ -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<Date> sortedKeys=new ArrayList<Date>(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<Boolean>() {
public void onFailure(Throwable caught) {
}
public void onSuccess(Boolean result) {
}
});
}
};
t.schedule(3000);
}
}

View File

@ -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;
}
}