partially implemented get more feeds but still buggy

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@93003 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-03-11 18:29:39 +00:00
parent 8ccca59096
commit fc97c11bba
10 changed files with 197 additions and 32 deletions

View File

@ -4,9 +4,6 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<dependent-module archiveName="wsmail-widget-1.4.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/wsmail-widget/wsmail-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/> <property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="news-feed"/> <property name="context-root" value="news-feed"/>
</wb-module> </wb-module>

View File

@ -24,6 +24,8 @@ public interface NewsService extends RemoteService {
ArrayList<EnhancedFeed> getOnlyLikedFeeds(); ArrayList<EnhancedFeed> getOnlyLikedFeeds();
ArrayList<EnhancedFeed> getMoreFeeds(int from, int quantity);
boolean like(String feedid, String feedText, String feedOwnerId); boolean like(String feedid, String feedText, String feedOwnerId);
boolean deleteComment(String commentid, String feedid); boolean deleteComment(String commentid, String feedid);

View File

@ -46,5 +46,8 @@ public interface NewsServiceAsync {
void getOnlyLikedFeeds(AsyncCallback<ArrayList<EnhancedFeed>> callback); void getOnlyLikedFeeds(AsyncCallback<ArrayList<EnhancedFeed>> callback);
void getSingleFeed(String feedKey, AsyncCallback<EnhancedFeed> callback); void getSingleFeed(String feedKey, AsyncCallback<EnhancedFeed> callback);
void getMoreFeeds(int from, int quantity,
AsyncCallback<ArrayList<EnhancedFeed>> callback);
} }

View File

@ -0,0 +1,21 @@
package org.gcube.portlets.user.newsfeed.client.event;
import com.google.gwt.event.shared.GwtEvent;
public class ShowMoreUpdatesEvent extends GwtEvent<ShowMoreUpdatesEventHandler> {
public static Type<ShowMoreUpdatesEventHandler> TYPE = new Type<ShowMoreUpdatesEventHandler>();
public ShowMoreUpdatesEvent() { }
@Override
public Type<ShowMoreUpdatesEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(ShowMoreUpdatesEventHandler handler) {
handler.onShowMoreUpdatesClick(this);
}
}

View File

@ -0,0 +1,7 @@
package org.gcube.portlets.user.newsfeed.client.event;
import com.google.gwt.event.shared.EventHandler;
public interface ShowMoreUpdatesEventHandler extends EventHandler {
void onShowMoreUpdatesClick(ShowMoreUpdatesEvent event);
}

View File

