removed aslsession, moved to liferay logging system and to version 2.1.1

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/user-statistics@134177 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-15 13:05:12 +00:00
parent 96395eaa77
commit fe9bd532e1
14 changed files with 191 additions and 235 deletions

View File

@ -12,11 +12,6 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -34,5 +29,10 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/user-statistics-2.1.1-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/user-statistics-2.1.1-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -4,6 +4,7 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
<property name="java-output-path" value="/user-statistics/target/user-statistics-portlet-0.0.1-SNAPSHOT/WEB-INF/classes"/> <property name="java-output-path" value="/user-statistics/target/user-statistics-portlet-0.0.1-SNAPSHOT/WEB-INF/classes"/>
<property name="context-root" value="user-statistics"/> <property name="context-root" value="user-statistics"/>
</wb-module> </wb-module>

View File

@ -1,7 +1,9 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets-user.user-statistics.2-1-1" <Changeset component="org.gcube.portlets-user.user-statistics.2-1-1"
date="2016-12-02"> date="2016-12-02">
<Change>Minor fixes</Change> <Change>Minor fixes</Change>
<Change>Removed asl session</Change>
<Change>Moved to Liferay logging system</Change>
</Changeset> </Changeset>
<Changeset component="org.gcube.portlets-user.user-statistics.2-1-0" <Changeset component="org.gcube.portlets-user.user-statistics.2-1-0"
date="2016-10-02"> date="2016-10-02">

28
pom.xml
View File

@ -57,8 +57,11 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.github.gwtbootstrap</groupId> <groupId>xerces</groupId>
<artifactId>gwt-bootstrap</artifactId> <artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
<scope>provided</scope>
<!-- put at provided for deploying -->
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.gwt</groupId> <groupId>com.google.gwt</groupId>
@ -78,30 +81,24 @@
<scope>provided</scope> <scope>provided</scope>
<version>2.7.0</version> <version>2.7.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>compile</scope>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId> <artifactId>custom-portal-handler</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.google</groupId> <groupId>com.google</groupId>
<artifactId>gwt-jsonmaker</artifactId> <artifactId>gwt-jsonmaker</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.github.gwtbootstrap</groupId>
<artifactId>gwt-bootstrap</artifactId>
</dependency>
<dependency> <dependency>
<groupId>commons-codec</groupId> <groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
@ -113,6 +110,11 @@
<artifactId>portlet-api</artifactId> <artifactId>portlet-api</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId> <artifactId>social-networking-library</artifactId>

View File

