2015-12-09 14:34:41 +01:00
|
|
|
package org.gcube.portlet.user.userstatisticsportlet.server;
|
|
|
|
|
2017-02-12 21:14:11 +01:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.URL;
|
2016-09-30 12:35:37 +02:00
|
|
|
import java.util.ArrayList;
|
2016-05-10 18:40:55 +02:00
|
|
|
import java.util.Calendar;
|
2016-08-02 17:42:05 +02:00
|
|
|
import java.util.HashMap;
|
2015-12-09 14:34:41 +01:00
|
|
|
import java.util.List;
|
2016-08-02 17:42:05 +02:00
|
|
|
import java.util.Map;
|
2016-09-30 12:35:37 +02:00
|
|
|
import java.util.Set;
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2017-02-12 21:14:11 +01:00
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
import javax.xml.xpath.XPath;
|
|
|
|
import javax.xml.xpath.XPathFactory;
|
|
|
|
|
2017-02-13 14:37:12 +01:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
2015-12-09 14:34:41 +01:00
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
2016-05-20 15:12:01 +02:00
|
|
|
import org.gcube.common.portal.PortalContext;
|
2017-02-13 14:37:12 +01:00
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.portal.custom.communitymanager.SiteManagerUtil;
|
2015-12-09 14:34:41 +01:00
|
|
|
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
2016-08-02 17:42:05 +02:00
|
|
|
import org.gcube.portal.databook.shared.Comment;
|
2015-12-09 14:34:41 +01:00
|
|
|
import org.gcube.portal.databook.shared.Feed;
|
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.client.UserStatisticsService;
|
2017-02-12 21:14:11 +01:00
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.server.cache.UserInfrastructureQuotaStorageCache;
|
2016-05-23 17:45:17 +02:00
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.server.cache.UserInfrastructureSpaceCache;
|
2017-02-12 21:14:11 +01:00
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.server.utils.DiscoverQuotaServiceEndPoint;
|
2015-12-09 14:34:41 +01:00
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.shared.PostsStatsBean;
|
2017-02-12 21:14:11 +01:00
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.shared.QuotaInfo;
|
2015-12-09 14:34:41 +01:00
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.shared.UserInformation;
|
2016-09-30 12:35:37 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
2016-05-10 18:40:55 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
2016-09-30 12:35:37 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
2016-05-10 18:40:55 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
2016-09-30 12:35:37 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
2016-05-10 18:40:55 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
|
2017-02-12 21:14:11 +01:00
|
|
|
import org.w3c.dom.Document;
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
2016-07-11 16:02:37 +02:00
|
|
|
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
|
2016-11-15 14:05:12 +01:00
|
|
|
import com.liferay.portal.kernel.log.Log;
|
|
|
|
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
2015-12-09 14:34:41 +01:00
|
|
|
import com.liferay.portal.model.User;
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
public class UserStatisticsServiceImpl extends RemoteServiceServlet implements UserStatisticsService {
|
|
|
|
|
2016-11-15 14:05:12 +01:00
|
|
|
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserStatisticsServiceImpl.class);
|
|
|
|
private static final Log logger = LogFactoryUtil.getLog(UserStatisticsServiceImpl.class);
|
2015-12-09 14:34:41 +01:00
|
|
|
private DatabookStore store;
|
2017-02-12 21:14:11 +01:00
|
|
|
private String quotaServiceBaseUrl;
|
2016-05-10 18:40:55 +02:00
|
|
|
private static final String CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY = "show_user_statistics_other_people";
|
2016-09-30 12:35:37 +02:00
|
|
|
private UserManager userManager = new LiferayUserManager();
|
|
|
|
private GroupManager groupManager = new LiferayGroupManager();
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
@Override
|
|
|
|
public void init() {
|
2016-11-10 23:12:44 +01:00
|
|
|
logger.info("Getting connection to Cassandra..");
|
2015-12-09 14:34:41 +01:00
|
|
|
store = new DBCassandraAstyanaxImpl();
|
2016-08-03 16:26:49 +02:00
|
|
|
ServerUtils.createUserCustomField(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY, true);
|
2017-02-12 21:14:11 +01:00
|
|
|
|
|
|
|
logger.info("Retrieving quota service endpoint");
|
|
|
|
quotaServiceBaseUrl = DiscoverQuotaServiceEndPoint.discover();
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void destroy(){
|
2016-08-03 16:26:49 +02:00
|
|
|
logger.info("Closing connection to Cassandra");
|
2015-12-09 14:34:41 +01:00
|
|
|
store.closeConnection();
|
|
|
|
}
|
|
|
|
|
2017-02-12 21:14:11 +01:00
|
|
|
@Override
|
|
|
|
public QuotaInfo getQuotaStorage(String userid) {
|
|
|
|
|
|
|
|
QuotaInfo toReturn = null;
|
|
|
|
String userName = null;
|
2017-02-13 14:37:12 +01:00
|
|
|
String quotaOfUser = null;
|
2017-02-12 21:14:11 +01:00
|
|
|
if(quotaServiceBaseUrl != null){
|
|
|
|
|
|
|
|
userName = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
// do not show quota info to other users
|
|
|
|
if(userid != null && !userid.equals(userName))
|
2017-02-13 14:37:12 +01:00
|
|
|
quotaOfUser = userid;
|
2017-02-12 21:14:11 +01:00
|
|
|
|
2017-02-13 14:37:12 +01:00
|
|
|
quotaOfUser = userName;
|
2017-02-12 21:14:11 +01:00
|
|
|
logger.debug("Fetching info for quota of user " + quotaOfUser);
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
UserInfrastructureQuotaStorageCache cache = UserInfrastructureQuotaStorageCache.getCacheInstance();
|
|
|
|
|
2017-02-13 14:37:12 +01:00
|
|
|
if(cache.get(quotaOfUser) != null)
|
|
|
|
toReturn = cache.get(quotaOfUser);
|
2017-02-12 21:14:11 +01:00
|
|
|
else{
|
|
|
|
|
|
|
|
// ask the service ...
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
2017-02-13 14:37:12 +01:00
|
|
|
String rootContextToken = pContext.getCurrentUserToken("/" + pContext.getInfrastructureName(), quotaOfUser);
|
2017-02-12 21:14:11 +01:00
|
|
|
URL request = new URL(quotaServiceBaseUrl + "?timeinterval=FOREVER&gcube-token=" + rootContextToken);
|
|
|
|
InputStream result = request.openStream();
|
|
|
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
|
|
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
|
|
|
Document document = dBuilder.parse(result);
|
|
|
|
document.getDocumentElement().normalize();
|
|
|
|
|
|
|
|
logger.debug("Result is " + document);
|
|
|
|
|
|
|
|
XPathFactory xpf = XPathFactory.newInstance();
|
2017-02-13 14:37:12 +01:00
|
|
|
XPath xpath = xpf.newXPath();
|
|
|
|
Float maxQuota = ServerUtils.queryQuotaService(document, xpath, "/quotaStatus/quotaValue/text()");
|
|
|
|
Float usageQuota = ServerUtils.queryQuotaService(document, xpath, "/quotaStatus/quotaUsage/text()");
|
|
|
|
|
|
|
|
logger.debug("Information retrieved are: maxQuota=" + maxQuota + " and usageQuota=" + usageQuota);
|
2017-02-12 21:14:11 +01:00
|
|
|
|
2017-02-13 14:37:12 +01:00
|
|
|
if(usageQuota != null && maxQuota != null && maxQuota > 0){
|
|
|
|
toReturn = new QuotaInfo(maxQuota, usageQuota);
|
|
|
|
cache.insert(quotaOfUser, toReturn);
|
|
|
|
}
|
2017-02-12 21:14:11 +01:00
|
|
|
}
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("Failed to retrieve quota information for user", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-13 14:37:12 +01:00
|
|
|
logger.debug("Quota for user " + quotaOfUser + " is " + toReturn);
|
2017-02-12 21:14:11 +01:00
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
@Override
|
2016-05-10 18:40:55 +02:00
|
|
|
public String getTotalSpaceInUse(String userid) {
|
2015-12-09 14:34:41 +01:00
|
|
|
String storageInUse = null;
|
2016-11-15 14:05:12 +01:00
|
|
|
String userName = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
2016-05-10 18:40:55 +02:00
|
|
|
String statisticsOfUsername = userName;
|
|
|
|
|
|
|
|
if(userid != null && !userid.equals(userName))
|
|
|
|
statisticsOfUsername = userid;
|
|
|
|
|
2016-11-15 14:05:12 +01:00
|
|
|
logger.debug("Getting " + statisticsOfUsername + " amount of workspace in use.");
|
|
|
|
try{
|
|
|
|
UserInfrastructureSpaceCache cacheWorkspace = UserInfrastructureSpaceCache.getCacheInstance();
|
|
|
|
Long storageInUseLong = (Long) cacheWorkspace.get(statisticsOfUsername);
|
|
|
|
if(storageInUseLong == null){
|
2017-02-13 14:37:12 +01:00
|
|
|
String userToken = PortalContext.getConfiguration().getCurrentUserToken(ScopeProvider.instance.get(), statisticsOfUsername);
|
|
|
|
SecurityTokenProvider.instance.set(userToken);
|
2016-11-15 14:05:12 +01:00
|
|
|
Workspace workspace = HomeLibrary.getUserWorkspace(statisticsOfUsername);
|
|
|
|
storageInUseLong = workspace.getDiskUsage();
|
|
|
|
cacheWorkspace.insert(statisticsOfUsername, storageInUseLong);
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
2016-11-15 14:05:12 +01:00
|
|
|
storageInUse = ServerUtils.formatFileSize(storageInUseLong);
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("Unable to retrieve workspace information!", e);
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
2016-11-15 14:05:12 +01:00
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
return storageInUse;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-10 18:40:55 +02:00
|
|
|
public int getProfileStrength(String userid) {
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
int profileStrenght = -1;
|
2016-11-15 14:05:12 +01:00
|
|
|
String userName = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
if(userName == null){
|
|
|
|
logger.warn("Unable to determine the current user, returing null");
|
|
|
|
}
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
String statisticsOfUsername = userName;
|
|
|
|
|
|
|
|
if(userid != null && !userid.equals(userName))
|
|
|
|
statisticsOfUsername = userid;
|
|
|
|
|
2016-11-15 14:05:12 +01:00
|
|
|
if(ServerUtils.isWithinPortal()){
|
|
|
|
try{
|
|
|
|
boolean avatarPresent = (userManager.getUserAvatarBytes(statisticsOfUsername) != null);
|
|
|
|
User user = UserLocalServiceUtil.getUserByScreenName(SiteManagerUtil.getCompany().getCompanyId(), statisticsOfUsername);
|
|
|
|
profileStrenght = ServerUtils.evaluateProfileStrenght(user, avatarPresent);
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("Profile strenght evaluation failed!!" + e.toString(), e);
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-15 14:05:12 +01:00
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
return profileStrenght;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-10 18:40:55 +02:00
|
|
|
public UserInformation getUserSettings(String userid) {
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2016-11-15 14:05:12 +01:00
|
|
|
String userName = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
if(userName == null){
|
|
|
|
logger.warn("Unable to determine the current user, returing null");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
String statisticsOfUsername = userName;
|
|
|
|
boolean isOwner = false;
|
|
|
|
boolean isProfileShowable = true;
|
|
|
|
|
|
|
|
if(userid == null || (userid !=null && userid.equals(userName))){
|
|
|
|
isOwner = true;
|
|
|
|
isProfileShowable = checkUserPrivacyOption(userName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(userid != null && !userid.equals(userName)){
|
|
|
|
statisticsOfUsername = userid;
|
|
|
|
isProfileShowable = checkUserPrivacyOption(statisticsOfUsername);
|
2016-08-03 16:26:49 +02:00
|
|
|
logger.info("Is profile showable for user " + userid + " " + isProfileShowable);
|
2016-05-10 18:40:55 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 16:26:49 +02:00
|
|
|
if(ServerUtils.isWithinPortal()){
|
2016-11-15 14:05:12 +01:00
|
|
|
boolean isInfrastructure = ServerUtils.isInfrastructureScope(userid, this.getThreadLocalRequest());
|
2016-08-03 16:26:49 +02:00
|
|
|
logger.debug("User scope is " + (isInfrastructure ? " the whole infrastucture " : " a VRE"));
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
String thumbnailURL = null;
|
|
|
|
try {
|
2016-09-30 12:35:37 +02:00
|
|
|
thumbnailURL = userManager.getUserByUsername(statisticsOfUsername).getUserAvatarURL();
|
2016-11-10 23:12:44 +01:00
|
|
|
} catch (Exception e) {
|
2016-11-15 15:19:51 +01:00
|
|
|
logger.error("Unable to retrieve avatar url for user " + statisticsOfUsername +". Likely he/she doesn't have an avatar");
|
2016-05-10 18:40:55 +02:00
|
|
|
}
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
String actualVre = null;
|
|
|
|
|
|
|
|
if(!isInfrastructure){
|
2016-11-15 14:05:12 +01:00
|
|
|
|
|
|
|
String[] temp = ServerUtils.getCurrentContext(this.getThreadLocalRequest(), true).split("/");
|
2015-12-09 14:34:41 +01:00
|
|
|
actualVre = temp[temp.length - 1];
|
|
|
|
}
|
2016-05-23 17:45:17 +02:00
|
|
|
|
2016-05-20 15:12:01 +02:00
|
|
|
String pageLanding = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest());
|
|
|
|
UserInformation bean = new UserInformation(isInfrastructure, thumbnailURL, userName, actualVre, isOwner, isProfileShowable);
|
|
|
|
bean.setCurrentPageLanding(pageLanding);
|
|
|
|
return bean;
|
2016-05-10 18:40:55 +02:00
|
|
|
}
|
2016-08-31 10:45:58 +02:00
|
|
|
else
|
2016-11-15 14:05:12 +01:00
|
|
|
return new UserInformation(true, null, userName, ServerUtils.getCurrentContext(this.getThreadLocalRequest(), false), true, true);
|
2016-05-10 18:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check privacy option for user's own statistics
|
|
|
|
* @param username
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private boolean checkUserPrivacyOption(String username) {
|
2016-11-15 14:05:12 +01:00
|
|
|
if(ServerUtils.isWithinPortal()){
|
|
|
|
try{
|
|
|
|
ServerUtils.setPermissionChecker();
|
|
|
|
CacheRegistryUtil.clear();
|
|
|
|
User user = UserLocalServiceUtil.getUserByScreenName(ManagementUtils.getCompany().getCompanyId(), username);
|
|
|
|
if(!user.getExpandoBridge().hasAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY))
|
|
|
|
return true;
|
|
|
|
return (boolean)user.getExpandoBridge().getAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY);
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("Unable to retrieve user's privacy option for his statistics");
|
2016-05-10 18:40:55 +02:00
|
|
|
return true;
|
2016-11-15 14:05:12 +01:00
|
|
|
}
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
2016-11-15 14:05:12 +01:00
|
|
|
return false;
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-10 18:40:55 +02:00
|
|
|
public PostsStatsBean getPostsStats(String userid){
|
2016-04-06 15:42:41 +02:00
|
|
|
|
2016-11-15 14:05:12 +01:00
|
|
|
String userName = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
2016-05-10 18:40:55 +02:00
|
|
|
|
2016-11-15 14:05:12 +01:00
|
|
|
if(userName == null){
|
|
|
|
logger.warn("Unable to determine the current user, returing null");
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 14:05:12 +01:00
|
|
|
String scope = ServerUtils.getCurrentContext(this.getThreadLocalRequest(), true);
|
2016-11-10 23:12:44 +01:00
|
|
|
PostsStatsBean toReturn = null;
|
2016-09-30 12:35:37 +02:00
|
|
|
|
2016-11-10 23:12:44 +01:00
|
|
|
String statisticsOfUsername = userName;
|
2016-09-30 12:35:37 +02:00
|
|
|
if(userid != null && !userid.equals(userName))
|
|
|
|
statisticsOfUsername = userid;
|
|
|
|
|
2016-11-15 14:05:12 +01:00
|
|
|
boolean isInfrastructure = ServerUtils.isInfrastructureScope(userid, this.getThreadLocalRequest());
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
Calendar oneYearAgo = Calendar.getInstance();
|
|
|
|
oneYearAgo.set(Calendar.YEAR, oneYearAgo.get(Calendar.YEAR) - 1);
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2016-08-03 16:26:49 +02:00
|
|
|
logger.debug("Reference time is " + oneYearAgo.getTime());
|
2015-12-09 14:34:41 +01:00
|
|
|
try {
|
2016-09-30 12:35:37 +02:00
|
|
|
long userId = userManager.getUserId(statisticsOfUsername);
|
2016-08-03 16:26:49 +02:00
|
|
|
|
2016-11-10 23:12:44 +01:00
|
|
|
List<Feed> userFeeds = store.getRecentFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTimeInMillis());
|
|
|
|
List<Feed> recentLikedFeeds = store.getRecentLikedFeedsByUserAndDate(statisticsOfUsername, oneYearAgo.getTimeInMillis());
|
|
|
|
List<Comment> recentComments = store.getRecentCommentsByUserAndDate(statisticsOfUsername, oneYearAgo.getTimeInMillis());
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2016-09-30 12:35:37 +02:00
|
|
|
// Evaluate the contexts to use
|
|
|
|
List<String> contexts = new ArrayList<String>();
|
|
|
|
if(isInfrastructure){
|
|
|
|
Set<GCubeGroup> vresInPortal = groupManager.listGroupsByUserAndSite(userId, getThreadLocalRequest().getServerName());
|
|
|
|
for (GCubeGroup gCubeGroup : vresInPortal) {
|
|
|
|
contexts.add(groupManager.getInfrastructureScope(gCubeGroup.getGroupId()));
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
contexts.add(scope);
|
|
|
|
}
|
|
|
|
|
2016-11-10 23:12:44 +01:00
|
|
|
logger.info("Context(s) that are going to be used " + contexts);
|
|
|
|
|
|
|
|
long feedsMade = 0, likesGot = 0, commentsGot = 0, commentsMade = 0, likesMade = 0;
|
2016-09-30 12:35:37 +02:00
|
|
|
|
|
|
|
for (Feed feed : userFeeds) {
|
|
|
|
|
|
|
|
if(contexts.contains(feed.getVreid())){
|
2016-08-02 17:42:05 +02:00
|
|
|
feedsMade ++;
|
|
|
|
commentsGot += Integer.parseInt(feed.getCommentsNo());
|
|
|
|
likesGot += Integer.parseInt(feed.getLikesNo());
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
2016-09-30 12:35:37 +02:00
|
|
|
}
|
2016-08-02 17:42:05 +02:00
|
|
|
for (Feed feed : recentLikedFeeds) {
|
|
|
|
|
2016-09-30 12:35:37 +02:00
|
|
|
if(contexts.contains(feed.getVreid()))
|
2016-11-10 23:12:44 +01:00
|
|
|
likesMade ++;
|
2016-08-02 17:42:05 +02:00
|
|
|
}
|
|
|
|
|
2016-11-10 23:12:44 +01:00
|
|
|
Map<String, Feed> parentFeeds = new HashMap<String, Feed>();
|
2016-08-02 17:42:05 +02:00
|
|
|
|
2016-11-10 23:12:44 +01:00
|
|
|
for (Comment comment : recentComments) {
|
2016-08-02 17:42:05 +02:00
|
|
|
Feed parentFeed = null;
|
|
|
|
if(!parentFeeds.containsKey(comment.getFeedid())){
|
|
|
|
parentFeed = store.readFeed(comment.getFeedid());
|
|
|
|
parentFeeds.put(comment.getFeedid(), parentFeed);
|
2016-09-30 12:35:37 +02:00
|
|
|
}else
|
|
|
|
parentFeed = parentFeeds.get(comment.getFeedid());
|
|
|
|
if((contexts.contains(parentFeed.getVreid())))
|
|
|
|
commentsMade ++;
|
2016-08-02 17:42:05 +02:00
|
|
|
}
|
|
|
|
|
2016-11-10 23:12:44 +01:00
|
|
|
toReturn = new PostsStatsBean(feedsMade, likesGot, commentsGot, commentsMade, likesMade);
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
}catch(Exception e){
|
2016-11-10 23:12:44 +01:00
|
|
|
logger.error("Error while retrieving user's statistics", e);
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
|
|
|
|
2016-11-10 23:12:44 +01:00
|
|
|
return toReturn;
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
@Override
|
|
|
|
public void setShowMyOwnStatisticsToOtherPeople(boolean show) {
|
|
|
|
|
2016-08-03 16:26:49 +02:00
|
|
|
if(ServerUtils.isWithinPortal()){
|
2016-11-15 14:05:12 +01:00
|
|
|
|
|
|
|
String username = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
if(username == null){
|
|
|
|
logger.warn("Unable to determine the current user, returing null");
|
2016-05-10 18:40:55 +02:00
|
|
|
}
|
2016-11-15 14:05:12 +01:00
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
try{
|
2016-08-03 16:26:49 +02:00
|
|
|
ServerUtils.setPermissionChecker();
|
2016-07-11 16:02:37 +02:00
|
|
|
CacheRegistryUtil.clear();
|
2016-05-10 18:40:55 +02:00
|
|
|
User user = UserLocalServiceUtil.getUserByScreenName(ManagementUtils.getCompany().getCompanyId(), username);
|
|
|
|
boolean hasAttribute = user.getExpandoBridge().hasAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY);
|
|
|
|
|
|
|
|
if(hasAttribute){
|
2016-08-03 16:26:49 +02:00
|
|
|
logger.debug("Setting custom field value to " + show + " for user " + username);
|
2016-05-10 18:40:55 +02:00
|
|
|
user.getExpandoBridge().setAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY, show);
|
|
|
|
}
|
|
|
|
}catch(Exception e){
|
2016-08-03 16:26:49 +02:00
|
|
|
logger.error("Unable to check user's privacy for his statistics", e);
|
2016-05-10 18:40:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|