Added Export CSV Monitor

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@86338 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2013-11-28 17:35:11 +00:00
parent c5bf5a1d4f
commit 1127ad51c2
7 changed files with 396 additions and 95 deletions

View File

@ -7,6 +7,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList; 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.CSVImportMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVRowError; 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.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; 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.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@ -241,4 +242,26 @@ public interface TDGWTService extends RemoteService {
*/ */
public CSVImportMonitor getCSVImportMonitor() throws TDGWTServiceException; 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;
} }

View File

@ -7,6 +7,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList; 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.CSVImportMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVRowError; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVRowError;
@ -84,5 +86,10 @@ public interface TDGWTServiceAsync {
void startCSVImport(CSVImportSession csvImportSession, AsyncCallback<Void> callback); void startCSVImport(CSVImportSession csvImportSession, AsyncCallback<Void> callback);
//Export CSV
void getCSVExportMonitor(AsyncCallback<CSVExportMonitor> callback);
void startCSVExport(CSVExportSession csvExportSession, AsyncCallback<Void> callback);
} }

View File

@ -57,6 +57,11 @@ public class SessionUtil {
protected static final String CSV_IMPORT_TASK="CSV_IMPORT_TASK"; 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_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 Logger logger = LoggerFactory.getLogger(SessionUtil.class);
protected static ASLSession getAslSession(HttpSession httpSession) { protected static ASLSession getAslSession(HttpSession httpSession) {
@ -367,6 +372,22 @@ public class SessionUtil {
httpSession.setAttribute(CSV_IMPORT_TASK, task); 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) { public static TRTasksManager getTRTasksManager(HttpSession httpSession) {
TRTasksManager tasksManager = (TRTasksManager) httpSession.getAttribute(TR_TASK_MANAGER); TRTasksManager tasksManager = (TRTasksManager) httpSession.getAttribute(TR_TASK_MANAGER);

View File

@ -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.file.FileUtil;
import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage; 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.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.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.CSVFileUtil;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor; 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.CSVImportSession;
@ -194,7 +197,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
tData.setMetaData(cMeta.toString()); tData.setMetaData(cMeta.toString());
ArrayList<ColumnData> lColumnData = new ArrayList<ColumnData>(); ArrayList<ColumnData> lColumnData = new ArrayList<ColumnData>();
for (Column column : table.getColumns()) { for (Column column : table.getColumns()) {
ColumnData colData = new ColumnData(); ColumnData colData = new ColumnData();
@ -569,8 +571,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
Map<String, Object> parameterInstance = retrieveOperationParameters(sdmxImportSession); Map<String, Object> parameterInstance = retrieveOperationParameters(sdmxImportSession);
InvocationCreator ic=InvocationCreator.getCreator(importSDMXCodelistOperation); InvocationCreator ic = InvocationCreator
OperationInvocation invocation = ic.setParameters(parameterInstance).create(); .getCreator(importSDMXCodelistOperation);
OperationInvocation invocation = ic
.setParameters(parameterInstance).create();
logger.debug("OperationInvocation: \n" + invocation.toString()); logger.debug("OperationInvocation: \n" + invocation.toString());
Task trTask = oService.execute(invocation, serviceTR.getId()); Task trTask = oService.execute(invocation, serviceTR.getId());
@ -592,13 +596,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* @throws TDGWTServiceException * @throws TDGWTServiceException
*/ */
protected OperationDescriptor getOperationDescriptorWithId(String op, protected OperationDescriptor getOperationDescriptorWithId(String op,
List<OperationDescriptor> capabilities) throws TDGWTServiceException { List<OperationDescriptor> capabilities)
throws TDGWTServiceException {
for (OperationDescriptor operation : capabilities) { for (OperationDescriptor operation : capabilities) {
if (Long.valueOf(op) == operation.getOperationId().getValue()) { if (Long.valueOf(op) == operation.getOperationId().getValue()) {
return operation; return operation;
} }
} }
throw new TDGWTServiceException("OperationDescriptor not found"); throw new TDGWTServiceException("OperationDescriptor not found");
@ -623,7 +627,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -656,13 +659,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
logger.debug("Service Task.getStatus(): " logger.debug("Service Task.getStatus(): "
+ task.getStatus()); + task.getStatus());
importMonitor.setStatus(matchTaskState(task.getStatus())); importMonitor
.setStatus(matchTaskState(task.getStatus()));
switch (importMonitor.getStatus()) { switch (importMonitor.getStatus()) {
case SUCCEDED: case SUCCEDED:
importMonitor.setProgress(task.getProgress()); importMonitor.setProgress(task.getProgress());
logger.debug("Task Result: " + task.getResult()); 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); sdmxImportTabResource.setTrId(trId);
SessionUtil.setSDMXImportTabResource(session, SessionUtil.setSDMXImportTabResource(session,
sdmxImportTabResource); sdmxImportTabResource);
@ -675,8 +680,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (task.getResult() != null) { if (task.getResult() != null) {
logger.debug("Task exception:" logger.debug("Task exception:"
+ task.getErrorCause()); + task.getErrorCause());
importMonitor importMonitor.setError(task.getErrorCause());
.setError(task.getErrorCause());
} else { } else {
logger.debug("Task exception: Error In Import"); logger.debug("Task exception: Error In Import");
importMonitor.setError(new Throwable( importMonitor.setError(new Throwable(
@ -913,22 +917,18 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
protected Map<String, Object> csvImportFileParameter( protected Map<String, Object> csvImportFileParameter(
String fileUrlOnStorage, FileUploadSession fileUploadSession, String fileUrlOnStorage, FileUploadSession fileUploadSession,
CSVImportSession csvImportSession) { CSVImportSession csvImportSession) {
final String ENCODING = "encoding";
final String HASHEADER = "hasHeader";
final String SEPARATOR = "separator";
final String URL = "url";
Map<String, Object> parameterInstances = new HashMap<String, Object>(); Map<String, Object> parameterInstances = new HashMap<String, Object>();
parameterInstances.put(URL, fileUrlOnStorage); parameterInstances.put(Constants.URL, fileUrlOnStorage);
parameterInstances.put(SEPARATOR, String.valueOf(fileUploadSession parameterInstances.put(Constants.SEPARATOR, String
.getParserConfiguration().getDelimiter()));// ',' .valueOf(fileUploadSession.getParserConfiguration()
parameterInstances.put(ENCODING, fileUploadSession .getDelimiter()));// ','
parameterInstances.put(Constants.ENCODING, fileUploadSession
.getParserConfiguration().getCharset().name());// "UTF-8" .getParserConfiguration().getCharset().name());// "UTF-8"
boolean hasHeader = true; boolean hasHeader = true;
if (fileUploadSession.getParserConfiguration().getHeaderPresence() == HeaderPresence.NONE) { if (fileUploadSession.getParserConfiguration().getHeaderPresence() == HeaderPresence.NONE) {
hasHeader = false; hasHeader = false;
} }
parameterInstances.put(HASHEADER, hasHeader);// true parameterInstances.put(Constants.HASHEADER, hasHeader);// true
return parameterInstances; return parameterInstances;
} }
@ -950,7 +950,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
fileUploadSession.getCsvFile()); fileUploadSession.getCsvFile());
logger.debug("File Url On Storage:" + fileUrlOnStorage); logger.debug("File Url On Storage:" + fileUrlOnStorage);
Map<String, Object> parameterInstance = csvImportFileParameter( Map<String, Object> parameterInstance = csvImportFileParameter(
fileUrlOnStorage, fileUploadSession, csvImportSession); fileUrlOnStorage, fileUploadSession, csvImportSession);
@ -964,8 +963,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
OperationDescriptor importCSVFileOperation = getOperationDescriptorWithId( OperationDescriptor importCSVFileOperation = getOperationDescriptorWithId(
OperationsId.CSVImport.toString(), capabilities); OperationsId.CSVImport.toString(), capabilities);
InvocationCreator ic=InvocationCreator.getCreator(importCSVFileOperation); InvocationCreator ic = InvocationCreator
OperationInvocation invocation = ic.setParameters(parameterInstance).create(); .getCreator(importCSVFileOperation);
OperationInvocation invocation = ic.setParameters(parameterInstance)
.create();
logger.debug("OperationInvocation: \n" + invocation.toString()); logger.debug("OperationInvocation: \n" + invocation.toString());
TabularResource tabularResource = service.createTabularResource(); TabularResource tabularResource = service.createTabularResource();
@ -1019,14 +1020,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} else { } else {
logger.debug("Status: " + task.getStatus()); logger.debug("Status: " + task.getStatus());
importMonitor.setStatus(matchTaskState(task.getStatus())); importMonitor
.setStatus(matchTaskState(task.getStatus()));
switch (importMonitor.getStatus()) { switch (importMonitor.getStatus()) {
case FAILED: case FAILED:
if (task.getResult() != null) { if (task.getResult() != null) {
logger.debug("Task exception:" logger.debug("Task exception:"
+ task.getErrorCause()); + task.getErrorCause());
importMonitor importMonitor.setError(task
.setError(new Throwable(task.getErrorCause())); .getErrorCause());
} else { } else {
logger.debug("Task exception: Error In Import"); logger.debug("Task exception: Error In Import");
importMonitor.setError(new Throwable( importMonitor.setError(new Throwable(
@ -1079,6 +1081,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
/**
*
* {@inheritDoc}
*/
@Override @Override
public void getFileFromWorkspace(CSVImportSession csvImportSession) public void getFileFromWorkspace(CSVImportSession csvImportSession)
throws TDGWTServiceException { throws TDGWTServiceException {
@ -1157,6 +1163,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
SessionUtil.setFileUploadSession(session, fileUploadSession); SessionUtil.setFileUploadSession(session, fileUploadSession);
} }
/**
*
* {@inheritDoc}
*/
@Override @Override
public ArrayList<TRMetadata> getTableMetadata(TRId trId) public ArrayList<TRMetadata> getTableMetadata(TRId trId)
throws TDGWTServiceException { throws TDGWTServiceException {
@ -1167,7 +1177,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
service = TabularDataServiceFactory.getService(aslSession service = TabularDataServiceFactory.getService(aslSession
.getUsername()); .getUsername());
Table table = service.getTable(new TableId(Long.valueOf(trId.getTableId()))); Table table = service.getTable(new TableId(Long.valueOf(trId
.getTableId())));
Collection<TableMetadata> cMeta = table.getAllMetadata(); Collection<TableMetadata> cMeta = table.getAllMetadata();
@ -1177,7 +1188,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
if (tMetadata instanceof DescriptionsMetadata) { if (tMetadata instanceof DescriptionsMetadata) {
TRDescriptionsMetadata trDescriptionsMetadata = new TRDescriptionsMetadata(); TRDescriptionsMetadata trDescriptionsMetadata = new TRDescriptionsMetadata();
ArrayList<TRLocalizedText> listTRLocalizedText = new ArrayList<TRLocalizedText>(); ArrayList<TRLocalizedText> listTRLocalizedText = new ArrayList<TRLocalizedText>();
List<LocalizedText> lLocalizedText=((DescriptionsMetadata) tMetadata).getTexts(); List<LocalizedText> lLocalizedText = ((DescriptionsMetadata) tMetadata)
.getTexts();
int i = 0; int i = 0;
for (LocalizedText lt : lLocalizedText) { for (LocalizedText lt : lLocalizedText) {
TRLocalizedText trLocalizedText = new TRLocalizedText(); TRLocalizedText trLocalizedText = new TRLocalizedText();
@ -1187,14 +1199,16 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
listTRLocalizedText.add(trLocalizedText); listTRLocalizedText.add(trLocalizedText);
i++; i++;
} }
trDescriptionsMetadata.setListTRLocalizedText(listTRLocalizedText); trDescriptionsMetadata
.setListTRLocalizedText(listTRLocalizedText);
listTRMetadata.add(trDescriptionsMetadata); listTRMetadata.add(trDescriptionsMetadata);
} else { } else {
if (tMetadata instanceof NamesMetadata) { if (tMetadata instanceof NamesMetadata) {
TRNamesMetadata trNamesMetadata = new TRNamesMetadata(); TRNamesMetadata trNamesMetadata = new TRNamesMetadata();
ArrayList<TRLocalizedText> listTRLocalizedText = new ArrayList<TRLocalizedText>(); ArrayList<TRLocalizedText> listTRLocalizedText = new ArrayList<TRLocalizedText>();
List<LocalizedText> lLocalizedText=((NamesMetadata) tMetadata).getTexts(); List<LocalizedText> lLocalizedText = ((NamesMetadata) tMetadata)
.getTexts();
int i = 0; int i = 0;
for (LocalizedText lt : lLocalizedText) { for (LocalizedText lt : lLocalizedText) {
TRLocalizedText trLocalizedText = new TRLocalizedText(); TRLocalizedText trLocalizedText = new TRLocalizedText();
@ -1204,33 +1218,52 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
listTRLocalizedText.add(trLocalizedText); listTRLocalizedText.add(trLocalizedText);
i++; i++;
} }
trNamesMetadata.setListTRLocalizedText(listTRLocalizedText); trNamesMetadata
.setListTRLocalizedText(listTRLocalizedText);
listTRMetadata.add(trNamesMetadata); listTRMetadata.add(trNamesMetadata);
} else { } else {
if (tMetadata instanceof VersionMetadata) { if (tMetadata instanceof VersionMetadata) {
TRVersionMetadata trVersionMetadata = new TRVersionMetadata(); TRVersionMetadata trVersionMetadata = new TRVersionMetadata();
trVersionMetadata.setVersion(((VersionMetadata)tMetadata).getVersion()); trVersionMetadata
.setVersion(((VersionMetadata) tMetadata)
.getVersion());
listTRMetadata.add(trVersionMetadata); listTRMetadata.add(trVersionMetadata);
} else { } else {
if (tMetadata instanceof ExportMetadata) { if (tMetadata instanceof ExportMetadata) {
TRExportMetadata trExportMetadata = new TRExportMetadata(); TRExportMetadata trExportMetadata = new TRExportMetadata();
trExportMetadata.setDestinationType(((ExportMetadata)tMetadata).getDestinationType()); trExportMetadata
trExportMetadata.setExportDate(sdf.format(((ExportMetadata)tMetadata).getExportDate())); .setDestinationType(((ExportMetadata) tMetadata)
trExportMetadata.setUrl(((ExportMetadata)tMetadata).getUri()); .getDestinationType());
trExportMetadata.setExportDate(sdf
.format(((ExportMetadata) tMetadata)
.getExportDate()));
trExportMetadata
.setUrl(((ExportMetadata) tMetadata)
.getUri());
listTRMetadata.add(trExportMetadata); listTRMetadata.add(trExportMetadata);
} else { } else {
if (tMetadata instanceof ImportMetadata) { if (tMetadata instanceof ImportMetadata) {
TRImportMetadata trImportMetadata = new TRImportMetadata(); TRImportMetadata trImportMetadata = new TRImportMetadata();
trImportMetadata.setSourceType(((ImportMetadata)tMetadata).getSourceType()); trImportMetadata
trImportMetadata.setImportDate(sdf.format(((ImportMetadata)tMetadata).getImportDate())); .setSourceType(((ImportMetadata) tMetadata)
trImportMetadata.setUrl(((ImportMetadata)tMetadata).getUri()); .getSourceType());
trImportMetadata
.setImportDate(sdf
.format(((ImportMetadata) tMetadata)
.getImportDate()));
trImportMetadata
.setUrl(((ImportMetadata) tMetadata)
.getUri());
listTRMetadata.add(trImportMetadata); listTRMetadata.add(trImportMetadata);
} else { } else {
if (tMetadata instanceof GenericMapMetadata) { if (tMetadata instanceof GenericMapMetadata) {
TRGenericMapMetadata trGenericMapMetadata = new TRGenericMapMetadata(); TRGenericMapMetadata trGenericMapMetadata = new TRGenericMapMetadata();
trGenericMapMetadata.setMetadataMap(((GenericMapMetadata)tMetadata).getMetadataMap()); trGenericMapMetadata
listTRMetadata.add(trGenericMapMetadata); .setMetadataMap(((GenericMapMetadata) tMetadata)
.getMetadataMap());
listTRMetadata
.add(trGenericMapMetadata);
} else { } else {
} }
@ -1242,15 +1275,194 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
} }
return listTRMetadata; return listTRMetadata;
} catch (Exception e) { } catch (Exception e) {
logger.error("Error in getTableMetadata(): " + e.getLocalizedMessage(), logger.error(
"Error in getTableMetadata(): " + e.getLocalizedMessage(),
e); e);
throw new TDGWTServiceException("Error in getTableMetadata(): " throw new TDGWTServiceException("Error in getTableMetadata(): "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
} }
} }
/**
*
* @param exportSession
* @return
*/
protected Map<String, Object> csvExportFileParameter(
CSVExportSession exportSession) {
Map<String, Object> parameterInstances = new HashMap<String, Object>();
parameterInstances.put(Constants.ENCODING, exportSession.getEncoding());
parameterInstances.put(Constants.SEPARATOR,
exportSession.getSeparator());
parameterInstances.put(Constants.COLUMNS, exportSession.getColumns());
// TODO
/*
* List<String> 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<String, Object> parameterInstance = csvExportFileParameter(exportSession);
logger.debug("Tabular Data Service");
service = TabularDataServiceFactory
.getService(aslSession.getUsername());
List<OperationDescriptor> 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());
}
}
} }

View File

@ -16,5 +16,10 @@ public class Constants {
public final static String DEFAULT_USER = "giancarlo.panichi"; public final static String DEFAULT_USER = "giancarlo.panichi";
public final static String DEFAULT_SCOPE = "/gcube/devsec"; 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";
} }

View File

@ -4,7 +4,10 @@
package org.gcube.portlets.user.td.gwtservice.shared.csv; package org.gcube.portlets.user.td.gwtservice.shared.csv;
import java.io.Serializable; 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; import org.gcube.portlets.user.td.gwtservice.shared.destination.Destination;
@ -25,6 +28,29 @@ public class CSVExportSession implements Serializable {
protected String itemId; protected String itemId;
protected String fileName; protected String fileName;
protected ArrayList<String> columns;
protected String encoding;
protected String separator;
public ArrayList<String> getColumns() {
return columns;
}
public void setColumns(ArrayList<String> 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() { public String getId() {
return id; return id;
} }
@ -52,11 +78,15 @@ public class CSVExportSession implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "CSVExportSession [id=" + id + ", destination=" + destination return "CSVExportSession [id=" + id + ", destination=" + destination
+ ", itemId=" + itemId + ", fileName=" + fileName + "]"; + ", itemId=" + itemId + ", fileName=" + fileName
+ ", columns=" + columns + ", encoding=" + encoding
+ ", separator=" + separator + "]";
} }
} }

View File

@ -28,7 +28,10 @@ public class TestServiceOperations {
System.out System.out
.println("------------Tabular Resource Operation--------------"); .println("------------Tabular Resource Operation--------------");
for (OperationDescriptor operation : trOperations) { 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("-----------------------------------");
} }
} }