diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java index 6e2d15b..ec080c4 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java @@ -50,6 +50,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.OccurrencesForRepla import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ChangeColumnsPositionSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnSession; @@ -344,9 +345,8 @@ public interface TDGWTService extends RemoteService { /** * Set Current Tabular Resource that passed as parameter if not null * - * * @param activeTRId - * @return TODO + * @return * @throws TDGWTServiceException */ public TRId setActiveTabularResource(TRId activeTRId) @@ -824,6 +824,17 @@ public interface TDGWTService extends RemoteService { public String startLabelColumn(LabelColumnSession labelColumnSession) throws TDGWTServiceException; + /** + * Start change columns position + * + * + * @param changeColumnsPositionSession + * @return + * @throws TDGWTServiceException + */ + public String startChangeColumnsPosition(ChangeColumnsPositionSession changeColumnsPositionSession) + throws TDGWTServiceException; + /** * Start split column * diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java index d07722b..0f56bfe 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java @@ -49,6 +49,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.OccurrencesForRepla import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ChangeColumnsPositionSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnSession; @@ -307,7 +308,11 @@ public interface TDGWTServiceAsync { void startLabelColumn(LabelColumnSession labelColumnSession, AsyncCallback callback); - + + void startChangeColumnsPosition(ChangeColumnsPositionSession changeColumnsPositionSession, + AsyncCallback callback); + + /* * void startSplitColumn(SplitColumnSession * splitColumnSession,AsyncCallback callback); 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 15c4d89..d94ae6b 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 @@ -68,6 +68,8 @@ public class SessionConstants { public static final String UNION_SESSION = "UNION_SESSION"; + public static final String CHANGE_COLUMNS_POSITION_SESSION = "CHANGE_COLUMNS_POSITION_SESSION"; + public static final String REPLACE_BY_EXTERNAL_SESSION = "REPLACE_BY_EXTERNAL_SESSION"; public static final String STATISTICAL_OPERATION_SESSION = "STATISTICAL_OPERATION_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 05fc264..25beffd 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 @@ -41,6 +41,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ChangeColumnsPositionSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnSession; @@ -1709,6 +1710,32 @@ public class SessionUtil { httpSession.setAttribute(SessionConstants.UNION_SESSION, unionSession); } + + + // + public static ChangeColumnsPositionSession getChangeColumnsPositionSession(HttpSession httpSession) { + ChangeColumnsPositionSession changeColumnsPositionSession = (ChangeColumnsPositionSession) httpSession + .getAttribute(SessionConstants.CHANGE_COLUMNS_POSITION_SESSION); + if (changeColumnsPositionSession != null) { + return changeColumnsPositionSession; + } else { + changeColumnsPositionSession = new ChangeColumnsPositionSession(); + httpSession.setAttribute(SessionConstants.CHANGE_COLUMNS_POSITION_SESSION, + changeColumnsPositionSession); + return changeColumnsPositionSession; + } + } + + public static void setChangeColumnsPositionSession(HttpSession httpSession, + ChangeColumnsPositionSession changeColumnsPositionSession) { + ChangeColumnsPositionSession ccps = (ChangeColumnsPositionSession) httpSession + .getAttribute(SessionConstants.CHANGE_COLUMNS_POSITION_SESSION); + if (ccps != null) { + httpSession.removeAttribute(SessionConstants.CHANGE_COLUMNS_POSITION_SESSION); + } + httpSession.setAttribute(SessionConstants.CHANGE_COLUMNS_POSITION_SESSION, changeColumnsPositionSession); + + } // public static ReplaceByExternalSession getReplaceByExternalSession( 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 fb0b5a1..da5ff7b 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 @@ -115,6 +115,7 @@ import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4AddColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4CSVExport; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ChangeColumnType; +import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ChangeColumnsPosition; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ChangeTableType; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ChartTopRating; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Clone; @@ -219,6 +220,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.OccurrencesForRepla import org.gcube.portlets.user.td.gwtservice.shared.tr.batch.ReplaceBatchColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.AddColumnSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ChangeColumnsPositionSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnSession; @@ -7973,6 +7975,67 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + + + /** + * + * {@inheritDoc} + */ + @Override + public String startChangeColumnsPosition(ChangeColumnsPositionSession changeColumnsPositionSession) + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + SessionUtil.setChangeColumnsPositionSession(session, changeColumnsPositionSession); + ASLSession aslSession = SessionUtil.getAslSession(session); + + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + + checkTRId(changeColumnsPositionSession.getTrId()); + + TabularResourceId tabularResourceId = new TabularResourceId( + Long.valueOf(changeColumnsPositionSession.getTrId().getId())); + TabularResource tabularResource = service + .getTabularResource(tabularResourceId); + + checkTabularResourceIsFlow(tabularResource); + checkTabularResourceLocked(tabularResource); + checkTabularResourceIsFinal(tabularResource); + + OpExecution4ChangeColumnsPosition opEx = new OpExecution4ChangeColumnsPosition(service, + changeColumnsPositionSession); + OpExecutionDirector director = new OpExecutionDirector(); + director.setOperationExecutionBuilder(opEx); + director.constructOperationExecution(); + OperationExecution invocation = director.getOperationExecution(); + + if (invocation == null) { + throw new TDGWTServiceException( + "Error in Change Columns Position invocation: Operation not supported"); + } + + logger.debug("OperationInvocation: \n" + invocation.toString()); + Task trTask = service.execute(invocation, tabularResourceId); + logger.debug("Start Task on service: TaskId " + trTask.getId()); + TaskWrapper taskWrapper = new TaskWrapper(trTask, + UIOperationsId.ChangeColumnsPosition, changeColumnsPositionSession.getTrId()); + SessionUtil.setStartedTask(session, taskWrapper); + 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 change columns position: " + + e.getLocalizedMessage()); + } + + } /** * @@ -8574,6 +8637,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements .getApplicationType().toString()); params.put("smp-uri", uriResolverSession.getUuid()); params.put("fileName", uriResolverSession.getFileName()); + params.put("contentType", ""); logger.debug("Uri Resolver params: " + params); link = resolver.getLink(params, true); // true, link is shorted // otherwise none diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4ChangeColumnsPosition.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4ChangeColumnsPosition.java new file mode 100644 index 0000000..d959889 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4ChangeColumnsPosition.java @@ -0,0 +1,54 @@ +package org.gcube.portlets.user.td.gwtservice.server.opexecution; + +import java.util.HashMap; +import java.util.Map; + +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition; +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; +import org.gcube.data.analysis.tabulardata.service.TabularDataService; +import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; +import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ChangeColumnsPositionSession; +import org.gcube.portlets.user.td.widgetcommonevent.shared.operations.OperationsId; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Operation Execution for change column position + * + * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it + * + */ +public class OpExecution4ChangeColumnsPosition extends OpExecutionBuilder { + private static Logger logger = LoggerFactory + .getLogger(OpExecution4ChangeColumnsPosition.class); + + private TabularDataService service; + private ChangeColumnsPositionSession changeColumnsPositionSession; + + public OpExecution4ChangeColumnsPosition(TabularDataService service, + ChangeColumnsPositionSession changeColumnsPositionSession) { + this.service = service; + this.changeColumnsPositionSession = changeColumnsPositionSession; + } + + @Override + public void buildOpEx() throws TDGWTServiceException { + logger.debug("Change Columns Position: "+changeColumnsPositionSession); + + OperationDefinition operationDefinition; + operationDefinition = OperationDefinitionMap.map( + OperationsId.ChangeColumnPosition.toString(), service); + Map map = new HashMap(); + + map.put("listColumns", changeColumnsPositionSession.getColumns()); + + OperationExecution invocation = new OperationExecution( + operationDefinition.getOperationId(), map); + + operationExecutionSpec.setOp(invocation); + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/AddColumnSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/AddColumnSession.java index b007309..b46926e 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/AddColumnSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/AddColumnSession.java @@ -15,8 +15,8 @@ public class AddColumnSession implements Serializable { private static final long serialVersionUID = -1896235499708614266L; - protected TRId trId; - protected DefNewColumn column; + private TRId trId; + private DefNewColumn column; public AddColumnSession(){ diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ChangeColumnsPositionSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ChangeColumnsPositionSession.java new file mode 100644 index 0000000..ecb5995 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ChangeColumnsPositionSession.java @@ -0,0 +1,53 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr.column; + +import java.io.Serializable; +import java.util.ArrayList; + +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class ChangeColumnsPositionSession implements Serializable { + + private static final long serialVersionUID = -1896235499708614266L; + + private TRId trId; + private ArrayList columns; + + public ChangeColumnsPositionSession() { + + } + + public ChangeColumnsPositionSession(TRId trId, ArrayList columns) { + this.trId = trId; + this.columns = columns; + } + + public TRId getTrId() { + return trId; + } + + public void setTrId(TRId trId) { + this.trId = trId; + } + + public ArrayList getColumns() { + return columns; + } + + public void setColumns(ArrayList columns) { + this.columns = columns; + } + + @Override + public String toString() { + return "ReorderColumnsSession [trId=" + trId + ", columns=" + columns + + "]"; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/DeleteColumnSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/DeleteColumnSession.java index 0d9a1e3..7cd8064 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/DeleteColumnSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/DeleteColumnSession.java @@ -16,8 +16,8 @@ public class DeleteColumnSession implements Serializable { private static final long serialVersionUID = -1896235499708614266L; - protected TRId trId; - protected ArrayList columns; + private TRId trId; + private ArrayList columns; public DeleteColumnSession(){ diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/FilterColumnSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/FilterColumnSession.java index d381522..d030f91 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/FilterColumnSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/FilterColumnSession.java @@ -14,8 +14,8 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expressi public class FilterColumnSession implements Serializable{ private static final long serialVersionUID = -5362632291599472352L; - protected ColumnData column; - protected C_Expression cexpression; + private ColumnData column; + private C_Expression cexpression; public FilterColumnSession(){ diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/LabelColumnSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/LabelColumnSession.java index a7bd7ab..059447f 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/LabelColumnSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/LabelColumnSession.java @@ -16,8 +16,8 @@ public class LabelColumnSession implements Serializable { private static final long serialVersionUID = -1896235499708614266L; - protected TRId trId; - protected HashMap maps; + private TRId trId; + private HashMap maps; public LabelColumnSession() { diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/MergeColumnSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/MergeColumnSession.java index 7689ad0..e6d5a71 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/MergeColumnSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/MergeColumnSession.java @@ -17,13 +17,13 @@ public class MergeColumnSession implements Serializable { private static final long serialVersionUID = -1896235499708614266L; - protected ColumnData columnDataSource1; - protected ColumnData columnDataSource2; - protected String label; - protected Expression expression; - protected ColumnTypeCode mergeColumnType; - protected ColumnDataType mergeColumnDataType; - protected boolean deleteColumn; + private ColumnData columnDataSource1; + private ColumnData columnDataSource2; + private String label; + private Expression expression; + private ColumnTypeCode mergeColumnType; + private ColumnDataType mergeColumnDataType; + private boolean deleteColumn; public MergeColumnSession() { diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ReplaceColumnByExpressionSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ReplaceColumnByExpressionSession.java index ef55b54..d5d96b6 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ReplaceColumnByExpressionSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ReplaceColumnByExpressionSession.java @@ -14,11 +14,11 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expressi public class ReplaceColumnByExpressionSession implements Serializable{ private static final long serialVersionUID = -3940140817918362233L; - protected ColumnData column; - protected C_Expression cConditionExpression; - protected C_Expression cReplaceExpression; - protected String replaceValue; - protected boolean replaceByValue; + private ColumnData column; + private C_Expression cConditionExpression; + private C_Expression cReplaceExpression; + private String replaceValue; + private boolean replaceByValue; public ReplaceColumnByExpressionSession(){ diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ReplaceColumnSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ReplaceColumnSession.java index 169e752..d3e4d92 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ReplaceColumnSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/ReplaceColumnSession.java @@ -15,12 +15,12 @@ public class ReplaceColumnSession implements Serializable { private static final long serialVersionUID = -1896235499708614266L; - protected String value; //Original value - protected String replaceValue; //New value - protected TRId trId; - protected ColumnData columnData; - protected String rowId; - protected boolean replaceDimension; + private String value; //Original value + private String replaceValue; //New value + private TRId trId; + private ColumnData columnData; + private String rowId; + private boolean replaceDimension; public ReplaceColumnSession() { diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/SplitColumnSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/SplitColumnSession.java index 071ea76..d9ff6a0 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/SplitColumnSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/column/SplitColumnSession.java @@ -18,15 +18,15 @@ public class SplitColumnSession implements Serializable { private static final long serialVersionUID = -1896235499708614266L; - protected ColumnData columnData; - protected ArrayList expressions; - protected String label1; - protected ColumnTypeCode firstSplitColumnType; - protected ColumnDataType firstSplitColumnDataType; - protected String label2; - protected ColumnTypeCode secondSplitColumnType; - protected ColumnDataType secondSplitColumnDataType; - protected boolean deleteColumn; + private ColumnData columnData; + private ArrayList expressions; + private String label1; + private ColumnTypeCode firstSplitColumnType; + private ColumnDataType firstSplitColumnDataType; + private String label2; + private ColumnTypeCode secondSplitColumnType; + private ColumnDataType secondSplitColumnDataType; + private boolean deleteColumn; public SplitColumnSession() {