minor fixes
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/user-statistics@134070 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2d3a14f777
commit
120ac4a0d7
|
@ -22,8 +22,6 @@ 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.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.UserRetrievalFault;
|
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
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.model.GCubeGroup;
|
||||||
|
@ -41,176 +39,97 @@ import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class UserStatisticsServiceImpl extends RemoteServiceServlet implements UserStatisticsService {
|
public class UserStatisticsServiceImpl extends RemoteServiceServlet implements UserStatisticsService {
|
||||||
|
|
||||||
// Logger
|
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserStatisticsServiceImpl.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserStatisticsServiceImpl.class);
|
||||||
|
|
||||||
//dev user
|
|
||||||
public static final String defaultUserId = "test.user";
|
public static final String defaultUserId = "test.user";
|
||||||
|
|
||||||
//dev vre
|
|
||||||
public static final String vreID = "/gcube/devsec/devVRE";
|
public static final String vreID = "/gcube/devsec/devVRE";
|
||||||
|
|
||||||
// Cassandra connection
|
|
||||||
private DatabookStore store;
|
private DatabookStore store;
|
||||||
|
|
||||||
// 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 UserManager userManager = new LiferayUserManager();
|
||||||
private GroupManager groupManager = new LiferayGroupManager();
|
private GroupManager groupManager = new LiferayGroupManager();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
|
logger.info("Getting connection to Cassandra..");
|
||||||
// get connection to Cassandra
|
|
||||||
logger.debug("Getting connection to Cassandra..");
|
|
||||||
store = new DBCassandraAstyanaxImpl();
|
store = new DBCassandraAstyanaxImpl();
|
||||||
|
|
||||||
// add statistics option for profile pages and set to true
|
|
||||||
ServerUtils.createUserCustomField(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY, true);
|
ServerUtils.createUserCustomField(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy(){
|
public void destroy(){
|
||||||
// shutting down connection to Cassandra
|
|
||||||
logger.info("Closing connection to Cassandra");
|
logger.info("Closing connection to Cassandra");
|
||||||
store.closeConnection();
|
store.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTotalSpaceInUse(String userid) {
|
public String getTotalSpaceInUse(String userid) {
|
||||||
|
|
||||||
String storageInUse = null;
|
String storageInUse = null;
|
||||||
|
|
||||||
// get the session
|
|
||||||
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
||||||
|
|
||||||
// username in the session
|
|
||||||
String userName = session.getUsername();
|
String userName = session.getUsername();
|
||||||
|
|
||||||
// retrieve statistics of...
|
|
||||||
String statisticsOfUsername = userName;
|
String statisticsOfUsername = userName;
|
||||||
|
|
||||||
if(userid != null && !userid.equals(userName))
|
if(userid != null && !userid.equals(userName))
|
||||||
statisticsOfUsername = userid;
|
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)
|
|
||||||
//this check just return nothing if that happens
|
|
||||||
if (userName.compareTo(defaultUserId) == 0) {
|
if (userName.compareTo(defaultUserId) == 0) {
|
||||||
|
|
||||||
logger.debug("Found " + userName + " returning nothing");
|
logger.debug("Found " + userName + " returning nothing");
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
logger.debug("Getting " + statisticsOfUsername + " amount of workspace in use.");
|
logger.debug("Getting " + statisticsOfUsername + " amount of workspace in use.");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
long init = System.currentTimeMillis();
|
|
||||||
|
|
||||||
// retrieve the cache
|
|
||||||
UserInfrastructureSpaceCache cacheWorkspace = UserInfrastructureSpaceCache.getCacheInstance();
|
UserInfrastructureSpaceCache cacheWorkspace = UserInfrastructureSpaceCache.getCacheInstance();
|
||||||
|
|
||||||
// check if information is present
|
|
||||||
Long storageInUseLong = (Long) cacheWorkspace.get(statisticsOfUsername);
|
Long storageInUseLong = (Long) cacheWorkspace.get(statisticsOfUsername);
|
||||||
|
|
||||||
// if not, ask the workspace
|
|
||||||
if(storageInUseLong == null){
|
if(storageInUseLong == null){
|
||||||
|
|
||||||
logger.debug("Information not available in the cache, asking workspace");
|
|
||||||
Workspace workspace = HomeLibrary.getUserWorkspace(statisticsOfUsername);
|
Workspace workspace = HomeLibrary.getUserWorkspace(statisticsOfUsername);
|
||||||
storageInUseLong = workspace.getDiskUsage();
|
storageInUseLong = workspace.getDiskUsage();
|
||||||
|
|
||||||
logger.debug("Put information in the cache");
|
|
||||||
cacheWorkspace.insert(statisticsOfUsername, storageInUseLong);
|
cacheWorkspace.insert(statisticsOfUsername, storageInUseLong);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
storageInUse = ServerUtils.formatFileSize(storageInUseLong);
|
storageInUse = ServerUtils.formatFileSize(storageInUseLong);
|
||||||
|
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
logger.debug("[USER-STATISTICS] time taken to retrieve user space is " + (end - init) + "ms");
|
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|
||||||
logger.error("Unable to retrieve workspace information!");
|
logger.error("Unable to retrieve workspace information!");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return storageInUse;
|
return storageInUse;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getProfileStrength(String userid) {
|
public int getProfileStrength(String userid) {
|
||||||
|
|
||||||
int profileStrenght = -1;
|
int profileStrenght = -1;
|
||||||
|
|
||||||
// get the session
|
|
||||||
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
||||||
|
|
||||||
// username
|
|
||||||
String userName = session.getUsername();
|
String userName = session.getUsername();
|
||||||
|
|
||||||
// retrieve statistics of...
|
|
||||||
String statisticsOfUsername = userName;
|
String statisticsOfUsername = userName;
|
||||||
|
|
||||||
if(userid != null && !userid.equals(userName))
|
if(userid != null && !userid.equals(userName))
|
||||||
statisticsOfUsername = userid;
|
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)
|
|
||||||
//this check just return nothing if that happens
|
|
||||||
if (userName.compareTo(defaultUserId) == 0) {
|
if (userName.compareTo(defaultUserId) == 0) {
|
||||||
logger.debug("Found " + userName + " returning nothing");
|
logger.debug("Found " + userName + " returning nothing");
|
||||||
return profileStrenght;
|
return profileStrenght;
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
// valuate profile strength
|
|
||||||
if(ServerUtils.isWithinPortal()){
|
if(ServerUtils.isWithinPortal()){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
long init = System.currentTimeMillis();
|
|
||||||
|
|
||||||
// check if the avatar is present
|
|
||||||
boolean avatarPresent = (userManager.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);
|
||||||
|
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
logger.debug("[USER-STATISTICS] time taken to evaluate user profile strenght is " + (end - init) + "ms");
|
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|
||||||
logger.error("Profile strenght evaluation failed!!" + e.toString(), e);
|
logger.error("Profile strenght evaluation failed!!" + e.toString(), e);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return profileStrenght;
|
return profileStrenght;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserInformation getUserSettings(String userid) {
|
public UserInformation getUserSettings(String userid) {
|
||||||
|
|
||||||
// get the session
|
|
||||||
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
||||||
|
|
||||||
//username of the asl session
|
|
||||||
String userName = session.getUsername();
|
String userName = session.getUsername();
|
||||||
|
|
||||||
// retrieve statistics of...
|
|
||||||
String statisticsOfUsername = userName;
|
String statisticsOfUsername = userName;
|
||||||
|
|
||||||
// is he the owner of the profile?
|
|
||||||
boolean isOwner = false;
|
boolean isOwner = false;
|
||||||
|
|
||||||
// can we show this profile to other people?
|
|
||||||
boolean isProfileShowable = true;
|
boolean isProfileShowable = true;
|
||||||
|
|
||||||
if(userid == null || (userid !=null && userid.equals(userName))){
|
if(userid == null || (userid !=null && userid.equals(userName))){
|
||||||
|
@ -219,48 +138,34 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
}
|
}
|
||||||
|
|
||||||
if(userid != null && !userid.equals(userName)){
|
if(userid != null && !userid.equals(userName)){
|
||||||
// the stastics to show will be of the userid
|
|
||||||
statisticsOfUsername = userid;
|
statisticsOfUsername = userid;
|
||||||
isProfileShowable = checkUserPrivacyOption(statisticsOfUsername);
|
isProfileShowable = checkUserPrivacyOption(statisticsOfUsername);
|
||||||
|
|
||||||
logger.info("Is profile showable for user " + userid + " " + isProfileShowable);
|
logger.info("Is profile showable for user " + userid + " " + isProfileShowable);
|
||||||
}
|
}
|
||||||
|
|
||||||
//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(defaultUserId) == 0) {
|
if (userName.compareTo(defaultUserId) == 0) {
|
||||||
logger.debug("Found " + userName + " returning nothing");
|
logger.debug("Found " + userName + " returning nothing");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ServerUtils.isWithinPortal()){
|
if(ServerUtils.isWithinPortal()){
|
||||||
// If the user is in the root panel (or is visiting a profile page), we have to send him the overall number of posts made, comments/likes(received) and the space in use.
|
|
||||||
// Otherwise we have to filter on the vre.
|
|
||||||
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"));
|
||||||
|
|
||||||
String thumbnailURL = null;
|
String thumbnailURL = null;
|
||||||
try {
|
try {
|
||||||
thumbnailURL = userManager.getUserByUsername(statisticsOfUsername).getUserAvatarURL();
|
thumbnailURL = userManager.getUserByUsername(statisticsOfUsername).getUserAvatarURL();
|
||||||
} catch (UserManagementSystemException e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to retrieve avatar url for user " + statisticsOfUsername, e);
|
|
||||||
} catch (UserRetrievalFault e) {
|
|
||||||
logger.error("Unable to retrieve avatar url for user " + statisticsOfUsername, e);
|
logger.error("Unable to retrieve avatar url for user " + statisticsOfUsername, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(statisticsOfUsername + " avatar has url " + thumbnailURL);
|
|
||||||
|
|
||||||
// get the vre (if not in the infrastructure)
|
|
||||||
String actualVre = null;
|
String actualVre = null;
|
||||||
|
|
||||||
if(!isInfrastructure){
|
if(!isInfrastructure){
|
||||||
|
|
||||||
String[] temp = session.getScope().split("/");
|
String[] temp = session.getScope().split("/");
|
||||||
actualVre = temp[temp.length - 1];
|
actualVre = temp[temp.length - 1];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// page landing
|
|
||||||
String pageLanding = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest());
|
String pageLanding = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest());
|
||||||
UserInformation bean = new UserInformation(isInfrastructure, thumbnailURL, userName, actualVre, isOwner, isProfileShowable);
|
UserInformation bean = new UserInformation(isInfrastructure, thumbnailURL, userName, actualVre, isOwner, isProfileShowable);
|
||||||
bean.setCurrentPageLanding(pageLanding);
|
bean.setCurrentPageLanding(pageLanding);
|
||||||
|
@ -278,22 +183,13 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
private boolean checkUserPrivacyOption(String username) {
|
private boolean checkUserPrivacyOption(String username) {
|
||||||
try{
|
try{
|
||||||
|
|
||||||
// set permission checker
|
|
||||||
ServerUtils.setPermissionChecker();
|
ServerUtils.setPermissionChecker();
|
||||||
|
|
||||||
//needed to avoid cache use by liferay API
|
|
||||||
CacheRegistryUtil.clear();
|
CacheRegistryUtil.clear();
|
||||||
|
|
||||||
User user = UserLocalServiceUtil.getUserByScreenName(ManagementUtils.getCompany().getCompanyId(), username);
|
User user = UserLocalServiceUtil.getUserByScreenName(ManagementUtils.getCompany().getCompanyId(), username);
|
||||||
|
|
||||||
// the user has not decided yet
|
|
||||||
if(!user.getExpandoBridge().hasAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY))
|
if(!user.getExpandoBridge().hasAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return (boolean)user.getExpandoBridge().getAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY);
|
return (boolean)user.getExpandoBridge().getAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY);
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|
||||||
logger.error("Unable to retrieve user's privacy option for his statistics");
|
logger.error("Unable to retrieve user's privacy option for his statistics");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -302,169 +198,105 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
||||||
@Override
|
@Override
|
||||||
public PostsStatsBean getPostsStats(String userid){
|
public PostsStatsBean getPostsStats(String userid){
|
||||||
|
|
||||||
// get the session
|
|
||||||
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
||||||
|
|
||||||
//username
|
|
||||||
String userName = session.getUsername();
|
String userName = session.getUsername();
|
||||||
String scope = session.getScope();
|
String scope = session.getScope();
|
||||||
|
|
||||||
//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(defaultUserId) == 0) {
|
if (userName.compareTo(defaultUserId) == 0) {
|
||||||
logger.debug("Found " + userName + " returning nothing");
|
logger.debug("Found " + userName + " returning nothing");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// retrieve statistics of...
|
PostsStatsBean toReturn = null;
|
||||||
String statisticsOfUsername = userName;
|
|
||||||
|
|
||||||
|
String statisticsOfUsername = userName;
|
||||||
if(userid != null && !userid.equals(userName))
|
if(userid != null && !userid.equals(userName))
|
||||||
statisticsOfUsername = userid;
|
statisticsOfUsername = userid;
|
||||||
|
|
||||||
long feedsMade = 0, likesGot = 0, commentsGot = 0, commentsMade = 0, likesMade = 0;
|
|
||||||
|
|
||||||
// check if the user is or not in a VRE
|
|
||||||
boolean isInfrastructure = ServerUtils.isInfrastructureScope(userid, this.getThreadLocalRequest().getSession());
|
boolean isInfrastructure = ServerUtils.isInfrastructureScope(userid, this.getThreadLocalRequest().getSession());
|
||||||
|
|
||||||
// date corresponding to one year ago
|
|
||||||
Calendar oneYearAgo = Calendar.getInstance();
|
Calendar oneYearAgo = Calendar.getInstance();
|
||||||
oneYearAgo.set(Calendar.YEAR, oneYearAgo.get(Calendar.YEAR) - 1);
|
oneYearAgo.set(Calendar.YEAR, oneYearAgo.get(Calendar.YEAR) - 1);
|
||||||
|
|
||||||
logger.debug("Reference time is " + oneYearAgo.getTime());
|
logger.debug("Reference time is " + oneYearAgo.getTime());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
long init = System.currentTimeMillis();
|
|
||||||
long userId = userManager.getUserId(statisticsOfUsername);
|
long userId = userManager.getUserId(statisticsOfUsername);
|
||||||
|
|
||||||
logger.debug("Retrieving " + statisticsOfUsername + "'s statistics in the last year.");
|
List<Feed> userFeeds = store.getRecentFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTimeInMillis());
|
||||||
|
List<Feed> recentLikedFeeds = store.getRecentLikedFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTimeInMillis());
|
||||||
// retrieve the most recent user's feeds
|
List<Comment> recentComments = store.getRecentCommentsByUserAndDate(statisticsOfUsername, oneYearAgo.getTimeInMillis());
|
||||||
List<Feed> userFeeds = store.getRecentFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTime().getTime());
|
|
||||||
|
|
||||||
// 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
|
// Evaluate the contexts to use
|
||||||
List<String> contexts = new ArrayList<String>();
|
List<String> contexts = new ArrayList<String>();
|
||||||
|
|
||||||
if(isInfrastructure){
|
if(isInfrastructure){
|
||||||
|
|
||||||
// filter for site
|
|
||||||
Set<GCubeGroup> vresInPortal = groupManager.listGroupsByUserAndSite(userId, getThreadLocalRequest().getServerName());
|
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) {
|
for (GCubeGroup gCubeGroup : vresInPortal) {
|
||||||
contexts.add(groupManager.getInfrastructureScope(gCubeGroup.getGroupId()));
|
contexts.add(groupManager.getInfrastructureScope(gCubeGroup.getGroupId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
// just the current scope
|
|
||||||
contexts.add(scope);
|
contexts.add(scope);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Context(s) that are going to be used " + contexts);
|
logger.info("Context(s) that are going to be used " + contexts);
|
||||||
|
|
||||||
|
long feedsMade = 0, likesGot = 0, commentsGot = 0, commentsMade = 0, likesMade = 0;
|
||||||
|
|
||||||
for (Feed feed : userFeeds) {
|
for (Feed feed : userFeeds) {
|
||||||
|
|
||||||
if(contexts.contains(feed.getVreid())){
|
if(contexts.contains(feed.getVreid())){
|
||||||
|
|
||||||
// increment feeds number
|
|
||||||
feedsMade ++;
|
feedsMade ++;
|
||||||
|
|
||||||
//increment number of post replies and likes
|
|
||||||
commentsGot += Integer.parseInt(feed.getCommentsNo());
|
commentsGot += Integer.parseInt(feed.getCommentsNo());
|
||||||
likesGot += Integer.parseInt(feed.getLikesNo());
|
likesGot += Integer.parseInt(feed.getLikesNo());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Feed feed : recentLikedFeeds) {
|
for (Feed feed : recentLikedFeeds) {
|
||||||
|
|
||||||
if(contexts.contains(feed.getVreid()))
|
if(contexts.contains(feed.getVreid()))
|
||||||
likesMade ++; // no further check is needed since the user can do like just one time per feed
|
likesMade ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Feed> parentFeeds = new HashMap<String, Feed>();
|
||||||
|
|
||||||
for (Comment comment : recentComments) {
|
for (Comment comment : recentComments) {
|
||||||
|
|
||||||
Feed parentFeed = null;
|
Feed parentFeed = null;
|
||||||
|
|
||||||
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
|
}else
|
||||||
parentFeed = parentFeeds.get(comment.getFeedid());
|
parentFeed = parentFeeds.get(comment.getFeedid());
|
||||||
|
|
||||||
if((contexts.contains(parentFeed.getVreid())))
|
if((contexts.contains(parentFeed.getVreid())))
|
||||||
commentsMade ++;
|
commentsMade ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toReturn = new PostsStatsBean(feedsMade, likesGot, commentsGot, commentsMade, likesMade);
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
|
|
||||||
logger.debug("time taken to retrieve statistics is " + (end - init) + " ms");
|
|
||||||
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 comments got (after time filtering) for " + statisticsOfUsername + " is " + commentsGot);
|
|
||||||
logger.debug("Total number of likes done (after time filtering) for " + statisticsOfUsername + " is " + likesMade);
|
|
||||||
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("Error while retrieving user's statistics", e);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the object
|
return toReturn;
|
||||||
return new PostsStatsBean(feedsMade, likesGot, commentsGot, commentsMade, likesMade);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setShowMyOwnStatisticsToOtherPeople(boolean show) {
|
public void setShowMyOwnStatisticsToOtherPeople(boolean show) {
|
||||||
|
|
||||||
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)
|
|
||||||
//this check just return nothing if that happens
|
|
||||||
if (username.compareTo(defaultUserId) == 0) {
|
if (username.compareTo(defaultUserId) == 0) {
|
||||||
logger.debug("Found " + username + " returning nothing");
|
logger.debug("Found " + username + " returning nothing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
// set permission checker
|
|
||||||
ServerUtils.setPermissionChecker();
|
ServerUtils.setPermissionChecker();
|
||||||
|
|
||||||
//needed to avoid cache use by liferay API
|
|
||||||
CacheRegistryUtil.clear();
|
CacheRegistryUtil.clear();
|
||||||
|
|
||||||
logger.debug("User " + username + (show ? " want to show " : " doesn't want to show ") + " his statistics");
|
|
||||||
|
|
||||||
User user = UserLocalServiceUtil.getUserByScreenName(ManagementUtils.getCompany().getCompanyId(), username);
|
User user = UserLocalServiceUtil.getUserByScreenName(ManagementUtils.getCompany().getCompanyId(), username);
|
||||||
boolean hasAttribute = user.getExpandoBridge().hasAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY);
|
boolean hasAttribute = user.getExpandoBridge().hasAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY);
|
||||||
|
|
||||||
if(hasAttribute){
|
if(hasAttribute){
|
||||||
|
|
||||||
// set the new value
|
|
||||||
logger.debug("Setting custom field value to " + show + " for user " + username);
|
logger.debug("Setting custom field value to " + show + " for user " + username);
|
||||||
|
|
||||||
// set the current value
|
|
||||||
user.getExpandoBridge().setAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY, show);
|
user.getExpandoBridge().setAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY, show);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Unable to check user's privacy for his statistics", e);
|
logger.error("Unable to check user's privacy for his statistics", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue