From 37e88a05986a2d7abb9441527c1ffe5dfe05fb67 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 27 May 2015 16:36:01 +0000 Subject: [PATCH] 81: Allow the creation and use of expressions on multi column in TDM portlet Task-Url: https://support.d4science.org/issues/81 Updated apply rule on table git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@115078 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/server/SessionConstants.java | 3 + .../td/gwtservice/server/SessionUtil.java | 34 ++++++++++ .../gwtservice/server/TDGWTServiceImpl.java | 67 +++++++++++++++++++ .../shared/rule/ApplyTableRuleSession.java | 67 +++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/rule/ApplyTableRuleSession.java diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java index 4b0d80c..3302ffd 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java @@ -120,5 +120,8 @@ public class SessionConstants { public static final String RULES_ON_COLUMN_APPLY_AND_DETACH_SESSION = "RULES_ON_COLUMN_APPLY_AND_DETACH_SESSION"; public static final String RULES_ON_COLUMN_DETACH_SESSION = "RULES_ON_COLUMN_DETACH_SESSION"; + + public static final String RULES_ON_TABLE_APPLY_SESSION = "RULES_ON_TABLE_APPLY_SESSION"; + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java index bbc460d..7ce8418 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java @@ -31,6 +31,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession; import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession; import org.gcube.portlets.user.td.gwtservice.shared.map.MapCreationSession; import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyAndDetachColumnRulesSession; +import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyTableRuleSession; import org.gcube.portlets.user.td.gwtservice.shared.rule.DetachColumnRulesSession; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportSession; @@ -90,6 +91,7 @@ public class SessionUtil { if (username == null) { logger.warn("no user found in session, use test user"); throw new TDGWTSessionExpiredException("Session Expired!"); + /* // Remove comment for Test username = Constants.DEFAULT_USER; @@ -1123,6 +1125,38 @@ public class SessionUtil { } + + // + public static ApplyTableRuleSession getApplyTableRuleSession( + HttpSession httpSession) { + ApplyTableRuleSession applyTableRuleSession = (ApplyTableRuleSession) httpSession + .getAttribute(SessionConstants.RULES_ON_TABLE_APPLY_SESSION); + if (applyTableRuleSession != null) { + return applyTableRuleSession; + } else { + applyTableRuleSession = new ApplyTableRuleSession(); + httpSession.setAttribute( + SessionConstants.RULES_ON_TABLE_APPLY_SESSION, + applyTableRuleSession); + return applyTableRuleSession; + } + } + + public static void setApplyTableRuleSession( + HttpSession httpSession, + ApplyTableRuleSession applyTableRuleSession) { + ApplyTableRuleSession atrs = (ApplyTableRuleSession) httpSession + .getAttribute(SessionConstants.RULES_ON_TABLE_APPLY_SESSION); + if (atrs != null) { + httpSession + .removeAttribute(SessionConstants.RULES_ON_TABLE_APPLY_SESSION); + } + httpSession.setAttribute( + SessionConstants.RULES_ON_TABLE_APPLY_SESSION, + applyTableRuleSession); + + } + // public static DetachColumnRulesSession getDetachColumnRulesSession( HttpSession httpSession) { diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index 5821b47..e755128 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -196,6 +196,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorCreator; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorSession; import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyAndDetachColumnRulesSession; +import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyTableRuleSession; import org.gcube.portlets.user.td.gwtservice.shared.rule.DetachColumnRulesSession; import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; @@ -9559,6 +9560,72 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + + + + /** + * + * @param applyTableRuleSession + * @param session + * @return + * @throws TDGWTServiceException + */ + public String startApplyTableRule( + ApplyTableRuleSession applyTableRuleSession, + HttpSession session) throws TDGWTServiceException { + try { + // HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + + SessionUtil.setApplyTableRuleSession(session, + applyTableRuleSession); + + if (applyTableRuleSession == null) { + logger.error("Apply Table Rule Session is null"); + throw new TDGWTServiceException( + "Error in apply rule on table: ApplyTableRuleSession is null"); + } + + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + + checkTRId(applyTableRuleSession.getTrId()); + + TabularResourceId tabularResourceId = new TabularResourceId( + Long.valueOf(applyTableRuleSession.getTrId() + .getId())); + TabularResource tabularResource = service + .getTabularResource(tabularResourceId); + + checkTabularResourceIsFlow(tabularResource); + checkTabularResourceLocked(tabularResource); + checkTabularResourceIsFinal(tabularResource); + + //TODO + Task trTask = null; + //service.applyTableRule(tabularResourceId,....); + //logger.debug("Rules On Table Apply: TaskId " + trTask.getId()); + + TaskWrapper taskWrapper = new TaskWrapper(trTask, + UIOperationsId.RuleOnColumnApply, + applyTableRuleSession.getTrId()); + SessionUtil.setStartedTask(session, taskWrapper); + return null; + //return trTask.getId().getValue(); + + } catch (TDGWTServiceException e) { + throw e; + } catch (SecurityException e) { + e.printStackTrace(); + throw new TDGWTServiceException(SECURITY_EXCEPTION_RIGHTS); + } catch (Throwable e) { + e.printStackTrace(); + throw new TDGWTServiceException("Error in apply rules on table: " + + e.getLocalizedMessage()); + } + + } /** * diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/rule/ApplyTableRuleSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/rule/ApplyTableRuleSession.java new file mode 100644 index 0000000..7876e78 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/rule/ApplyTableRuleSession.java @@ -0,0 +1,67 @@ +package org.gcube.portlets.user.td.gwtservice.shared.rule; + +import java.io.Serializable; +import java.util.HashMap; + +import org.gcube.portlets.user.td.gwtservice.shared.rule.description.RuleDescriptionData; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class ApplyTableRuleSession implements Serializable { + + private static final long serialVersionUID = -1922171869337643740L; + private TRId trId; + private RuleDescriptionData ruleDescriptionData; + private HashMap placeHolderToColumnMap; + + public ApplyTableRuleSession() { + super(); + } + + public ApplyTableRuleSession(TRId trId, + RuleDescriptionData ruleDescriptionData, + HashMap placeHolderToColumnMap) { + super(); + this.trId = trId; + this.ruleDescriptionData = ruleDescriptionData; + this.placeHolderToColumnMap = placeHolderToColumnMap; + } + + public TRId getTrId() { + return trId; + } + + public void setTrId(TRId trId) { + this.trId = trId; + } + + public RuleDescriptionData getRuleDescriptionData() { + return ruleDescriptionData; + } + + public void setRuleDescriptionData(RuleDescriptionData ruleDescriptionData) { + this.ruleDescriptionData = ruleDescriptionData; + } + + public HashMap getPlaceHolderToColumnMap() { + return placeHolderToColumnMap; + } + + public void setPlaceHolderToColumnMap( + HashMap placeHolderToColumnMap) { + this.placeHolderToColumnMap = placeHolderToColumnMap; + } + + @Override + public String toString() { + return "ApplyTableRuleSession [trId=" + trId + ", ruleDescriptionData=" + + ruleDescriptionData + ", placeHolderToColumnMap=" + + placeHolderToColumnMap + "]"; + } + +}