" +
+ "We're sorry, it seems you used an invalid character, please check the query
"));
+ return;
+ }
+ // show
+ showFeedsSearch(query, 0, SEARCHED_FEEDS_TO_SHOW);
+ filterPanel.removeFilterSelected();
}
else {
showAllUpdatesFeeds();
@@ -311,7 +326,7 @@ public class NewsFeedPanel extends Composite {
else
mainPanel.addStyleName("framed");
- }
+ }
});
feedsTimer = new Timer() {
@@ -372,6 +387,15 @@ 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
+ */
+ private String getSearchParam() {
+ return Window.Location.getParameter(Encoder.encode(GCubeSocialNetworking.SEARCH_OID));
+ }
+
/**
* used from notification referrals (see this Post)
* @param feedKey
@@ -531,6 +555,65 @@ public class NewsFeedPanel extends Composite {
}
});
}
+
+ /**
+ * Called when a user search something
+ */
+ private void showFeedsSearch(final String query, final int from, final int to) {
+ showLoader();
+ newsService.getUserSettings(new AsyncCallback
() {
+ @Override
+ public void onFailure(Throwable caught) {
+ doStopFeedsTimer();
+ }
+ @Override
+ public void onSuccess(UserSettings result) {
+ if (result.getUserInfo().getUsername().equals(NewsConstants.TEST_USER)) {
+ doStopFeedsTimer();
+ doShowSessionExpired();
+ } else {
+ /**
+ * this check avoids the 2 tabs open in 2 different scope, if the previous tab was open at VRE Level and then antoher
+ * is open at infra level the first tab stops checking for updates
+ */
+ if (result.getCurrentScope().compareTo(currentScope) == 0) {
+ newsService.getFeedsByQuery(query, from, to, new AsyncCallback>() {
+ @Override
+ public void onSuccess(ArrayList feeds) {
+ filterPanelWrapper.setVisible(false);
+ newsPanel.clear();
+ if (feeds != null) {
+ if (feeds.size() == 0) {
+ newsPanel.add(new ResultsFor("results for", query));
+ newsPanel.add(new HTML("" +
+ "Sorry, looks like we found no updates for: " + query +"
"));
+ }
+ else {
+ newsPanel.setHeight("");
+ newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
+ newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
+ newsPanel.add(new ResultsFor("results for", query));
+ for (EnhancedFeed feed : feeds) {
+ newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
+ }
+ if (feeds.size() < 5) {
+ newsPanel.add(new Image(spacer));
+ }
+ }
+ } else {
+ showProblems();
+ }
+ }
+ @Override
+ public void onFailure(Throwable caught) {
+ showProblems();
+ }
+ });
+ }
+ }
+ }
+ });
+ }
/**
* called when a user click on the are new updates
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
index b8c36b4..d2edb50 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
@@ -12,6 +12,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
+import java.util.Set;
import java.util.UUID;
import javax.servlet.ServletContext;
@@ -48,6 +49,7 @@ import org.gcube.portlets.user.newsfeed.shared.NewsConstants;
import org.gcube.portlets.user.newsfeed.shared.OperationResult;
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
+import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClientImpl;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
import org.slf4j.Logger;
@@ -87,16 +89,29 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
private String APP_ID;
-
/**
- *
+ * Cassandra client
*/
private DatabookStore store;
+ /**
+ * Elasticsearch client
+ */
+ private ElasticSearchClientImpl el;
+
private final static int MAX_FEEDS_NO = 45;
public void init() {
store = new DBCassandraAstyanaxImpl();
+
+ try {
+ el = new ElasticSearchClientImpl(null);
+ _log.info("Elasticsearch connection created");
+ } catch (Exception e) {
+ el = null;
+ _log.error("Unable to create elasticsearch client connection!!!", e);
+ }
+
APP_ID = this.getClass().getName();
}
@@ -124,7 +139,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
*/
public String getDevelopmentUser() {
String user = NewsConstants.TEST_USER;
-// user = "costantino.perciante";
+ user = "costantino.perciante";
return user;
}
/**
@@ -370,6 +385,70 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return null;
}
+ @Override
+ public ArrayList getFeedsByQuery(String query, int from, int to) {
+
+ // TODO : check this error better
+ if(el == null){
+
+ _log.debug("There is no connection to elasticsearch, sorry.");
+ return null;
+
+ }
+
+ ASLSession session = getASLSession();
+ String userName = session.getUsername();
+ try {
+ //in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info)
+ //this check just return nothing if that happens
+ if (userName.compareTo("test.user") == 0) {
+ _log.debug("Found " + userName + " returning nothing");
+ return null;
+ }
+
+ // Retrieve user's vres in which we must search
+ Set vres = new HashSet();
+
+ if (isInfrastructureScope()) {
+ User currUser = OrganizationsUtil.validateUser(userName);
+ for (Organization org : currUser.getOrganizations()) {
+ GroupManager gm = new LiferayGroupManager();
+ if (gm.isVRE(org.getOrganizationId()+"")) {
+ String vreid = gm.getScope(""+org.getOrganizationId()); //get the scope
+ vres.add(vreid);
+ }
+ }
+ }
+ //else must be in a VRE scope
+ else {
+ vres.add(session.getScopeName());
+ }
+
+ // query elastic search
+ List enhancedFeeds = el.searchInEnhancedFeeds(query, vres, from, to);
+
+ // retrieve the ids of liked feeds by the user
+ List likedFeeds = store.getAllLikedFeedIdsByUser(userName);
+
+ // update fields "liked" and "isuser"
+ for (EnhancedFeed enhancedFeed : enhancedFeeds) {
+
+ if(isUsers(enhancedFeed.getFeed(), userName))
+ enhancedFeed.setUsers(true);
+
+ if(likedFeeds.contains(enhancedFeed.getFeed().getKey()))
+ enhancedFeed.setLiked(true);
+
+ }
+
+ return (ArrayList) enhancedFeeds;
+
+ }catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
/**
* return only the user connection feeds
@@ -794,9 +873,6 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return thumbnailURL.append(user.getPortraitId()).toString();
}
-
-
-
@Override
public ArrayList getAllLikesByFeed(String feedid) {
ArrayList toReturn = (ArrayList) store.getAllLikesByFeed(feedid);