2253: Accounting Manager - Top N Active Users

https://support.d4science.org/issues/2253

Added Debug Mode

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@128473 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-05-05 13:20:59 +00:00
parent 85564df0ab
commit a12eee72fe
4 changed files with 108 additions and 39 deletions

38
pom.xml
View File

@ -39,7 +39,7 @@
<properties>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<distroDirectory>distro</distroDirectory>
<configDirectory>config</configDirectory>
@ -77,9 +77,16 @@
<artifactId>accounting-lib</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
@ -174,6 +181,27 @@
</dependency>
<!-- Authorization -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope>provided</scope>
</dependency>
<!-- GCube Widgets -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>compile</scope>
</dependency>
<!-- Social -->
<dependency>
<groupId>org.gcube.portal</groupId>
@ -187,12 +215,6 @@
<scope>provided</scope>
</dependency>
<!-- GCube Widgets -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>compile</scope>
</dependency>
<!-- WSLT dependencies <dependency> <groupId>org.gcube.portlets.widgets</groupId>
@ -382,7 +404,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<version>2.6.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>

View File

@ -9,6 +9,8 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerService;
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCaller;
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerInterface;
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerTester;
import org.gcube.portlets.admin.accountingmanager.shared.Constants;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
@ -59,7 +61,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
public UserInfo hello() throws AccountingManagerServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
ASLSession aslSession = SessionUtil.getASLSession(session);
UserInfo userInfo = new UserInfo(aslSession.getUsername(),
aslSession.getGroupId(), aslSession.getGroupName(),
aslSession.getScope(), aslSession.getScopeName(),
@ -87,8 +89,13 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
throws AccountingManagerServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
AccountingCallerInterface accountingCaller = new AccountingCaller();
SessionUtil.getASLSession(session);
AccountingCallerInterface accountingCaller;
if(Constants.DEBUG_MODE){
accountingCaller= new AccountingCallerTester();
} else {
accountingCaller= new AccountingCaller();
}
SeriesResponse seriesResponse = accountingCaller.getSeries(
accountingType, seriesRequest);
@ -114,9 +121,13 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
throws AccountingManagerServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
AccountingCallerInterface accountingCaller = new AccountingCaller();
SessionUtil.getASLSession(session);
AccountingCallerInterface accountingCaller;
if(Constants.DEBUG_MODE){
accountingCaller= new AccountingCallerTester();
} else {
accountingCaller= new AccountingCaller();
}
ArrayList<FilterKey> filterKeys = accountingCaller.getFilterKeys(accountingType);
return filterKeys;
@ -142,9 +153,14 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
throws AccountingManagerServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
SessionUtil.getASLSession(session);
AccountingCallerInterface accountingCaller = new AccountingCaller();
AccountingCallerInterface accountingCaller;
if(Constants.DEBUG_MODE){
accountingCaller= new AccountingCallerTester();
} else {
accountingCaller= new AccountingCaller();
}
ArrayList<FilterValue> filterValues = accountingCaller.getFilterValues(filterValuesRequest);
return filterValues;

View File

@ -3,11 +3,18 @@
*/
package org.gcube.portlets.admin.accountingmanager.server;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpSession;
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.portlets.admin.accountingmanager.shared.Constants;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerSessionExpiredException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -22,37 +29,59 @@ public class SessionUtil {
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
public static ASLSession getAslSession(HttpSession httpSession)
throws AccountingManagerSessionExpiredException {
public static ASLSession getASLSession(HttpSession httpSession)
throws AccountingManagerServiceException {
String username = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
ASLSession session;
ASLSession aslSession;
if (username == null) {
logger.warn("no user found in session, use test user");
throw new AccountingManagerSessionExpiredException("Session Expired!");
/*
// Remove comment for Test
username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE;
if (Constants.DEBUG_MODE) {
logger.info("no user found in session, use test user");
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username);
session = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
session.setScope(scope);
*/
// Remove comment for Test
username = org.gcube.portlets.admin.accountingmanager.shared.Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE;
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE,
username);
aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
aslSession.setScope(scope);
} else {
logger.info("No user found in session");
throw new AccountingManagerSessionExpiredException("Session Expired!");
}
} else {
session = SessionManager.getInstance().getASLSession(
aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
}
logger.info("SessionUtil: aslSession " + session.getUsername() + " "
+ session.getScope());
return session;
logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " "
+ aslSession.getScope());
return aslSession;
}
public static String getToken(ASLSession aslSession) {
String token=null;
if (Constants.DEBUG_MODE) {
List<String> userRoles = new ArrayList<>();
userRoles.add(Constants.DEFAULT_ROLE);
/*if (aslSession.getUsername().compareTo("lucio.lelii") == 0)
userRoles.add("VRE-Manager");*/
token = authorizationService().build().generate(
aslSession.getUsername(), userRoles);
} else {
token = aslSession.getSecurityToken();
}
logger.info("received token: " + token);
return token;
}
}

View File

@ -7,19 +7,21 @@ package org.gcube.portlets.admin.accountingmanager.shared;
*
*/
public class Constants {
public static final boolean DEBUG_MODE = false;
public static final String APPLICATION_ID = "org.gcube.portlets.admin.accountingmanager.server.portlet.AccountingManagerPortlet";
public static final String ACCOUNTING_MANAGER_ID = "AccountingManagerId";
public static final String AM_LANG_COOKIE = "AMLangCookie";
public static final String AM_LANG = "AMLang";
public final static String DEFAULT_USER = "giancarlo.panichi";
public static final String DEFAULT_USER = "giancarlo.panichi";
//public final static String DEFAULT_USER = "test.user";
//public final static String DEFAULT_SCOPE = "/gcube/devNext";
//public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
//public final static String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
public final static String DEFAULT_SCOPE = "/gcube";
public static final String DEFAULT_SCOPE = "/gcube";
public static final String DEFAULT_ROLE = "OrganizationMember";
}