Support for search (on elasticsearch index) added.

Guava and compress-lzf dependencies have been set to compile, since newer versions are needed for elasticsearch to work

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@124195 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-02-15 14:37:58 +00:00
parent b4197ceec3
commit 2407ec528a
7 changed files with 142 additions and 65 deletions

View File

@ -4,12 +4,6 @@
<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="/target/generated-sources/gwt"/>
<dependent-module archiveName="social-data-search-client-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/social-data-search-client/social-data-search-client">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="social-data-indexing-common-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/social-data-indexing-common/social-data-indexing-common">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="news-feed"/>
</wb-module>

View File

@ -3,6 +3,7 @@
date="2016-01-22">
<Change>Multi-attachment supported</Change>
<Change>Image preview available</Change>
<Change>Search functionality supported</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.newsfeed.1-12-0"
date="2015-11-12">

38
pom.xml
View File

@ -74,6 +74,28 @@
<artifactId>accesslogger</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guavaVersion}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.ning</groupId>
<artifactId>compress-lzf</artifactId>
<version>1.0.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.socialnetworking</groupId>
<artifactId>social-data-search-client</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
@ -114,22 +136,6 @@
<artifactId>notifications-common-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>{guavaVersion}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.socialnetworking</groupId>
<artifactId>social-data-search-client</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>user-selection-dialog</artifactId>

View File

