Updated to PortalContext

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@135004 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-11-28 16:38:32 +00:00
parent 54915903f9
commit 244d745b4c
18 changed files with 399 additions and 291 deletions

26
pom.xml
View File

@ -197,18 +197,11 @@
<scope>compile</scope>
</dependency>
<!-- GCube 4.2 -->
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
</dependency>
<!-- <dependency> <groupId>org.gcube.common.portal</groupId> <artifactId>portal-manager</artifactId>
<scope>provided</scope> </dependency> -->
<dependency>
<groupId>org.gcube.dvos</groupId>
@ -216,6 +209,12 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>client-context-library</artifactId>
<version>[1.0.0-SNAPSHOT,)</version>
<scope>compile</scope>
</dependency>
<!-- Authorization -->
<dependency>
@ -251,13 +250,6 @@
<scope>provided</scope>
</dependency>
<!-- Session Checker -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- Common Encryption -->
<dependency>
<groupId>org.gcube.core</groupId>

View File

@ -10,8 +10,8 @@
<!-- Add this for using GXT charts -->
<inherits name='com.sencha.gxt.chart.Chart' />
<!-- GXT Theme -->
<!-- <inherits name='com.sencha.gxt.theme.blue.Blue' /> -->
@ -23,18 +23,17 @@
<inherits name="com.allen_sauer.gwt.log.gwt-log-TRACE" />
<inherits name="com.google.gwt.resources.Resources" />
<!--<inherits name="org.moxieapps.gwt.highcharts.Highcharts"/> -->
<inherits name='com.github.highcharts4gwt.highcharts' />
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<!--<inherits name="org.moxieapps.gwt.highcharts.Highcharts"/> -->
<inherits name='com.github.highcharts4gwt.highcharts' />
<!--Inherit the GCubeClientContext widget code -->
<inherits name='org.gcube.portal.clientcontext.GCubeClientContext' />
<!-- Specify the app entry point class. -->
<entry-point class='org.gcube.portlets.admin.accountingmanager.client.AccountingManager' />
<entry-point
class='org.gcube.portlets.admin.accountingmanager.client.AccountingManager' />
<!-- <set-configuration-property name="locale.cookie" value="AMLangCookie"
/> <set-configuration-property name="locale.queryparam" value="AMLang" />
@ -44,18 +43,17 @@
values="en" /> <extend-property name="locale" values="it" /> <extend-property
name="locale" values="es" /> <set-property name="locale" value="en, it, es"
/> <set-property-fallback name="locale" value="en" /> -->
<!--
<set-property name="log_DivLogger" value="ENABLED" /> <set-property
<!-- <set-property name="log_DivLogger" value="ENABLED" /> <set-property
name="log_ConsoleLogger" value="ENABLED" /> <set-property name="log_GWTLogger"
value="ENABLED" /> <set-property name="log_SystemLogger" value="ENABLED"
/> -->
/> -->
<set-property name="log_DivLogger" value="DISABLED" />
<set-property name="log_ConsoleLogger" value="DISABLED" />
<set-property name="log_GWTLogger" value="DISABLED" />
<set-property name="log_SystemLogger" value="DISABLED" />
<set-property name="log_SystemLogger" value="DISABLED" />

View File