@ -31,10 +31,13 @@ import org.gcube.portlets.user.newsfeed.client.event.SeeCommentsEvent;
import org.gcube.portlets.user.newsfeed.client.event.SeeCommentsEventHandler; import org.gcube.portlets.user.newsfeed.client.event.SeeCommentsEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.SeeLikesEvent; import org.gcube.portlets.user.newsfeed.client.event.SeeLikesEvent;
import org.gcube.portlets.user.newsfeed.client.event.SeeLikesEventHandler; import org.gcube.portlets.user.newsfeed.client.event.SeeLikesEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.ShowMoreUpdatesEvent;
import org.gcube.portlets.user.newsfeed.client.event.ShowMoreUpdatesEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEvent; import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEvent;
import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEventHandler; import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEventHandler;
import org.gcube.portlets.user.newsfeed.client.templates.FilterPanel; import org.gcube.portlets.user.newsfeed.client.templates.FilterPanel;
import org.gcube.portlets.user.newsfeed.client.templates.NewFeedsAvailable; import org.gcube.portlets.user.newsfeed.client.templates.NewFeedsAvailable;
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.SingleComment;
import org.gcube.portlets.user.newsfeed.client.templates.TweetTemplate; import org.gcube.portlets.user.newsfeed.client.templates.TweetTemplate;
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed; import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
@ -78,6 +81,7 @@ public class NewsFeedPanel extends Composite {
private HorizontalPanel filterPanelWrapper = new HorizontalPanel(); private HorizontalPanel filterPanelWrapper = new HorizontalPanel();
private FilterPanel filterPanel; private FilterPanel filterPanel;
private SimplePanel newUpdatesPanel = new SimplePanel(); private SimplePanel newUpdatesPanel = new SimplePanel();
private SimplePanel showMoreUpdatesPanel = new SimplePanel();
private VerticalPanel newsPanel = new VerticalPanel(); private VerticalPanel newsPanel = new VerticalPanel();
private NewFeedsAvailable newsFeedAlert; private NewFeedsAvailable newsFeedAlert;
@ -118,7 +122,13 @@ public class NewsFeedPanel extends Composite {
* events binder * events binder
*/ */
private void bind() { private void bind() {
eventBus.addHandler(ShowMoreUpdatesEvent.TYPE, new ShowMoreUpdatesEventHandler() {
@Override
public void onShowMoreUpdatesClick(ShowMoreUpdatesEvent event) {
doShowMoreUpdates();
}
});
eventBus.addHandler(ShowNewUpdatesEvent.TYPE, new ShowNewUpdatesEventHandler() { eventBus.addHandler(ShowNewUpdatesEvent.TYPE, new ShowNewUpdatesEventHandler() {
@Override @Override
public void onShowNewUpdatesClick(ShowNewUpdatesEvent event) { public void onShowNewUpdatesClick(ShowNewUpdatesEvent event) {
@ -357,6 +367,7 @@ public class NewsFeedPanel extends Composite {
}); });
} }
/** /**
* called when a user click on the are new updates * called when a user click on the are new updates
*/ */
@ -448,11 +459,18 @@ public class NewsFeedPanel extends Composite {
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT); newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP); newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
for (EnhancedFeed feed : feeds) { for (EnhancedFeed feed : feeds) {
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
allUpdates.add(feed); allUpdates.add(feed); //in the model
} }
if (feeds.size() < 5) { if (feeds.size() < 5) {
newsPanel.add(new Image(spacer)); 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) {
GWT.log("Show MORE " + feedsNoPerCategory);
showMoreUpdatesPanel.add(new ShowMoreFeeds(eventBus));
newsPanel.add(showMoreUpdatesPanel);
} }
isFirstTweet = false; isFirstTweet = false;
} }
@ -471,7 +489,38 @@ 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>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
if (feeds != null) {
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
c++;
}
if (c >= quantity) { //there could be more feeds
GWT.log("there could be more feeds");
newsPanel.add(showMoreUpdatesPanel);
}
}
}
@Override
public void onFailure(Throwable caught) {
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>"));
}
});
}
/** /**
* Only User Connections * Only User Connections
*/ */

View File

@ -0,0 +1,47 @@
package org.gcube.portlets.user.newsfeed.client.templates;
import org.gcube.portlets.user.newsfeed.client.event.ShowMoreUpdatesEvent;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
public class ShowMoreFeeds extends Composite {
private static NewFeedsAvailableUiBinder uiBinder = GWT
.create(NewFeedsAvailableUiBinder.class);
interface NewFeedsAvailableUiBinder extends
UiBinder<Widget, ShowMoreFeeds> {
}
private HandlerManager eventBus;
@UiField HTML caption;
@UiField HTMLPanel panel;
public ShowMoreFeeds(HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
this.eventBus = eventBus;
panel.getElement().getStyle().setMarginTop(10, Unit.PX);
caption.addStyleName("new-feeds-show");
caption.getElement().getStyle().setBackgroundColor("transparent");
caption.getElement().getStyle().setFontSize(14, Unit.PX);
caption.setHTML("Show more feeds");
}
@UiHandler("caption")
void onClick(ClickEvent e) {
eventBus.fireEvent(new ShowMoreUpdatesEvent());
}
}

View File