@ -1,15 +1,10 @@
package org.gcube.portlet.user.userstatisticsportlet.client; package org.gcube.portlet.user.userstatisticsportlet.client;
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.RootPanel;
/** /**
* Entry point classes define <code>onModuleLoad()</code>. * Entry point classes define <code>onModuleLoad()</code>.
*
* @author Costantino Perciante at ISTI-CNR * @author Costantino Perciante at ISTI-CNR
*/ */
public class Statistics implements EntryPoint { public class Statistics implements EntryPoint {
@ -18,15 +13,8 @@ public class Statistics implements EntryPoint {
* This is the entry point method. * This is the entry point method.
*/ */
public void onModuleLoad() { public void onModuleLoad() {
ClientScopeHelper.getService().setScope(Location.getHref(), new AsyncCallback<Boolean>() {
@Override RootPanel.get("statistics-container").add(new StatisticsPanel());
public void onSuccess(Boolean result) {
// fill container with incoming statistics
RootPanel.get("statistics-container").add(new StatisticsPanel());
}
@Override
public void onFailure(Throwable caught) {
}
});
} }
} }

View File

@ -7,7 +7,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
/** /**
* Async version of the UserStatisticsService interface * Async version of the UserStatisticsService interface
*
* @author Costantino Perciante at ISTI-CNR * @author Costantino Perciante at ISTI-CNR
*/ */
public interface UserStatisticsServiceAsync { public interface UserStatisticsServiceAsync {

View File

@ -4,17 +4,19 @@ import java.io.Serializable;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.application.framework.core.session.SessionManager; import org.gcube.common.portal.PortalContext;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
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.GCubeUser;
import org.gcube.vomanagement.usermanagement.util.ManagementUtils; import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
import org.slf4j.LoggerFactory;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.model.Contact; import com.liferay.portal.model.Contact;
import com.liferay.portal.model.User; import com.liferay.portal.model.User;
import com.liferay.portal.model.Website; import com.liferay.portal.model.Website;
@ -33,36 +35,63 @@ import com.liferay.portlet.expando.model.ExpandoColumnConstants;
public class ServerUtils { public class ServerUtils {
// Logger // Logger
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ServerUtils.class); // private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserStatisticsServiceImpl.class);
private static final Log logger = LogFactoryUtil.getLog(ServerUtils.class);
/** /**
* the current ASLSession * Retrieve the current user by using the portal manager
* @return the session * @return a GcubeUser object
*/ */
public static ASLSession getASLSession(HttpSession session) { public static GCubeUser getCurrentUser(HttpServletRequest request){
String sessionID = session.getId(); if(request == null)
String user = (String) session.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); throw new IllegalArgumentException("HttpServletRequest is null!");
if (user == null) { PortalContext pContext = PortalContext.getConfiguration();
GCubeUser user = pContext.getCurrentUser(request);
logger.warn("USER IS NULL setting " + UserStatisticsServiceImpl.TEST_USER + " and Running OUTSIDE PORTAL"); logger.debug("Returning user " + user);
user = getDevelopmentUser(); return user;
SessionManager.getInstance().getASLSession(sessionID, user).setScope(UserStatisticsServiceImpl.TEST_CONTEXT);
}
return SessionManager.getInstance().getASLSession(sessionID, user);
} }
/** /**
* when packaging test will fail if the user is not set to test.user * Retrieve the current scope by using the portal manager
* @return . * @param b
* @return a GcubeUser object
*/ */
public static String getDevelopmentUser() { public static String getCurrentContext(HttpServletRequest request, boolean setInThread){
String user = UserStatisticsServiceImpl.TEST_USER;
// user = "costantino.perciante"; if(request == null)
return user; throw new IllegalArgumentException("HttpServletRequest is null!");
PortalContext pContext = PortalContext.getConfiguration();
String context = pContext.getCurrentScope(request);
logger.debug("Returning context " + context);
if(context != null && setInThread)
ScopeProvider.instance.set(context);
return context;
}
/**
* Get current user token
* @param request
* @param setInThread
* @return
*/
public static String getCurrentSecurityToken(
HttpServletRequest request, boolean setInThread) {
if(request == null)
throw new IllegalArgumentException("HttpServletRequest is null!");
PortalContext pContext = PortalContext.getConfiguration();
String token = pContext.getCurrentUserToken(request);
logger.debug("Returning token " + token);
if(token != null && setInThread)
SecurityTokenProvider.instance.set(token);
return token;
} }
/** /**
@ -71,11 +100,11 @@ public class ServerUtils {
* the statistics to return are the ones available in the whole infrastructure * the statistics to return are the ones available in the whole infrastructure
* @return <code>true</code> if it is, <code>false</code> otherwise. * @return <code>true</code> if it is, <code>false</code> otherwise.
*/ */
public static boolean isInfrastructureScope(String userid, HttpSession session) { public static boolean isInfrastructureScope(String userid, HttpServletRequest request) {
boolean toReturn = false; boolean toReturn = false;
try { try {
GroupManager manager = new LiferayGroupManager(); GroupManager manager = new LiferayGroupManager();
long groupId = manager.getGroupIdFromInfrastructureScope(getASLSession(session).getScope()); long groupId = manager.getGroupIdFromInfrastructureScope(getCurrentContext(request, false));
toReturn = !manager.isVRE(groupId) || userid != null; toReturn = !manager.isVRE(groupId) || userid != null;
return toReturn; return toReturn;
} }
@ -242,17 +271,16 @@ public class ServerUtils {
* Set the permission checker to set/get custom fields into liferay * Set the permission checker to set/get custom fields into liferay
*/ */
public static void setPermissionChecker(){ public static void setPermissionChecker(){
if(isWithinPortal()){
// set permission checker try{
try{ long adminId = LiferayUserManager.getAdmin().getUserId();
long adminId = LiferayUserManager.getAdmin().getUserId(); PrincipalThreadLocal.setName(adminId);
PrincipalThreadLocal.setName(adminId); PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(adminId));
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(adminId)); PermissionThreadLocal.setPermissionChecker(permissionChecker);
PermissionThreadLocal.setPermissionChecker(permissionChecker); }catch(Exception e){
}catch(Exception e){ logger.error("Unable to set permission checker. Custom fields set/get operations are likely to fail...");
logger.error("Unable to set permission checker. Custom fields set/get operations are likely to fail..."); }
} }
} }
/** /**
@ -260,35 +288,23 @@ public class ServerUtils {
* @param customFieldNameUserStatisticsVisibility * @param customFieldNameUserStatisticsVisibility
* @param b * @param b
*/ */
public static void createUserCustomField( public static void createUserCustomField(String customFieldNameUserStatisticsVisibility, boolean startingValue) {
String customFieldNameUserStatisticsVisibility, boolean startingValue) { if(isWithinPortal()){
try{
// set permission checker ServerUtils.setPermissionChecker();
ServerUtils.setPermissionChecker(); User defaultUser = UserLocalServiceUtil.getDefaultUser(ManagementUtils.getCompany().getCompanyId());
boolean exists = defaultUser.getExpandoBridge().hasAttribute(customFieldNameUserStatisticsVisibility);
try{ if(exists){
logger.debug("Custom field already exists... There is no need to create it");
User defaultUser = UserLocalServiceUtil.getDefaultUser(ManagementUtils.getCompany().getCompanyId()); }else{
logger.debug("Creating custom field " + customFieldNameUserStatisticsVisibility +
// check if it exists " with starting value " + startingValue);
boolean exists = defaultUser.getExpandoBridge().hasAttribute(customFieldNameUserStatisticsVisibility); defaultUser.getExpandoBridge().addAttribute(customFieldNameUserStatisticsVisibility, ExpandoColumnConstants.BOOLEAN, (Serializable)(true));
}
if(exists){ }catch(Exception e){
logger.error("Unable to create custom field " + customFieldNameUserStatisticsVisibility);
logger.debug("Custom field already exists... There is no need to create it"); }
}
}else{
logger.debug("Creating custom field " + customFieldNameUserStatisticsVisibility +
" with starting value " + startingValue);
// create
defaultUser.getExpandoBridge().addAttribute(customFieldNameUserStatisticsVisibility, ExpandoColumnConstants.BOOLEAN, (Serializable)(true));
}
}catch(Exception e){
logger.error("Unable to create custom field " + customFieldNameUserStatisticsVisibility);
}
} }
} }

View File

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

View File

@ -3,7 +3,8 @@ package org.gcube.portlet.user.userstatisticsportlet.server.cache;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.LoggerFactory; import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
/** /**
* Cache for the user's space in use within the infrastructure * Cache for the user's space in use within the infrastructure
@ -11,8 +12,9 @@ import org.slf4j.LoggerFactory;
* (costantino.perciante@isti.cnr.it) * (costantino.perciante@isti.cnr.it)
*/ */
public class UserInfrastructureSpaceCache implements CacheInterface<String, Long> { public class UserInfrastructureSpaceCache implements CacheInterface<String, Long> {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserInfrastructureSpaceCache.class); //private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserInfrastructureSpaceCache.class);
private static final Log logger = LogFactoryUtil.getLog(UserInfrastructureSpaceCache.class);
/** /**
* The instance * The instance
@ -33,9 +35,7 @@ public class UserInfrastructureSpaceCache implements CacheInterface<String, Long
* Private constructor * Private constructor
*/ */
private UserInfrastructureSpaceCache(){ private UserInfrastructureSpaceCache(){
userSpaceMap = new ConcurrentHashMap<>(); userSpaceMap = new ConcurrentHashMap<>();
} }
/** /**
@ -43,18 +43,14 @@ public class UserInfrastructureSpaceCache implements CacheInterface<String, Long
* @return * @return
*/ */
public static UserInfrastructureSpaceCache getCacheInstance(){ public static UserInfrastructureSpaceCache getCacheInstance(){
return instance; return instance;
} }
@Override @Override
public Long get(String key) { public Long get(String key) {
if(userSpaceMap.containsKey(key)){ if(userSpaceMap.containsKey(key)){
CacheValueBean<Long> bean = userSpaceMap.get(key); CacheValueBean<Long> bean = userSpaceMap.get(key);
if(CacheUtilities.expired(bean.getTTL(), EXPIRED_AFTER)){ if(CacheUtilities.expired(bean.getTTL(), EXPIRED_AFTER)){
userSpaceMap.remove(key); userSpaceMap.remove(key);
logger.debug("Amount of space in the infrastructure used expired for key " + key + ", returning null"); logger.debug("Amount of space in the infrastructure used expired for key " + key + ", returning null");
@ -62,21 +58,13 @@ public class UserInfrastructureSpaceCache implements CacheInterface<String, Long
else else
return bean.getValue(); return bean.getValue();
} }
return null; return null;
} }
@Override @Override
public boolean insert(String key, Long value) { public boolean insert(String key, Long value) {
CacheValueBean<Long> newBean = new CacheValueBean<Long>(value, System.currentTimeMillis()); CacheValueBean<Long> newBean = new CacheValueBean<Long>(value, System.currentTimeMillis());
if(userSpaceMap.containsKey(key))
userSpaceMap.remove(key);
userSpaceMap.put(key, newBean); userSpaceMap.put(key, newBean);
return true; return true;
} }
} }

View File

@ -10,12 +10,9 @@ import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest; import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse; import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
public class UserStatisticsPortlet extends GenericPortlet { public class UserStatisticsPortlet extends GenericPortlet {
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType("text/html"); response.setContentType("text/html");
ScopeHelper.setContext(request);
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/Statistics_view.jsp"); PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/Statistics_view.jsp");
dispatcher.include(request, response); dispatcher.include(request, response);
} }

View File

@ -1,12 +0,0 @@
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# Print only messages of level TRACE or above in the package org.gcube
log4j.logger.org.gcube=TRACE
log4j.logger.org.gcube.application.framework.core.session=INFO
log4j.logger.org.gcube.common.scope.impl.DefaultScopeProvider=ERROR
log4j.logger.com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor=ERROR

View File

@ -5,7 +5,6 @@
<!-- Other module inherits --> <!-- Other module inherits -->
<!-- <inherits name='org.gcube.portlets.widgets.widgettour.WidgetTour' /> --> <!-- <inherits name='org.gcube.portlets.widgets.widgettour.WidgetTour' /> -->
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
<inherits name='org.gcube.portal.databook.GCubeSocialNetworking' /> <inherits name='org.gcube.portal.databook.GCubeSocialNetworking' />
<!-- Bootstrap import --> <!-- Bootstrap import -->

View File

@ -10,19 +10,11 @@
<servlet-name>userStatisticsServlet</servlet-name> <servlet-name>userStatisticsServlet</servlet-name>
<servlet-class>org.gcube.portlet.user.userstatisticsportlet.server.UserStatisticsServiceImpl</servlet-class> <servlet-class>org.gcube.portlet.user.userstatisticsportlet.server.UserStatisticsServiceImpl</servlet-class>
</servlet> </servlet>
<servlet>
<servlet-name>scopeService</servlet-name>
<servlet-class>org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl</servlet-class>
</servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>userStatisticsServlet</servlet-name> <servlet-name>userStatisticsServlet</servlet-name>
<url-pattern>/statistics/statisticservice</url-pattern> <url-pattern>/statistics/statisticservice</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet-mapping>
<servlet-name>scopeService</servlet-name>
<url-pattern>/statistics/scopeService</url-pattern>
</servlet-mapping>
<!-- <servlet> --> <!-- <servlet> -->
<!-- <servlet-name>widgettourServlet</servlet-name> --> <!-- <servlet-name>widgettourServlet</servlet-name> -->

View File

@ -1,19 +0,0 @@
package org.gcube.portlet.user.userstatisticsportlet.client;
import static org.junit.Assert.assertTrue;
import org.gcube.portlet.user.userstatisticsportlet.server.ServerUtils;
import org.gcube.portlet.user.userstatisticsportlet.server.UserStatisticsServiceImpl;
import org.junit.Test;
public class TestForDeploy {
@Test
public void testUserIsTestUser() {
String username = ServerUtils.getDevelopmentUser();
System.out.println("username for deploy is: " + username);
assertTrue(username.compareTo(UserStatisticsServiceImpl.TEST_USER) == 0);
System.out.println("Test OK!");
}
}