started supporting likes and comments made by the user
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/user-statistics@130951 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b48848f9df
commit
3b47fc80b2
|
@ -3,7 +3,9 @@ package org.gcube.portlet.user.userstatisticsportlet.server;
|
|||
import java.io.Serializable;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.application.framework.core.session.SessionManager;
|
||||
|
@ -14,6 +16,7 @@ import org.gcube.portal.custom.communitymanager.SiteManagerUtil;
|
|||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
||||
import org.gcube.portal.databook.server.DatabookStore;
|
||||
import org.gcube.portal.databook.shared.Comment;
|
||||
import org.gcube.portal.databook.shared.Feed;
|
||||
import org.gcube.portlet.user.userstatisticsportlet.client.UserStatisticsService;
|
||||
import org.gcube.portlet.user.userstatisticsportlet.server.cache.UserInfrastructureSpaceCache;
|
||||
|
@ -241,7 +244,7 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|||
try{
|
||||
|
||||
long init = System.currentTimeMillis();
|
||||
|
||||
|
||||
// check if the avatar is present
|
||||
boolean avatarPresent = (new LiferayUserManager().getUserAvatarBytes(statisticsOfUsername) != null);
|
||||
|
||||
|
@ -289,7 +292,7 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|||
// the stastics to show will be of the userid
|
||||
statisticsOfUsername = userid;
|
||||
isProfileShowable = checkUserPrivacyOption(statisticsOfUsername);
|
||||
|
||||
|
||||
_log.info("Is profile showable for user " + userid + " " + isProfileShowable);
|
||||
}
|
||||
|
||||
|
@ -350,7 +353,7 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|||
|
||||
// set permission checker
|
||||
setPermissionChecker();
|
||||
|
||||
|
||||
//needed to avoid cache use by liferay API
|
||||
CacheRegistryUtil.clear();
|
||||
|
||||
|
@ -391,7 +394,7 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|||
return null;
|
||||
}
|
||||
|
||||
long totalFeeds = 0, totalLikes = 0, totalComments = 0;
|
||||
long feedsMade = 0, likesGot = 0, commentsGot = 0, commentsMade = 0, likesMade = 0;
|
||||
|
||||
// check if the user is or not in a VRE
|
||||
boolean isInfrastructure = isInfrastructureScope(userid);
|
||||
|
@ -405,8 +408,10 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|||
try {
|
||||
|
||||
long init = System.currentTimeMillis();
|
||||
|
||||
_log.debug("Getting " + statisticsOfUsername + " feeds in the last year.");
|
||||
|
||||
// retrieve the most recent user's feeds
|
||||
List<Feed> userFeeds = store.getRecentFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTime().getTime());
|
||||
|
||||
_log.debug("Evaluating number of comments and likes of " + statisticsOfUsername + "'s feeds.");
|
||||
|
@ -420,23 +425,59 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|||
continue;
|
||||
|
||||
// increment feeds number
|
||||
totalFeeds ++;
|
||||
feedsMade ++;
|
||||
|
||||
//increment number of post replies and likes
|
||||
totalComments += Integer.parseInt(feed.getCommentsNo());
|
||||
totalLikes += Integer.parseInt(feed.getLikesNo());
|
||||
commentsGot += Integer.parseInt(feed.getCommentsNo());
|
||||
likesGot += Integer.parseInt(feed.getLikesNo());
|
||||
|
||||
}catch(NumberFormatException e){
|
||||
_log.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// retrieve the most recent user's liked feeds
|
||||
List<Feed> recentLikedFeeds = store.getRecentLikedFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTime().getTime());
|
||||
|
||||
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(!isInfrastructure && !feed.getVreid().equals(session.getScope()))
|
||||
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) {
|
||||
|
||||
Feed parentFeed = null;
|
||||
|
||||
if(!parentFeeds.containsKey(comment.getFeedid())){
|
||||
parentFeed = store.readFeed(comment.getFeedid());
|
||||
parentFeeds.put(comment.getFeedid(), parentFeed);
|
||||
}
|
||||
|
||||
parentFeed = parentFeeds.get(comment.getFeedid());
|
||||
|
||||
// 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();
|
||||
|
||||
_log.debug("[USER-STATISTICS] time taken to retrieve and filter user feeds, get likes and replies got is " + (end - init) + "ms");
|
||||
_log.debug("Total number of feeds (after time filtering) of " + statisticsOfUsername + " is " + totalFeeds);
|
||||
_log.debug("Total number of likes (after time filtering) for " + statisticsOfUsername + " is " + totalLikes);
|
||||
_log.debug("Total number of comments (after time filtering) for " + statisticsOfUsername + " is " + totalComments);
|
||||
_log.debug("[USER-STATISTICS] time taken to retrieve statistics is " + (end - init) + " ms");
|
||||
_log.debug("Total number of feeds made (after time filtering) of " + statisticsOfUsername + " is " + feedsMade);
|
||||
_log.debug("Total number of likes got (after time filtering) for " + statisticsOfUsername + " is " + likesGot);
|
||||
_log.debug("Total number of comments got (after time filtering) for " + statisticsOfUsername + " is " + commentsGot);
|
||||
_log.debug("Total number of likes made (after time filtering) for " + statisticsOfUsername + " is " + likesMade);
|
||||
_log.debug("Total number of comments made (after time filtering) for " + statisticsOfUsername + " is " + commentsMade);
|
||||
|
||||
}catch(Exception e){
|
||||
_log.error(e.toString());
|
||||
|
@ -444,7 +485,7 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|||
}
|
||||
|
||||
// return the object
|
||||
return new PostsStatsBean(totalFeeds, totalLikes, totalComments);
|
||||
return new PostsStatsBean(feedsMade, likesGot, commentsGot, commentsMade, likesMade);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -467,7 +508,7 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|||
|
||||
// set permission checker
|
||||
setPermissionChecker();
|
||||
|
||||
|
||||
//needed to avoid cache use by liferay API
|
||||
CacheRegistryUtil.clear();
|
||||
|
||||
|
|
|
@ -13,27 +13,39 @@ public class PostsStatsBean implements Serializable{
|
|||
* Generated serial version id
|
||||
*/
|
||||
private static final long serialVersionUID = 2043823499293477290L;
|
||||
private long feeds;
|
||||
private long feedsNumber;
|
||||
private long likesReceived;
|
||||
private long commentsReceived;
|
||||
private long commentsMade;
|
||||
private long likesMade;
|
||||
|
||||
public PostsStatsBean(){
|
||||
super();
|
||||
}
|
||||
|
||||
public PostsStatsBean(long feeds, long likesReceived, long commentsReceived) {
|
||||
/**
|
||||
* @param feeds
|
||||
* @param likesReceived
|
||||
* @param commentsReceived
|
||||
* @param commentsMade
|
||||
* @param likesMade
|
||||
*/
|
||||
public PostsStatsBean(long feeds, long likesReceived,
|
||||
long commentsReceived, long commentsMade, long likesMade) {
|
||||
super();
|
||||
this.feeds = feeds;
|
||||
this.feedsNumber = feeds;
|
||||
this.likesReceived = likesReceived;
|
||||
this.commentsReceived = commentsReceived;
|
||||
this.commentsMade = commentsMade;
|
||||
this.likesMade = likesMade;
|
||||
}
|
||||
|
||||
public long getFeedsNumber() {
|
||||
return feeds;
|
||||
return feedsNumber;
|
||||
}
|
||||
|
||||
public void setFeedsNumber(long feeds) {
|
||||
this.feeds = feeds;
|
||||
this.feedsNumber = feeds;
|
||||
}
|
||||
|
||||
public long getLikesReceived() {
|
||||
|
@ -52,10 +64,27 @@ public class PostsStatsBean implements Serializable{
|
|||
this.commentsReceived = commentsReceived;
|
||||
}
|
||||
|
||||
public long getCommentsMade() {
|
||||
return commentsMade;
|
||||
}
|
||||
|
||||
public void setCommentsMade(long commentsMade) {
|
||||
this.commentsMade = commentsMade;
|
||||
}
|
||||
|
||||
public long getLikesMade() {
|
||||
return likesMade;
|
||||
}
|
||||
|
||||
public void setLikesMade(long likesMade) {
|
||||
this.likesMade = likesMade;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FeedsInformation [feeds=" + feeds + ", likesReceived="
|
||||
return "PostsStatsBean [feeds=" + feedsNumber + ", likesReceived="
|
||||
+ likesReceived + ", commentsReceived=" + commentsReceived
|
||||
+ ", commentsMade=" + commentsMade + ", likesMade=" + likesMade
|
||||
+ "]";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue