|
|
|
@ -7,7 +7,6 @@ import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import org.gcube.application.framework.core.session.ASLSession;
|
|
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
@ -26,10 +25,11 @@ import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
|
|
|
|
|
import com.liferay.portal.kernel.log.Log;
|
|
|
|
|
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
|
|
|
|
import com.liferay.portal.model.User;
|
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
|
|
|
|
|
@ -39,9 +39,8 @@ import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
|
public class UserStatisticsServiceImpl extends RemoteServiceServlet implements UserStatisticsService {
|
|
|
|
|
|
|
|
|
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserStatisticsServiceImpl.class);
|
|
|
|
|
public static final String TEST_USER = "test.user";
|
|
|
|
|
public static final String TEST_CONTEXT = "/gcube/devsec/devVRE";
|
|
|
|
|
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserStatisticsServiceImpl.class);
|
|
|
|
|
private static final Log logger = LogFactoryUtil.getLog(UserStatisticsServiceImpl.class);
|
|
|
|
|
private DatabookStore store;
|
|
|
|
|
private static final String CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY = "show_user_statistics_other_people";
|
|
|
|
|
private UserManager userManager = new LiferayUserManager();
|
|
|
|
@ -63,34 +62,37 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|
|
|
|
@Override
|
|
|
|
|
public String getTotalSpaceInUse(String userid) {
|
|
|
|
|
String storageInUse = null;
|
|
|
|
|
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
|
|
|
|
String userName = session.getUsername();
|
|
|
|
|
String userName = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
|
|
// get context & token and set
|
|
|
|
|
ServerUtils.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
|
ServerUtils.getCurrentSecurityToken(this.getThreadLocalRequest(), true);
|
|
|
|
|
|
|
|
|
|
if(userName == null){
|
|
|
|
|
logger.warn("Unable to determine the current user, returing null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String statisticsOfUsername = userName;
|
|
|
|
|
|
|
|
|
|
if(userid != null && !userid.equals(userName))
|
|
|
|
|
statisticsOfUsername = userid;
|
|
|
|
|
|
|
|
|
|
if (userName.compareTo(TEST_USER) == 0) {
|
|
|
|
|
logger.debug("Found " + userName + " returning nothing");
|
|
|
|
|
return null;
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
logger.debug("Getting " + statisticsOfUsername + " amount of workspace in use.");
|
|
|
|
|
try{
|
|
|
|
|
UserInfrastructureSpaceCache cacheWorkspace = UserInfrastructureSpaceCache.getCacheInstance();
|
|
|
|
|
Long storageInUseLong = (Long) cacheWorkspace.get(statisticsOfUsername);
|
|
|
|
|
|
|
|
|
|
if(storageInUseLong == null){
|
|
|
|
|
Workspace workspace = HomeLibrary.getUserWorkspace(statisticsOfUsername);
|
|
|
|
|
storageInUseLong = workspace.getDiskUsage();
|
|
|
|
|
cacheWorkspace.insert(statisticsOfUsername, storageInUseLong);
|
|
|
|
|
}
|
|
|
|
|
logger.debug("Getting " + statisticsOfUsername + " amount of workspace in use.");
|
|
|
|
|
try{
|
|
|
|
|
UserInfrastructureSpaceCache cacheWorkspace = UserInfrastructureSpaceCache.getCacheInstance();
|
|
|
|
|
Long storageInUseLong = (Long) cacheWorkspace.get(statisticsOfUsername);
|
|
|
|
|
|
|
|
|
|
storageInUse = ServerUtils.formatFileSize(storageInUseLong);
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
logger.error("Unable to retrieve workspace information!");
|
|
|
|
|
if(storageInUseLong == null){
|
|
|
|
|
Workspace workspace = HomeLibrary.getUserWorkspace(statisticsOfUsername);
|
|
|
|
|
storageInUseLong = workspace.getDiskUsage();
|
|
|
|
|
cacheWorkspace.insert(statisticsOfUsername, storageInUseLong);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
storageInUse = ServerUtils.formatFileSize(storageInUseLong);
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
logger.error("Unable to retrieve workspace information!", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return storageInUse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -98,36 +100,40 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|
|
|
|
public int getProfileStrength(String userid) {
|
|
|
|
|
|
|
|
|
|
int profileStrenght = -1;
|
|
|
|
|
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
|
|
|
|
String userName = session.getUsername();
|
|
|
|
|
String userName = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
|
|
if(userName == null){
|
|
|
|
|
logger.warn("Unable to determine the current user, returing null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String statisticsOfUsername = userName;
|
|
|
|
|
|
|
|
|
|
if(userid != null && !userid.equals(userName))
|
|
|
|
|
statisticsOfUsername = userid;
|
|
|
|
|
|
|
|
|
|
if (userName.compareTo(TEST_USER) == 0) {
|
|
|
|
|
logger.debug("Found " + userName + " returning nothing");
|
|
|
|
|
return profileStrenght;
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return profileStrenght;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public UserInformation getUserSettings(String userid) {
|
|
|
|
|
|
|
|
|
|
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
|
|
|
|
String userName = session.getUsername();
|
|
|
|
|
String userName = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
|
|
if(userName == null){
|
|
|
|
|
logger.warn("Unable to determine the current user, returing null");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String statisticsOfUsername = userName;
|
|
|
|
|
boolean isOwner = false;
|
|
|
|
|
boolean isProfileShowable = true;
|
|
|
|
@ -143,13 +149,8 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|
|
|
|
logger.info("Is profile showable for user " + userid + " " + isProfileShowable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (userName.compareTo(TEST_USER) == 0) {
|
|
|
|
|
logger.debug("Found " + userName + " returning nothing");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ServerUtils.isWithinPortal()){
|
|
|
|
|
boolean isInfrastructure = ServerUtils.isInfrastructureScope(userid, this.getThreadLocalRequest().getSession());
|
|
|
|
|
boolean isInfrastructure = ServerUtils.isInfrastructureScope(userid, this.getThreadLocalRequest());
|
|
|
|
|
logger.debug("User scope is " + (isInfrastructure ? " the whole infrastucture " : " a VRE"));
|
|
|
|
|
|
|
|
|
|
String thumbnailURL = null;
|
|
|
|
@ -162,7 +163,8 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|
|
|
|
String actualVre = null;
|
|
|
|
|
|
|
|
|
|
if(!isInfrastructure){
|
|
|
|
|
String[] temp = session.getScope().split("/");
|
|
|
|
|
|
|
|
|
|
String[] temp = ServerUtils.getCurrentContext(this.getThreadLocalRequest(), true).split("/");
|
|
|
|
|
actualVre = temp[temp.length - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -172,7 +174,7 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|
|
|
|
return bean;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return new UserInformation(true, null, userName, TEST_CONTEXT, true, true);
|
|
|
|
|
return new UserInformation(true, null, userName, ServerUtils.getCurrentContext(this.getThreadLocalRequest(), false), true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -181,39 +183,39 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean checkUserPrivacyOption(String username) {
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
|
|
ServerUtils.setPermissionChecker();
|
|
|
|
|
CacheRegistryUtil.clear();
|
|
|
|
|
User user = UserLocalServiceUtil.getUserByScreenName(ManagementUtils.getCompany().getCompanyId(), username);
|
|
|
|
|
if(!user.getExpandoBridge().hasAttribute(CUSTOM_FIELD_NAME_USER_STATISTICS_VISIBILITY))
|
|
|
|
|
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");
|
|
|
|
|
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");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PostsStatsBean getPostsStats(String userid){
|
|
|
|
|
|
|
|
|
|
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
|
|
|
|
String userName = session.getUsername();
|
|
|
|
|
String scope = session.getScope();
|
|
|
|
|
String userName = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
|
|
if (userName.compareTo(TEST_USER) == 0) {
|
|
|
|
|
logger.debug("Found " + userName + " returning nothing");
|
|
|
|
|
return null;
|
|
|
|
|
if(userName == null){
|
|
|
|
|
logger.warn("Unable to determine the current user, returing null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String scope = ServerUtils.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
|
PostsStatsBean toReturn = null;
|
|
|
|
|
|
|
|
|
|
String statisticsOfUsername = userName;
|
|
|
|
|
if(userid != null && !userid.equals(userName))
|
|
|
|
|
statisticsOfUsername = userid;
|
|
|
|
|
|
|
|
|
|
boolean isInfrastructure = ServerUtils.isInfrastructureScope(userid, this.getThreadLocalRequest().getSession());
|
|
|
|
|
boolean isInfrastructure = ServerUtils.isInfrastructureScope(userid, this.getThreadLocalRequest());
|
|
|
|
|
|
|
|
|
|
Calendar oneYearAgo = Calendar.getInstance();
|
|
|
|
|
oneYearAgo.set(Calendar.YEAR, oneYearAgo.get(Calendar.YEAR) - 1);
|
|
|
|
@ -281,12 +283,13 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
|
|
|
|
|
public void setShowMyOwnStatisticsToOtherPeople(boolean show) {
|
|
|
|
|
|
|
|
|
|
if(ServerUtils.isWithinPortal()){
|
|
|
|
|
ASLSession session = ServerUtils.getASLSession(this.getThreadLocalRequest().getSession());
|
|
|
|
|
String username = session.getUsername();
|
|
|
|
|
if (username.compareTo(TEST_USER) == 0) {
|
|
|
|
|
logger.debug("Found " + username + " returning nothing");
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
String username = ServerUtils.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
|
|
if(username == null){
|
|
|
|
|
logger.warn("Unable to determine the current user, returing null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
ServerUtils.setPermissionChecker();
|
|
|
|
|
CacheRegistryUtil.clear();
|
|
|
|
|