git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@124150 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
fe1361615c
commit
28bc6966d6
|
@ -4,13 +4,10 @@
|
|||
<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="session-checker-0.5.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
|
||||
<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="pickitem-widget-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/pickitem-widget/pickitem-widget">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="gcube-widgets-1.9.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
|
||||
<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"/>
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -113,6 +113,11 @@
|
|||
<artifactId>notifications-common-library</artifactId>
|
||||
<scope>provided</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>org.gcube.portlets.widgets</groupId>
|
||||
<artifactId>user-selection-dialog</artifactId>
|
||||
|
|
|
@ -29,6 +29,8 @@ public interface NewsService extends RemoteService {
|
|||
|
||||
ArrayList<EnhancedFeed> getFeedsByHashtag(String hashtag);
|
||||
|
||||
ArrayList<EnhancedFeed> getFeedsByQuery(String query, int from, int to);
|
||||
|
||||
MoreFeedsBean getMoreFeeds(int from, int quantity);
|
||||
|
||||
boolean like(String feedid, String feedText, String feedOwnerId);
|
||||
|
|
|
@ -63,5 +63,8 @@ public interface NewsServiceAsync {
|
|||
|
||||
void getFeedsByHashtag(String hashtag,
|
||||
AsyncCallback<ArrayList<EnhancedFeed>> callback);
|
||||
|
||||
void getFeedsByQuery(String query, int from, int to,
|
||||
AsyncCallback<ArrayList<EnhancedFeed>> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -119,6 +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 String vreLabel;
|
||||
|
||||
|
@ -259,7 +260,6 @@ public class NewsFeedPanel extends Composite {
|
|||
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
|
||||
loadingImage = new Image(loading);
|
||||
newsPanel.add(loadingIcon);
|
||||
|
||||
CheckSession.getInstance().startPolling();
|
||||
|
||||
newsService.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||
|
@ -296,6 +296,21 @@ public class NewsFeedPanel extends Composite {
|
|||
}
|
||||
showFeedsByHashtag(hashtag);
|
||||
filterPanel.removeFilterSelected();
|
||||
}
|
||||
else if (getSearchParam() != null) {
|
||||
// TODO
|
||||
String query = "";
|
||||
try {
|
||||
query = Encoder.decode(getSearchParam());
|
||||
} catch (Exception e) {
|
||||
newsPanel.clear();
|
||||
newsPanel.add(new HTML("<div class=\"nofeed-message\"><div style=\"padding-top: 90px;\">" +
|
||||
"We're sorry, it seems you used an invalid character, please check the query</div>"));
|
||||
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<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 {
|
||||
/**
|
||||
* 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<ArrayList<EnhancedFeed>>() {
|
||||
@Override
|
||||
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
|
||||
filterPanelWrapper.setVisible(false);
|
||||
newsPanel.clear();
|
||||
if (feeds != null) {
|
||||
if (feeds.size() == 0) {
|
||||
newsPanel.add(new ResultsFor("results for", query));
|
||||
newsPanel.add(new HTML("<div class=\"nofeed-message\" style=\"height: 200px;\">" +
|
||||
"Sorry, looks like we found no updates for: " + query +"</div>"));
|
||||
}
|
||||
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
|
||||
|
|
|
@ -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<EnhancedFeed> 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<String> vres = new HashSet<String>();
|
||||
|
||||
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<EnhancedFeed> enhancedFeeds = el.searchInEnhancedFeeds(query, vres, from, to);
|
||||
|
||||
// retrieve the ids of liked feeds by the user
|
||||
List<String> 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<EnhancedFeed>) 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<Like> getAllLikesByFeed(String feedid) {
|
||||
ArrayList<Like> toReturn = (ArrayList<Like>) store.getAllLikesByFeed(feedid);
|
||||
|
|
Loading…
Reference in New Issue