@ -29,7 +29,7 @@ public interface NewsService extends RemoteService {
ArrayList<EnhancedFeed> getFeedsByHashtag(String hashtag);
ArrayList<EnhancedFeed> getFeedsByQuery(String query, int from, int to);
ArrayList<EnhancedFeed> getFeedsByQuery(String query, int from, int quantity);
MoreFeedsBean getMoreFeeds(int from, int quantity);

View File

@ -64,7 +64,7 @@ public interface NewsServiceAsync {
void getFeedsByHashtag(String hashtag,
AsyncCallback<ArrayList<EnhancedFeed>> callback);
void getFeedsByQuery(String query, int from, int to,
void getFeedsByQuery(String query, int from, int quantity,
AsyncCallback<ArrayList<EnhancedFeed>> callback);
}

View File

@ -119,7 +119,7 @@ public class NewsFeedPanel extends Composite {
public static final String LIKED_LABEL = "Favorited";
public static final String COMMENT_LABEL = "Reply";
public static final String SHARE_FWD_LABEL = "Share";
private static final int SEARCHED_FEEDS_TO_SHOW = 20;
private static final int SEARCHED_FEEDS_TO_SHOW = 10;
private String vreLabel;
@ -132,6 +132,12 @@ public class NewsFeedPanel extends Composite {
private boolean isFirstTweet = false;
// is user searching for something?
private boolean isSearch = false;
// the current query (if isSearch is true)
protected String currentQuery;
private LoadingText loadingIcon = new LoadingText();
private Image loadingImage;
private UserInfo myUserInfo;
@ -261,6 +267,7 @@ public class NewsFeedPanel extends Composite {
loadingImage = new Image(loading);
newsPanel.add(loadingIcon);
CheckSession.getInstance().startPolling();
isSearch = false;
newsService.getUserSettings(new AsyncCallback<UserSettings>() {
@Override
@ -298,10 +305,10 @@ public class NewsFeedPanel extends Composite {
filterPanel.removeFilterSelected();
}
else if (getSearchParam() != null) {
// TODO
String query = "";
try {
query = Encoder.decode(getSearchParam());
currentQuery = query;
} catch (Exception e) {
newsPanel.clear();
newsPanel.add(new HTML("<div class=\"nofeed-message\"><div style=\"padding-top: 90px;\">" +
@ -309,6 +316,7 @@ public class NewsFeedPanel extends Composite {
return;
}
// show
isSearch = true;
showFeedsSearch(query, 0, SEARCHED_FEEDS_TO_SHOW);
filterPanel.removeFilterSelected();
}
@ -387,7 +395,7 @@ public class NewsFeedPanel extends Composite {
private String getHashtagParam() {
return Window.Location.getParameter(Encoder.encode(GCubeSocialNetworking.HASHTAG_OID));
}
/**
* check if it has to show the feeds given a query
* @return
@ -395,7 +403,7 @@ public class NewsFeedPanel extends Composite {
private String getSearchParam() {
return Window.Location.getParameter(Encoder.encode(GCubeSocialNetworking.SEARCH_OID));
}
/**
* used from notification referrals (see this Post)
* @param feedKey
@ -555,21 +563,25 @@ public class NewsFeedPanel extends Composite {
}
});
}
/**
* Called when a user search something
*/
private void showFeedsSearch(final String query, final int from, final int to) {
// show loader while waiting
showLoader();
// stop asking for feeds
doStopFeedsTimer();
newsService.getUserSettings(new AsyncCallback<UserSettings>() {
@Override
public void onFailure(Throwable caught) {
doStopFeedsTimer();
}
@Override
public void onSuccess(UserSettings result) {
if (result.getUserInfo().getUsername().equals(NewsConstants.TEST_USER)) {
doStopFeedsTimer();
doShowSessionExpired();
} else {
/**
@ -583,6 +595,8 @@ public class NewsFeedPanel extends Composite {
filterPanelWrapper.setVisible(false);
newsPanel.clear();
if (feeds != null) {
GWT.log("Retrieved " + feeds.size() + " hits for search.");
if (feeds.size() == 0) {
newsPanel.add(new ResultsFor("results for", query));
newsPanel.add(new HTML("<div class=\"nofeed-message\" style=\"height: 200px;\">" +
@ -595,10 +609,21 @@ public class NewsFeedPanel extends Composite {
newsPanel.add(new ResultsFor("results for", query));
for (EnhancedFeed feed : feeds) {
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
// save them (they will be used when asking more feeds)
allUpdates.add(feed);
}
if (feeds.size() < 5) {
newsPanel.add(new Image(spacer));
}
}
// add widget to lookup more feeds: if the size of the returned data is less
// than the required disable this feature.
if(feeds.size() == SEARCHED_FEEDS_TO_SHOW){
showMoreUpdatesPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
showMoreWidget = new ShowMoreFeeds(eventBus);
showMoreUpdatesPanel.add(showMoreWidget);
newsPanel.add(showMoreUpdatesPanel);
}
}
} else {
showProblems();
@ -640,7 +665,7 @@ public class NewsFeedPanel extends Composite {
// one or more feed belongs to user himself
if(tt.isUser()){
try{
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postIncrement, "", Defaults.STRING_JSONIZER);
int numComments = tt.numberOfComments();
@ -792,44 +817,95 @@ public class NewsFeedPanel extends Composite {
* called when a user scroll down the page to the bottom
*/
protected void doShowMoreUpdates() {
showMoreUpdatesPanel.remove(0);
loadingImage.getElement().getStyle().setMargin(10, Unit.PX);
showMoreUpdatesPanel.add(loadingIcon);
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(MoreFeedsBean rangeFeeds) {
newsPanel.remove(showMoreUpdatesPanel);
if (rangeFeeds.getFeeds() != null) {
fromStartingPoint = rangeFeeds.getLastReturnedFeedTimelineIndex();
int c = 1;
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
if(isSearch){
GWT.log("Going to request more feeds for this search");
// start position
int start = allUpdates.size();
GWT.log("StartingPoint = " + start);
newsService.getFeedsByQuery(currentQuery, start, SEARCHED_FEEDS_TO_SHOW , new AsyncCallback<ArrayList<EnhancedFeed>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> feeds){
newsPanel.remove(showMoreUpdatesPanel);
if (feeds != null) {
GWT.log("There are " + feeds.size() + " more feeds");
for (EnhancedFeed feed : feeds) {
// avoid to insert same data
if(!isFeedPresent(feed)){
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
allUpdates.add(feed);
}
}
c++;
}
if (c >= quantity) { //there could be more feeds
GWT.log("there could be more feeds");
// clear panel
showMoreUpdatesPanel.clear();
showMoreWidget = new ShowMoreFeeds(eventBus);
showMoreUpdatesPanel.add(showMoreWidget);
newsPanel.add(showMoreUpdatesPanel);
// check if we can ask for other data
if(feeds.size() == SEARCHED_FEEDS_TO_SHOW){
GWT.log("It seems there are no more feeds for this query. Stop asking further");
showMoreWidget = new ShowMoreFeeds(eventBus);
showMoreUpdatesPanel.add(showMoreWidget);
newsPanel.add(showMoreUpdatesPanel);
}else{
showMoreWidget = null;
}
}
}
}
@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>"));
}
});
@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>"));
}
});
}
else{
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(MoreFeedsBean rangeFeeds) {
newsPanel.remove(showMoreUpdatesPanel);
if (rangeFeeds.getFeeds() != null) {
fromStartingPoint = rangeFeeds.getLastReturnedFeedTimelineIndex();
int c = 1;
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();
showMoreWidget = new ShowMoreFeeds(eventBus);
showMoreUpdatesPanel.add(showMoreWidget);
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>"));
}
});
}
}
/**
* @param widget the widget to check

View File

@ -386,7 +386,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
@Override
public ArrayList<EnhancedFeed> getFeedsByQuery(String query, int from, int to) {
public ArrayList<EnhancedFeed> getFeedsByQuery(String query, int from, int quantity) {
// TODO : check this error better
if(el == null){
@ -425,7 +425,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
// query elastic search
List<EnhancedFeed> enhancedFeeds = el.searchInEnhancedFeeds(query, vres, from, to);
List<EnhancedFeed> enhancedFeeds = el.searchInEnhancedFeeds(query, vres, from, quantity);
// retrieve the ids of liked feeds by the user
List<String> likedFeeds = store.getAllLikedFeedIdsByUser(userName);