fix for hashtags' feeds filter per site

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@132179 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-09-30 12:11:30 +00:00
parent 3141795b1c
commit ef7215c895
2 changed files with 45 additions and 46 deletions

View File

@ -5,15 +5,6 @@
<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"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="gcube-widgets-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="social-util-library-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/social-util-library/social-util-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="session-checker-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<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

@ -332,40 +332,48 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
public ArrayList<EnhancedFeed> getFeedsByHashtag(String hashtag) { public ArrayList<EnhancedFeed> getFeedsByHashtag(String hashtag) {
ASLSession session = getASLSession(); ASLSession session = getASLSession();
String userName = session.getUsername(); String userName = session.getUsername();
ArrayList<Feed> toMerge = new ArrayList<Feed>(); String currentScope = session.getScopeName();
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
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;
}
//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(NewsConstants.TEST_USER) == 0) {
_log.debug("Found " + userName + " returning nothing");
return null;
}
try {
ArrayList<Feed> toMerge = new ArrayList<Feed>();
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
String lowerCaseHashtag = hashtag.toLowerCase(); String lowerCaseHashtag = hashtag.toLowerCase();
/** // the contexts of the user
* this handles the case where the portlet is deployed outside of VREs (regular) List<String> contexts = new ArrayList<String>();
*/
//this handles the case where the portlet is deployed outside of VREs (regular)
if (isInfrastructureScope()) { if (isInfrastructureScope()) {
UserManager um = new LiferayUserManager();
GCubeUser currUser = um.getUserByUsername(userName);
//VRE Feeds
GroupManager gm = new LiferayGroupManager(); GroupManager gm = new LiferayGroupManager();
for (GCubeGroup group : gm.listGroupsByUser(currUser.getUserId())) { UserManager um = new LiferayUserManager();
if (gm.isVRE(group.getGroupId())) { GCubeUser user = um.getUserByUsername(userName);
String vreid = gm.getInfrastructureScope(group.getGroupId()); //get the scope Set<GCubeGroup> vresInPortal = gm.listGroupsByUserAndSite(user.getUserId(), getThreadLocalRequest().getServerName());
ArrayList<Feed> feeds = (ArrayList<Feed>) store.getVREFeedsByHashtag(vreid, lowerCaseHashtag); _log.debug("Contexts in this site are per user " + vresInPortal);
for (Feed feed : feeds) {
feedsMap.put(feed.getKey(), feed); // get the scopes associated with such groups
} for (GCubeGroup gCubeGroup : vresInPortal) {
} contexts.add(gm.getInfrastructureScope(gCubeGroup.getGroupId()));
} }
} }
//else must be in a VRE scope
else { else {
String vreid = session.getScopeName();
ArrayList<Feed> feeds = (ArrayList<Feed>) store.getVREFeedsByHashtag(vreid, lowerCaseHashtag); contexts.add(currentScope);
}
_log.debug("Contexts for hashtags is " + contexts);
for (String context : contexts) {
ArrayList<Feed> feeds = (ArrayList<Feed>) store.getVREFeedsByHashtag(context, lowerCaseHashtag);
for (Feed feed : feeds) { for (Feed feed : feeds) {
feedsMap.put(feed.getKey(), feed); feedsMap.put(feed.getKey(), feed);
} }
@ -388,16 +396,13 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
} }
return enhanceFeeds(toReturn, 2); return enhanceFeeds(toReturn, 2);
} catch (PrivacyLevelTypeNotFoundException e) { } catch (PrivacyLevelTypeNotFoundException e) {
_log.error("Privacy Level not Found " + e.getMessage()); _log.error("Privacy Level not Found ", e);
e.printStackTrace();
} catch (FeedTypeNotFoundException e) { } catch (FeedTypeNotFoundException e) {
_log.error("Feed Type not Found " + e.getMessage()); _log.error("Feed Type not Found ", e);
e.printStackTrace();
} catch (ColumnNameNotFoundException e) { } catch (ColumnNameNotFoundException e) {
_log.error("Column name not Found " + e.getMessage()); _log.error("Column name not Found ", e);
e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); _log.error("Error while retrieving feeds for hashtag ", e);
} }
return null; return null;
} }
@ -408,17 +413,20 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
// TODO : check this error better // TODO : check this error better
if(escl == null){ if(escl == null){
_log.debug("There is no connection to elasticsearch, sorry."); _log.warn("There is no connection to elasticsearch, sorry.");
return null; return null;
} }
ASLSession session = getASLSession(); ASLSession session = getASLSession();
String userName = session.getUsername(); String userName = session.getUsername();
String currentScope = session.getScopeName();
try { 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) //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 //this check just return nothing if that happens
if (userName.compareTo("test.user") == 0) { if (userName.compareTo(NewsConstants.TEST_USER) == 0) {
_log.debug("Found " + userName + " returning nothing"); _log.debug("Found " + userName + " returning nothing");
return null; return null;
} }
@ -440,7 +448,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
} }
//else must be in a VRE scope //else must be in a VRE scope
else { else {
vres.add(session.getScopeName()); vres.add(currentScope);
} }
// query elastic search // query elastic search
@ -1181,7 +1189,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
default : return new ArrayList<EnhancedFeed>(); default : return new ArrayList<EnhancedFeed>();
} }
List<String> contexts = new ArrayList<String>(); List<String> contexts = new ArrayList<String>();
if(isInfrastructureScope()){ if(isInfrastructureScope()){