@ -7,9 +7,7 @@ import org.gcube.portlets.admin.accountingmanager.client.menu.AccountingManagerM
import org.gcube.portlets.admin.accountingmanager.client.resource.AccountingManagerResources;
import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerService;
import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerServiceAsync;
import org.gcube.portlets.admin.accountingmanager.client.utils.UtilsGXT3;
import org.gcube.portlets.admin.accountingmanager.shared.tabs.EnableTabs;
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.EntryPoint;
@ -17,8 +15,6 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.shared.EventBus;
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.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer;
@ -61,36 +57,12 @@ public class AccountingManager implements EntryPoint {
// onModuleLoad2
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
loadScope();
loadMainPanel();
}
});
}
private void loadScope() {
ClientScopeHelper.getService().setScope(Location.getHref(),
new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
if (result) {
loadMainPanel();
} else {
UtilsGXT3
.info("Attention",
"ClientScopeHelper has returned a false value!");
}
}
@Override
public void onFailure(Throwable caught) {
UtilsGXT3.alert("Error", "Error setting scope: "
+ caught.getLocalizedMessage());
caught.printStackTrace();
}
});
}
private void bindToEvents() {
eventBus.addHandler(EnableTabsEvent.TYPE,
new EnableTabsEvent.EnableTabsEventHandler() {

View File

@ -3,6 +3,7 @@ package org.gcube.portlets.admin.accountingmanager.client;
import java.util.ArrayList;
import java.util.Date;
import org.gcube.portal.clientcontext.client.GCubeClientContext;
import org.gcube.portlets.admin.accountingmanager.client.event.AccountingMenuEvent;
import org.gcube.portlets.admin.accountingmanager.client.event.EnableTabsEvent;
import org.gcube.portlets.admin.accountingmanager.client.event.ExportRequestEvent;
@ -17,7 +18,7 @@ import org.gcube.portlets.admin.accountingmanager.client.state.AccountingClientS
import org.gcube.portlets.admin.accountingmanager.client.type.SessionExpiredType;
import org.gcube.portlets.admin.accountingmanager.client.type.StateChangeType;
import org.gcube.portlets.admin.accountingmanager.client.type.UIStateType;
import org.gcube.portlets.admin.accountingmanager.client.utils.UtilsGXT3;
import org.gcube.portlets.admin.accountingmanager.client.util.UtilsGXT3;
import org.gcube.portlets.admin.accountingmanager.shared.Constants;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterBasic;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingPeriod;
@ -31,7 +32,6 @@ import org.gcube.portlets.admin.accountingmanager.shared.exception.SessionExpire
import org.gcube.portlets.admin.accountingmanager.shared.session.UserInfo;
import org.gcube.portlets.admin.accountingmanager.shared.tabs.EnableTabs;
import org.gcube.portlets.admin.accountingmanager.shared.workspace.ItemDescription;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
@ -85,7 +85,7 @@ public class AccountingManagerController {
*/
private void sessionExpiredShow() {
CheckSession.showLogoutDialog();
//CheckSession.showLogoutDialog();
}
/**
@ -568,7 +568,10 @@ public class AccountingManagerController {
+ Constants.EXPORT_SERVLET_TYPE_PARAMETER + "="
+ event.getExportType().name() + "&"
+ Constants.EXPORT_SERVLET_ACCOUNTING_TYPE_PARAMETER + "="
+ event.getAccountingType().name());
+ event.getAccountingType().name()
+ "&"
+ Constants.CURR_GROUP_ID + "="
+ GCubeClientContext.getCurrentContextId());
Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), event.getAccountingType().toString(),

View File

@ -6,7 +6,7 @@ import org.gcube.portlets.admin.accountingmanager.client.event.AccountingPeriodE
import org.gcube.portlets.admin.accountingmanager.client.event.AccountingPeriodRequestEvent;
import org.gcube.portlets.admin.accountingmanager.client.event.StateChangeEvent;
import org.gcube.portlets.admin.accountingmanager.client.properties.AccountingPeriodModePropertiesCombo;
import org.gcube.portlets.admin.accountingmanager.client.utils.UtilsGXT3;
import org.gcube.portlets.admin.accountingmanager.client.util.UtilsGXT3;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingPeriod;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingPeriodMode;

View File

@ -14,7 +14,7 @@ import org.gcube.portlets.admin.accountingmanager.client.resource.AccountingMana
import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerServiceAsync;
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingClientStateData;
import org.gcube.portlets.admin.accountingmanager.client.type.SessionExpiredType;
import org.gcube.portlets.admin.accountingmanager.client.utils.UtilsGXT3;
import org.gcube.portlets.admin.accountingmanager.client.util.UtilsGXT3;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilter;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterBasic;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilterContext;

View File

@ -1,7 +1,7 @@
/**
*
*/
package org.gcube.portlets.admin.accountingmanager.client.utils;
package org.gcube.portlets.admin.accountingmanager.client.util;
/**
*

View File

@ -1,4 +1,4 @@
package org.gcube.portlets.admin.accountingmanager.client.utils;
package org.gcube.portlets.admin.accountingmanager.client.util;
import com.sencha.gxt.widget.core.client.box.MessageBox;

View File

@ -1,4 +1,4 @@
package org.gcube.portlets.admin.accountingmanager.client.utils;
package org.gcube.portlets.admin.accountingmanager.client.util;
import com.google.gwt.core.client.Callback;

View File

@ -5,7 +5,6 @@ import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
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;
@ -15,6 +14,7 @@ import org.gcube.portlets.admin.accountingmanager.server.export.CSVManager;
import org.gcube.portlets.admin.accountingmanager.server.is.BuildEnableTabs;
import org.gcube.portlets.admin.accountingmanager.server.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.server.storage.StorageUtil;
import org.gcube.portlets.admin.accountingmanager.server.util.ServiceCredentials;
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.Context;
@ -47,7 +47,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
private static Logger logger = LoggerFactory
.getLogger(AccountingManagerServiceImpl.class);
private static AccountingCache accountingCache;
/**
@ -60,27 +60,30 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
System.setProperty("jdk.xml.entityExpansionLimit", "0");
logger.info("initializing AccountingManager");
try {
accountingCache = new AccountingCache();
} catch (ServiceException e) {
logger.error("Error initializing AccountingCache: "+e.getLocalizedMessage(),e);
logger.error(
"Error initializing AccountingCache: "
+ e.getLocalizedMessage(), e);
}
}
@Override
@Override
public void destroy() {
super.destroy();
logger.info("Clear AccountingCache");
try {
accountingCache.finalize();
} catch (Throwable e) {
logger.error("Error initializing AccountingCache: "+e.getLocalizedMessage(),e);
logger.error(
"Error initializing AccountingCache: "
+ e.getLocalizedMessage(), e);
}
}
/**
*
* {@inheritDoc}
@ -88,22 +91,21 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
@Override
public UserInfo hello() throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
UserInfo userInfo = new UserInfo(aslSession.getUsername(),
aslSession.getGroupId(), aslSession.getGroupName(),
aslSession.getScope(), aslSession.getScopeName(),
aslSession.getUserEmailAddress(),
aslSession.getUserFullName());
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("hello()");
UserInfo userInfo = new UserInfo(serviceCredentials.getUserName(),
serviceCredentials.getGroupId(),
serviceCredentials.getGroupName(),
serviceCredentials.getScope(),
serviceCredentials.getEmail(),
serviceCredentials.getFullName());
logger.debug("UserInfo: " + userInfo);
logger.debug("UserToken: " + token);
return userInfo;
} catch (ServiceException e) {
e.printStackTrace();
throw e;
} catch (Throwable e) {
e.printStackTrace();
logger.error("Hello(): " + e.getLocalizedMessage(), e);
throw new ServiceException(e.getLocalizedMessage());
}
@ -113,13 +115,11 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
@Override
public EnableTabs getEnableTabs() throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
EnableTabs enableTabs = BuildEnableTabs
.build(aslSession.getScope());
EnableTabs enableTabs = BuildEnableTabs.build(serviceCredentials
.getScope());
return enableTabs;
} catch (ServiceException e) {
@ -141,14 +141,13 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
SeriesRequest seriesRequest) throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
String key = new String(aslSession.getScope()+"_"+accountingType.name() + "_"
+ seriesRequest.toString());
logger.info("Search Accounting data in Cache with key: "+key);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
String key = new String(serviceCredentials.getScope() + "_"
+ accountingType.name() + "_" + seriesRequest.toString());
logger.info("Search Accounting data in Cache with key: " + key);
SeriesResponse seriesResponse = accountingCache.get(key);
if (seriesResponse == null) {
@ -166,7 +165,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
} else {
logger.info("Accounting use data in Cache");
}
AccountingStateData accountingStateData = new AccountingStateData(
accountingType, seriesRequest, seriesResponse);
SessionUtil.setAccountingStateData(session, accountingType,
@ -192,10 +191,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
public ArrayList<FilterKey> getFilterKeys(AccountingType accountingType)
throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
AccountingCallerInterface accountingCaller;
if (Constants.DEBUG_MODE) {
@ -227,10 +223,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
public ArrayList<FilterValue> getFilterValues(
FilterValuesRequest filterValuesRequest) throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
SessionUtil.getServiceCredentials(this.getThreadLocalRequest());
AccountingCallerInterface accountingCaller;
if (Constants.DEBUG_MODE) {
@ -261,12 +254,10 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
@Override
public Context getContext() throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
Context context = SessionUtil.getContext(aslSession);
Context context = SessionUtil.getContext(serviceCredentials);
logger.debug("getContext(): " + context);
return context;
@ -287,9 +278,8 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("SaveDataOnWorkspace(): " + accountingType);
AccountingStateData accountingStateData = SessionUtil
@ -302,7 +292,8 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
+ accountingType);
}
CSVManager csvManager = new CSVManager(aslSession.getUsername());
CSVManager csvManager = new CSVManager(
serviceCredentials.getUserName());
ItemDescription itemDescription = csvManager
.saveOnWorkspace(accountingStateData);
return itemDescription;
@ -320,14 +311,12 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
public String getPublicLink(ItemDescription itemDescription)
throws ServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(this.getThreadLocalRequest());
logger.debug("GetPublicLink(): " + itemDescription);
String link = StorageUtil.getPublicLink(aslSession.getUsername(),
itemDescription.getId());
String link = StorageUtil.getPublicLink(
serviceCredentials.getUserName(), itemDescription.getId());
return link;
} catch (ServiceException e) {

View File

@ -10,11 +10,12 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.admin.accountingmanager.server.export.CSVManager;
import org.gcube.portlets.admin.accountingmanager.server.export.JSONManager;
import org.gcube.portlets.admin.accountingmanager.server.export.XMLManager;
import org.gcube.portlets.admin.accountingmanager.server.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.server.util.ServiceCredentials;
import org.gcube.portlets.admin.accountingmanager.shared.Constants;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
@ -25,16 +26,15 @@ import org.slf4j.LoggerFactory;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
* Export Servlet
* Export Servlet
*
*/
public class ExportServlet extends HttpServlet {
private static final long serialVersionUID = -1838255772767180518L;
private static Logger logger = LoggerFactory
.getLogger(ExportServlet.class);
private static Logger logger = LoggerFactory.getLogger(ExportServlet.class);
/**
* @see HttpServlet#HttpServlet()
@ -80,85 +80,101 @@ public class ExportServlet extends HttpServlet {
}
logger.debug("ExportServlet session id: " + session.getId());
ASLSession aslSession;
ServiceCredentials serviceCredentials;
try {
aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
String scopeGroupId = request
.getParameter(Constants.CURR_GROUP_ID);
serviceCredentials = SessionUtil.getServiceCredentials(request,
scopeGroupId);
ScopeProvider.instance.set(serviceCredentials.getScope());
} catch (ServiceException e) {
logger.error(e.getLocalizedMessage());
logger.error(
"Error retrieving credentials:"
+ e.getLocalizedMessage(), e);
e.printStackTrace();
throw new ServletException(e.getLocalizedMessage());
}
String exportType = request.getParameter(Constants.EXPORT_SERVLET_TYPE_PARAMETER);
String accountingType = request.getParameter(Constants.EXPORT_SERVLET_ACCOUNTING_TYPE_PARAMETER);
logger.debug("Request: [exportType="+exportType+", accountingType=" + accountingType + "]");
AccountingStateData accountingStateData=SessionUtil.getAccountingStateData(session, AccountingType.valueOf(accountingType));
if(accountingStateData==null){
logger.error("No series present in session for this accounting type: "+accountingType);
throw new ServletException("No series present in session for this accounting type: "+accountingType);
String exportType = request
.getParameter(Constants.EXPORT_SERVLET_TYPE_PARAMETER);
String accountingType = request
.getParameter(Constants.EXPORT_SERVLET_ACCOUNTING_TYPE_PARAMETER);
logger.debug("Request: [exportType=" + exportType
+ ", accountingType=" + accountingType + "]");
AccountingStateData accountingStateData = SessionUtil
.getAccountingStateData(session,
AccountingType.valueOf(accountingType));
if (accountingStateData == null) {
logger.error("No series present in session for this accounting type: "
+ accountingType);
throw new ServletException(
"No series present in session for this accounting type: "
+ accountingType);
}
ExportType exportT=ExportType.valueOf(exportType);
if(exportT==null){
logger.error("Invalid Export Type Request: "+exportType);
throw new ServletException("Invalid Export Type Request: "+exportType);
ExportType exportT = ExportType.valueOf(exportType);
if (exportT == null) {
logger.error("Invalid Export Type Request: " + exportType);
throw new ServletException("Invalid Export Type Request: "
+ exportType);
}
ExportDescriptor exportDescriptor=null;
switch(exportT){
ExportDescriptor exportDescriptor = null;
switch (exportT) {
case CSV:
CSVManager csvManager=new CSVManager(aslSession.getUsername());
exportDescriptor=csvManager.download(accountingStateData);
CSVManager csvManager = new CSVManager(
serviceCredentials.getUserName());
exportDescriptor = csvManager.download(accountingStateData);
response.setContentType("text/csv");
break;
case JSON:
JSONManager jsonManager=new JSONManager(aslSession.getUsername());
exportDescriptor=jsonManager.download(accountingStateData);
JSONManager jsonManager = new JSONManager(
serviceCredentials.getUserName());
exportDescriptor = jsonManager.download(accountingStateData);
response.setContentType("application/json");
break;
case XML:
XMLManager xmlManager=new XMLManager(aslSession.getUsername());
exportDescriptor=xmlManager.download(accountingStateData);
XMLManager xmlManager = new XMLManager(
serviceCredentials.getUserName());
exportDescriptor = xmlManager.download(accountingStateData);
response.setContentType("text/xml");
break;
default:
logger.error("Export Type not supported: "+exportType);
throw new ServletException("Export Type not supported: "+exportType);
logger.error("Export Type not supported: " + exportType);
throw new ServletException("Export Type not supported: "
+ exportType);
}
logger.debug("ExportDescriptor: "+exportDescriptor);
logger.debug("ExportDescriptor: " + exportDescriptor);
response.setHeader("Content-Disposition", "attachment; filename=\""
+ exportDescriptor.getCsvModel().getName()+exportDescriptor.getFileExtension() + "\"");
response.setHeader("Content-Length",
String.valueOf(exportDescriptor.getPath().toFile().length()));
+ exportDescriptor.getCsvModel().getName()
+ exportDescriptor.getFileExtension() + "\"");
response.setHeader("Content-Length", String
.valueOf(exportDescriptor.getPath().toFile().length()));
OutputStream out = response.getOutputStream();
Files.copy(exportDescriptor.getPath(), out);
out.flush();
out.close();
try {
Files.delete(exportDescriptor.getPath());
} catch (IOException e) {
logger.error("Error in deleting temp file: "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException("Error deleting temp file: "+e.getLocalizedMessage(),
e);
throw new ServiceException("Error deleting temp file: "
+ e.getLocalizedMessage(), e);
}
return;
} catch (Throwable e) {
logger.error("Error in ExportServlet: "
+ e.getLocalizedMessage());
logger.error("Error in ExportServlet: " + e.getLocalizedMessage());
e.printStackTrace();
throw new ServletException("Error: "
+ e.getLocalizedMessage(), e);
throw new ServletException("Error: " + e.getLocalizedMessage(), e);
}
}

View File

@ -6,18 +6,17 @@ package org.gcube.portlets.admin.accountingmanager.server;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
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.common.portal.PortalContext;
import org.gcube.portlets.admin.accountingmanager.server.state.AccountingState;
import org.gcube.portlets.admin.accountingmanager.server.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.server.util.ServiceCredentials;
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.Context;
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
import org.gcube.portlets.admin.accountingmanager.shared.exception.SessionExpiredException;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
@ -34,52 +33,87 @@ public class SessionUtil {
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
public static ASLSession getASLSession(HttpSession httpSession)
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest)
throws ServiceException {
String username = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
ASLSession portalContext;
if (username == null) {
if (Constants.DEBUG_MODE) {
logger.info("no user found in session, use test user");
// 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);
portalContext = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
portalContext.setScope(scope);
} else {
logger.info("No user found in session");
throw new SessionExpiredException("Session Expired!");
}
} else {
portalContext = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
}
logger.info("SessionUtil: aslSession " + portalContext.getUsername()
+ " " + portalContext.getScope());
return portalContext;
return getServiceCredentials(httpServletRequest, null);
}
public static String getToken(ASLSession aslSession)
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest, String scopeGroupId)
throws ServiceException {
String token = null;
if (Constants.DEBUG_MODE) {
token = Constants.DEFAULT_TOKEN;
} else {
token = aslSession.getSecurityToken();
}
logger.info("received token: " + token);
return token;
ServiceCredentials sCredentials = null;
String userName = null;
String scope = null;
String token = null;
if (Constants.DEBUG_MODE) {
logger.info("No credential found in session, use test user!");
userName = Constants.DEFAULT_USER;
scope = Constants.DEFAULT_SCOPE;
token = Constants.DEFAULT_TOKEN;
sCredentials = new ServiceCredentials(userName, scope, token);
} else {
logger.info("Retrieving credential in session!");
PortalContext pContext = PortalContext.getConfiguration();
if (scopeGroupId != null && !scopeGroupId.isEmpty()) {
scope = pContext.getCurrentScope(scopeGroupId);
} else {
scope = pContext.getCurrentScope(httpServletRequest);
}
if (scope == null || scope.isEmpty()) {
String error = "Error retrieving scope: " + scope;
logger.error(error);
throw new ServiceException(error);
}
userName = pContext.getCurrentUser(httpServletRequest)
.getUsername();
if (userName == null || userName.isEmpty()) {
String error = "Error retrieving username in scope " + scope
+ ": " + userName;
logger.error(error);
throw new ServiceException(error);
}
token = pContext.getCurrentUserToken(httpServletRequest);
if (token == null || token.isEmpty()) {
String error = "Error retrieving token for " + userName
+ " in " + scope + ": " + token;
logger.error(error);
throw new ServiceException(error);
}
String name = pContext.getCurrentUser(httpServletRequest)
.getFirstName();
String lastName = pContext.getCurrentUser(httpServletRequest)
.getLastName();
String fullName = pContext.getCurrentUser(httpServletRequest)
.getFullname();
String userAvatarURL = pContext.getCurrentUser(httpServletRequest)
.getUserAvatarURL();
String email = pContext.getCurrentUser(httpServletRequest)
.getEmail();
String groupId = String.valueOf(pContext
.getCurrentGroupId(httpServletRequest));
String groupName = pContext.getCurrentGroupName(httpServletRequest);
sCredentials = new ServiceCredentials(userName, fullName, name,
lastName, email, scope, groupId, groupName, userAvatarURL,
token);
}
logger.info("ServiceCredentials: " + sCredentials);
return sCredentials;
}
public static void setAccountingStateData(HttpSession httpSession,
@ -111,23 +145,23 @@ public class SessionUtil {
}
}
public static Context getContext(ASLSession aslSession)
public static Context getContext(ServiceCredentials serviceCredentials)
throws ServiceException {
try {
logger.info("Current context is " + aslSession.getScope());
logger.info("Current context is " + serviceCredentials.getScope());
ArrayList<String> contexts = new ArrayList<>();
if (Constants.DEBUG_MODE) {
contexts.add(aslSession.getScope());
contexts.add(serviceCredentials.getScope());
for(int i=0; i<50 ; i++){
contexts.add("/d4science.research-infrastructures.eu/gCubeApps/PerformanceEvaluationInAquaculture"+i);
}
} else {
contexts.add(aslSession.getScope());
contexts.add(serviceCredentials.getScope());
GroupManager gm = new LiferayGroupManager();
long currentGroupId = gm
.getGroupIdFromInfrastructureScope(aslSession
.getGroupIdFromInfrastructureScope(serviceCredentials
.getScope());
GCubeGroup currentGroup = gm.getGroup(currentGroupId);

View File

@ -11,7 +11,6 @@ import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -46,8 +45,8 @@ public class AccountingManagerPortlet extends GenericPortlet {
logger.trace("Loading from JSP: "+VIEW_JSP);
logger.trace("setting context using ScopeHelper");
ScopeHelper.setContext(request);
//logger.trace("setting context using ScopeHelper");
//ScopeHelper.setContext(request);
logger.trace("passing to the render");
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);

View File

@ -0,0 +1,141 @@
package org.gcube.portlets.admin.accountingmanager.server.util;
import java.io.Serializable;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ServiceCredentials implements Serializable {
private static final long serialVersionUID = 3560918948310315680L;
private String userName;
private String fullName;
private String name;
private String lastName;
private String email;
private String scope;
private String groupId;
private String groupName;
private String userAvatarURL;
private String token;
public ServiceCredentials() {
super();
}
public ServiceCredentials(String userName, String scope, String token) {
super();
this.userName = userName;
this.scope = scope;
this.token = token;
}
public ServiceCredentials(String userName, String fullName, String name,
String lastName, String email, String scope, String groupId,
String groupName, String userAvatarURL, String token) {
super();
this.userName = userName;
this.fullName = fullName;
this.name = name;
this.lastName = lastName;
this.email = email;
this.scope = scope;
this.groupId = groupId;
this.groupName = groupName;
this.userAvatarURL = userAvatarURL;
this.token = token;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getUserAvatarURL() {
return userAvatarURL;
}
public void setUserAvatarURL(String userAvatarURL) {
this.userAvatarURL = userAvatarURL;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
@Override
public String toString() {
return "ServiceCredentials [userName=" + userName + ", fullName="
+ fullName + ", name=" + name + ", lastName=" + lastName
+ ", email=" + email + ", scope=" + scope + ", groupId="
+ groupId + ", groupName=" + groupName + ", userAvatarURL="
+ userAvatarURL + ", token=" + token + "]";
}
}

View File

@ -12,16 +12,18 @@ public class Constants {
public static final boolean DEBUG_MODE = false;
public static final boolean TEST_ENABLE = false;
public static final String CURR_GROUP_ID = "CURR_GROUP_ID";
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 static final String DEFAULT_USER = "giancarlo.panichi";
public final static String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
public final static String DEFAULT_TOKEN = "ae1208f0-210d-47c9-9b24-d3f2dfcce05f-98187548";
// public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
// public final static String DEFAULT_TOKEN =
public static final String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
public static final String DEFAULT_TOKEN = "ae1208f0-210d-47c9-9b24-d3f2dfcce05f-98187548";
// public static final String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
// public static final String DEFAULT_TOKEN =
// "16e65d4f-11e0-4e4a-84b9-351688fccc12-98187548";
public static final String DEFAULT_ROLE = "OrganizationMember";
@ -30,14 +32,11 @@ public class Constants {
public static final String EXPORT_SERVLET_ACCOUNTING_TYPE_PARAMETER = "AccountingType";
public static final String SESSION_ACCOUNTING_STATE = "ACCOUNTING_STATE";
public static final AccountingType[] DEFAULT_TABS = new AccountingType[] { AccountingType.STORAGE };;
//IS Resource
// IS Resource
public static final String ACCOUNTING_NAME = "AccountingManager";
public static final String ACCOUNTING_CATEGORY = "AccountingProfile";
}

View File

@ -4,8 +4,8 @@ import java.io.Serializable;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class UserInfo implements Serializable {
@ -13,10 +13,9 @@ public class UserInfo implements Serializable {
private static final long serialVersionUID = -2826549639677017234L;
private String username;
private long groupId;
private String groupId;
private String groupName;
private String scope;
private String scopeName;
private String userEmailAddress;
private String userFullName;
@ -34,15 +33,13 @@ public class UserInfo implements Serializable {
* @param userEmailAddress
* @param userFullName
*/
public UserInfo(String username, long groupId, String groupName,
String scope, String scopeName, String userEmailAddress,
String userFullName) {
public UserInfo(String username, String groupId, String groupName,
String scope, String userEmailAddress, String userFullName) {
super();
this.username = username;
this.groupId = groupId;
this.groupName = groupName;
this.scope = scope;
this.scopeName = scopeName;
this.userEmailAddress = userEmailAddress;
this.userFullName = userFullName;
}
@ -55,11 +52,11 @@ public class UserInfo implements Serializable {
this.username = username;
}
public long getGroupId() {
public String getGroupId() {
return groupId;
}
public void setGroupId(long groupId) {
public void setGroupId(String groupId) {
this.groupId = groupId;
}
@ -79,14 +76,6 @@ public class UserInfo implements Serializable {
this.scope = scope;
}
public String getScopeName() {
return scopeName;
}
public void setScopeName(String scopeName) {
this.scopeName = scopeName;
}
public String getUserEmailAddress() {
return userEmailAddress;
}
@ -107,8 +96,8 @@ public class UserInfo implements Serializable {
public String toString() {
return "UserInfo [username=" + username + ", groupId=" + groupId
+ ", groupName=" + groupName + ", scope=" + scope
+ ", scopeName=" + scopeName + ", userEmailAddress="
+ userEmailAddress + ", userFullName=" + userFullName + "]";
+ ", userEmailAddress=" + userEmailAddress + ", userFullName="
+ userFullName + "]";
}
}

View File

@ -31,7 +31,8 @@
<inherits name='com.github.highcharts4gwt.highcharts' />
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' />
<!--Inherit the GCubeClientContext widget code -->
<inherits name='org.gcube.portal.clientcontext.GCubeClientContext' />
<!-- Specify the app entry point class. -->
<entry-point
@ -47,16 +48,15 @@
values="en" /> <extend-property name="locale" values="it" /> <extend-property
name="locale" values="es" /> <set-property name="locale" value="en, it, es"
/> <set-property-fallback name="locale" value="en" /> -->
<!--
<set-property name="log_ConsoleLogger" value="ENABLED" /> <set-property
<!-- <set-property name="log_ConsoleLogger" value="ENABLED" /> <set-property
name="log_DivLogger" value="ENABLED" /> <set-property name="log_GWTLogger"
value="ENABLED" /> <set-property name="log_SystemLogger" value="ENABLED"
/> -->
/> -->
<!-- Not in GWT 2.6 <set-property name="log_FirebugLogger" value="ENABLED"
/> -->
<set-property name="log_ConsoleLogger" value="DISABLED" />
<set-property name="log_DivLogger" value="DISABLED" />
<set-property name="log_GWTLogger" value="DISABLED" />

View File

@ -11,19 +11,6 @@
<servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class>
</servlet>
<!-- Check Session Expired -->
<servlet>
<servlet-name>checkServlet</servlet-name>
<servlet-class>org.gcube.portlets.widgets.sessionchecker.server.SessionCheckerServiceImpl</servlet-class>
</servlet>
<!-- Scope Helper -->
<servlet>
<servlet-name>scopeService</servlet-name>
<servlet-class>org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl</servlet-class>
</servlet>
<!-- AccountingManagerService -->
<servlet>
<servlet-name>AccountingManagerService</servlet-name>
@ -43,17 +30,6 @@
<url-pattern>/accountingman/junithost/*</url-pattern>
</servlet-mapping>
<!-- Check Session Expired -->
<servlet-mapping>
<servlet-name>checkServlet</servlet-name>
<url-pattern>/accountingman/checksession</url-pattern>
</servlet-mapping>
<!-- Scope Helper -->
<servlet-mapping>
<servlet-name>scopeService</servlet-name>
<url-pattern>/accountingman/scopeService</url-pattern>
</servlet-mapping>
<!-- AccountingManagerService -->
<servlet-mapping>