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
master
Costantino Perciante 8 years ago
parent 96395eaa77
commit fe9bd532e1

@ -12,11 +12,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</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">
<attributes>
<attribute name="maven.pomderived" value="true"/>
@ -34,5 +29,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</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"/>
</classpath>

@ -4,6 +4,7 @@
<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/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="context-root" value="user-statistics"/>
</wb-module>

@ -1,7 +1,9 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-user.user-statistics.2-1-1"
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 component="org.gcube.portlets-user.user-statistics.2-1-0"
date="2016-10-02">

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

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

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

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

@ -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();

@ -3,7 +3,8 @@ package org.gcube.portlet.user.userstatisticsportlet.server.cache;
import java.util.Map;
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
@ -11,8 +12,9 @@ import org.slf4j.LoggerFactory;
* (costantino.perciante@isti.cnr.it)
*/
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
@ -33,9 +35,7 @@ public class UserInfrastructureSpaceCache implements CacheInterface<String, Long
* Private constructor
*/
private UserInfrastructureSpaceCache(){
userSpaceMap = new ConcurrentHashMap<>();
}
/**
@ -43,18 +43,14 @@ public class UserInfrastructureSpaceCache implements CacheInterface<String, Long
* @return
*/
public static UserInfrastructureSpaceCache getCacheInstance(){
return instance;
}
@Override
public Long get(String key) {
if(userSpaceMap.containsKey(key)){
CacheValueBean<Long> bean = userSpaceMap.get(key);
if(CacheUtilities.expired(bean.getTTL(), EXPIRED_AFTER)){
userSpaceMap.remove(key);
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
return bean.getValue();
}
return null;
}
@Override
public boolean insert(String key, Long value) {
CacheValueBean<Long> newBean = new CacheValueBean<Long>(value, System.currentTimeMillis());
if(userSpaceMap.containsKey(key))
userSpaceMap.remove(key);
userSpaceMap.put(key, newBean);
return true;
}
}

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

@ -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

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

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

@ -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!");
}
}
Loading…
Cancel
Save