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-expression-widget@141744 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-01-24 16:53:58 +00:00
parent 4a5027657c
commit 9db7271d3e
9 changed files with 174 additions and 225 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-expression-widget-1.8.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/tabular-data-expression-widget-1.9.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-expression-widget-1.8.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/tabular-data-expression-widget-1.9.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>
@ -32,5 +32,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/tabular-data-expression-widget-1.8.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/tabular-data-expression-widget-1.9.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -1,4 +1,8 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets-user.tabular-data-expression-widget.1-9-0"
date="2017-02-15">
<Change>Updated to new PortalContext [ticket #6548]</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.tabular-data-expression-widget.1-8-0" <Changeset component="org.gcube.portlets-user.tabular-data-expression-widget.1-8-0"
date="2016-07-15"> date="2016-07-15">
<Change>Updated to Liferay 6.2</Change> <Change>Updated to Liferay 6.2</Change>

28
pom.xml
View File

@ -13,7 +13,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-expression-widget</artifactId> <artifactId>tabular-data-expression-widget</artifactId>
<version>1.8.0-SNAPSHOT</version> <version>1.9.0-SNAPSHOT</version>
<name>tabular-data-expression-widget</name> <name>tabular-data-expression-widget</name>
@ -108,32 +108,14 @@
<version>${gxtVersion}</version> <version>${gxtVersion}</version>
</dependency> </dependency>
<!-- Portal --> <!-- PORTAL -->
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId> <artifactId>common-scope-maps</artifactId>
<version>[1.0.2-SNAPSHOT,2.0.0-SNAPSHOT)</version> <!-- <version>[1.0.2-SNAPSHOT,2.0.0-SNAPSHOT)</version> -->
<scope>provided</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>accesslogger</artifactId>
<scope>provided</scope>
</dependency>
<!-- service-client-impl --> <!-- service-client-impl -->
<dependency> <dependency>
<groupId>org.gcube.data.analysis.tabulardata</groupId> <groupId>org.gcube.data.analysis.tabulardata</groupId>

View File

@ -13,10 +13,12 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data.analysis.tabulardata.expression.Expression; import org.gcube.data.analysis.tabulardata.expression.Expression;
import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionParserException; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ExpressionParserException;
import org.gcube.portlets.user.td.gwtservice.server.SessionUtil; import org.gcube.portlets.user.td.gwtservice.server.SessionUtil;
import org.gcube.portlets.user.td.gwtservice.server.util.ServiceCredentials;
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -64,14 +66,19 @@ public class CExpressionMapServlet extends HttpServlet {
logger.info("CExpressionMapServlet import session id: " logger.info("CExpressionMapServlet import session id: "
+ session.getId()); + session.getId());
ServiceCredentials serviceCredentials;
try { try {
ASLSession aslSession = SessionUtil.getAslSession(session); String scopeGroupId = request.getParameter(Constants.CURR_GROUP_ID);
String token = SessionUtil.getToken(aslSession); serviceCredentials = SessionUtil.getServiceCredentials(request,
logger.debug("UserToken: " + token); scopeGroupId);
ScopeProvider.instance.set(serviceCredentials.getScope());
} catch (TDGWTServiceException e) { } catch (TDGWTServiceException e) {
logger.error(e.getLocalizedMessage()); logger.error(
e.printStackTrace(); "Error retrieving credentials:" + e.getLocalizedMessage(),
e);
throw new ServletException(e.getLocalizedMessage()); throw new ServletException(e.getLocalizedMessage());
} }

View File

@ -4,12 +4,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleType; import org.gcube.data.analysis.tabulardata.commons.rules.types.RuleType;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider;
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.AppliedRulesResponse; import org.gcube.data.analysis.tabulardata.commons.webservice.types.AppliedRulesResponse;
import org.gcube.data.analysis.tabulardata.commons.webservice.types.RuleDescription; import org.gcube.data.analysis.tabulardata.commons.webservice.types.RuleDescription;
import org.gcube.data.analysis.tabulardata.expression.Expression; import org.gcube.data.analysis.tabulardata.expression.Expression;
@ -29,6 +26,7 @@ import org.gcube.portlets.user.td.gwtservice.server.SessionUtil;
import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl; import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceImpl;
import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceMessagesConstants; import org.gcube.portlets.user.td.gwtservice.server.TDGWTServiceMessagesConstants;
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap;
import org.gcube.portlets.user.td.gwtservice.server.util.ServiceCredentials;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.rule.AppliedRulesResponseData; import org.gcube.portlets.user.td.gwtservice.shared.rule.AppliedRulesResponseData;
import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyAndDetachColumnRulesSession; import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyAndDetachColumnRulesSession;
@ -73,18 +71,21 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
@Override @Override
public String startFilterColumn(FilterColumnSession filterColumnSession) public String startFilterColumn(FilterColumnSession filterColumnSession)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpSession session=null; HttpServletRequest httpRequest = null;
try { try {
logger.debug("ExpressionService submitColumnFilter"); httpRequest = this.getThreadLocalRequest();
session = this.getThreadLocalRequest().getSession(); ServiceCredentials serviceCredentials = SessionUtil
logger.debug("Session: " + session); .getServiceCredentials(httpRequest);
if (filterColumnSession == null) { if (filterColumnSession == null) {
logger.error("FilterColumnSession is null"); logger.error("FilterColumnSession is null");
new ExpressionServiceException("FilterColumnSession is null"); new ExpressionServiceException("FilterColumnSession is null");
} else {
logger.debug("FilterColumnSession: " + filterColumnSession);
} }
ExpressionSession.setColumnFilterSession(session,
filterColumnSession); ExpressionSession.setColumnFilterSession(httpRequest,
serviceCredentials, filterColumnSession);
C_ExpressionParser parser = new C_ExpressionParser(); C_ExpressionParser parser = new C_ExpressionParser();
Expression expression = null; Expression expression = null;
@ -99,7 +100,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
// TDGWTServiceImpl gwtService = new TDGWTServiceImpl(); // TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
String taskId = startFilterColumn(filterColumnSession, expression, String taskId = startFilterColumn(filterColumnSession, expression,
session); httpRequest);
return taskId; return taskId;
@ -108,9 +109,9 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} catch (SecurityException e) { } catch (SecurityException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
ResourceBundle messages = getResourceBundle(session); ResourceBundle messages = getResourceBundle(httpRequest);
throw new TDGWTServiceException( throw new TDGWTServiceException(
messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights));
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
throw new TDGWTServiceException(e.getLocalizedMessage()); throw new TDGWTServiceException(e.getLocalizedMessage());
@ -124,15 +125,16 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
public String startAddColumn(AddColumnSession addColumnSession) public String startAddColumn(AddColumnSession addColumnSession)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpSession session=null; HttpServletRequest httpRequest = null;
try { try {
logger.debug("AddColumn"); httpRequest = this.getThreadLocalRequest();
session = this.getThreadLocalRequest().getSession();
logger.debug("Session: " + session);
logger.debug("AddColumn");
if (addColumnSession == null) { if (addColumnSession == null) {
logger.error("AddColumnSession is null"); logger.error("AddColumnSession is null");
new ExpressionServiceException("AddColumnSession is null"); new ExpressionServiceException("AddColumnSession is null");
} else {
logger.debug("AddColumnSession: " + addColumnSession);
} }
ColumnMockUp columnMockUp = addColumnSession.getColumnMockUp(); ColumnMockUp columnMockUp = addColumnSession.getColumnMockUp();
@ -155,7 +157,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
// TDGWTServiceImpl gwtService = new TDGWTServiceImpl(); // TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
String taskId = startAddColumn(addColumnSession, expression, String taskId = startAddColumn(addColumnSession, expression,
session); httpRequest);
return taskId; return taskId;
@ -164,10 +166,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} catch (SecurityException e) { } catch (SecurityException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
ResourceBundle messages = getResourceBundle(session); ResourceBundle messages = getResourceBundle(httpRequest);
throw new TDGWTServiceException( throw new TDGWTServiceException(
messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights));
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
throw new TDGWTServiceException(e.getLocalizedMessage()); throw new TDGWTServiceException(e.getLocalizedMessage());
@ -183,19 +185,25 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
ReplaceColumnByExpressionSession replaceColumnByExpressionSession) ReplaceColumnByExpressionSession replaceColumnByExpressionSession)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpSession session=null; HttpServletRequest httpRequest = null;
try { try {
httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
logger.debug("ExpressionService submitReplaceColumnByExpression"); logger.debug("ExpressionService submitReplaceColumnByExpression");
session = this.getThreadLocalRequest().getSession();
logger.debug("Session: " + session);
if (replaceColumnByExpressionSession == null) { if (replaceColumnByExpressionSession == null) {
logger.error("ReplaceColumnByExpressionSession is null"); logger.error("ReplaceColumnByExpressionSession is null");
new ExpressionServiceException( new ExpressionServiceException(
"ReplaceColumnByExpressionSession is null"); "ReplaceColumnByExpressionSession is null");
} else {
logger.debug("ReplaceColumnByExpressionSession: "
+ replaceColumnByExpressionSession);
} }
ExpressionSession.setReplaceColumnByExpressionSession(session,
replaceColumnByExpressionSession); ExpressionSession.setReplaceColumnByExpressionSession(httpRequest,
serviceCredentials, replaceColumnByExpressionSession);
C_ExpressionParser parser = new C_ExpressionParser(); C_ExpressionParser parser = new C_ExpressionParser();
@ -226,7 +234,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
String taskId = startReplaceColumnByExpression( String taskId = startReplaceColumnByExpression(
replaceColumnByExpressionSession, conditionExpression, replaceColumnByExpressionSession, conditionExpression,
replaceExpression, session); replaceExpression, httpRequest);
return taskId; return taskId;
} catch (TDGWTServiceException e) { } catch (TDGWTServiceException e) {
@ -234,9 +242,9 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} catch (SecurityException e) { } catch (SecurityException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
ResourceBundle messages = getResourceBundle(session); ResourceBundle messages = getResourceBundle(httpRequest);
throw new TDGWTServiceException( throw new TDGWTServiceException(
messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights));
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
throw new TDGWTServiceException(e.getLocalizedMessage()); throw new TDGWTServiceException(e.getLocalizedMessage());
@ -250,16 +258,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
@Override @Override
public ArrayList<RuleDescriptionData> getRules() public ArrayList<RuleDescriptionData> getRules()
throws TDGWTServiceException { throws TDGWTServiceException {
HttpSession session=null; HttpServletRequest httpRequest = null;
try { try {
session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
ASLSession aslSession = SessionUtil.getAslSession(session); SessionUtil.getServiceCredentials(httpRequest);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("GetRules()"); logger.debug("GetRules()");
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
List<RuleDescription> rules = service.getRules(); List<RuleDescription> rules = service.getRules();
@ -284,10 +288,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} catch (SecurityException e) { } catch (SecurityException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
ResourceBundle messages = getResourceBundle(session); ResourceBundle messages = getResourceBundle(httpRequest);
throw new TDGWTServiceException( throw new TDGWTServiceException(
messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights));
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error in getRules(): " + e.getLocalizedMessage()); logger.error("Error in getRules(): " + e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
@ -304,16 +308,11 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
@Override @Override
public ArrayList<RuleDescriptionData> getRules(RuleScopeType scope) public ArrayList<RuleDescriptionData> getRules(RuleScopeType scope)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpSession session=null; HttpServletRequest httpRequest = null;
try { try {
session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
ASLSession aslSession = SessionUtil.getAslSession(session); SessionUtil.getServiceCredentials(httpRequest);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("GetRules(): " + scope); logger.debug("GetRules(): " + scope);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
List<RuleDescription> rules = service.getRulesByScope(RuleScopeMap List<RuleDescription> rules = service.getRulesByScope(RuleScopeMap
@ -339,7 +338,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} catch (SecurityException e) { } catch (SecurityException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
ResourceBundle messages = getResourceBundle(session); ResourceBundle messages = getResourceBundle(httpRequest);
throw new TDGWTServiceException( throw new TDGWTServiceException(
messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights));
} catch (Throwable e) { } catch (Throwable e) {
@ -358,16 +357,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
@Override @Override
public ArrayList<RuleDescriptionData> getApplicableBaseColumnRules( public ArrayList<RuleDescriptionData> getApplicableBaseColumnRules(
ColumnData columnData) throws TDGWTServiceException { ColumnData columnData) throws TDGWTServiceException {
HttpSession session=null; HttpServletRequest httpRequest = null;
try { try {
session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
ASLSession aslSession = SessionUtil.getAslSession(session); SessionUtil.getServiceCredentials(httpRequest);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("GetApplicableBaseColumnRules(): " + columnData); logger.debug("GetApplicableBaseColumnRules(): " + columnData);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
if (columnData == null) { if (columnData == null) {
@ -409,10 +404,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} catch (SecurityException e) { } catch (SecurityException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
ResourceBundle messages = getResourceBundle(session); ResourceBundle messages = getResourceBundle(httpRequest);
throw new TDGWTServiceException( throw new TDGWTServiceException(
messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights));
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error in getApplicableBaseColumnRules(): " logger.error("Error in getApplicableBaseColumnRules(): "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
@ -430,16 +425,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
@Override @Override
public AppliedRulesResponseData getActiveRulesByTabularResourceId(TRId trId) public AppliedRulesResponseData getActiveRulesByTabularResourceId(TRId trId)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpSession session=null; HttpServletRequest httpRequest = null;
try { try {
session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
ASLSession aslSession = SessionUtil.getAslSession(session); SessionUtil.getServiceCredentials(httpRequest);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("GetAppliedRulesByTabularResourceId(): " + trId); logger.debug("GetAppliedRulesByTabularResourceId(): " + trId);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
if (trId == null || trId.getId() == null || trId.getId().isEmpty()) { if (trId == null || trId.getId() == null || trId.getId().isEmpty()) {
@ -471,10 +462,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} catch (SecurityException e) { } catch (SecurityException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
ResourceBundle messages = getResourceBundle(session); ResourceBundle messages = getResourceBundle(httpRequest);
throw new TDGWTServiceException( throw new TDGWTServiceException(
messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights));
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error in getActiveRulesByTabularResourceId(): " logger.error("Error in getActiveRulesByTabularResourceId(): "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
@ -490,19 +481,14 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public String saveRule( public String saveRule(RuleDescriptionData ruleDescriptionData)
RuleDescriptionData ruleDescriptionData)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpSession session=null; HttpServletRequest httpRequest = null;
try { try {
session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
ASLSession aslSession = SessionUtil.getAslSession(session); SessionUtil.getServiceCredentials(httpRequest);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("SaveRule() :" + ruleDescriptionData); logger.debug("SaveRule() :" + ruleDescriptionData);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
C_ExpressionParser parser = new C_ExpressionParser(); C_ExpressionParser parser = new C_ExpressionParser();
@ -519,25 +505,22 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
logger.debug("Service Condition Expression:" + conditionExpression); logger.debug("Service Condition Expression:" + conditionExpression);
RuleType ruleType = RuleTypeMap RuleType ruleType = RuleTypeMap.map(ruleDescriptionData
.map(ruleDescriptionData.getTdRuleType()); .getTdRuleType());
if (ruleType == null) { if (ruleType == null) {
logger.error("Error saving rule, rule type is null!"); logger.error("Error saving rule, rule type is null!");
throw new TDGWTServiceException( throw new TDGWTServiceException(
"Error saving rule, rule type is null!"); "Error saving rule, rule type is null!");
} }
RuleId ruleId = service.saveRule( RuleId ruleId = service.saveRule(ruleDescriptionData.getName(),
ruleDescriptionData.getName(), ruleDescriptionData.getDescription(), conditionExpression,
ruleDescriptionData.getDescription(), ruleType);
conditionExpression, ruleType);
logger.debug("RuleId: " + ruleId); logger.debug("RuleId: " + ruleId);
String ruleIdent = null; String ruleIdent = null;
if (ruleId != null) { if (ruleId != null) {
ruleIdent = String.valueOf(ruleId.getValue()); ruleIdent = String.valueOf(ruleId.getValue());
} }
@ -550,13 +533,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} catch (SecurityException e) { } catch (SecurityException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
ResourceBundle messages = getResourceBundle(session); ResourceBundle messages = getResourceBundle(httpRequest);
throw new TDGWTServiceException( throw new TDGWTServiceException(
messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights));
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error in save rule: " logger.error("Error in save rule: " + e.getLocalizedMessage());
+ e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
throw new TDGWTServiceException("Error in save rule: " throw new TDGWTServiceException("Error in save rule: "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
@ -564,7 +546,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
@ -572,16 +553,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
@Override @Override
public void updateColumnRule(RuleDescriptionData ruleDescriptionData) public void updateColumnRule(RuleDescriptionData ruleDescriptionData)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpSession session=null; HttpServletRequest httpRequest = null;
try { try {
session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
ASLSession aslSession = SessionUtil.getAslSession(session); SessionUtil.getServiceCredentials(httpRequest);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("UpdateColumnRule() :" + ruleDescriptionData); logger.debug("UpdateColumnRule() :" + ruleDescriptionData);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
RuleDescription ruleDescription = RuleDescriptionMap RuleDescription ruleDescription = RuleDescriptionMap
@ -605,10 +582,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} catch (SecurityException e) { } catch (SecurityException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
ResourceBundle messages = getResourceBundle(session); ResourceBundle messages = getResourceBundle(httpRequest);
throw new TDGWTServiceException( throw new TDGWTServiceException(
messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights));
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error in getRule(): " + e.getLocalizedMessage()); logger.error("Error in getRule(): " + e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
@ -625,12 +602,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
@Override @Override
public void removeRulesById(ArrayList<RuleDescriptionData> rules) public void removeRulesById(ArrayList<RuleDescriptionData> rules)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpSession session=null; HttpServletRequest httpRequest = null;
try { try {
session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
ASLSession aslSession = SessionUtil.getAslSession(session); SessionUtil.getServiceCredentials(httpRequest);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("RemoveRuleById() :" + rules); logger.debug("RemoveRuleById() :" + rules);
if (rules == null || !(rules.size() > 0)) { if (rules == null || !(rules.size() > 0)) {
@ -638,8 +613,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
"Error removing the rule, no rules selected"); "Error removing the rule, no rules selected");
} }
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername(), aslSession.getScope()));
TabularDataService service = TabularDataServiceFactory.getService(); TabularDataService service = TabularDataServiceFactory.getService();
for (RuleDescriptionData ruleDescriptionData : rules) { for (RuleDescriptionData ruleDescriptionData : rules) {
@ -654,10 +627,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} catch (SecurityException e) { } catch (SecurityException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
ResourceBundle messages = getResourceBundle(session); ResourceBundle messages = getResourceBundle(httpRequest);
throw new TDGWTServiceException( throw new TDGWTServiceException(
messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights));
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error in removeRuleById(): " logger.error("Error in removeRuleById(): "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
@ -676,10 +649,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
public String startApplyAndDetachColumnRules( public String startApplyAndDetachColumnRules(
ApplyAndDetachColumnRulesSession applyAndDetachColumnRulesSession) ApplyAndDetachColumnRulesSession applyAndDetachColumnRulesSession)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpServletRequest httpRequest = null;
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
String taskId = startApplyAndDetachColumnnRules( String taskId = startApplyAndDetachColumnnRules(
applyAndDetachColumnRulesSession, session); applyAndDetachColumnRulesSession, httpRequest);
return taskId; return taskId;
} catch (TDGWTServiceException e) { } catch (TDGWTServiceException e) {
@ -690,16 +665,16 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} }
} }
@Override @Override
public String startApplyTableRule( public String startApplyTableRule(
ApplyTableRuleSession applyTableRuleSession) ApplyTableRuleSession applyTableRuleSession)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpServletRequest httpRequest = null;
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
String taskId = startApplyTableRule( String taskId = startApplyTableRule(applyTableRuleSession,
applyTableRuleSession, session); httpRequest);
return taskId; return taskId;
} catch (TDGWTServiceException e) { } catch (TDGWTServiceException e) {
@ -710,7 +685,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} }
} }
/** /**
* *
@ -720,9 +694,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
public void setDetachColumnRules( public void setDetachColumnRules(
DetachColumnRulesSession detachColumnRulesSession) DetachColumnRulesSession detachColumnRulesSession)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpServletRequest httpRequest = null;
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
setDetachColumnnRules(detachColumnRulesSession, session); setDetachColumnnRules(detachColumnRulesSession, httpRequest);
return; return;
} catch (TDGWTServiceException e) { } catch (TDGWTServiceException e) {
@ -734,7 +709,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
@ -743,9 +717,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
public void setDetachTableRules( public void setDetachTableRules(
DetachTableRulesSession detachTableRulesSession) DetachTableRulesSession detachTableRulesSession)
throws TDGWTServiceException { throws TDGWTServiceException {
HttpServletRequest httpRequest = null;
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); httpRequest = this.getThreadLocalRequest();
setDetachTableRules(detachTableRulesSession, session); setDetachTableRules(detachTableRulesSession, httpRequest);
return; return;
} catch (TDGWTServiceException e) { } catch (TDGWTServiceException e) {
@ -757,5 +732,4 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements
} }
} }

View File

@ -3,13 +3,16 @@
*/ */
package org.gcube.portlets.user.td.expressionwidget.server; package org.gcube.portlets.user.td.expressionwidget.server;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data.analysis.tabulardata.service.operation.Task; import org.gcube.data.analysis.tabulardata.service.operation.Task;
import org.gcube.portlets.user.td.gwtservice.server.SessionConstants;
import org.gcube.portlets.user.td.gwtservice.server.SessionOp;
import org.gcube.portlets.user.td.gwtservice.server.util.ServiceCredentials;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
@ -19,86 +22,62 @@ import org.slf4j.LoggerFactory;
*/ */
public class ExpressionSession { public class ExpressionSession {
protected static final String COLUMN_FILTER_SESSION = "COLUMN_FILTER_SESSION";
protected static final String COLUMN_FILTER_SESSION_TASK = "COLUMN_FILTER_SESSION_TASK";
protected static final String REPLACE_COLUMN_BY_EXPRESSION_SESSION = "REPLACE_COLUMN_BY_EXPRESSION_SESSION";
protected static Logger logger = LoggerFactory.getLogger(ExpressionSession.class);
public static FilterColumnSession getColumnFilterSession( public static FilterColumnSession getColumnFilterSession(
HttpSession httpSession) { HttpServletRequest httpRequest,
FilterColumnSession columnFilterSession = (FilterColumnSession) httpSession ServiceCredentials serviceCredentials) throws TDGWTServiceException {
.getAttribute(COLUMN_FILTER_SESSION); ScopeProvider.instance.set(serviceCredentials.getScope());
if (columnFilterSession != null) { SessionOp<FilterColumnSession> sessionOp = new SessionOp<>();
return columnFilterSession; FilterColumnSession columnFilterSession = sessionOp.get(httpRequest,
} else { serviceCredentials, SessionConstants.COLUMN_FILTER_SESSION,
columnFilterSession = new FilterColumnSession(); FilterColumnSession.class);
httpSession.setAttribute(COLUMN_FILTER_SESSION, return columnFilterSession;
columnFilterSession);
return columnFilterSession;
}
} }
public static void setColumnFilterSession(HttpSession httpSession, public static void setColumnFilterSession(HttpServletRequest httpRequest,
ServiceCredentials serviceCredentials,
FilterColumnSession columnFilterSession) { FilterColumnSession columnFilterSession) {
FilterColumnSession cf = (FilterColumnSession) httpSession SessionOp<FilterColumnSession> sessionOp = new SessionOp<>();
.getAttribute(COLUMN_FILTER_SESSION); sessionOp.set(httpRequest, serviceCredentials,
if (cf != null) { SessionConstants.COLUMN_FILTER_SESSION, columnFilterSession);
httpSession.removeAttribute(COLUMN_FILTER_SESSION);
}
httpSession.setAttribute(COLUMN_FILTER_SESSION,
columnFilterSession);
} }
public static ReplaceColumnByExpressionSession getReplaceColumnByExpressionSession( public static ReplaceColumnByExpressionSession getReplaceColumnByExpressionSession(
HttpSession httpSession) { HttpServletRequest httpRequest,
ReplaceColumnByExpressionSession replaceColumnByExpressionSession = (ReplaceColumnByExpressionSession) httpSession ServiceCredentials serviceCredentials) throws TDGWTServiceException {
.getAttribute(REPLACE_COLUMN_BY_EXPRESSION_SESSION); ScopeProvider.instance.set(serviceCredentials.getScope());
if (replaceColumnByExpressionSession != null) { SessionOp<ReplaceColumnByExpressionSession> sessionOp = new SessionOp<>();
return replaceColumnByExpressionSession; ReplaceColumnByExpressionSession replaceColumnByExpressionSession = sessionOp
} else { .get(httpRequest, serviceCredentials,
replaceColumnByExpressionSession = new ReplaceColumnByExpressionSession(); SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION,
httpSession.setAttribute(REPLACE_COLUMN_BY_EXPRESSION_SESSION, ReplaceColumnByExpressionSession.class);
replaceColumnByExpressionSession); return replaceColumnByExpressionSession;
return replaceColumnByExpressionSession;
}
} }
public static void setReplaceColumnByExpressionSession(HttpSession httpSession, public static void setReplaceColumnByExpressionSession(
HttpServletRequest httpRequest,
ServiceCredentials serviceCredentials,
ReplaceColumnByExpressionSession replaceColumnByExpressionSession) { ReplaceColumnByExpressionSession replaceColumnByExpressionSession) {
ReplaceColumnByExpressionSession rce = (ReplaceColumnByExpressionSession) httpSession SessionOp<ReplaceColumnByExpressionSession> sessionOp = new SessionOp<>();
.getAttribute(REPLACE_COLUMN_BY_EXPRESSION_SESSION); sessionOp.set(httpRequest, serviceCredentials,
if (rce != null) { SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION,
httpSession.removeAttribute(REPLACE_COLUMN_BY_EXPRESSION_SESSION);
}
httpSession.setAttribute(REPLACE_COLUMN_BY_EXPRESSION_SESSION,
replaceColumnByExpressionSession); replaceColumnByExpressionSession);
} }
public static Task getColumnFilterTask(HttpServletRequest httpRequest,
ServiceCredentials serviceCredentials) {
public static Task getColumnFilterTask(HttpSession httpSession) { ScopeProvider.instance.set(serviceCredentials.getScope());
Task monitor = (Task) httpSession.getAttribute(COLUMN_FILTER_SESSION_TASK); SessionOp<Task> sessionOp = new SessionOp<>();
if (monitor == null) { Task monitor = sessionOp.get(httpRequest, serviceCredentials,
logger.error("CHANGE_THE_COLUMN_LABEL_TASK was not acquired"); SessionConstants.COLUMN_FILTER_SESSION_TASK);
}
return monitor; return monitor;
} }
public static void setColumnFilterTask(HttpSession httpSession, public static void setColumnFilterTask(HttpServletRequest httpRequest,
Task task) { ServiceCredentials serviceCredentials, Task task) {
Task monitor = (Task) httpSession.getAttribute(COLUMN_FILTER_SESSION_TASK); SessionOp<Task> sessionOp = new SessionOp<>();
if (monitor != null) sessionOp.set(httpRequest, serviceCredentials,
httpSession.removeAttribute(COLUMN_FILTER_SESSION_TASK); SessionConstants.COLUMN_FILTER_SESSION_TASK, task);
httpSession.setAttribute(COLUMN_FILTER_SESSION_TASK, task);
} }
} }

View File

@ -23,4 +23,6 @@ public class Constants {
public static final String PARAMETER_ID ="id"; public static final String PARAMETER_ID ="id";
public static final String PARAMETER_VERSION ="version"; public static final String PARAMETER_VERSION ="version";
public static final String C_EXPRESSION_MAP_SERVLET="CExpressionMapServlet";
} }

View File

@ -32,7 +32,7 @@
</servlet-mapping> </servlet-mapping>
<servlet-mapping> <servlet-mapping>
<servlet-name>CExpressionMapServlet</servlet-name> <servlet-name>CExpressionMapServlet</servlet-name>
<url-pattern>/ExpressionWidget/CExpressionMap</url-pattern> <url-pattern>/ExpressionWidget/CExpressionMapServlet</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet-mapping> <servlet-mapping>
<servlet-name>TDGWTService</servlet-name> <servlet-name>TDGWTService</servlet-name>

View File

@ -10,6 +10,7 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import org.gcube.data.analysis.tabulardata.expression.Expression; import org.gcube.data.analysis.tabulardata.expression.Expression;
import org.gcube.portlets.user.td.expressionwidget.shared.Constants;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.junit.Test; import org.junit.Test;
@ -19,10 +20,10 @@ public class TestCExpressionServlet {
public void test() { public void test() {
HttpURLConnection cs = null; HttpURLConnection cs = null;
String path = "ExpressionWidget/CExpressionMap"; String path = "ExpressionWidget/";
URL url = null; URL url = null;
try { try {
url = new URL("http://127.0.0.1:8888/" + path); url = new URL("http://127.0.0.1:8888/" + path+Constants.C_EXPRESSION_MAP_SERVLET);
} catch (MalformedURLException e1) { } catch (MalformedURLException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }