From e1a265e9c0be3ea7f0d66fe2b5ecbd29a8152102 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 29 Nov 2013 10:07:31 +0000 Subject: [PATCH] Added getColumns git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@86348 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/client/rpc/TDGWTService.java | 10 ++++ .../client/rpc/TDGWTServiceAsync.java | 5 +- .../gwtservice/server/TDGWTServiceImpl.java | 53 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) 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 c4887ea..25b2241 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 @@ -17,6 +17,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; import org.gcube.portlets.user.td.gwtservice.shared.file.HeaderPresence; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TRId; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; @@ -26,6 +27,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist; import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -114,6 +116,14 @@ public interface TDGWTService extends RemoteService { */ public void setTDOpenSession(TDOpenSession tdOpenSession) throws TDGWTServiceException; + /** + * Retrieves the list of columns in the current table + * + * @return + * @throws TDGWTServiceException + */ + public ArrayList getColumns() throws TDGWTServiceException; + // Import SDMX /** 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 5f20139..9bac61b 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 @@ -16,6 +16,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; import org.gcube.portlets.user.td.gwtservice.shared.file.HeaderPresence; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportSession; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.gwtservice.shared.tr.TRId; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData; @@ -53,6 +54,8 @@ public interface TDGWTServiceAsync { void getTableMetadata(TRId trId, AsyncCallback> callback); + void getColumns(AsyncCallback> callback); + //Open void setTDOpenSession(TDOpenSession tdOpenSession, AsyncCallback callback); @@ -82,7 +85,7 @@ public interface TDGWTServiceAsync { void configureCSVParser(String encoding, HeaderPresence headerPresence, char delimiter, char comment, AsyncCallback> callback); - void checkCSV(long errorsLimit, AsyncCallback > callback); + void checkCSV(long errorsLimit, AsyncCallback> callback); void startCSVImport(CSVImportSession csvImportSession, 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 78bbf58..085917b 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 @@ -148,6 +148,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } /** + * * {@inheritDoc} */ @Override @@ -175,6 +176,58 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } + /** + * + * {@inheritDoc} + */ + @Override + public ArrayList getColumns() throws TDGWTServiceException { + try { + session = this.getThreadLocalRequest().getSession(); + aslSession = SessionUtil.getAslSession(session); + + TabResource currentTR = SessionUtil.getTabResource(session); + if (currentTR == null) { + logger.error("CURRENT_TABULAR_RESOURCE is null"); + throw new TDGWTServiceException( + "CURRENT_TABULAR_RESOURCE is null"); + } + TRId trId=currentTR.getTrId(); + + service = TabularDataServiceFactory.getService(aslSession + .getUsername()); + + Table table = service.getLastTable(new TabularResourceId(Long + .valueOf(trId.getId()))); + + ArrayList columns=new ArrayList(); + + List cols=table.getColumns(); + for(Column c: cols){ + ColumnData cData=new ColumnData(); + cData.setName(c.getName()); + cData.setTypeCode(c.getColumnType().getCode()); + cData.setTypeName(c.getColumnType().getName()); + cData.setTrId(trId); + } + + return columns; + + } catch (Exception e) { + logger.error( + "Error setting TabResource parameter: " + + e.getLocalizedMessage(), e); + throw new TDGWTServiceException( + "Error setting TabResource parameter: " + + e.getLocalizedMessage()); + } + } + + + /** + * + * {@inheritDoc} + */ @Override public TableData getLastTable(TRId trId) throws TDGWTServiceException { try {