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 2344332..d5570d1 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 @@ -11,7 +11,9 @@ import org.gcube.portlets.user.td.gwtservice.shared.Codelist; import org.gcube.portlets.user.td.gwtservice.shared.Dataset; import org.gcube.portlets.user.td.gwtservice.shared.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.TDOpenSession; +import org.gcube.portlets.user.td.gwtservice.shared.TRId; import org.gcube.portlets.user.td.gwtservice.shared.TabResource; +import org.gcube.portlets.user.td.gwtservice.shared.TableData; import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; @@ -70,6 +72,16 @@ public interface TDGWTService extends RemoteService { public TabResource createTabularResource(TabResource tabResource) throws TDGWTServiceException; + + /** + * Return Last Table + * + * @param trId + * @return + * @throws TDGWTServiceException + */ + public TableData getLastTable(TRId trId) throws TDGWTServiceException; + // Open /** 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 39b0021..cefd20e 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 @@ -10,7 +10,9 @@ import org.gcube.portlets.user.td.gwtservice.shared.Agencies; import org.gcube.portlets.user.td.gwtservice.shared.Codelist; import org.gcube.portlets.user.td.gwtservice.shared.Dataset; import org.gcube.portlets.user.td.gwtservice.shared.TDOpenSession; +import org.gcube.portlets.user.td.gwtservice.shared.TRId; import org.gcube.portlets.user.td.gwtservice.shared.TabResource; +import org.gcube.portlets.user.td.gwtservice.shared.TableData; import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; @@ -42,6 +44,8 @@ public interface TDGWTServiceAsync { void setTabResource(TabResource tabResource, AsyncCallback callback); void getTabularResources(AsyncCallback> callback); + + void getLastTable(TRId trId, AsyncCallback callback); //Open void setTDOpenSession(TDOpenSession tdOpenSession, AsyncCallback callback); 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 12d1c86..2a9dd8b 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 @@ -24,6 +24,7 @@ import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.data.analysis.tabulardata.metadata.NoSuchMetadataException; +import org.gcube.data.analysis.tabulardata.model.column.Column; import org.gcube.data.analysis.tabulardata.model.table.Table; import org.gcube.data.analysis.tabulardata.model.table.TableId; import org.gcube.data.analysis.tabulardata.operation.worker.ActivityStatus; @@ -53,11 +54,13 @@ import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage; import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationsId; import org.gcube.portlets.user.td.gwtservice.shared.Agencies; import org.gcube.portlets.user.td.gwtservice.shared.Codelist; +import org.gcube.portlets.user.td.gwtservice.shared.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.Dataset; import org.gcube.portlets.user.td.gwtservice.shared.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.TDOpenSession; import org.gcube.portlets.user.td.gwtservice.shared.TRId; import org.gcube.portlets.user.td.gwtservice.shared.TabResource; +import org.gcube.portlets.user.td.gwtservice.shared.TableData; import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVFileUtil; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor; @@ -148,6 +151,54 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements + e.getLocalizedMessage()); } } + + + + + @Override + public TableData getLastTable(TRId trId) throws TDGWTServiceException { + try { + session = this.getThreadLocalRequest().getSession(); + aslSession = SessionUtil.getAslSession(session); + + service = TabularDataServiceFactory.getService(aslSession + .getUsername()); + + long id=Long.valueOf(trId.getId()); + + TabularResourceId tabularResourceId=new TabularResourceId(id); + Table table = service.getLastTable(tabularResourceId); + + TableData tData=new TableData(); + trId.setTableId(String.valueOf(table.getId().getValue())); + tData.setTrId(trId); + tData.setName(table.getName()); + tData.setTypeName(table.getTableType().getName()); + tData.setTypeCode(table.getTableType().getCode()); + + ArrayList lColumnData=new ArrayList(); + for(Column column:table.getColumns()){ + ColumnData colData=new ColumnData(); + colData.setName(column.getName()); + colData.setTypeName(column.getColumnType().getName()); + colData.setTypeCode(column.getColumnType().getCode()); + lColumnData.add(colData); + }; + + tData.setListColumnData(lColumnData); + + return tData; + + } catch (Exception e) { + logger.error( + "Error in getLastTable(): " + + e.getLocalizedMessage(), e); + throw new TDGWTServiceException( + "Error in getLastTable(): " + + e.getLocalizedMessage()); + } + } + /** * {@inheritDoc}