diff --git a/.classpath b/.classpath index a31d5dc..5b53453 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -32,5 +32,5 @@ - + diff --git a/distro/changelog.xml b/distro/changelog.xml index 50391f7..e40161a 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,8 @@ + + Updated to new PortalContext [ticket #6548] + Updated to Liferay 6.2 diff --git a/pom.xml b/pom.xml index fcf346f..3ad184f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 4.0.0 org.gcube.portlets.user tabular-data-expression-widget - 1.8.0-SNAPSHOT + 1.9.0-SNAPSHOT tabular-data-expression-widget @@ -108,32 +108,14 @@ ${gxtVersion} - + org.gcube.core common-scope-maps - [1.0.2-SNAPSHOT,2.0.0-SNAPSHOT) - provided + + compile - - - org.gcube.portal - custom-portal-handler - provided - - - org.gcube.applicationsupportlayer - aslcore - provided - - - - org.gcube.applicationsupportlayer - accesslogger - provided - - - + org.gcube.data.analysis.tabulardata diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/CExpressionMapServlet.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/CExpressionMapServlet.java index ca88b88..6dd898c 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/CExpressionMapServlet.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/CExpressionMapServlet.java @@ -13,10 +13,12 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.common.scope.api.ScopeProvider; import org.gcube.data.analysis.tabulardata.expression.Expression; 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.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.widgetcommonevent.shared.expression.C_Expression; import org.slf4j.Logger; @@ -64,14 +66,19 @@ public class CExpressionMapServlet extends HttpServlet { logger.info("CExpressionMapServlet import session id: " + session.getId()); + ServiceCredentials serviceCredentials; + try { - ASLSession aslSession = SessionUtil.getAslSession(session); - String token = SessionUtil.getToken(aslSession); - logger.debug("UserToken: " + token); + String scopeGroupId = request.getParameter(Constants.CURR_GROUP_ID); + serviceCredentials = SessionUtil.getServiceCredentials(request, + scopeGroupId); + + ScopeProvider.instance.set(serviceCredentials.getScope()); } catch (TDGWTServiceException e) { - logger.error(e.getLocalizedMessage()); - e.printStackTrace(); + logger.error( + "Error retrieving credentials:" + e.getLocalizedMessage(), + e); throw new ServletException(e.getLocalizedMessage()); } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java index 24d1aa2..acc0501 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java @@ -4,12 +4,9 @@ import java.util.ArrayList; import java.util.List; 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.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.RuleDescription; 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.TDGWTServiceMessagesConstants; 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.rule.AppliedRulesResponseData; import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyAndDetachColumnRulesSession; @@ -73,18 +71,21 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements @Override public String startFilterColumn(FilterColumnSession filterColumnSession) throws TDGWTServiceException { - HttpSession session=null; + HttpServletRequest httpRequest = null; try { - logger.debug("ExpressionService submitColumnFilter"); - session = this.getThreadLocalRequest().getSession(); - logger.debug("Session: " + session); + httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); if (filterColumnSession == null) { logger.error("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(); Expression expression = null; @@ -99,7 +100,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements // TDGWTServiceImpl gwtService = new TDGWTServiceImpl(); String taskId = startFilterColumn(filterColumnSession, expression, - session); + httpRequest); return taskId; @@ -108,9 +109,9 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } catch (SecurityException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); - ResourceBundle messages = getResourceBundle(session); + ResourceBundle messages = getResourceBundle(httpRequest); throw new TDGWTServiceException( - messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); + messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); } catch (Throwable e) { e.printStackTrace(); throw new TDGWTServiceException(e.getLocalizedMessage()); @@ -124,15 +125,16 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements public String startAddColumn(AddColumnSession addColumnSession) throws TDGWTServiceException { - HttpSession session=null; + HttpServletRequest httpRequest = null; try { - logger.debug("AddColumn"); - session = this.getThreadLocalRequest().getSession(); - logger.debug("Session: " + session); + httpRequest = this.getThreadLocalRequest(); + logger.debug("AddColumn"); if (addColumnSession == null) { logger.error("AddColumnSession is null"); new ExpressionServiceException("AddColumnSession is null"); + } else { + logger.debug("AddColumnSession: " + addColumnSession); } ColumnMockUp columnMockUp = addColumnSession.getColumnMockUp(); @@ -155,7 +157,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements // TDGWTServiceImpl gwtService = new TDGWTServiceImpl(); String taskId = startAddColumn(addColumnSession, expression, - session); + httpRequest); return taskId; @@ -164,10 +166,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } catch (SecurityException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); - ResourceBundle messages = getResourceBundle(session); + ResourceBundle messages = getResourceBundle(httpRequest); throw new TDGWTServiceException( - messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); - + messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); + } catch (Throwable e) { e.printStackTrace(); throw new TDGWTServiceException(e.getLocalizedMessage()); @@ -183,19 +185,25 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements ReplaceColumnByExpressionSession replaceColumnByExpressionSession) throws TDGWTServiceException { - HttpSession session=null; + HttpServletRequest httpRequest = null; try { + httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + logger.debug("ExpressionService submitReplaceColumnByExpression"); - session = this.getThreadLocalRequest().getSession(); - logger.debug("Session: " + session); if (replaceColumnByExpressionSession == null) { logger.error("ReplaceColumnByExpressionSession is null"); new ExpressionServiceException( "ReplaceColumnByExpressionSession is null"); + } else { + logger.debug("ReplaceColumnByExpressionSession: " + + replaceColumnByExpressionSession); } - ExpressionSession.setReplaceColumnByExpressionSession(session, - replaceColumnByExpressionSession); + + ExpressionSession.setReplaceColumnByExpressionSession(httpRequest, + serviceCredentials, replaceColumnByExpressionSession); C_ExpressionParser parser = new C_ExpressionParser(); @@ -226,7 +234,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements String taskId = startReplaceColumnByExpression( replaceColumnByExpressionSession, conditionExpression, - replaceExpression, session); + replaceExpression, httpRequest); return taskId; } catch (TDGWTServiceException e) { @@ -234,9 +242,9 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } catch (SecurityException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); - ResourceBundle messages = getResourceBundle(session); + ResourceBundle messages = getResourceBundle(httpRequest); throw new TDGWTServiceException( - messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); + messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); } catch (Throwable e) { e.printStackTrace(); throw new TDGWTServiceException(e.getLocalizedMessage()); @@ -250,16 +258,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements @Override public ArrayList getRules() throws TDGWTServiceException { - HttpSession session=null; + HttpServletRequest httpRequest = null; try { - session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession = SessionUtil.getAslSession(session); - String token = SessionUtil.getToken(aslSession); - logger.debug("UserToken: " + token); - + httpRequest = this.getThreadLocalRequest(); + SessionUtil.getServiceCredentials(httpRequest); + logger.debug("GetRules()"); - AuthorizationProvider.instance.set(new AuthorizationToken( - aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); List rules = service.getRules(); @@ -284,10 +288,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } catch (SecurityException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); - ResourceBundle messages = getResourceBundle(session); + ResourceBundle messages = getResourceBundle(httpRequest); throw new TDGWTServiceException( messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); - + } catch (Throwable e) { logger.error("Error in getRules(): " + e.getLocalizedMessage()); e.printStackTrace(); @@ -304,16 +308,11 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements @Override public ArrayList getRules(RuleScopeType scope) throws TDGWTServiceException { - HttpSession session=null; + HttpServletRequest httpRequest = null; try { - session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession = SessionUtil.getAslSession(session); - String token = SessionUtil.getToken(aslSession); - logger.debug("UserToken: " + token); - + httpRequest = this.getThreadLocalRequest(); + SessionUtil.getServiceCredentials(httpRequest); logger.debug("GetRules(): " + scope); - AuthorizationProvider.instance.set(new AuthorizationToken( - aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); List rules = service.getRulesByScope(RuleScopeMap @@ -339,7 +338,7 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } catch (SecurityException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); - ResourceBundle messages = getResourceBundle(session); + ResourceBundle messages = getResourceBundle(httpRequest); throw new TDGWTServiceException( messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); } catch (Throwable e) { @@ -358,16 +357,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements @Override public ArrayList getApplicableBaseColumnRules( ColumnData columnData) throws TDGWTServiceException { - HttpSession session=null; + HttpServletRequest httpRequest = null; try { - session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession = SessionUtil.getAslSession(session); - String token = SessionUtil.getToken(aslSession); - logger.debug("UserToken: " + token); + httpRequest = this.getThreadLocalRequest(); + SessionUtil.getServiceCredentials(httpRequest); logger.debug("GetApplicableBaseColumnRules(): " + columnData); - AuthorizationProvider.instance.set(new AuthorizationToken( - aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); if (columnData == null) { @@ -409,10 +404,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } catch (SecurityException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); - ResourceBundle messages = getResourceBundle(session); + ResourceBundle messages = getResourceBundle(httpRequest); throw new TDGWTServiceException( messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); - + } catch (Throwable e) { logger.error("Error in getApplicableBaseColumnRules(): " + e.getLocalizedMessage()); @@ -430,16 +425,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements @Override public AppliedRulesResponseData getActiveRulesByTabularResourceId(TRId trId) throws TDGWTServiceException { - HttpSession session=null; + HttpServletRequest httpRequest = null; try { - session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession = SessionUtil.getAslSession(session); - String token = SessionUtil.getToken(aslSession); - logger.debug("UserToken: " + token); + httpRequest = this.getThreadLocalRequest(); + SessionUtil.getServiceCredentials(httpRequest); logger.debug("GetAppliedRulesByTabularResourceId(): " + trId); - AuthorizationProvider.instance.set(new AuthorizationToken( - aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); if (trId == null || trId.getId() == null || trId.getId().isEmpty()) { @@ -471,10 +462,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } catch (SecurityException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); - ResourceBundle messages = getResourceBundle(session); + ResourceBundle messages = getResourceBundle(httpRequest); throw new TDGWTServiceException( messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); - + } catch (Throwable e) { logger.error("Error in getActiveRulesByTabularResourceId(): " + e.getLocalizedMessage()); @@ -490,19 +481,14 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements * {@inheritDoc} */ @Override - public String saveRule( - RuleDescriptionData ruleDescriptionData) + public String saveRule(RuleDescriptionData ruleDescriptionData) throws TDGWTServiceException { - HttpSession session=null; + HttpServletRequest httpRequest = null; try { - session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession = SessionUtil.getAslSession(session); - String token = SessionUtil.getToken(aslSession); - logger.debug("UserToken: " + token); + httpRequest = this.getThreadLocalRequest(); + SessionUtil.getServiceCredentials(httpRequest); logger.debug("SaveRule() :" + ruleDescriptionData); - AuthorizationProvider.instance.set(new AuthorizationToken( - aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); C_ExpressionParser parser = new C_ExpressionParser(); @@ -519,25 +505,22 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements logger.debug("Service Condition Expression:" + conditionExpression); - RuleType ruleType = RuleTypeMap - .map(ruleDescriptionData.getTdRuleType()); + RuleType ruleType = RuleTypeMap.map(ruleDescriptionData + .getTdRuleType()); if (ruleType == null) { logger.error("Error saving rule, rule type is null!"); throw new TDGWTServiceException( "Error saving rule, rule type is null!"); } - - - RuleId ruleId = service.saveRule( - ruleDescriptionData.getName(), - ruleDescriptionData.getDescription(), - conditionExpression, ruleType); - + RuleId ruleId = service.saveRule(ruleDescriptionData.getName(), + ruleDescriptionData.getDescription(), conditionExpression, + ruleType); + logger.debug("RuleId: " + ruleId); - + String ruleIdent = null; - + if (ruleId != null) { ruleIdent = String.valueOf(ruleId.getValue()); } @@ -550,13 +533,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } catch (SecurityException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); - ResourceBundle messages = getResourceBundle(session); + ResourceBundle messages = getResourceBundle(httpRequest); throw new TDGWTServiceException( messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); - + } catch (Throwable e) { - logger.error("Error in save rule: " - + e.getLocalizedMessage()); + logger.error("Error in save rule: " + e.getLocalizedMessage()); e.printStackTrace(); throw new TDGWTServiceException("Error in save rule: " + e.getLocalizedMessage()); @@ -564,7 +546,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } - /** * * {@inheritDoc} @@ -572,16 +553,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements @Override public void updateColumnRule(RuleDescriptionData ruleDescriptionData) throws TDGWTServiceException { - HttpSession session=null; + HttpServletRequest httpRequest = null; try { - session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession = SessionUtil.getAslSession(session); - String token = SessionUtil.getToken(aslSession); - logger.debug("UserToken: " + token); + httpRequest = this.getThreadLocalRequest(); + SessionUtil.getServiceCredentials(httpRequest); logger.debug("UpdateColumnRule() :" + ruleDescriptionData); - AuthorizationProvider.instance.set(new AuthorizationToken( - aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); RuleDescription ruleDescription = RuleDescriptionMap @@ -605,10 +582,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } catch (SecurityException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); - ResourceBundle messages = getResourceBundle(session); + ResourceBundle messages = getResourceBundle(httpRequest); throw new TDGWTServiceException( messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); - + } catch (Throwable e) { logger.error("Error in getRule(): " + e.getLocalizedMessage()); e.printStackTrace(); @@ -625,12 +602,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements @Override public void removeRulesById(ArrayList rules) throws TDGWTServiceException { - HttpSession session=null; + HttpServletRequest httpRequest = null; try { - session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession = SessionUtil.getAslSession(session); - String token = SessionUtil.getToken(aslSession); - logger.debug("UserToken: " + token); + httpRequest = this.getThreadLocalRequest(); + SessionUtil.getServiceCredentials(httpRequest); logger.debug("RemoveRuleById() :" + rules); if (rules == null || !(rules.size() > 0)) { @@ -638,8 +613,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements "Error removing the rule, no rules selected"); } - AuthorizationProvider.instance.set(new AuthorizationToken( - aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); for (RuleDescriptionData ruleDescriptionData : rules) { @@ -654,10 +627,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } catch (SecurityException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); - ResourceBundle messages = getResourceBundle(session); + ResourceBundle messages = getResourceBundle(httpRequest); throw new TDGWTServiceException( messages.getString(TDGWTServiceMessagesConstants.securityExceptionRights)); - + } catch (Throwable e) { logger.error("Error in removeRuleById(): " + e.getLocalizedMessage()); @@ -676,10 +649,12 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements public String startApplyAndDetachColumnRules( ApplyAndDetachColumnRulesSession applyAndDetachColumnRulesSession) throws TDGWTServiceException { + HttpServletRequest httpRequest = null; try { - HttpSession session = this.getThreadLocalRequest().getSession(); + httpRequest = this.getThreadLocalRequest(); + String taskId = startApplyAndDetachColumnnRules( - applyAndDetachColumnRulesSession, session); + applyAndDetachColumnRulesSession, httpRequest); return taskId; } catch (TDGWTServiceException e) { @@ -690,16 +665,16 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } } - - + @Override public String startApplyTableRule( ApplyTableRuleSession applyTableRuleSession) throws TDGWTServiceException { + HttpServletRequest httpRequest = null; try { - HttpSession session = this.getThreadLocalRequest().getSession(); - String taskId = startApplyTableRule( - applyTableRuleSession, session); + httpRequest = this.getThreadLocalRequest(); + String taskId = startApplyTableRule(applyTableRuleSession, + httpRequest); return taskId; } 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( DetachColumnRulesSession detachColumnRulesSession) throws TDGWTServiceException { + HttpServletRequest httpRequest = null; try { - HttpSession session = this.getThreadLocalRequest().getSession(); - setDetachColumnnRules(detachColumnRulesSession, session); + httpRequest = this.getThreadLocalRequest(); + setDetachColumnnRules(detachColumnRulesSession, httpRequest); return; } catch (TDGWTServiceException e) { @@ -734,7 +709,6 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } - /** * * {@inheritDoc} @@ -743,9 +717,10 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements public void setDetachTableRules( DetachTableRulesSession detachTableRulesSession) throws TDGWTServiceException { + HttpServletRequest httpRequest = null; try { - HttpSession session = this.getThreadLocalRequest().getSession(); - setDetachTableRules(detachTableRulesSession, session); + httpRequest = this.getThreadLocalRequest(); + setDetachTableRules(detachTableRulesSession, httpRequest); return; } catch (TDGWTServiceException e) { @@ -757,5 +732,4 @@ public class ExpressionServiceImpl extends TDGWTServiceImpl implements } - } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionSession.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionSession.java index 266f2fd..24b9ed3 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionSession.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionSession.java @@ -3,13 +3,16 @@ */ 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.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.ReplaceColumnByExpressionSession; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * @@ -19,86 +22,62 @@ import org.slf4j.LoggerFactory; */ 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( - HttpSession httpSession) { - FilterColumnSession columnFilterSession = (FilterColumnSession) httpSession - .getAttribute(COLUMN_FILTER_SESSION); - if (columnFilterSession != null) { - return columnFilterSession; - } else { - columnFilterSession = new FilterColumnSession(); - httpSession.setAttribute(COLUMN_FILTER_SESSION, - columnFilterSession); - return columnFilterSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + FilterColumnSession columnFilterSession = sessionOp.get(httpRequest, + serviceCredentials, SessionConstants.COLUMN_FILTER_SESSION, + FilterColumnSession.class); + return columnFilterSession; } - public static void setColumnFilterSession(HttpSession httpSession, + public static void setColumnFilterSession(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, FilterColumnSession columnFilterSession) { - FilterColumnSession cf = (FilterColumnSession) httpSession - .getAttribute(COLUMN_FILTER_SESSION); - if (cf != null) { - httpSession.removeAttribute(COLUMN_FILTER_SESSION); - } - httpSession.setAttribute(COLUMN_FILTER_SESSION, - columnFilterSession); - + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.COLUMN_FILTER_SESSION, columnFilterSession); } - + public static ReplaceColumnByExpressionSession getReplaceColumnByExpressionSession( - HttpSession httpSession) { - ReplaceColumnByExpressionSession replaceColumnByExpressionSession = (ReplaceColumnByExpressionSession) httpSession - .getAttribute(REPLACE_COLUMN_BY_EXPRESSION_SESSION); - if (replaceColumnByExpressionSession != null) { - return replaceColumnByExpressionSession; - } else { - replaceColumnByExpressionSession = new ReplaceColumnByExpressionSession(); - httpSession.setAttribute(REPLACE_COLUMN_BY_EXPRESSION_SESSION, - replaceColumnByExpressionSession); - return replaceColumnByExpressionSession; - } + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) throws TDGWTServiceException { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + ReplaceColumnByExpressionSession replaceColumnByExpressionSession = sessionOp + .get(httpRequest, serviceCredentials, + SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, + ReplaceColumnByExpressionSession.class); + return replaceColumnByExpressionSession; } - public static void setReplaceColumnByExpressionSession(HttpSession httpSession, + public static void setReplaceColumnByExpressionSession( + HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, ReplaceColumnByExpressionSession replaceColumnByExpressionSession) { - ReplaceColumnByExpressionSession rce = (ReplaceColumnByExpressionSession) httpSession - .getAttribute(REPLACE_COLUMN_BY_EXPRESSION_SESSION); - if (rce != null) { - httpSession.removeAttribute(REPLACE_COLUMN_BY_EXPRESSION_SESSION); - } - httpSession.setAttribute(REPLACE_COLUMN_BY_EXPRESSION_SESSION, + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, replaceColumnByExpressionSession); } - - - - public static Task getColumnFilterTask(HttpSession httpSession) { - Task monitor = (Task) httpSession.getAttribute(COLUMN_FILTER_SESSION_TASK); - if (monitor == null) { - logger.error("CHANGE_THE_COLUMN_LABEL_TASK was not acquired"); - } + public static Task getColumnFilterTask(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + ScopeProvider.instance.set(serviceCredentials.getScope()); + SessionOp sessionOp = new SessionOp<>(); + Task monitor = sessionOp.get(httpRequest, serviceCredentials, + SessionConstants.COLUMN_FILTER_SESSION_TASK); return monitor; } - public static void setColumnFilterTask(HttpSession httpSession, - Task task) { - Task monitor = (Task) httpSession.getAttribute(COLUMN_FILTER_SESSION_TASK); - if (monitor != null) - httpSession.removeAttribute(COLUMN_FILTER_SESSION_TASK); - httpSession.setAttribute(COLUMN_FILTER_SESSION_TASK, task); + public static void setColumnFilterTask(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials, Task task) { + SessionOp sessionOp = new SessionOp<>(); + sessionOp.set(httpRequest, serviceCredentials, + SessionConstants.COLUMN_FILTER_SESSION_TASK, task); } - - } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/Constants.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/Constants.java index 1d878f1..b7edcd5 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/Constants.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/Constants.java @@ -23,4 +23,6 @@ public class Constants { public static final String PARAMETER_ID ="id"; public static final String PARAMETER_VERSION ="version"; + public static final String C_EXPRESSION_MAP_SERVLET="CExpressionMapServlet"; + } diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index c574615..be045d8 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -32,7 +32,7 @@ CExpressionMapServlet - /ExpressionWidget/CExpressionMap + /ExpressionWidget/CExpressionMapServlet TDGWTService diff --git a/src/test/java/org/gcube/portlets/user/td/expressionwidget/client/TestCExpressionServlet.java b/src/test/java/org/gcube/portlets/user/td/expressionwidget/client/TestCExpressionServlet.java index 39301dc..7e3efc4 100644 --- a/src/test/java/org/gcube/portlets/user/td/expressionwidget/client/TestCExpressionServlet.java +++ b/src/test/java/org/gcube/portlets/user/td/expressionwidget/client/TestCExpressionServlet.java @@ -10,6 +10,7 @@ import java.net.MalformedURLException; import java.net.URL; 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.junit.Test; @@ -19,10 +20,10 @@ public class TestCExpressionServlet { public void test() { HttpURLConnection cs = null; - String path = "ExpressionWidget/CExpressionMap"; + String path = "ExpressionWidget/"; URL url = null; 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) { e1.printStackTrace(); }