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 c9ffabf..c4887ea 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 @@ -7,6 +7,8 @@ import java.util.ArrayList; import java.util.List; import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList; +import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVRowError; @@ -24,7 +26,6 @@ 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; @@ -241,4 +242,26 @@ public interface TDGWTService extends RemoteService { */ public CSVImportMonitor getCSVImportMonitor() throws TDGWTServiceException; + + //Export CSV + /** + * Get Operation Monitor during the CSV Export operation + * + * @return + * @throws TDGWTServiceException + */ + public CSVExportMonitor getCSVExportMonitor() throws TDGWTServiceException; + + + /** + * Start CSV Export and invokes the client library + * + * @param csvExportSession + * @throws TDGWTServiceException + */ + public void startCSVExport(CSVExportSession csvExportSession) throws TDGWTServiceException; + + + + } 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 74caa94..5f20139 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 @@ -7,6 +7,8 @@ import java.util.ArrayList; import java.util.List; import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList; +import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVRowError; @@ -84,5 +86,10 @@ public interface TDGWTServiceAsync { void startCSVImport(CSVImportSession csvImportSession, AsyncCallback callback); - + //Export CSV + void getCSVExportMonitor(AsyncCallback callback); + + void startCSVExport(CSVExportSession csvExportSession, 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 feff180..c50e9a4 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 @@ -57,6 +57,11 @@ public class SessionUtil { protected static final String CSV_IMPORT_TASK="CSV_IMPORT_TASK"; protected static final String CSV_IMPORT_TABULAR_RESOURCE = "CSV_IMPORT_TABULAR_RESOURCE"; + protected static final String CSV_EXPORT_FILE_SESSION = "CSV_EXPORT_FILE"; + protected static final String CSV_EXPORT_FILE_TASK="CSV_EXPORT_FILE_TASK"; + + + protected static Logger logger = LoggerFactory.getLogger(SessionUtil.class); protected static ASLSession getAslSession(HttpSession httpSession) { @@ -367,6 +372,22 @@ public class SessionUtil { httpSession.setAttribute(CSV_IMPORT_TASK, task); } + public static Task getCSVExportFileTask(HttpSession httpSession) { + Task monitor = (Task) httpSession.getAttribute(CSV_EXPORT_FILE_TASK); + if (monitor == null) { + logger.error("CSV_EXPORT_FILE_TASK was not acquired"); + } + return monitor; + } + + public static void setCSVExportFileTask(HttpSession httpSession, Task task) { + Task monitor = (Task) httpSession.getAttribute(CSV_EXPORT_FILE_TASK); + if (monitor != null) + httpSession.removeAttribute(CSV_EXPORT_FILE_TASK); + httpSession.setAttribute(CSV_EXPORT_FILE_TASK, task); + } + + public static TRTasksManager getTRTasksManager(HttpSession httpSession) { TRTasksManager tasksManager = (TRTasksManager) httpSession.getAttribute(TR_TASK_MANAGER); 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 5a3b907..78bbf58 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 @@ -63,7 +63,10 @@ import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil; 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.Constants; import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList; +import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor; +import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVFileUtil; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; @@ -190,11 +193,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements tData.setName(table.getName()); tData.setTypeName(table.getTableType().getName()); tData.setTypeCode(table.getTableType().getCode()); - Collection cMeta=table.getAllMetadata(); - + Collection cMeta = table.getAllMetadata(); + tData.setMetaData(cMeta.toString()); - - + ArrayList lColumnData = new ArrayList(); for (Column column : table.getColumns()) { ColumnData colData = new ColumnData(); @@ -569,9 +571,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements Map parameterInstance = retrieveOperationParameters(sdmxImportSession); - InvocationCreator ic=InvocationCreator.getCreator(importSDMXCodelistOperation); - OperationInvocation invocation = ic.setParameters(parameterInstance).create(); - + InvocationCreator ic = InvocationCreator + .getCreator(importSDMXCodelistOperation); + OperationInvocation invocation = ic + .setParameters(parameterInstance).create(); + logger.debug("OperationInvocation: \n" + invocation.toString()); Task trTask = oService.execute(invocation, serviceTR.getId()); logger.debug("Start Task on service: TaskId " + trTask.getId()); @@ -592,19 +596,19 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements * @throws TDGWTServiceException */ protected OperationDescriptor getOperationDescriptorWithId(String op, - List capabilities) throws TDGWTServiceException { + List capabilities) + throws TDGWTServiceException { for (OperationDescriptor operation : capabilities) { if (Long.valueOf(op) == operation.getOperationId().getValue()) { return operation; } - } throw new TDGWTServiceException("OperationDescriptor not found"); } - - protected State matchTaskState(TaskStatus status){ + + protected State matchTaskState(TaskStatus status) { switch (status) { case INITIALIZING: return State.INITIALIZING; @@ -622,7 +626,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements return State.FAILED; } } - /** * {@inheritDoc} @@ -655,14 +658,16 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } else { logger.debug("Service Task.getStatus(): " + task.getStatus()); - - importMonitor.setStatus(matchTaskState(task.getStatus())); - + + importMonitor + .setStatus(matchTaskState(task.getStatus())); + switch (importMonitor.getStatus()) { case SUCCEDED: importMonitor.setProgress(task.getProgress()); logger.debug("Task Result: " + task.getResult()); - trId.setTableId(String.valueOf(task.getResult().getPrimaryTable().getId().getValue())); + trId.setTableId(String.valueOf(task.getResult() + .getPrimaryTable().getId().getValue())); sdmxImportTabResource.setTrId(trId); SessionUtil.setSDMXImportTabResource(session, sdmxImportTabResource); @@ -675,8 +680,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements if (task.getResult() != null) { logger.debug("Task exception:" + task.getErrorCause()); - importMonitor - .setError(task.getErrorCause()); + importMonitor.setError(task.getErrorCause()); } else { logger.debug("Task exception: Error In Import"); importMonitor.setError(new Throwable( @@ -913,22 +917,18 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements protected Map csvImportFileParameter( String fileUrlOnStorage, FileUploadSession fileUploadSession, CSVImportSession csvImportSession) { - final String ENCODING = "encoding"; - final String HASHEADER = "hasHeader"; - final String SEPARATOR = "separator"; - final String URL = "url"; - Map parameterInstances = new HashMap(); - parameterInstances.put(URL, fileUrlOnStorage); - parameterInstances.put(SEPARATOR, String.valueOf(fileUploadSession - .getParserConfiguration().getDelimiter()));// ',' - parameterInstances.put(ENCODING, fileUploadSession + parameterInstances.put(Constants.URL, fileUrlOnStorage); + parameterInstances.put(Constants.SEPARATOR, String + .valueOf(fileUploadSession.getParserConfiguration() + .getDelimiter()));// ',' + parameterInstances.put(Constants.ENCODING, fileUploadSession .getParserConfiguration().getCharset().name());// "UTF-8" boolean hasHeader = true; if (fileUploadSession.getParserConfiguration().getHeaderPresence() == HeaderPresence.NONE) { hasHeader = false; } - parameterInstances.put(HASHEADER, hasHeader);// true + parameterInstances.put(Constants.HASHEADER, hasHeader);// true return parameterInstances; } @@ -943,14 +943,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements FileUploadSession fileUploadSession, CSVImportSession csvImportSession) throws TDGWTServiceException { logger.debug("File Storage Access"); - + FilesStorage filesStorage = new FilesStorage(); String fileUrlOnStorage = filesStorage.storageCSVTempFile(user, fileUploadSession.getCsvFile()); - logger.debug("File Url On Storage:"+fileUrlOnStorage); - - + logger.debug("File Url On Storage:" + fileUrlOnStorage); + Map parameterInstance = csvImportFileParameter( fileUrlOnStorage, fileUploadSession, csvImportSession); @@ -960,13 +959,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements List capabilities = service.getCapabilities(); // Import CSV file - + OperationDescriptor importCSVFileOperation = getOperationDescriptorWithId( OperationsId.CSVImport.toString(), capabilities); - InvocationCreator ic=InvocationCreator.getCreator(importCSVFileOperation); - OperationInvocation invocation = ic.setParameters(parameterInstance).create(); - + InvocationCreator ic = InvocationCreator + .getCreator(importCSVFileOperation); + OperationInvocation invocation = ic.setParameters(parameterInstance) + .create(); + logger.debug("OperationInvocation: \n" + invocation.toString()); TabularResource tabularResource = service.createTabularResource(); TabResource csvImportTabResource = csvImportSession.getTabResource(); @@ -1018,15 +1019,16 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements "Error in importCSV Status null"); } else { logger.debug("Status: " + task.getStatus()); - - importMonitor.setStatus(matchTaskState(task.getStatus())); + + importMonitor + .setStatus(matchTaskState(task.getStatus())); switch (importMonitor.getStatus()) { case FAILED: if (task.getResult() != null) { logger.debug("Task exception:" + task.getErrorCause()); - importMonitor - .setError(new Throwable(task.getErrorCause())); + importMonitor.setError(task + .getErrorCause()); } else { logger.debug("Task exception: Error In Import"); importMonitor.setError(new Throwable( @@ -1079,6 +1081,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } + /** + * + * {@inheritDoc} + */ @Override public void getFileFromWorkspace(CSVImportSession csvImportSession) throws TDGWTServiceException { @@ -1157,6 +1163,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements SessionUtil.setFileUploadSession(session, fileUploadSession); } + /** + * + * {@inheritDoc} + */ @Override public ArrayList getTableMetadata(TRId trId) throws TDGWTServiceException { @@ -1167,90 +1177,292 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements service = TabularDataServiceFactory.getService(aslSession .getUsername()); - Table table = service.getTable(new TableId(Long.valueOf(trId.getTableId()))); - - Collection cMeta=table.getAllMetadata(); - - ArrayList listTRMetadata=new ArrayList(); - - for(TableMetadata tMetadata:cMeta){ - if(tMetadata instanceof DescriptionsMetadata){ - TRDescriptionsMetadata trDescriptionsMetadata=new TRDescriptionsMetadata(); - ArrayList listTRLocalizedText=new ArrayList(); - List lLocalizedText=((DescriptionsMetadata) tMetadata).getTexts(); - int i=0; - for(LocalizedText lt:lLocalizedText){ - TRLocalizedText trLocalizedText=new TRLocalizedText(); + Table table = service.getTable(new TableId(Long.valueOf(trId + .getTableId()))); + + Collection cMeta = table.getAllMetadata(); + + ArrayList listTRMetadata = new ArrayList(); + + for (TableMetadata tMetadata : cMeta) { + if (tMetadata instanceof DescriptionsMetadata) { + TRDescriptionsMetadata trDescriptionsMetadata = new TRDescriptionsMetadata(); + ArrayList listTRLocalizedText = new ArrayList(); + List lLocalizedText = ((DescriptionsMetadata) tMetadata) + .getTexts(); + int i = 0; + for (LocalizedText lt : lLocalizedText) { + TRLocalizedText trLocalizedText = new TRLocalizedText(); trLocalizedText.setId(i); trLocalizedText.setValue(lt.getValue()); trLocalizedText.setLocaleCode(lt.getLocale()); listTRLocalizedText.add(trLocalizedText); i++; } - trDescriptionsMetadata.setListTRLocalizedText(listTRLocalizedText); + trDescriptionsMetadata + .setListTRLocalizedText(listTRLocalizedText); listTRMetadata.add(trDescriptionsMetadata); - + } else { - if(tMetadata instanceof NamesMetadata){ - TRNamesMetadata trNamesMetadata=new TRNamesMetadata(); - ArrayList listTRLocalizedText=new ArrayList(); - List lLocalizedText=((NamesMetadata) tMetadata).getTexts(); - int i=0; - for(LocalizedText lt:lLocalizedText){ - TRLocalizedText trLocalizedText=new TRLocalizedText(); + if (tMetadata instanceof NamesMetadata) { + TRNamesMetadata trNamesMetadata = new TRNamesMetadata(); + ArrayList listTRLocalizedText = new ArrayList(); + List lLocalizedText = ((NamesMetadata) tMetadata) + .getTexts(); + int i = 0; + for (LocalizedText lt : lLocalizedText) { + TRLocalizedText trLocalizedText = new TRLocalizedText(); trLocalizedText.setId(i); trLocalizedText.setValue(lt.getValue()); trLocalizedText.setLocaleCode(lt.getLocale()); listTRLocalizedText.add(trLocalizedText); i++; } - trNamesMetadata.setListTRLocalizedText(listTRLocalizedText); + trNamesMetadata + .setListTRLocalizedText(listTRLocalizedText); listTRMetadata.add(trNamesMetadata); - + } else { - if(tMetadata instanceof VersionMetadata){ - TRVersionMetadata trVersionMetadata=new TRVersionMetadata(); - trVersionMetadata.setVersion(((VersionMetadata)tMetadata).getVersion()); + if (tMetadata instanceof VersionMetadata) { + TRVersionMetadata trVersionMetadata = new TRVersionMetadata(); + trVersionMetadata + .setVersion(((VersionMetadata) tMetadata) + .getVersion()); listTRMetadata.add(trVersionMetadata); - }else{ - if(tMetadata instanceof ExportMetadata){ - TRExportMetadata trExportMetadata=new TRExportMetadata(); - trExportMetadata.setDestinationType(((ExportMetadata)tMetadata).getDestinationType()); - trExportMetadata.setExportDate(sdf.format(((ExportMetadata)tMetadata).getExportDate())); - trExportMetadata.setUrl(((ExportMetadata)tMetadata).getUri()); + } else { + if (tMetadata instanceof ExportMetadata) { + TRExportMetadata trExportMetadata = new TRExportMetadata(); + trExportMetadata + .setDestinationType(((ExportMetadata) tMetadata) + .getDestinationType()); + trExportMetadata.setExportDate(sdf + .format(((ExportMetadata) tMetadata) + .getExportDate())); + trExportMetadata + .setUrl(((ExportMetadata) tMetadata) + .getUri()); listTRMetadata.add(trExportMetadata); - }else{ - if(tMetadata instanceof ImportMetadata){ - TRImportMetadata trImportMetadata=new TRImportMetadata(); - trImportMetadata.setSourceType(((ImportMetadata)tMetadata).getSourceType()); - trImportMetadata.setImportDate(sdf.format(((ImportMetadata)tMetadata).getImportDate())); - trImportMetadata.setUrl(((ImportMetadata)tMetadata).getUri()); + } else { + if (tMetadata instanceof ImportMetadata) { + TRImportMetadata trImportMetadata = new TRImportMetadata(); + trImportMetadata + .setSourceType(((ImportMetadata) tMetadata) + .getSourceType()); + trImportMetadata + .setImportDate(sdf + .format(((ImportMetadata) tMetadata) + .getImportDate())); + trImportMetadata + .setUrl(((ImportMetadata) tMetadata) + .getUri()); listTRMetadata.add(trImportMetadata); - }else{ - if(tMetadata instanceof GenericMapMetadata){ - TRGenericMapMetadata trGenericMapMetadata=new TRGenericMapMetadata(); - trGenericMapMetadata.setMetadataMap(((GenericMapMetadata)tMetadata).getMetadataMap()); - listTRMetadata.add(trGenericMapMetadata); - }else{ - + } else { + if (tMetadata instanceof GenericMapMetadata) { + TRGenericMapMetadata trGenericMapMetadata = new TRGenericMapMetadata(); + trGenericMapMetadata + .setMetadataMap(((GenericMapMetadata) tMetadata) + .getMetadataMap()); + listTRMetadata + .add(trGenericMapMetadata); + } else { + } - + } } } } } } - - + return listTRMetadata; } catch (Exception e) { - logger.error("Error in getTableMetadata(): " + e.getLocalizedMessage(), + logger.error( + "Error in getTableMetadata(): " + e.getLocalizedMessage(), e); throw new TDGWTServiceException("Error in getTableMetadata(): " + e.getLocalizedMessage()); } } + /** + * + * @param exportSession + * @return + */ + protected Map csvExportFileParameter( + CSVExportSession exportSession) { + Map parameterInstances = new HashMap(); + parameterInstances.put(Constants.ENCODING, exportSession.getEncoding()); + parameterInstances.put(Constants.SEPARATOR, + exportSession.getSeparator()); + parameterInstances.put(Constants.COLUMNS, exportSession.getColumns()); + // TODO + + /* + * List columns = Lists.newArrayList(); for(Column column : + * table.getColumns()) if (!(column.getColumnType() instanceof + * IdColumnType)) columns.add(column.getName()); + * + * instances.put(Constants.COLUMNS, columns); + */ + + return parameterInstances; + } + + /** + * + * {@inheritDoc} + */ + @Override + public void startCSVExport(CSVExportSession exportSession) + throws TDGWTServiceException { + logger.debug("Start CSV Export"); + session = this.getThreadLocalRequest().getSession(); + if (session == null) { + throw new TDGWTServiceException( + "Error retrieving the session: null"); + } + logger.info("Session:" + session.getId()); + + aslSession = SessionUtil.getAslSession(session); + if (aslSession == null) { + throw new TDGWTServiceException( + "Error retrieving the asl session: null"); + } + String user = aslSession.getUsername(); + logger.info("Session User:" + user); + + TRId trId = SessionUtil.getTRId(session); + if (trId == null) { + throw new TDGWTServiceException( + "Error no tabular resource in session"); + } + + if (trId.getTableId() == null) { + throw new TDGWTServiceException("Error no table present in session"); + } + + Map parameterInstance = csvExportFileParameter(exportSession); + + logger.debug("Tabular Data Service"); + service = TabularDataServiceFactory + .getService(aslSession.getUsername()); + + List capabilities = service.getCapabilities(); + + // Export CSV file + + OperationDescriptor exportCSVFileOperation = getOperationDescriptorWithId( + OperationsId.CSVExport.toString(), capabilities); + + InvocationCreator ic = InvocationCreator + .getCreator(exportCSVFileOperation); + OperationInvocation invocation = ic + .setTargetTable(new TableId(Long.valueOf(trId.getTableId()))) + .setParameters(parameterInstance).create(); + + logger.debug("OperationInvocation: \n" + invocation.toString()); + + Task trTask; + try { + trTask = service.execute(invocation, + new TabularResourceId(Long.valueOf(trId.getId()))); + } catch (Exception e) { + e.printStackTrace(); + throw new TDGWTServiceException( + "Tabular Data Service error exporting TabularResource: " + + e.getLocalizedMessage()); + } + + logger.debug("Start Task on service: TaskId " + trTask.getId()); + SessionUtil.setCSVExportFileTask(session, trTask); + } + + /** + * {@inheritDoc} + */ + @Override + public CSVExportMonitor getCSVExportMonitor() throws TDGWTServiceException { + try { + session = this.getThreadLocalRequest().getSession(); + aslSession = SessionUtil.getAslSession(session); + Task task = SessionUtil.getCSVExportFileTask(session); + CSVExportMonitor exportMonitor = new CSVExportMonitor(); + + if (task == null) { + logger.debug("Task null"); + throw new TDGWTServiceException("Error in exportCSV task null"); + } else { + TaskStatus status = task.getStatus(); + if (status == null) { + throw new TDGWTServiceException( + "Error in exportCSV Status null"); + } else { + logger.debug("Status: " + task.getStatus()); + + exportMonitor.setStatus(matchTaskState(task.getStatus())); + switch (exportMonitor.getStatus()) { + case FAILED: + if (task.getResult() != null) { + logger.debug("Task exception:" + + task.getErrorCause()); + exportMonitor.setError(task + .getErrorCause()); + } else { + logger.debug("Task exception: Error In Export"); + exportMonitor.setError(new Throwable( + "Error In Export")); + } + exportMonitor.setProgress(task.getProgress()); + break; + case SUCCEDED: + logger.debug("Task Result:" + task.getResult()); + exportMonitor.setProgress(task.getProgress()); + Table table = task.getResult().getPrimaryTable(); + logger.debug("Table retrived: " + table.toString()); + ExportMetadata exportMetadata = table + .getMetadata(ExportMetadata.class); + logger.debug("ExportMetadata: " + exportMetadata); + + exportMonitor.setTrId(SessionUtil.getTRId(session)); + TRExportMetadata trExportMetadata = new TRExportMetadata(); + trExportMetadata.setUrl(exportMetadata.getUri()); + trExportMetadata.setDestinationType(exportMetadata + .getDestinationType()); + trExportMetadata.setExportDate(sdf + .format(exportMetadata.getExportDate())); + exportMonitor.setTrExportMetadata(trExportMetadata); + + break; + case IN_PROGRESS: + exportMonitor.setProgress(task.getProgress()); + break; + case ABORTED: + break; + case INITIALIZING: + break; + case WAITING: + break; + default: + break; + } + } + SessionUtil.setCSVExportFileTask(session, task); + } + + + logger.info("getExportMonitor(): " + exportMonitor); + return exportMonitor; + } catch (Exception e) { + e.printStackTrace(); + throw new TDGWTServiceException( + "Error in exportCSV CSVExportMonitor: " + + e.getLocalizedMessage()); + + } + + } + } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java index 1e4c9ab..2ac9322 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/Constants.java @@ -16,5 +16,10 @@ public class Constants { public final static String DEFAULT_USER = "giancarlo.panichi"; public final static String DEFAULT_SCOPE = "/gcube/devsec"; + public static final String ENCODING = "encoding"; + public static final String HASHEADER = "hasHeader"; + public static final String SEPARATOR = "separator"; + public static final String COLUMNS = "columns"; + public static final String URL = "url"; } diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVExportSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVExportSession.java index 6a3eb6d..43bf8fb 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVExportSession.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVExportSession.java @@ -4,7 +4,10 @@ package org.gcube.portlets.user.td.gwtservice.shared.csv; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.gcube.portlets.user.td.gwtservice.shared.Constants; import org.gcube.portlets.user.td.gwtservice.shared.destination.Destination; @@ -25,6 +28,29 @@ public class CSVExportSession implements Serializable { protected String itemId; protected String fileName; + protected ArrayList columns; + protected String encoding; + protected String separator; + + + public ArrayList getColumns() { + return columns; + } + public void setColumns(ArrayList columns) { + this.columns = columns; + } + public String getEncoding() { + return encoding; + } + public void setEncoding(String encoding) { + this.encoding = encoding; + } + public String getSeparator() { + return separator; + } + public void setSeparator(String separator) { + this.separator = separator; + } public String getId() { return id; } @@ -52,10 +78,14 @@ public class CSVExportSession implements Serializable { @Override public String toString() { return "CSVExportSession [id=" + id + ", destination=" + destination - + ", itemId=" + itemId + ", fileName=" + fileName + "]"; + + ", itemId=" + itemId + ", fileName=" + fileName + + ", columns=" + columns + ", encoding=" + encoding + + ", separator=" + separator + "]"; } + + diff --git a/src/test/java/org/gcube/portlets/user/td/gwtservice/client/TestServiceOperations.java b/src/test/java/org/gcube/portlets/user/td/gwtservice/client/TestServiceOperations.java index 6d84cf2..71da20f 100644 --- a/src/test/java/org/gcube/portlets/user/td/gwtservice/client/TestServiceOperations.java +++ b/src/test/java/org/gcube/portlets/user/td/gwtservice/client/TestServiceOperations.java @@ -28,7 +28,10 @@ public class TestServiceOperations { System.out .println("------------Tabular Resource Operation--------------"); for (OperationDescriptor operation : trOperations) { - System.out.println(operation.toString()); + System.out.println("Name: "+operation.getName()); + System.out.println("Scope: "+operation.getScope()); + System.out.println("Desc: "+operation.toString()); + System.out.println("-----------------------------------"); } }