@ -0,0 +1,7 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel ui:field="panel" styleName="new-feeds-container">
<g:HTML ui:field="caption" styleName="new-feeds-available" />
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -98,7 +98,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
_log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL"); _log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL");
user = "test.user"; user = "test.user";
user = "massimiliano.assante"; user = "massimiliano.assante";
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devVRE/testvrefolder2"); SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
} }
else { else {
withinPortal = true; withinPortal = true;
@ -308,8 +308,36 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
} }
return new EnhancedFeed(); return new EnhancedFeed();
} }
/**
* @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) {
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;
try {
OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVREAndRange(vreid, start, quantity);
for (Feed feed : OrganizationFeeds) {
feedsMap.put(feed.getKey(), feed);
}
}
catch (Exception e) {
e.printStackTrace();
return null;
}
for (String key: feedsMap.keySet()) {
toMerge.add(feedsMap.get(key));
}
//sort the feeds in reverse chronological order
Collections.sort(toMerge, Collections.reverseOrder());
return enhanceFeeds(toMerge, 2);
}
/** /**
* just for testing purposes * just for testing purposes
* *
@ -324,29 +352,29 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
ArrayList<Feed> toMerge = new ArrayList<Feed>(); ArrayList<Feed> toMerge = new ArrayList<Feed>();
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>(); HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE("/gcube/devsec/devVRE", 10); ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE("/gcube/devsec/devVRE", 5);
for (Feed feed : OrganizationFeeds) { for (Feed feed : OrganizationFeeds) {
feedsMap.put(feed.getKey(), feed); feedsMap.put(feed.getKey(), feed);
_log.trace("Reading desc: " + feed.getDescription()); _log.trace("Reading desc: " + feed.getDescription());
} }
if (! onlyConnections) { // if (! onlyConnections) {
//User Own Feeds // //User Own Feeds
ArrayList<Feed> userFeeds = (ArrayList<Feed>) store.getRecentFeedsByUser(userName, 10); // ArrayList<Feed> userFeeds = (ArrayList<Feed>) store.getRecentFeedsByUser(userName, 10);
for (Feed feed : userFeeds) // for (Feed feed : userFeeds)
feedsMap.put(feed.getKey(), feed); // feedsMap.put(feed.getKey(), feed);
// //Portal Feeds // // //Portal Feeds
ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds(); // ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds();
for (Feed feed : portalFeeds) // for (Feed feed : portalFeeds)
feedsMap.put(feed.getKey(), feed); // feedsMap.put(feed.getKey(), feed);
} // }
//UserFriends Feeds // //UserFriends Feeds
ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName); // ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName);
for (String userid : userFriendsIds) { // for (String userid : userFriendsIds) {
for (Feed feed : store.getRecentFeedsByUser(userid, 10)) { // for (Feed feed : store.getRecentFeedsByUser(userid, 10)) {
feedsMap.put(feed.getKey(), feed); // feedsMap.put(feed.getKey(), feed);
} // }
} // }
for (String key: feedsMap.keySet()) { for (String key: feedsMap.keySet()) {
toMerge.add(feedsMap.get(key)); toMerge.add(feedsMap.get(key));
} }
@ -744,7 +772,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
int minutes = 0; int minutes = 0;
String label = ""; String label = "";
boolean showTimelineSource = true; boolean showTimelineSource = true;
String propertyfile = ""; String propertyfile = "";
try { try {
ServletContext servletContext = getServletContext(); ServletContext servletContext = getServletContext();
@ -766,14 +794,14 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
label = props.getProperty(VRE_LABEL); label = props.getProperty(VRE_LABEL);
try { try {
showTimelineSource = Boolean.parseBoolean(props.getProperty(SHOW_TIMELINE_SOURCE)); showTimelineSource = Boolean.parseBoolean(props.getProperty(SHOW_TIMELINE_SOURCE));
} }
//catch exception in case the property value isNot true or false //catch exception in case the property value isNot true or false
catch (ClassCastException ex) { catch (ClassCastException ex) {
showTimelineSource = true; showTimelineSource = true;
_log.error(showTimelineSource + " must be true or false, returning true"); _log.error(showTimelineSource + " must be true or false, returning true");
} }
} }
//catch exception in case properties file does not exist //catch exception in case properties file does not exist
catch(IOException e) { catch(IOException e) {
@ -785,4 +813,6 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return new CustomConfiguration(minutes, label, showTimelineSource); return new CustomConfiguration(minutes, label, showTimelineSource);
} }
} }

View File

@ -7,4 +7,6 @@ log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# Print only messages of level TRACE or above in the package org.gcube # Print only messages of level TRACE or above in the package org.gcube
log4j.logger.org.gcube=TRACE log4j.logger.org.gcube=TRACE
log4j.logger.org.gcube.application.framework.core.session=INFO log4j.logger.org.gcube.application.framework.core.session=INFO
log4j.logger.org.gcube.common.scope.impl.DefaultScopeProvider=ERROR
log4j.logger.com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor=ERROR