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"?>
<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>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</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>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -40,5 +40,5 @@
</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-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>

View File

@ -1,19 +1,25 @@
<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">
<Change>Added fix for support new portal theme</Change>
</Changeset>
<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 component="${groupId}.${artifactId}.1-7-0" date="2015-04-30">
<Change>Updated Inline Filter to support soundex, text begin and text
end</Change>
end
</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-6-0" date="2015-02-16">
<Change>Updated to GWT 2.6.1</Change>
<Change>Updated to GXT 3.1.1</Change>
<Change>Strengthened tabular-data-widgetx now support more rows [issue
#3238]</Change>
#3238]
</Change>
<Change>Fixed SelectionModel to select rows on different pages
</Change>
</Changeset>

52
pom.xml
View File

@ -10,7 +10,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-widgetx</artifactId>
<version>1.9.0-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
<name>tabular-data-widgetx</name>
<description>Widget that allows visualization of tabular data</description>
@ -24,7 +24,7 @@
<gwtLogVersion>3.3.2</gwtLogVersion>
<gxtVersion>3.1.1</gxtVersion>
<KEYS>${env.KEYS}</KEYS>
<!-- Don't let your Mac use a crazy non-standard encoding -->
@ -82,17 +82,49 @@
<version>${gxtVersion}</version>
</dependency>
<!-- Portal -->
<!-- PORTAL -->
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</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>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
@ -169,8 +201,8 @@
<module>org.gcube.portlets.user.tdwx.TabularDataWidgetX</module>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
@ -190,7 +222,7 @@
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencyManagement>

View File

@ -9,6 +9,7 @@ import java.util.HashMap;
import java.util.List;
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.type.GridHeaderColumnMenuItemType;
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.util.ColumnPositionComparator;
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.StaticFilterInformation;
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.SeparatorMenuItem;
import com.sencha.gxt.widget.core.client.selection.CellSelection;
import com.sencha.gxt.widget.core.client.toolbar.PagingToolBar;
/**
*
@ -101,12 +102,12 @@ public class TabularDataXGridPanel extends ContentPanel {
private ListStore<DataRow> store;
private Grid<DataRow> grid;
private TableDefinition tableDefinition;
private VerticalLayoutContainer container;
//private ExtendedLiveGridView<DataRow> liveGridView;
// private ExtendedLiveGridView<DataRow> liveGridView;
private DataRowPagingReader reader;
@ -132,7 +133,6 @@ public class TabularDataXGridPanel extends ContentPanel {
private PagingToolBarX pagingToolBar;
/**
* @param eventBus
*/
@ -149,7 +149,7 @@ public class TabularDataXGridPanel extends ContentPanel {
container = new VerticalLayoutContainer();
container.setBorders(false);
add(container, new MarginData(0));
}
/**
@ -447,14 +447,14 @@ public class TabularDataXGridPanel extends ContentPanel {
List<ColumnConfig<DataRow, ?>> columns = columnModel.getColumns();
List<ColumnConfig<DataRow, ?>> columnsNew = new ArrayList<ColumnConfig<DataRow, ?>>();
DataRowColumnConfig<?> columnTarget = null;
for (ColumnConfig<DataRow, ?> col : columns) {
columnTarget = (DataRowColumnConfig<?>) col;
String columnLocal = columnTarget.getDefinition()
.getColumnLocalId();
if (visibleOnlyColumn.compareTo(columnLocal) == 0) {
columnTarget.setHidden(false);
columnsNew.add(columnTarget);
} else {
@ -683,64 +683,55 @@ public class TabularDataXGridPanel extends ContentPanel {
.generateConfiguration(columnDefinition));
}
columnModel = new ColumnModel<DataRow>(columnsConfig);
columnModel = checkOnlyColumn(columnModel);
/*
columnModel
.addColumnMoveHandler(new ColumnMoveEvent.ColumnMoveHandler() {
@Override
public void onColumnMove(ColumnMoveEvent event) {
int columnIndex = event.getIndex();
@SuppressWarnings("unchecked")
ColumnConfig<DataRow, ?> col = (ColumnConfig<DataRow, ?>) event
.getColumnConfig();
DataRowColumnConfig<?> columnDataRow = (DataRowColumnConfig<?>) col;
ColumnDefinition colDef = columnDataRow.getDefinition();
Log.debug("Column Reordering", "Index: " + columnIndex
+ " Label: " + colDef.getLabel()
+ " Position: " + colDef.getPosition()
+ " ColumnId: " + colDef.getColumnLocalId());
if (colDef.isViewColumn()) {
Info.display("Attention",
"The view columns can not be moved");
// ColumnHeader<DataRow>
// colHeader=grid.getView().getHeader();
// event.getSource().moveColumn(columnIndex,
// colDef.getPosition());
} else {
ColumnsReorderingConfig columnsReorderingConfig = new ColumnsReorderingConfig(
columnIndex, colDef);
ColumnsReorderingEvent columnsReorderingEvent = new ColumnsReorderingEvent(
columnsReorderingConfig);
eventBus.fireEvent(columnsReorderingEvent);
}
}
});
*/
* columnModel .addColumnMoveHandler(new
* ColumnMoveEvent.ColumnMoveHandler() {
*
* @Override public void onColumnMove(ColumnMoveEvent event) { int
* columnIndex = event.getIndex();
*
* @SuppressWarnings("unchecked") ColumnConfig<DataRow, ?> col =
* (ColumnConfig<DataRow, ?>) event .getColumnConfig();
* DataRowColumnConfig<?> columnDataRow = (DataRowColumnConfig<?>) col;
* ColumnDefinition colDef = columnDataRow.getDefinition();
*
* Log.debug("Column Reordering", "Index: " + columnIndex + " Label: " +
* colDef.getLabel() + " Position: " + colDef.getPosition() +
* " ColumnId: " + colDef.getColumnLocalId());
*
* if (colDef.isViewColumn()) { Info.display("Attention",
* "The view columns can not be moved"); // ColumnHeader<DataRow> //
* colHeader=grid.getView().getHeader();
*
* // event.getSource().moveColumn(columnIndex, //
* colDef.getPosition()); } else { ColumnsReorderingConfig
* columnsReorderingConfig = new ColumnsReorderingConfig( columnIndex,
* colDef); ColumnsReorderingEvent columnsReorderingEvent = new
* ColumnsReorderingEvent( columnsReorderingConfig);
* eventBus.fireEvent(columnsReorderingEvent); } } });
*/
if (grid == null) {
Log.debug("Setup reader");
reader = new DataRowPagingReader(tableDefinition);
String path = GWT.getModuleBaseURL() + "tdwxdata";
String path = GWT.getModuleBaseURL()
+ Constants.TABULAR_DATA_X_SERVLET;
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
path);
builder.setHeader(ServletParameters.TD_SESSION_ID,
String.valueOf(tdSessionId));
builder.setHeader(Constants.CURR_GROUP_ID,
GCubeClientContext.getCurrentContextId());
HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
builder);
proxy.setWriter(new PagingLoadUrlEncoder(staticFilters));
loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>>(
proxy, reader) {
@Override
@ -756,12 +747,11 @@ public class TabularDataXGridPanel extends ContentPanel {
pagingToolBar = new PagingToolBarX(PAGINGDIMENSION);
pagingToolBar.getElement().getStyle()
.setProperty("borderBottom", "none");
.setProperty("borderBottom", "none");
pagingToolBar.fixPageTextWidth();
pagingToolBar.setItemId("TDMPagingToolBarX");
pagingToolBar.bind(loader);
grid = new Grid<DataRow>(store, columnModel) {
@Override
protected void onAfterFirstAttach() {
@ -779,7 +769,7 @@ public class TabularDataXGridPanel extends ContentPanel {
grid.setSelectionModel(sm);
grid.setLoadMask(true);
grid.setLoader(loader);
grid.setBorders(false);
grid.setColumnReordering(false);
@ -799,7 +789,6 @@ public class TabularDataXGridPanel extends ContentPanel {
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
container.add(pagingToolBar, new VerticalLayoutData(1, -1));
if (contextMenu != null) {
grid.setContextMenu(contextMenu);
} else
@ -811,7 +800,7 @@ public class TabularDataXGridPanel extends ContentPanel {
} else {
Log.debug("Setup grid not null");
reader.setDefinition(tableDefinition);
loader.clearSortInfo();
@ -819,20 +808,18 @@ public class TabularDataXGridPanel extends ContentPanel {
store));
grid.reconfigure(store, columnModel);
// Filter
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
.generate(columnModel);
Log.debug("Filters: " + filters.size());
for (Filter<DataRow, ?> filterGeneric : filters) {
gridFilters.addFilter(filterGeneric);
}
loader.load();
}
if (tableViewConfig != null) {
@ -852,7 +839,7 @@ public class TabularDataXGridPanel extends ContentPanel {
grid.getView().setViewConfig(
new TabularDataGridViewConfig(tableViewConfig,
tableDefinition));
}
container.forceLayout();

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;
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.TabularDataXServiceException;
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.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.model.TableDefinition;
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;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* @author "Giancarlo Panichi" <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;
protected static Logger logger = LoggerFactory.getLogger(TabularDataXServiceImpl.class);
protected DataSourceX getDataSource(int tdSessionId)
{
HttpSession httpSession = this.getThreadLocalRequest().getSession();
return SessionUtil.getDataSource(httpSession, tdSessionId);
}
private static Logger logger = LoggerFactory
.getLogger(TabularDataXServiceImpl.class);
/**
* {@inheritDoc}
*/
@Override
public TableDefinition openTable(int tdSessionId, TableId tableId) throws TabularDataXServiceException {
logger.debug("openTable tdSessionId: "+tdSessionId+" tableId: "+tableId);
public TableDefinition openTable(int tdSessionId, TableId tableId)
throws TabularDataXServiceException {
logger.debug("openTable tdSessionId: " + tdSessionId + " tableId: "
+ tableId);
try{
closeCurrentTable(tdSessionId, true);
HttpSession httpSession = this.getThreadLocalRequest().getSession();
DataSourceX dataSource = SessionUtil.openDataSource(httpSession, tableId);
SessionUtil.setDataSource(httpSession, tdSessionId, dataSource);
try {
HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
closeCurrentTable(httpRequest, serviceCredentials, tdSessionId,
true);
DataSourceX dataSource = SessionUtil.openDataSource(httpRequest,
serviceCredentials, tableId);
SessionUtil.setDataSource(httpRequest, serviceCredentials,
tdSessionId, dataSource);
logger.debug("Open table get table definition");
return dataSource.getTableDefinition();
}catch (Exception e) {
logger.error("An error occurred opening the specified table "+tableId+" in session "+tdSessionId, e);
throw new TabularDataXServiceException("An error occurred opening the specified table: "+e.getMessage());
} catch (Exception e) {
logger.error("An error occurred opening the specified table "
+ tableId + " in session " + tdSessionId, e);
throw new TabularDataXServiceException(
"An error occurred opening the specified table: "
+ e.getMessage());
}
}
@ -61,54 +66,75 @@ public class TabularDataXServiceImpl extends RemoteServiceServlet implements Tab
* {@inheritDoc}
*/
@Override
public TableDefinition getCurrentTableDefinition(int tdSessionId) throws TabularDataXServiceException {
logger.debug("getCurrentTableDefinition tdSessionId: "+tdSessionId);
public TableDefinition getCurrentTableDefinition(int tdSessionId)
throws TabularDataXServiceException {
logger.debug("getCurrentTableDefinition tdSessionId: " + tdSessionId);
try{
DataSourceX dataSource = getDataSource(tdSessionId);
try {
HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
DataSourceX dataSource = SessionUtil.getDataSource(httpRequest,
serviceCredentials, tdSessionId);
logger.debug("Service get current table definition");
return dataSource.getTableDefinition();
}catch (Exception e) {
} catch (Exception 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}
*/
@Override
public TableDefinition setCurrentTableColumnsReordering(int tdSessionId, ColumnsReorderingConfig columnReorderingConfig) throws TabularDataXServiceException {
logger.debug("setCurrentTableColumnsReordering tdSessionId: "+tdSessionId);
public TableDefinition setCurrentTableColumnsReordering(int tdSessionId,
ColumnsReorderingConfig columnReorderingConfig)
throws TabularDataXServiceException {
logger.debug("setCurrentTableColumnsReordering tdSessionId: "
+ tdSessionId);
try{
DataSourceX dataSource = getDataSource(tdSessionId);
try {
HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
DataSourceX dataSource = SessionUtil.getDataSource(httpRequest,
serviceCredentials, tdSessionId);
logger.debug("Service get current table definition");
TableDefinition tableDefinition=dataSource.setColumnReordering(columnReorderingConfig);
TableDefinition tableDefinition = dataSource
.setColumnReordering(columnReorderingConfig);
return tableDefinition;
}catch (Exception e) {
} catch (Exception 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());
}
}
/**
* {@inheritDoc}
*/
@Override
public TableDefinition getTableDefinition(TableId id) throws TabularDataXServiceException {
logger.debug("getTableDefinition TableId: "+id);
public TableDefinition getTableDefinition(TableId id)
throws TabularDataXServiceException {
logger.debug("getTableDefinition TableId: " + id);
try{
HttpSession httpSession = this.getThreadLocalRequest().getSession();
DataSourceX dataSource = SessionUtil.openDataSource(httpSession,id);
try {
HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
DataSourceX dataSource = SessionUtil.openDataSource(httpRequest,
serviceCredentials, id);
logger.debug("Service get table definition");
return dataSource.getTableDefinition();
}catch (Exception e) {
} catch (Exception 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
public void closeTable(int tdSessionId) throws TabularDataXServiceException {
try {
closeCurrentTable(tdSessionId, false);
} catch (DataSourceXException e) {
HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
closeCurrentTable(httpRequest, serviceCredentials, tdSessionId,
false);
} catch (Exception 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(int tdSessionId, boolean silent) throws DataSourceXException {
protected void closeCurrentTable(HttpServletRequest httpRequest,
ServiceCredentials serviceCredentials, int tdSessionId,
boolean silent) throws DataSourceXException {
try {
HttpSession httpSession = this.getThreadLocalRequest().getSession();
SessionUtil.closeDataSource(httpSession, tdSessionId);
} catch (DataSourceXException e)
{
if (!silent) throw e;
SessionUtil.closeDataSource(httpRequest, serviceCredentials,
tdSessionId);
} catch (DataSourceXException e) {
if (!silent)
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.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.ServletParameters;
import org.gcube.portlets.user.tdwx.shared.SortInformation;
@ -52,6 +53,32 @@ public class TabularDataXServlet extends HttpServlet {
logger.debug("TabularDataServlet handleRequest");
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
String tdSessionIdParameter = request
@ -153,7 +180,7 @@ public class TabularDataXServlet extends HttpServlet {
DataSourceX dataSource = SessionUtil.getDataSource(
request.getSession(), tdSessionId);
request,serviceCredentials, tdSessionId);
String json = dataSource.getDataAsJSon(start, limit, sortColumn,
direction, filtersList, staticFiltersList);

View File

@ -1,6 +1,6 @@
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;
@ -24,18 +24,21 @@ public interface DataSourceXFactory {
/**
* Open the specified datasource {@link DataSourceX}.
*
* @param serviceCredentials credentials
* @param id the datasource id.
* @return the retrieved 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.
* @param session
*
* @param serviceCredentials
* @param dataSource
* @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 {
protected int id;
protected DataSourceX dataSource;
private int id;
private DataSourceX dataSource;
/**
* @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;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class Constants {
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 final static String VERSION = "1.0.0";
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";
}