added posssibility to go back in time and retrieve the feeds
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@93074 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
fc97c11bba
commit
053564a916
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/news-feed-1.5.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<classpathentry kind="src" output="target/news-feed-1.6.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
@ -31,5 +31,5 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/news-feed-1.5.1-SNAPSHOT/WEB-INF/classes"/>
|
||||
<classpathentry kind="output" path="target/news-feed-1.6.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
jarsExcludedFromWebInfLib=
|
||||
lastWarOutDir=/Users/massi/Documents/workspace/news-feed/target/news-feed-1.5.1-SNAPSHOT
|
||||
lastWarOutDir=/Users/massi/Documents/workspace/news-feed/target/news-feed-1.6.0-SNAPSHOT
|
||||
warSrcDir=src/main/webapp
|
||||
warSrcDirIsOutput=false
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -13,7 +13,7 @@
|
|||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>news-feed</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.5.1-SNAPSHOT</version>
|
||||
<version>1.6.0-SNAPSHOT</version>
|
||||
|
||||
<name>gCube News Feed Portlet</name>
|
||||
<description>
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.gcube.portal.databook.shared.Comment;
|
|||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portal.databook.shared.UserInfo;
|
||||
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
|
||||
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
|
||||
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
|
||||
|
||||
import com.google.gwt.user.client.rpc.RemoteService;
|
||||
|
@ -24,7 +25,7 @@ public interface NewsService extends RemoteService {
|
|||
|
||||
ArrayList<EnhancedFeed> getOnlyLikedFeeds();
|
||||
|
||||
ArrayList<EnhancedFeed> getMoreFeeds(int from, int quantity);
|
||||
MoreFeedsBean getMoreFeeds(int from, int quantity);
|
||||
|
||||
boolean like(String feedid, String feedText, String feedOwnerId);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||
import org.gcube.portal.databook.shared.Comment;
|
||||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
|
||||
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
|
||||
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
|
||||
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
@ -48,6 +49,6 @@ public interface NewsServiceAsync {
|
|||
void getSingleFeed(String feedKey, AsyncCallback<EnhancedFeed> callback);
|
||||
|
||||
void getMoreFeeds(int from, int quantity,
|
||||
AsyncCallback<ArrayList<EnhancedFeed>> callback);
|
||||
AsyncCallback<MoreFeedsBean> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.gcube.portlets.user.newsfeed.client.templates.ShowMoreFeeds;
|
|||
import org.gcube.portlets.user.newsfeed.client.templates.SingleComment;
|
||||
import org.gcube.portlets.user.newsfeed.client.templates.TweetTemplate;
|
||||
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
|
||||
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
|
||||
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
|
||||
import org.gcube.portlets.widgets.userselection.client.UserSelectionDialog;
|
||||
import org.gcube.portlets.widgets.userselection.client.events.SelectedUserEvent;
|
||||
|
@ -59,6 +60,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
|||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HasAlignment;
|
||||
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
||||
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
|
@ -81,7 +83,7 @@ public class NewsFeedPanel extends Composite {
|
|||
private HorizontalPanel filterPanelWrapper = new HorizontalPanel();
|
||||
private FilterPanel filterPanel;
|
||||
private SimplePanel newUpdatesPanel = new SimplePanel();
|
||||
private SimplePanel showMoreUpdatesPanel = new SimplePanel();
|
||||
private VerticalPanel showMoreUpdatesPanel = new VerticalPanel();
|
||||
private VerticalPanel newsPanel = new VerticalPanel();
|
||||
|
||||
private NewFeedsAvailable newsFeedAlert;
|
||||
|
@ -109,10 +111,13 @@ public class NewsFeedPanel extends Composite {
|
|||
|
||||
private static final int feedsNoPerCategory = 10;
|
||||
|
||||
|
||||
private Image loadingImage;
|
||||
private UserInfo myUserInfo;
|
||||
private FilterType currentFilter;
|
||||
private Timer feedsTimer;
|
||||
//needed to know the next range start
|
||||
private Integer fromStartingPoint;
|
||||
|
||||
private ArrayList<EnhancedFeed> allUpdates = new ArrayList<EnhancedFeed>();
|
||||
|
||||
|
@ -128,7 +133,7 @@ public class NewsFeedPanel extends Composite {
|
|||
doShowMoreUpdates();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
eventBus.addHandler(ShowNewUpdatesEvent.TYPE, new ShowNewUpdatesEventHandler() {
|
||||
@Override
|
||||
public void onShowNewUpdatesClick(ShowNewUpdatesEvent event) {
|
||||
|
@ -222,6 +227,7 @@ public class NewsFeedPanel extends Composite {
|
|||
initWidget(mainPanel);
|
||||
newsPanel.clear();
|
||||
newsPanel.setWidth("100%");
|
||||
showMoreUpdatesPanel.setWidth("100%");
|
||||
newsPanel.setHeight("300px");
|
||||
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
|
||||
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
|
||||
|
@ -466,9 +472,9 @@ public class NewsFeedPanel extends Composite {
|
|||
newsPanel.add(new Image(spacer));
|
||||
}
|
||||
//if you are showing more than feedsNoPerCategory*3-1 feeds there is probably more
|
||||
//if (feeds.size() >= feedsNoPerCategory*3-1) {
|
||||
if (true) {
|
||||
if (feeds.size() >= feedsNoPerCategory*3-1) {
|
||||
GWT.log("Show MORE " + feedsNoPerCategory);
|
||||
showMoreUpdatesPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
|
||||
showMoreUpdatesPanel.add(new ShowMoreFeeds(eventBus));
|
||||
newsPanel.add(showMoreUpdatesPanel);
|
||||
}
|
||||
|
@ -492,35 +498,52 @@ public class NewsFeedPanel extends Composite {
|
|||
/**
|
||||
* called when a user click on show more updates
|
||||
*/
|
||||
protected void doShowMoreUpdates() {
|
||||
newsPanel.remove(showMoreUpdatesPanel);
|
||||
int from = allUpdates.size()+1;
|
||||
final int quantity = 5;
|
||||
GWT.log("AllUpdatesNo = " + from);
|
||||
newsService.getMoreFeeds(from, quantity, new AsyncCallback<ArrayList<EnhancedFeed>>() {
|
||||
protected void doShowMoreUpdates() {
|
||||
showMoreUpdatesPanel.remove(0);
|
||||
showMoreUpdatesPanel.add(loadingImage);
|
||||
int from = (fromStartingPoint == null) ? allUpdates.size()+1 : fromStartingPoint;
|
||||
|
||||
final int quantity = 10;
|
||||
GWT.log("StartingPoint = " + from);
|
||||
newsService.getMoreFeeds(from, quantity, new AsyncCallback<MoreFeedsBean>() {
|
||||
@Override
|
||||
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
|
||||
if (feeds != null) {
|
||||
public void onSuccess(MoreFeedsBean rangeFeeds) {
|
||||
newsPanel.remove(showMoreUpdatesPanel);
|
||||
if (rangeFeeds.getFeeds() != null) {
|
||||
fromStartingPoint = rangeFeeds.getLastReturnedFeedTimelineIndex();
|
||||
int c = 1;
|
||||
for (EnhancedFeed feed : feeds) {
|
||||
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
|
||||
allUpdates.add(feed); //in the model
|
||||
for (EnhancedFeed feed : rangeFeeds.getFeeds()) {
|
||||
if (!isFeedPresent(feed)) { //avoid possible duplicates
|
||||
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
|
||||
allUpdates.add(feed); //in the model
|
||||
}
|
||||
c++;
|
||||
}
|
||||
if (c >= quantity) { //there could be more feeds
|
||||
GWT.log("there could be more feeds");
|
||||
showMoreUpdatesPanel.clear();
|
||||
showMoreUpdatesPanel.add(new ShowMoreFeeds(eventBus));
|
||||
newsPanel.add(showMoreUpdatesPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
showMoreUpdatesPanel.clear();
|
||||
newsPanel.add(new HTML("<div class=\"nofeed-message\">" +
|
||||
"Ops! There were problems while retrieving your feeds!. <br> " +
|
||||
"Please try again in a short while.</div>"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isFeedPresent(EnhancedFeed toCheck) {
|
||||
for (EnhancedFeed feed : allUpdates) {
|
||||
if (feed.getFeed().getKey().compareTo(toCheck.getFeed().getKey()) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Only User Connections
|
||||
*/
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.gcube.portal.databook.server.DatabookStore;
|
|||
import org.gcube.portal.databook.shared.Comment;
|
||||
import org.gcube.portal.databook.shared.Feed;
|
||||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portal.databook.shared.RangeFeeds;
|
||||
import org.gcube.portal.databook.shared.UserInfo;
|
||||
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
||||
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
||||
|
@ -35,6 +36,7 @@ import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
|||
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
|
||||
import org.gcube.portlets.user.newsfeed.client.NewsService;
|
||||
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
|
||||
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
|
||||
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
|
||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
|
||||
|
@ -70,6 +72,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
|
||||
private static final String SESSION_ADMIN_ATTR = "SESSION_ADMIN_ATTR";
|
||||
private static final String USER_SETTINGS_ATTR = "USER_SETTINGS_ATTR";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -97,8 +100,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
if (user == null) {
|
||||
_log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL");
|
||||
user = "test.user";
|
||||
user = "massimiliano.assante";
|
||||
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
|
||||
// user = "massimiliano.assante";
|
||||
// SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/TestVREFolder2");
|
||||
}
|
||||
else {
|
||||
withinPortal = true;
|
||||
|
@ -309,20 +312,25 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
return new EnhancedFeed();
|
||||
}
|
||||
/**
|
||||
* MoreFeedsBean contains the timeline index of the last returned valid feed (because if you delete a feed is stays on in the timeline and is marked deleted)
|
||||
* and contains the Feeds
|
||||
* @param strat the range start (most recent feeds for this vre) has to be greater than 0
|
||||
* @param quantity the number of most recent feeds for this vre starting from "start" param
|
||||
*/
|
||||
@Override
|
||||
public ArrayList<EnhancedFeed> getMoreFeeds(int start, int quantity) {
|
||||
public MoreFeedsBean getMoreFeeds(int start, int quantity) {
|
||||
ArrayList<Feed> toMerge = new ArrayList<Feed>();
|
||||
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
|
||||
String vreid = getASLSession().getScope();
|
||||
_log.debug("Asking more feed for Timeline " + vreid + " from " + start + " get other " + quantity);
|
||||
ArrayList<Feed> OrganizationFeeds;
|
||||
_log.debug("\n\nAsking more feed for Timeline " + vreid + " from " + start + " get other " + quantity);
|
||||
ArrayList<Feed> organizationFeeds;
|
||||
RangeFeeds rangeFeeds = null;
|
||||
try {
|
||||
OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVREAndRange(vreid, start, quantity);
|
||||
for (Feed feed : OrganizationFeeds) {
|
||||
feedsMap.put(feed.getKey(), feed);
|
||||
rangeFeeds = store.getRecentFeedsByVREAndRange(vreid, start, quantity);
|
||||
organizationFeeds = rangeFeeds.getFeeds();
|
||||
for (Feed feed : organizationFeeds) {
|
||||
feedsMap.put(feed.getKey(), feed);
|
||||
//System.out.println("->\n"+feed.getDescription());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
@ -335,8 +343,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
}
|
||||
//sort the feeds in reverse chronological order
|
||||
Collections.sort(toMerge, Collections.reverseOrder());
|
||||
|
||||
return enhanceFeeds(toMerge, 2);
|
||||
ArrayList<EnhancedFeed> toReturn = enhanceFeeds(toMerge, 2);
|
||||
return new MoreFeedsBean(rangeFeeds.getLastReturnedFeedTimelineIndex(), toReturn);
|
||||
}
|
||||
/**
|
||||
* just for testing purposes
|
||||
|
@ -352,7 +360,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
ArrayList<Feed> toMerge = new ArrayList<Feed>();
|
||||
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
|
||||
|
||||
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE("/gcube/devsec/devVRE", 5);
|
||||
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(getASLSession().getScope(), 5);
|
||||
for (Feed feed : OrganizationFeeds) {
|
||||
feedsMap.put(feed.getKey(), feed);
|
||||
_log.trace("Reading desc: " + feed.getDescription());
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package org.gcube.portlets.user.newsfeed.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class MoreFeedsBean implements Serializable {
|
||||
private int lastReturnedFeedTimelineIndex;
|
||||
private ArrayList<EnhancedFeed> feeds;
|
||||
|
||||
public MoreFeedsBean() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MoreFeedsBean(int lastReturnedFeedTimelineIndex,
|
||||
ArrayList<EnhancedFeed> feeds) {
|
||||
super();
|
||||
this.lastReturnedFeedTimelineIndex = lastReturnedFeedTimelineIndex;
|
||||
this.feeds = feeds;
|
||||
}
|
||||
|
||||
public int getLastReturnedFeedTimelineIndex() {
|
||||
return lastReturnedFeedTimelineIndex;
|
||||
}
|
||||
public void setLastReturnedFeedTimelineIndex(int lastReturnedFeedTimelineIndex) {
|
||||
this.lastReturnedFeedTimelineIndex = lastReturnedFeedTimelineIndex;
|
||||
}
|
||||
public ArrayList<EnhancedFeed> getFeeds() {
|
||||
return feeds;
|
||||
}
|
||||
public void setFeeds(ArrayList<EnhancedFeed> feeds) {
|
||||
this.feeds = feeds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MoreFeedsBean [lastReturnedFeedTimelineIndex="
|
||||
+ lastReturnedFeedTimelineIndex + ", feeds=" + feeds + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue