Feature #4792, filter per site added
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/user-statistics@132171 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b4b0e7c75f
commit
2d3a14f777
|
@ -1,9 +1,11 @@
|
||||||
package org.gcube.portlet.user.userstatisticsportlet.server;
|
package org.gcube.portlet.user.userstatisticsportlet.server;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||||
|
@ -18,10 +20,13 @@ import org.gcube.portlet.user.userstatisticsportlet.client.UserStatisticsService
|
||||||
import org.gcube.portlet.user.userstatisticsportlet.server.cache.UserInfrastructureSpaceCache;
|
import org.gcube.portlet.user.userstatisticsportlet.server.cache.UserInfrastructureSpaceCache;
|
||||||
import org.gcube.portlet.user.userstatisticsportlet.shared.PostsStatsBean;
|
import org.gcube.portlet.user.userstatisticsportlet.shared.PostsStatsBean;
|
||||||
import org.gcube.portlet.user.userstatisticsportlet.shared.UserInformation;
|
import org.gcube.portlet.user.userstatisticsportlet.shared.UserInformation;
|
||||||
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||||
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||||
import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
|
import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -51,6 +56,10 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
// custom field' name to remember action to take for the portlet deployed in the user profile TODO (make it a resource?)
|
// custom field' name to remember action to take for the portlet deployed in the user profile TODO (make it a resource?)
|
||||||
private static final String CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY = "show_user_statistics_other_people";
|
private static final String CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY = "show_user_statistics_other_people";
|
||||||
|
|
||||||
|
// User manager
|
||||||
|
private UserManager userManager = new LiferayUserManager();
|
||||||
|
private GroupManager groupManager = new LiferayGroupManager();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
|
|
||||||
|
@ -167,7 +176,7 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
long init = System.currentTimeMillis();
|
long init = System.currentTimeMillis();
|
||||||
|
|
||||||
// check if the avatar is present
|
// check if the avatar is present
|
||||||
boolean avatarPresent = (new LiferayUserManager().getUserAvatarBytes(statisticsOfUsername) != null);
|
boolean avatarPresent = (userManager.getUserAvatarBytes(statisticsOfUsername) != null);
|
||||||
|
|
||||||
User user = UserLocalServiceUtil.getUserByScreenName(SiteManagerUtil.getCompany().getCompanyId(), statisticsOfUsername);
|
User user = UserLocalServiceUtil.getUserByScreenName(SiteManagerUtil.getCompany().getCompanyId(), statisticsOfUsername);
|
||||||
profileStrenght = ServerUtils.evaluateProfileStrenght(user, avatarPresent);
|
profileStrenght = ServerUtils.evaluateProfileStrenght(user, avatarPresent);
|
||||||
|
@ -230,12 +239,9 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
boolean isInfrastructure = ServerUtils.isInfrastructureScope(userid, this.getThreadLocalRequest().getSession());
|
boolean isInfrastructure = ServerUtils.isInfrastructureScope(userid, this.getThreadLocalRequest().getSession());
|
||||||
logger.debug("User scope is " + (isInfrastructure ? " the whole infrastucture " : " a VRE"));
|
logger.debug("User scope is " + (isInfrastructure ? " the whole infrastucture " : " a VRE"));
|
||||||
|
|
||||||
// get path of the avatar
|
|
||||||
UserManager um = new LiferayUserManager();
|
|
||||||
|
|
||||||
String thumbnailURL = null;
|
String thumbnailURL = null;
|
||||||
try {
|
try {
|
||||||
thumbnailURL = um.getUserByUsername(statisticsOfUsername).getUserAvatarURL();
|
thumbnailURL = userManager.getUserByUsername(statisticsOfUsername).getUserAvatarURL();
|
||||||
} catch (UserManagementSystemException e) {
|
} catch (UserManagementSystemException e) {
|
||||||
logger.error("Unable to retrieve avatar url for user " + statisticsOfUsername, e);
|
logger.error("Unable to retrieve avatar url for user " + statisticsOfUsername, e);
|
||||||
} catch (UserRetrievalFault e) {
|
} catch (UserRetrievalFault e) {
|
||||||
|
@ -301,12 +307,7 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
|
|
||||||
//username
|
//username
|
||||||
String userName = session.getUsername();
|
String userName = session.getUsername();
|
||||||
|
String scope = session.getScope();
|
||||||
// retrieve statistics of...
|
|
||||||
String statisticsOfUsername = userName;
|
|
||||||
|
|
||||||
if(userid != null && !userid.equals(userName))
|
|
||||||
statisticsOfUsername = userid;
|
|
||||||
|
|
||||||
//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
|
||||||
|
@ -315,6 +316,12 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// retrieve statistics of...
|
||||||
|
String statisticsOfUsername = userName;
|
||||||
|
|
||||||
|
if(userid != null && !userid.equals(userName))
|
||||||
|
statisticsOfUsername = userid;
|
||||||
|
|
||||||
long feedsMade = 0, likesGot = 0, commentsGot = 0, commentsMade = 0, likesMade = 0;
|
long feedsMade = 0, likesGot = 0, commentsGot = 0, commentsMade = 0, likesMade = 0;
|
||||||
|
|
||||||
// check if the user is or not in a VRE
|
// check if the user is or not in a VRE
|
||||||
|
@ -329,21 +336,46 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
try {
|
try {
|
||||||
|
|
||||||
long init = System.currentTimeMillis();
|
long init = System.currentTimeMillis();
|
||||||
|
long userId = userManager.getUserId(statisticsOfUsername);
|
||||||
|
|
||||||
logger.debug("Getting " + statisticsOfUsername + " feeds in the last year.");
|
logger.debug("Retrieving " + statisticsOfUsername + "'s statistics in the last year.");
|
||||||
|
|
||||||
// retrieve the most recent user's feeds
|
// retrieve the most recent user's feeds
|
||||||
List<Feed> userFeeds = store.getRecentFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTime().getTime());
|
List<Feed> userFeeds = store.getRecentFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTime().getTime());
|
||||||
|
|
||||||
logger.debug("Evaluating number of comments and likes of " + statisticsOfUsername + "'s feeds.");
|
// retrieve the most recent user's liked feeds
|
||||||
|
List<Feed> recentLikedFeeds = store.getRecentLikedFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTime().getTime());
|
||||||
|
|
||||||
|
// retrieve the most recent user's comments
|
||||||
|
List<Comment> recentComments = store.getRecentCommentsByUserAndDate(statisticsOfUsername, oneYearAgo.getTime().getTime());
|
||||||
|
Map<String, Feed> parentFeeds = new HashMap<String, Feed>();
|
||||||
|
|
||||||
|
// Evaluate the contexts to use
|
||||||
|
List<String> contexts = new ArrayList<String>();
|
||||||
|
|
||||||
|
if(isInfrastructure){
|
||||||
|
|
||||||
|
// filter for site
|
||||||
|
Set<GCubeGroup> vresInPortal = groupManager.listGroupsByUserAndSite(userId, getThreadLocalRequest().getServerName());
|
||||||
|
logger.debug("Contexts in this site are " + vresInPortal);
|
||||||
|
|
||||||
|
// get the scopes associated with such groups
|
||||||
|
for (GCubeGroup gCubeGroup : vresInPortal) {
|
||||||
|
contexts.add(groupManager.getInfrastructureScope(gCubeGroup.getGroupId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
// just the current scope
|
||||||
|
contexts.add(scope);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Context(s) that are going to be used " + contexts);
|
||||||
|
|
||||||
for (Feed feed : userFeeds) {
|
for (Feed feed : userFeeds) {
|
||||||
|
|
||||||
try{
|
if(contexts.contains(feed.getVreid())){
|
||||||
|
|
||||||
// check if the user is in the root, if not check if the VRE of the feed is the current one
|
|
||||||
if(!isInfrastructure && !feed.getVreid().equals(session.getScope()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// increment feeds number
|
// increment feeds number
|
||||||
feedsMade ++;
|
feedsMade ++;
|
||||||
|
@ -352,27 +384,16 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
commentsGot += Integer.parseInt(feed.getCommentsNo());
|
commentsGot += Integer.parseInt(feed.getCommentsNo());
|
||||||
likesGot += Integer.parseInt(feed.getLikesNo());
|
likesGot += Integer.parseInt(feed.getLikesNo());
|
||||||
|
|
||||||
}catch(NumberFormatException e){
|
|
||||||
logger.error(e.toString());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// retrieve the most recent user's liked feeds
|
}
|
||||||
List<Feed> recentLikedFeeds = store.getRecentLikedFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTime().getTime());
|
|
||||||
|
|
||||||
for (Feed feed : recentLikedFeeds) {
|
for (Feed feed : recentLikedFeeds) {
|
||||||
|
|
||||||
// check if the user is in the root, if not check if the VRE of the feed is the current one
|
if(contexts.contains(feed.getVreid()))
|
||||||
if(!isInfrastructure && !feed.getVreid().equals(session.getScope()))
|
likesMade ++; // no further check is needed since the user can do like just one time per feed
|
||||||
continue;
|
|
||||||
|
|
||||||
likesMade ++; // no further check is needed since the user can do like just one time per feed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// retrieve the most recent user's comments
|
|
||||||
List<Comment> recentComments = store.getRecentCommentsByUserAndDate(statisticsOfUsername, oneYearAgo.getTime().getTime());
|
|
||||||
Map<String, Feed> parentFeeds = new HashMap<String, Feed>();
|
|
||||||
|
|
||||||
for (Comment comment : recentComments) {
|
for (Comment comment : recentComments) {
|
||||||
|
|
||||||
Feed parentFeed = null;
|
Feed parentFeed = null;
|
||||||
|
@ -380,25 +401,22 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
if(!parentFeeds.containsKey(comment.getFeedid())){
|
if(!parentFeeds.containsKey(comment.getFeedid())){
|
||||||
parentFeed = store.readFeed(comment.getFeedid());
|
parentFeed = store.readFeed(comment.getFeedid());
|
||||||
parentFeeds.put(comment.getFeedid(), parentFeed);
|
parentFeeds.put(comment.getFeedid(), parentFeed);
|
||||||
}
|
}else
|
||||||
|
parentFeed = parentFeeds.get(comment.getFeedid());
|
||||||
|
|
||||||
parentFeed = parentFeeds.get(comment.getFeedid());
|
if((contexts.contains(parentFeed.getVreid())))
|
||||||
|
commentsMade ++;
|
||||||
// check if the user is in the root, if not check if the VRE of the feed is the current one
|
|
||||||
if(!isInfrastructure && !parentFeed.getVreid().equals(session.getScope()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
commentsMade ++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
|
|
||||||
logger.debug("[USER-STATISTICS] time taken to retrieve statistics is " + (end - init) + " ms");
|
logger.debug("time taken to retrieve statistics is " + (end - init) + " ms");
|
||||||
logger.debug("Total number of feeds made (after time filtering) of " + statisticsOfUsername + " is " + feedsMade);
|
logger.debug("Total number of feeds done (after time filtering) of " + statisticsOfUsername + " is " + feedsMade);
|
||||||
logger.debug("Total number of likes got (after time filtering) for " + statisticsOfUsername + " is " + likesGot);
|
logger.debug("Total number of likes got (after time filtering) for " + statisticsOfUsername + " is " + likesGot);
|
||||||
logger.debug("Total number of comments got (after time filtering) for " + statisticsOfUsername + " is " + commentsGot);
|
logger.debug("Total number of comments got (after time filtering) for " + statisticsOfUsername + " is " + commentsGot);
|
||||||
logger.debug("Total number of likes made (after time filtering) for " + statisticsOfUsername + " is " + likesMade);
|
logger.debug("Total number of likes done (after time filtering) for " + statisticsOfUsername + " is " + likesMade);
|
||||||
logger.debug("Total number of comments made (after time filtering) for " + statisticsOfUsername + " is " + commentsMade);
|
logger.debug("Total number of comments done (after time filtering) for " + statisticsOfUsername + " is " + commentsMade);
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error(e.toString());
|
logger.error(e.toString());
|
||||||
|
@ -415,7 +433,6 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
if(ServerUtils.isWithinPortal()){
|
if(ServerUtils.isWithinPortal()){
|
||||||
|
|
||||||
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
||||||
|
|
||||||
String username = session.getUsername();
|
String username = session.getUsername();
|
||||||
|
|
||||||
//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)
|
||||||
|
|
Loading…
Reference in New Issue