refs 6548: TDM - Migrate TabMan to new PortalContext

Task-Url: https://support.d4science.org/issues/6548

Updated to new PortalContext

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@141803 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-01-25 17:55:18 +00:00 committed by Giancarlo Panichi
parent 365401802c
commit 0400310e2c
12 changed files with 635 additions and 257 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/tabular-data-widgetx-1.9.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/tabular-data-widgetx-1.10.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/tabular-data-widgetx-1.9.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/tabular-data-widgetx-1.10.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
@ -40,5 +40,5 @@
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA.jar" sourcepath="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar"/> <classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA.jar" sourcepath="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar"/> <classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="output" path="target/tabular-data-widgetx-1.9.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/tabular-data-widgetx-1.10.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -1,19 +1,25 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="${groupId}.${artifactId}.1-10-0" date="2017-02-15">
<Change>Updated to new PortalContext [ticket #6548]</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-9-0" date="2016-12-01"> <Changeset component="${groupId}.${artifactId}.1-9-0" date="2016-12-01">
<Change>Added fix for support new portal theme</Change> <Change>Added fix for support new portal theme</Change>
</Changeset> </Changeset>
<Changeset component="${groupId}.${artifactId}.1-8-0" date="2015-07-03"> <Changeset component="${groupId}.${artifactId}.1-8-0" date="2015-07-03">
<Change>Added different colors for columns of different type [issue #251]</Change> <Change>Added different colors for columns of different type [issue
#251]</Change>
</Changeset> </Changeset>
<Changeset component="${groupId}.${artifactId}.1-7-0" date="2015-04-30"> <Changeset component="${groupId}.${artifactId}.1-7-0" date="2015-04-30">
<Change>Updated Inline Filter to support soundex, text begin and text <Change>Updated Inline Filter to support soundex, text begin and text
end</Change> end
</Change>
</Changeset> </Changeset>
<Changeset component="${groupId}.${artifactId}.1-6-0" date="2015-02-16"> <Changeset component="${groupId}.${artifactId}.1-6-0" date="2015-02-16">
<Change>Updated to GWT 2.6.1</Change> <Change>Updated to GWT 2.6.1</Change>
<Change>Updated to GXT 3.1.1</Change> <Change>Updated to GXT 3.1.1</Change>
<Change>Strengthened tabular-data-widgetx now support more rows [issue <Change>Strengthened tabular-data-widgetx now support more rows [issue
#3238]</Change> #3238]
</Change>
<Change>Fixed SelectionModel to select rows on different pages <Change>Fixed SelectionModel to select rows on different pages
</Change> </Change>
</Changeset> </Changeset>

44
pom.xml
View File

@ -10,7 +10,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-widgetx</artifactId> <artifactId>tabular-data-widgetx</artifactId>
<version>1.9.0-SNAPSHOT</version> <version>1.10.0-SNAPSHOT</version>
<name>tabular-data-widgetx</name> <name>tabular-data-widgetx</name>
<description>Widget that allows visualization of tabular data</description> <description>Widget that allows visualization of tabular data</description>
@ -82,17 +82,49 @@
<version>${gxtVersion}</version> <version>${gxtVersion}</version>
</dependency> </dependency>
<!-- Portal -->
<!-- PORTAL -->
<dependency> <dependency>
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.core</groupId>
<artifactId>custom-portal-handler</artifactId> <artifactId>common-scope-maps</artifactId>
<scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.applicationsupportlayer</groupId> <groupId>org.gcube.common.portal</groupId>
<artifactId>aslcore</artifactId> <artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<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>
<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>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>

View File

@ -9,6 +9,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.gcube.portal.clientcontext.client.GCubeClientContext;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.GridHeaderColumnMenuItemEvent; import org.gcube.portlets.user.td.widgetcommonevent.client.event.GridHeaderColumnMenuItemEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.GridHeaderColumnMenuItemType; import org.gcube.portlets.user.td.widgetcommonevent.client.type.GridHeaderColumnMenuItemType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.CellData; import org.gcube.portlets.user.td.widgetcommonevent.shared.CellData;
@ -33,6 +34,7 @@ import org.gcube.portlets.user.tdwx.client.model.util.ColumnConfigGenerator;
import org.gcube.portlets.user.tdwx.client.style.DefaultRowStyle; import org.gcube.portlets.user.tdwx.client.style.DefaultRowStyle;
import org.gcube.portlets.user.tdwx.client.util.ColumnPositionComparator; import org.gcube.portlets.user.tdwx.client.util.ColumnPositionComparator;
import org.gcube.portlets.user.tdwx.client.util.PagingLoadUrlEncoder; import org.gcube.portlets.user.tdwx.client.util.PagingLoadUrlEncoder;
import org.gcube.portlets.user.tdwx.shared.Constants;
import org.gcube.portlets.user.tdwx.shared.ServletParameters; import org.gcube.portlets.user.tdwx.shared.ServletParameters;
import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation; import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation;
import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition; import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition;
@ -77,7 +79,6 @@ import com.sencha.gxt.widget.core.client.menu.Menu;
import com.sencha.gxt.widget.core.client.menu.MenuItem; import com.sencha.gxt.widget.core.client.menu.MenuItem;
import com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem; import com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem;
import com.sencha.gxt.widget.core.client.selection.CellSelection; import com.sencha.gxt.widget.core.client.selection.CellSelection;
import com.sencha.gxt.widget.core.client.toolbar.PagingToolBar;
/** /**
* *
@ -106,7 +107,7 @@ public class TabularDataXGridPanel extends ContentPanel {
private VerticalLayoutContainer container; private VerticalLayoutContainer container;
//private ExtendedLiveGridView<DataRow> liveGridView; // private ExtendedLiveGridView<DataRow> liveGridView;
private DataRowPagingReader reader; private DataRowPagingReader reader;
@ -132,7 +133,6 @@ public class TabularDataXGridPanel extends ContentPanel {
private PagingToolBarX pagingToolBar; private PagingToolBarX pagingToolBar;
/** /**
* @param eventBus * @param eventBus
*/ */
@ -683,64 +683,55 @@ public class TabularDataXGridPanel extends ContentPanel {
.generateConfiguration(columnDefinition)); .generateConfiguration(columnDefinition));
} }
columnModel = new ColumnModel<DataRow>(columnsConfig); columnModel = new ColumnModel<DataRow>(columnsConfig);
columnModel = checkOnlyColumn(columnModel); columnModel = checkOnlyColumn(columnModel);
/* /*
columnModel * columnModel .addColumnMoveHandler(new
.addColumnMoveHandler(new ColumnMoveEvent.ColumnMoveHandler() { * ColumnMoveEvent.ColumnMoveHandler() {
*
@Override * @Override public void onColumnMove(ColumnMoveEvent event) { int
public void onColumnMove(ColumnMoveEvent event) { * columnIndex = event.getIndex();
int columnIndex = event.getIndex(); *
@SuppressWarnings("unchecked") * @SuppressWarnings("unchecked") ColumnConfig<DataRow, ?> col =
ColumnConfig<DataRow, ?> col = (ColumnConfig<DataRow, ?>) event * (ColumnConfig<DataRow, ?>) event .getColumnConfig();
.getColumnConfig(); * DataRowColumnConfig<?> columnDataRow = (DataRowColumnConfig<?>) col;
DataRowColumnConfig<?> columnDataRow = (DataRowColumnConfig<?>) col; * ColumnDefinition colDef = columnDataRow.getDefinition();
ColumnDefinition colDef = columnDataRow.getDefinition(); *
* Log.debug("Column Reordering", "Index: " + columnIndex + " Label: " +
Log.debug("Column Reordering", "Index: " + columnIndex * colDef.getLabel() + " Position: " + colDef.getPosition() +
+ " Label: " + colDef.getLabel() * " ColumnId: " + colDef.getColumnLocalId());
+ " Position: " + colDef.getPosition() *
+ " ColumnId: " + colDef.getColumnLocalId()); * if (colDef.isViewColumn()) { Info.display("Attention",
* "The view columns can not be moved"); // ColumnHeader<DataRow> //
if (colDef.isViewColumn()) { * colHeader=grid.getView().getHeader();
Info.display("Attention", *
"The view columns can not be moved"); * // event.getSource().moveColumn(columnIndex, //
// ColumnHeader<DataRow> * colDef.getPosition()); } else { ColumnsReorderingConfig
// colHeader=grid.getView().getHeader(); * columnsReorderingConfig = new ColumnsReorderingConfig( columnIndex,
* colDef); ColumnsReorderingEvent columnsReorderingEvent = new
// event.getSource().moveColumn(columnIndex, * ColumnsReorderingEvent( columnsReorderingConfig);
// colDef.getPosition()); * eventBus.fireEvent(columnsReorderingEvent); } } });
} else { */
ColumnsReorderingConfig columnsReorderingConfig = new ColumnsReorderingConfig(
columnIndex, colDef);
ColumnsReorderingEvent columnsReorderingEvent = new ColumnsReorderingEvent(
columnsReorderingConfig);
eventBus.fireEvent(columnsReorderingEvent);
}
}
});
*/
if (grid == null) { if (grid == null) {
Log.debug("Setup reader"); Log.debug("Setup reader");
reader = new DataRowPagingReader(tableDefinition); reader = new DataRowPagingReader(tableDefinition);
String path = GWT.getModuleBaseURL() + "tdwxdata"; String path = GWT.getModuleBaseURL()
+ Constants.TABULAR_DATA_X_SERVLET;
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
path); path);
builder.setHeader(ServletParameters.TD_SESSION_ID, builder.setHeader(ServletParameters.TD_SESSION_ID,
String.valueOf(tdSessionId)); String.valueOf(tdSessionId));
builder.setHeader(Constants.CURR_GROUP_ID,
GCubeClientContext.getCurrentContextId());
HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>( HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
builder); builder);
proxy.setWriter(new PagingLoadUrlEncoder(staticFilters)); proxy.setWriter(new PagingLoadUrlEncoder(staticFilters));
loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>>( loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>>(
proxy, reader) { proxy, reader) {
@Override @Override
@ -761,7 +752,6 @@ public class TabularDataXGridPanel extends ContentPanel {
pagingToolBar.setItemId("TDMPagingToolBarX"); pagingToolBar.setItemId("TDMPagingToolBarX");
pagingToolBar.bind(loader); pagingToolBar.bind(loader);
grid = new Grid<DataRow>(store, columnModel) { grid = new Grid<DataRow>(store, columnModel) {
@Override @Override
protected void onAfterFirstAttach() { protected void onAfterFirstAttach() {
@ -799,7 +789,6 @@ public class TabularDataXGridPanel extends ContentPanel {
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0))); container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
container.add(pagingToolBar, new VerticalLayoutData(1, -1)); container.add(pagingToolBar, new VerticalLayoutData(1, -1));
if (contextMenu != null) { if (contextMenu != null) {
grid.setContextMenu(contextMenu); grid.setContextMenu(contextMenu);
} else } else
@ -820,12 +809,10 @@ public class TabularDataXGridPanel extends ContentPanel {
grid.reconfigure(store, columnModel); grid.reconfigure(store, columnModel);
// Filter // Filter
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
.generate(columnModel); .generate(columnModel);
Log.debug("Filters: " + filters.size()); Log.debug("Filters: " + filters.size());
for (Filter<DataRow, ?> filterGeneric : filters) { for (Filter<DataRow, ?> filterGeneric : filters) {
gridFilters.addFilter(filterGeneric); gridFilters.addFilter(filterGeneric);

View File

@ -0,0 +1,251 @@
/**
*
*/
package org.gcube.portlets.user.tdwx.server;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXFactory;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXFactoryRegistry;
import org.gcube.portlets.user.tdwx.server.session.TDSession;
import org.gcube.portlets.user.tdwx.server.session.TDSessionList;
import org.gcube.portlets.user.tdwx.server.util.ServiceCredentials;
import org.gcube.portlets.user.tdwx.shared.Constants;
import org.gcube.portlets.user.tdwx.shared.model.TableId;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class SessionUtil {
private static final Logger logger = LoggerFactory
.getLogger(SessionUtil.class);
public static final String TDWX_SESSIONS_ATTRIBUTE_NAME = "TDWX.SESSIONS";
/**
*
* @param httpServletRequest
* @return
* @throws TDGWTServiceException
*/
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest) throws Exception {
return getServiceCredentials(httpServletRequest, null);
}
/**
*
* @param httpServletRequest
* @param scopeGroupId
* @return
* @throws TDGWTServiceException
*/
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest, String scopeGroupId)
throws Exception {
ServiceCredentials sCredentials = null;
String userName = null;
String scope = null;
String token = null;
String groupId = null;
String groupName = 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;
logger.info("Set SecurityToken: " + token);
SecurityTokenProvider.instance.set(token);
logger.info("Set ScopeProvider: " + scope);
ScopeProvider.instance.set(scope);
sCredentials = new ServiceCredentials(userName, scope, token);
} else {
logger.info("Retrieving credential in session!");
PortalContext pContext = PortalContext.getConfiguration();
boolean hasScopeGroupId = false;
if (scopeGroupId != null && !scopeGroupId.isEmpty()) {
hasScopeGroupId = true;
} else {
hasScopeGroupId = false;
}
if (hasScopeGroupId) {
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 Exception(error);
}
GCubeUser gCubeUser = pContext.getCurrentUser(httpServletRequest);
if (gCubeUser == null) {
String error = "Error retrieving gCubeUser in scope " + scope
+ ": " + gCubeUser;
logger.error(error);
throw new Exception(error);
}
userName = gCubeUser.getUsername();
if (userName == null || userName.isEmpty()) {
String error = "Error retrieving username in scope " + scope
+ ": " + userName;
logger.error(error);
throw new Exception(error);
}
token = pContext.getCurrentUserToken(scope, userName);
if (token == null || token.isEmpty()) {
String error = "Error retrieving token for " + userName
+ " in " + scope + ": " + token;
logger.error(error);
throw new Exception(error);
}
String name = gCubeUser.getFirstName();
String lastName = gCubeUser.getLastName();
String fullName = gCubeUser.getFullname();
String userAvatarURL = gCubeUser.getUserAvatarURL();
String email = gCubeUser.getEmail();
if (hasScopeGroupId) {
logger.info("Set SecurityToken: " + token);
SecurityTokenProvider.instance.set(token);
logger.info("Set ScopeProvider: " + scope);
ScopeProvider.instance.set(scope);
groupId = scopeGroupId;
long gId;
try {
gId = Long.parseLong(scopeGroupId);
} catch (Throwable e) {
String error = "Error retrieving groupId: " + scopeGroupId;
logger.error(error, e);
throw new Exception(error);
}
GCubeGroup group;
try {
group = new LiferayGroupManager().getGroup(gId);
} catch (Throwable e) {
String error = "Error retrieving group: " + groupName;
logger.error(error);
throw new Exception(error);
}
groupName = group.getGroupName();
} else {
groupId = String.valueOf(pContext
.getCurrentGroupId(httpServletRequest));
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 DataSourceX getDataSource(HttpServletRequest httpRequest,
ServiceCredentials serviceCredentials, int tdSessionId) {
TDSession tdSession = getSession(httpRequest, serviceCredentials,
tdSessionId);
return tdSession.getDataSource();
}
public static void setDataSource(HttpServletRequest httpRequest,
ServiceCredentials serviceCredentials, int tdSessionId,
DataSourceX datasource) {
TDSession tdSession = getSession(httpRequest, serviceCredentials,
tdSessionId);
tdSession.setDataSource(datasource);
logger.trace("datasource " + datasource + " set in session "
+ tdSessionId);
}
protected static TDSession getSession(HttpServletRequest httpRequest,
ServiceCredentials serviceCredentials, int tdSessionId) {
// workaround to TDSession object loaded from different class loader
HttpSession httpSession = httpRequest.getSession();
Object tsSession = httpSession
.getAttribute(TDWX_SESSIONS_ATTRIBUTE_NAME);
TDSessionList tdSessions = (tsSession instanceof TDSessionList) ? ((TDSessionList) tsSession)
: null;
if (tdSessions == null) {
tdSessions = new TDSessionList();
httpSession.setAttribute(TDWX_SESSIONS_ATTRIBUTE_NAME, tdSessions);
}
if (tdSessions.get(tdSessionId) == null) {
tdSessions.set(tdSessionId, new TDSession(tdSessionId));
logger.trace("created new td sessions " + tdSessionId);
}
return tdSessions.get(tdSessionId);
}
public static DataSourceX openDataSource(HttpServletRequest httpRequest,
ServiceCredentials serviceCredentials, TableId tableId)
throws DataSourceXException {
DataSourceXFactoryRegistry dataSourceFactoryRegistry = DataSourceXFactoryRegistry
.getInstance();
DataSourceXFactory factory = dataSourceFactoryRegistry.get(tableId
.getDataSourceFactoryId());
if (factory == null)
throw new DataSourceXException("DataSourceFactory with id "
+ tableId.getDataSourceFactoryId() + " don't exists");
return factory.openDataSource(serviceCredentials, tableId);
}
public static void closeDataSource(HttpServletRequest httpRequest,ServiceCredentials serviceCredentials, int tdSessionId)
throws DataSourceXException {
DataSourceX currentDataSource = getDataSource(httpRequest, serviceCredentials, tdSessionId);
if (currentDataSource != null) {
DataSourceXFactoryRegistry dataSourceFactoryRegistry = DataSourceXFactoryRegistry
.getInstance();
DataSourceXFactory factory = dataSourceFactoryRegistry
.get(currentDataSource.getDataSourceFactoryId());
factory.closeDataSource(serviceCredentials, currentDataSource);
}
}
}

View File

@ -3,57 +3,62 @@
*/ */
package org.gcube.portlets.user.tdwx.server; package org.gcube.portlets.user.tdwx.server;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.gcube.portlets.user.tdwx.client.rpc.TabularDataXService; import org.gcube.portlets.user.tdwx.client.rpc.TabularDataXService;
import org.gcube.portlets.user.tdwx.client.rpc.TabularDataXServiceException; import org.gcube.portlets.user.tdwx.client.rpc.TabularDataXServiceException;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX; import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException; import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException;
import org.gcube.portlets.user.tdwx.server.util.SessionUtil; import org.gcube.portlets.user.tdwx.server.util.ServiceCredentials;
import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig; import org.gcube.portlets.user.tdwx.shared.ColumnsReorderingConfig;
import org.gcube.portlets.user.tdwx.shared.model.TableDefinition; import org.gcube.portlets.user.tdwx.shared.model.TableDefinition;
import org.gcube.portlets.user.tdwx.shared.model.TableId; import org.gcube.portlets.user.tdwx.shared.model.TableId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/** /**
* *
* @author "Giancarlo Panichi" * @author "Giancarlo Panichi" <a
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class TabularDataXServiceImpl extends RemoteServiceServlet implements TabularDataXService { public class TabularDataXServiceImpl extends RemoteServiceServlet implements
TabularDataXService {
private static final long serialVersionUID = 193560783723693864L; private static final long serialVersionUID = 193560783723693864L;
protected static Logger logger = LoggerFactory.getLogger(TabularDataXServiceImpl.class); private static Logger logger = LoggerFactory
.getLogger(TabularDataXServiceImpl.class);
protected DataSourceX getDataSource(int tdSessionId)
{
HttpSession httpSession = this.getThreadLocalRequest().getSession();
return SessionUtil.getDataSource(httpSession, tdSessionId);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public TableDefinition openTable(int tdSessionId, TableId tableId) throws TabularDataXServiceException { public TableDefinition openTable(int tdSessionId, TableId tableId)
logger.debug("openTable tdSessionId: "+tdSessionId+" tableId: "+tableId); throws TabularDataXServiceException {
logger.debug("openTable tdSessionId: " + tdSessionId + " tableId: "
+ tableId);
try{ try {
closeCurrentTable(tdSessionId, true); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
HttpSession httpSession = this.getThreadLocalRequest().getSession(); .getServiceCredentials(httpRequest);
DataSourceX dataSource = SessionUtil.openDataSource(httpSession, tableId); closeCurrentTable(httpRequest, serviceCredentials, tdSessionId,
SessionUtil.setDataSource(httpSession, tdSessionId, dataSource); true);
DataSourceX dataSource = SessionUtil.openDataSource(httpRequest,
serviceCredentials, tableId);
SessionUtil.setDataSource(httpRequest, serviceCredentials,
tdSessionId, dataSource);
logger.debug("Open table get table definition"); logger.debug("Open table get table definition");
return dataSource.getTableDefinition(); return dataSource.getTableDefinition();
}catch (Exception e) { } catch (Exception e) {
logger.error("An error occurred opening the specified table "+tableId+" in session "+tdSessionId, e); logger.error("An error occurred opening the specified table "
throw new TabularDataXServiceException("An error occurred opening the specified table: "+e.getMessage()); + tableId + " in session " + tdSessionId, e);
throw new TabularDataXServiceException(
"An error occurred opening the specified table: "
+ e.getMessage());
} }
} }
@ -61,36 +66,51 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public TableDefinition getCurrentTableDefinition(int tdSessionId) throws TabularDataXServiceException { public TableDefinition getCurrentTableDefinition(int tdSessionId)
logger.debug("getCurrentTableDefinition tdSessionId: "+tdSessionId); throws TabularDataXServiceException {
logger.debug("getCurrentTableDefinition tdSessionId: " + tdSessionId);
try{ try {
DataSourceX dataSource = getDataSource(tdSessionId); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
DataSourceX dataSource = SessionUtil.getDataSource(httpRequest,
serviceCredentials, tdSessionId);
logger.debug("Service get current table definition"); logger.debug("Service get current table definition");
return dataSource.getTableDefinition(); return dataSource.getTableDefinition();
}catch (Exception e) { } catch (Exception e) {
logger.error("An error occurred retrieving the table definition", e); logger.error("An error occurred retrieving the table definition", e);
throw new TabularDataXServiceException("An error occurred retrieving the table definition: "+e.getMessage()); throw new TabularDataXServiceException(
"An error occurred retrieving the table definition: "
+ e.getMessage());
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public TableDefinition setCurrentTableColumnsReordering(int tdSessionId, ColumnsReorderingConfig columnReorderingConfig) throws TabularDataXServiceException { public TableDefinition setCurrentTableColumnsReordering(int tdSessionId,
logger.debug("setCurrentTableColumnsReordering tdSessionId: "+tdSessionId); ColumnsReorderingConfig columnReorderingConfig)
throws TabularDataXServiceException {
logger.debug("setCurrentTableColumnsReordering tdSessionId: "
+ tdSessionId);
try{ try {
DataSourceX dataSource = getDataSource(tdSessionId); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
DataSourceX dataSource = SessionUtil.getDataSource(httpRequest,
serviceCredentials, tdSessionId);
logger.debug("Service get current table definition"); logger.debug("Service get current table definition");
TableDefinition tableDefinition=dataSource.setColumnReordering(columnReorderingConfig); TableDefinition tableDefinition = dataSource
.setColumnReordering(columnReorderingConfig);
return tableDefinition; return tableDefinition;
}catch (Exception e) { } catch (Exception e) {
logger.error("An error occurred setting columns reordering", e); logger.error("An error occurred setting columns reordering", e);
throw new TabularDataXServiceException("An error occurred setting columns reordering: "+e.getMessage()); throw new TabularDataXServiceException(
"An error occurred setting columns reordering: "
+ e.getMessage());
} }
} }
@ -98,17 +118,23 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public TableDefinition getTableDefinition(TableId id) throws TabularDataXServiceException { public TableDefinition getTableDefinition(TableId id)
logger.debug("getTableDefinition TableId: "+id); throws TabularDataXServiceException {
logger.debug("getTableDefinition TableId: " + id);
try{ try {
HttpSession httpSession = this.getThreadLocalRequest().getSession(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
DataSourceX dataSource = SessionUtil.openDataSource(httpSession,id); ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
DataSourceX dataSource = SessionUtil.openDataSource(httpRequest,
serviceCredentials, id);
logger.debug("Service get table definition"); logger.debug("Service get table definition");
return dataSource.getTableDefinition(); return dataSource.getTableDefinition();
}catch (Exception e) { } catch (Exception e) {
logger.error("An error occurred getting the table definition", e); logger.error("An error occurred getting the table definition", e);
throw new TabularDataXServiceException("An error occurred getting the table definition: "+e.getMessage()); throw new TabularDataXServiceException(
"An error occurred getting the table definition: "
+ e.getMessage());
} }
} }
@ -118,21 +144,28 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab
@Override @Override
public void closeTable(int tdSessionId) throws TabularDataXServiceException { public void closeTable(int tdSessionId) throws TabularDataXServiceException {
try { try {
closeCurrentTable(tdSessionId, false); HttpServletRequest httpRequest = this.getThreadLocalRequest();
} catch (DataSourceXException e) { ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
closeCurrentTable(httpRequest, serviceCredentials, tdSessionId,
false);
} catch (Exception e) {
logger.error("An error occurred closing the current table", e); logger.error("An error occurred closing the current table", e);
throw new TabularDataXServiceException("An error occurred closing the current table: "+e.getMessage()); throw new TabularDataXServiceException(
"An error occurred closing the current table: "
+ e.getMessage());
} }
} }
protected void closeCurrentTable(HttpServletRequest httpRequest,
protected void closeCurrentTable(int tdSessionId, boolean silent) throws DataSourceXException { ServiceCredentials serviceCredentials, int tdSessionId,
boolean silent) throws DataSourceXException {
try { try {
HttpSession httpSession = this.getThreadLocalRequest().getSession(); SessionUtil.closeDataSource(httpRequest, serviceCredentials,
SessionUtil.closeDataSource(httpSession, tdSessionId); tdSessionId);
} catch (DataSourceXException e) } catch (DataSourceXException e) {
{ if (!silent)
if (!silent) throw e; throw e;
} }
} }

View File

@ -13,7 +13,8 @@ import javax.servlet.http.HttpServletResponse;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX; import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX;
import org.gcube.portlets.user.tdwx.server.datasource.Direction; import org.gcube.portlets.user.tdwx.server.datasource.Direction;
import org.gcube.portlets.user.tdwx.server.util.SessionUtil; import org.gcube.portlets.user.tdwx.server.util.ServiceCredentials;
import org.gcube.portlets.user.tdwx.shared.Constants;
import org.gcube.portlets.user.tdwx.shared.FilterInformation; import org.gcube.portlets.user.tdwx.shared.FilterInformation;
import org.gcube.portlets.user.tdwx.shared.ServletParameters; import org.gcube.portlets.user.tdwx.shared.ServletParameters;
import org.gcube.portlets.user.tdwx.shared.SortInformation; import org.gcube.portlets.user.tdwx.shared.SortInformation;
@ -53,6 +54,32 @@ public class TabularDataXServlet extends HttpServlet {
try { try {
ServiceCredentials serviceCredentials;
String scopeGroupId = request.getHeader(Constants.CURR_GROUP_ID);
if (scopeGroupId == null || scopeGroupId.isEmpty()) {
scopeGroupId = request.getParameter(Constants.CURR_GROUP_ID);
if (scopeGroupId == null || scopeGroupId.isEmpty()) {
logger.error("CURR_GROUP_ID is null, it is a mandatory parameter in custom servlet: "
+ scopeGroupId);
throw new ServletException(
"CURR_GROUP_ID is null, it is a mandatory parameter in custom servlet: "
+ scopeGroupId);
}
}
try {
serviceCredentials = SessionUtil.getServiceCredentials(request,
scopeGroupId);
} catch (Exception e) {
logger.error(
"Error retrieving credentials:" + e.getLocalizedMessage(),
e);
throw new ServletException(e.getLocalizedMessage());
}
// TD SESSION ID // TD SESSION ID
String tdSessionIdParameter = request String tdSessionIdParameter = request
.getHeader(ServletParameters.TD_SESSION_ID); .getHeader(ServletParameters.TD_SESSION_ID);
@ -153,7 +180,7 @@ public class TabularDataXServlet extends HttpServlet {
DataSourceX dataSource = SessionUtil.getDataSource( DataSourceX dataSource = SessionUtil.getDataSource(
request.getSession(), tdSessionId); request,serviceCredentials, tdSessionId);
String json = dataSource.getDataAsJSon(start, limit, sortColumn, String json = dataSource.getDataAsJSon(start, limit, sortColumn,
direction, filtersList, staticFiltersList); direction, filtersList, staticFiltersList);

View File

@ -1,6 +1,6 @@
package org.gcube.portlets.user.tdwx.server.datasource; package org.gcube.portlets.user.tdwx.server.datasource;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.portlets.user.tdwx.server.util.ServiceCredentials;
import org.gcube.portlets.user.tdwx.shared.model.TableId; import org.gcube.portlets.user.tdwx.shared.model.TableId;
@ -24,18 +24,21 @@ public interface DataSourceXFactory {
/** /**
* Open the specified datasource {@link DataSourceX}. * Open the specified datasource {@link DataSourceX}.
*
* @param serviceCredentials credentials
* @param id the datasource id. * @param id the datasource id.
* @return the retrieved datasource. * @return the retrieved datasource.
* @throws DataSourceXException if an error occurs retrieving the datasource. * @throws DataSourceXException if an error occurs retrieving the datasource.
*/ */
public DataSourceX openDataSource(ASLSession session, TableId id) throws DataSourceXException; public DataSourceX openDataSource(ServiceCredentials serviceCredentials, TableId id) throws DataSourceXException;
/** /**
* Close the specified DataSource releasing allocated resources. * Close the specified DataSource releasing allocated resources.
* @param session *
* @param serviceCredentials
* @param dataSource * @param dataSource
* @throws DataSourceXException * @throws DataSourceXException
*/ */
public void closeDataSource(ASLSession session, DataSourceX dataSource) throws DataSourceXException; public void closeDataSource(ServiceCredentials serviceCredentials, DataSourceX dataSource) throws DataSourceXException;
} }

View File

@ -13,8 +13,8 @@ import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX;
*/ */
public class TDSession { public class TDSession {
protected int id; private int id;
protected DataSourceX dataSource; private DataSourceX dataSource;
/** /**
* @param id * @param id

View File

@ -0,0 +1,141 @@
package org.gcube.portlets.user.tdwx.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

@ -1,110 +0,0 @@
/**
*
*/
package org.gcube.portlets.user.tdwx.server.util;
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.user.tdwx.server.datasource.DataSourceX;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXException;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXFactory;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceXFactoryRegistry;
import org.gcube.portlets.user.tdwx.server.session.TDSession;
import org.gcube.portlets.user.tdwx.server.session.TDSessionList;
import org.gcube.portlets.user.tdwx.shared.Constants;
import org.gcube.portlets.user.tdwx.shared.model.TableId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class SessionUtil {
private static final Logger log = LoggerFactory.getLogger(SessionUtil.class);
public static final String TDWX_SESSIONS_ATTRIBUTE_NAME = "TDWX.SESSIONS";
protected static ASLSession getSession(HttpSession httpSession)
{
String username = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
ASLSession session;
if (username == null) {
log.warn("no user found in session, using test one");
username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE;
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username);
session = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
session.setScope(scope);
} else {
session= SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
}
return session;
}
public static DataSourceX getDataSource(HttpSession httpSession, int tdSessionId)
{
ASLSession session = getSession(httpSession);
TDSession tdSession = getSession(session, tdSessionId);
return tdSession.getDataSource();
}
public static void setDataSource(HttpSession httpSession, int tdSessionId, DataSourceX datasource)
{
ASLSession session = getSession(httpSession);
TDSession tdSession = getSession(session, tdSessionId);
tdSession.setDataSource(datasource);
log.trace("datasource "+datasource+" set in session "+tdSessionId);
}
protected static TDSession getSession(ASLSession session, int tdSessionId)
{
//workaround to TDSession object loaded from different class loader
Object tsSession = session.getAttribute(TDWX_SESSIONS_ATTRIBUTE_NAME);
TDSessionList sessions = (tsSession instanceof TDSessionList)?((TDSessionList) tsSession):null;
if (sessions == null) {
sessions = new TDSessionList();
session.setAttribute(TDWX_SESSIONS_ATTRIBUTE_NAME, sessions);
}
if (sessions.get(tdSessionId)==null) {
sessions.set(tdSessionId, new TDSession(tdSessionId));
log.trace("created new sessions "+tdSessionId);
}
return sessions.get(tdSessionId);
}
public static DataSourceX openDataSource(HttpSession httpSession, TableId tableId) throws DataSourceXException
{
DataSourceXFactoryRegistry dataSourceFactoryRegistry = DataSourceXFactoryRegistry.getInstance();
DataSourceXFactory factory = dataSourceFactoryRegistry.get(tableId.getDataSourceFactoryId());
if (factory==null) throw new DataSourceXException("DataSourceFactory with id "+tableId.getDataSourceFactoryId()+" don't exists");
ASLSession session = getSession(httpSession);
return factory.openDataSource(session, tableId);
}
public static void closeDataSource(HttpSession httpSession, int tdSessionId) throws DataSourceXException
{
DataSourceX currentDataSource = getDataSource(httpSession, tdSessionId);
if (currentDataSource != null) {
DataSourceXFactoryRegistry dataSourceFactoryRegistry = DataSourceXFactoryRegistry.getInstance();
DataSourceXFactory factory = dataSourceFactoryRegistry.get(currentDataSource.getDataSourceFactoryId());
ASLSession session = getSession(httpSession);
factory.closeDataSource(session, currentDataSource);
}
}
}

View File

@ -3,20 +3,28 @@
*/ */
package org.gcube.portlets.user.tdwx.shared; package org.gcube.portlets.user.tdwx.shared;
/** /**
* *
* @author "Giancarlo Panichi" * @author "Giancarlo Panichi" <a
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class Constants { public class Constants {
public final static String VERSION = "1.0.0"; public final static String VERSION = "1.0.0";
public final static String DEFAULT_USER = "giancarlo.panichi";
public final static String DEFAULT_SCOPE = "/gcube/devsec";
public final static String REMOTE_SERVICE_RELATIVE_PATH= "tdwx";
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 CURR_USER_ID = "CURR_USER_ID";
public static final String DEFAULT_USER = "giancarlo.panichi";
public static final String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
public static final String DEFAULT_TOKEN = "ae1208f0-210d-47c9-9b24-d3f2dfcce05f-98187548";
public final static String REMOTE_SERVICE_RELATIVE_PATH = "tdwx";
public static final String TABULAR_DATA_X_SERVLET = "tdwxdata";
} }