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 1e052db..8102070 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 @@ -22,6 +22,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; +import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnMonitor; @@ -42,7 +43,6 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; -import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -167,6 +167,18 @@ public interface TDGWTService extends RemoteService { public ArrayList getTabularResources() throws TDGWTServiceException; + //Clone + /** + * Start clone tabular resource + * + * @param labelColumnSession + * @throws TDGWTServiceException + */ + public TRId startCloneTabularResource(CloneTabularResourceSession cloneTabularResourceSession) + throws TDGWTServiceException; + + + // /** * Initialize Codelists Paging Loader * 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 ed3e67d..fdc8754 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 @@ -21,6 +21,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; +import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnMonitor; @@ -59,6 +60,7 @@ public interface TDGWTServiceAsync { void hello(AsyncCallback callback); void createTabularResource(TabResource tabResource,AsyncCallback callback); + void getTabResourceInformation(AsyncCallback callback); @@ -99,6 +101,10 @@ public interface TDGWTServiceAsync { //Open void startTDOpen(TDOpenSession tdOpenSession, AsyncCallback callback); + //Clone + void startCloneTabularResource(CloneTabularResourceSession cloneTabularResourceSession,AsyncCallback callback); + + //SDMX void getCodelists(AsyncCallback> callback); 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 12f273f..1cf5f9d 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 @@ -23,6 +23,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportSession; import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; +import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnMonitor; @@ -55,9 +56,11 @@ public class SessionUtil { protected static final String TABULAR_RESOURCE_LIST = "TABULAR_RESOURCE_LIST"; protected static final String TR_TASK_MANAGER = "TR_TASK_MANAGER"; - + protected static final String SDMX_REGISTRY_SOURCE = "SDMX_REGISTRY_SOURCE"; + protected static final String CLONE_TABULAR_RESOURCE_SESSION = "CLONE_TABULAR_RESOURCE_SESSION"; + protected static final String SDMX_CLIENT_ATTRIBUTE = "SDMX_CLIENT"; protected static final String SDMX_IMPORT_SESSION = "SDMX_IMPORT"; protected static final String SDMX_IMPORT_TABULAR_RESOURCE = "SDMX_IMPORT_TABULAR_RESOURCE"; @@ -819,74 +822,104 @@ public class SessionUtil { /// - public static DeleteRowsSession getDeleteRowsSession( + public static CloneTabularResourceSession getCloneTabularResourceSession( HttpSession httpSession) { - DeleteRowsSession deleteRowsSession = (DeleteRowsSession) httpSession - .getAttribute(DELETE_ROWS_SESSION); - if (deleteRowsSession != null) { - return deleteRowsSession; + CloneTabularResourceSession cloneTabularResourceSession = (CloneTabularResourceSession) httpSession + .getAttribute(CLONE_TABULAR_RESOURCE_SESSION); + if (cloneTabularResourceSession != null) { + return cloneTabularResourceSession; } else { - deleteRowsSession = new DeleteRowsSession(); + cloneTabularResourceSession = new CloneTabularResourceSession(); + httpSession.setAttribute(CLONE_TABULAR_RESOURCE_SESSION, + cloneTabularResourceSession); + return cloneTabularResourceSession; + } + } + + public static void setCloneTabularResourceSession(HttpSession httpSession, + CloneTabularResourceSession cloneTabularResourceSession) { + CloneTabularResourceSession c = (CloneTabularResourceSession) httpSession + .getAttribute(CLONE_TABULAR_RESOURCE_SESSION); + if (c != null) { + httpSession.removeAttribute(CLONE_TABULAR_RESOURCE_SESSION); + } + httpSession.setAttribute(CLONE_TABULAR_RESOURCE_SESSION, + cloneTabularResourceSession); + + } + + + + /// + + public static DeleteRowsSession getDeleteRowsSession( + HttpSession httpSession) { + DeleteRowsSession deleteRowsSession = (DeleteRowsSession) httpSession + .getAttribute(DELETE_ROWS_SESSION); + if (deleteRowsSession != null) { + return deleteRowsSession; + } else { + deleteRowsSession = new DeleteRowsSession(); + httpSession.setAttribute(DELETE_ROWS_SESSION, + deleteRowsSession); + return deleteRowsSession; + } + } + + public static void setDeleteRowsSession(HttpSession httpSession, + DeleteRowsSession deleteRowsSession) { + DeleteRowsSession dr = (DeleteRowsSession) httpSession + .getAttribute(DELETE_ROWS_SESSION); + if (dr != null) { + httpSession.removeAttribute(DELETE_ROWS_SESSION); + } httpSession.setAttribute(DELETE_ROWS_SESSION, deleteRowsSession); - return deleteRowsSession; + } - } - public static void setDeleteRowsSession(HttpSession httpSession, - DeleteRowsSession deleteRowsSession) { - DeleteRowsSession dr = (DeleteRowsSession) httpSession - .getAttribute(DELETE_ROWS_SESSION); - if (dr != null) { - httpSession.removeAttribute(DELETE_ROWS_SESSION); + public static DeleteRowsMonitor getDeleteRowsMonitor( + HttpSession httpSession) { + DeleteRowsMonitor deleteRowsMonitor = (DeleteRowsMonitor) httpSession + .getAttribute(DELETE_ROWS_MONITOR); + if (deleteRowsMonitor != null) { + return deleteRowsMonitor; + } else { + deleteRowsMonitor = new DeleteRowsMonitor(); + httpSession.setAttribute(DELETE_ROWS_MONITOR, + deleteRowsMonitor); + return deleteRowsMonitor; + } } - httpSession.setAttribute(DELETE_ROWS_SESSION, - deleteRowsSession); - } - - public static DeleteRowsMonitor getDeleteRowsMonitor( - HttpSession httpSession) { - DeleteRowsMonitor deleteRowsMonitor = (DeleteRowsMonitor) httpSession - .getAttribute(DELETE_ROWS_MONITOR); - if (deleteRowsMonitor != null) { - return deleteRowsMonitor; - } else { - deleteRowsMonitor = new DeleteRowsMonitor(); + public static void setDeleteRowsMonitor(HttpSession httpSession, + DeleteRowsMonitor deleteRowsMonitor) { + DeleteRowsMonitor ctt = (DeleteRowsMonitor) httpSession + .getAttribute(DELETE_ROWS_MONITOR); + if (ctt != null) { + httpSession.removeAttribute(DELETE_ROWS_MONITOR); + } httpSession.setAttribute(DELETE_ROWS_MONITOR, deleteRowsMonitor); - return deleteRowsMonitor; + } - } - public static void setDeleteRowsMonitor(HttpSession httpSession, - DeleteRowsMonitor deleteRowsMonitor) { - DeleteRowsMonitor ctt = (DeleteRowsMonitor) httpSession - .getAttribute(DELETE_ROWS_MONITOR); - if (ctt != null) { - httpSession.removeAttribute(DELETE_ROWS_MONITOR); + public static Task getDeleteRowsTask(HttpSession httpSession) { + Task monitor = (Task) httpSession.getAttribute(DELETE_ROWS_TASK); + if (monitor == null) { + logger.error("DELETE_ROWS_TASK was not acquired"); + } + return monitor; } - httpSession.setAttribute(DELETE_ROWS_MONITOR, - deleteRowsMonitor); - } - - public static Task getDeleteRowsTask(HttpSession httpSession) { - Task monitor = (Task) httpSession.getAttribute(DELETE_ROWS_TASK); - if (monitor == null) { - logger.error("DELETE_ROWS_TASK was not acquired"); + public static void setDeleteRowsTask(HttpSession httpSession, + Task task) { + Task monitor = (Task) httpSession.getAttribute(DELETE_ROWS_TASK); + if (monitor != null) + httpSession.removeAttribute(DELETE_ROWS_TASK); + httpSession.setAttribute(DELETE_ROWS_TASK, task); } - return monitor; - } - - public static void setDeleteRowsTask(HttpSession httpSession, - Task task) { - Task monitor = (Task) httpSession.getAttribute(DELETE_ROWS_TASK); - if (monitor != null) - httpSession.removeAttribute(DELETE_ROWS_TASK); - httpSession.setAttribute(DELETE_ROWS_TASK, task); - } - + /// 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 df37767..ba63b52 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 @@ -100,6 +100,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; +import org.gcube.portlets.user.td.gwtservice.shared.tr.clone.CloneTabularResourceSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnMonitor; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.DeleteColumnSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnMonitor; @@ -2749,7 +2750,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements return invocation; } - + + + + + protected OperationExecution retrieveOperationExecution( TabularDataService service, LabelColumnSession labelColumnSession) throws TDGWTServiceException { @@ -3483,8 +3488,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } - - @Override public void startDeleteRows(DeleteRowsSession deleteRowsSession) throws TDGWTServiceException { @@ -3518,7 +3521,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } - + @Override public DeleteRowsMonitor getDeleteRowsMonitor() throws TDGWTServiceException { @@ -3621,5 +3624,45 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + + + @Override + public TRId startCloneTabularResource( + CloneTabularResourceSession cloneTabularResourceSession) + throws TDGWTServiceException { + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + SessionUtil.setCloneTabularResourceSession(session, cloneTabularResourceSession); + ASLSession aslSession = SessionUtil.getAslSession(session); + + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername())); + TabularDataService service = TabularDataServiceFactory.getService(); + + TabularResourceId serviceTR = new TabularResourceId( + Long.valueOf(cloneTabularResourceSession.getTrId().getId())); + + TabularResource cloned=service.cloneTabularResource(serviceTR); + Table table=service.getLastTable(serviceTR); + + TRId trId = new TRId(new Long(cloned.getId().getValue()).toString(), + new Long(table.getId().getValue()).toString()); + trId.setTableType(table.getTableType().getName()); + + TabResource tabResource = new TabResource(); + tabResource.setTrId(trId); + SessionUtil.setTabResource(session, tabResource); + SessionUtil.setTRId(session, trId); + + return trId; + } catch (Exception e) { + e.printStackTrace(); + throw new TDGWTServiceException("Error Cloning: " + + e.getLocalizedMessage()); + } + + } + + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/clone/CloneTabularResourceSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/clone/CloneTabularResourceSession.java new file mode 100644 index 0000000..a107e05 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/tr/clone/CloneTabularResourceSession.java @@ -0,0 +1,33 @@ +package org.gcube.portlets.user.td.gwtservice.shared.tr.clone; + +import java.io.Serializable; + +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 CloneTabularResourceSession implements Serializable { + + private static final long serialVersionUID = -1896235499708614266L; + + protected TRId trId; + + public TRId getTrId() { + return trId; + } + + public void setTrId(TRId trId) { + this.trId = trId; + } + + @Override + public String toString() { + return "CloneTabularResourceSession [trId=" + trId + "]"; + } + +}