|
|
|
@ -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<TableMetadata> cMeta=table.getAllMetadata();
|
|
|
|
|
Collection<TableMetadata> cMeta = table.getAllMetadata();
|
|
|
|
|
|
|
|
|
|
tData.setMetaData(cMeta.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<ColumnData> lColumnData = new ArrayList<ColumnData>();
|
|
|
|
|
for (Column column : table.getColumns()) {
|
|
|
|
|
ColumnData colData = new ColumnData();
|
|
|
|
@ -569,8 +571,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|
|
|
|
|
|
|
|
|
Map<String, Object> 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());
|
|
|
|
@ -592,19 +596,19 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|
|
|
|
* @throws TDGWTServiceException
|
|
|
|
|
*/
|
|
|
|
|
protected OperationDescriptor getOperationDescriptorWithId(String op,
|
|
|
|
|
List<OperationDescriptor> capabilities) throws TDGWTServiceException {
|
|
|
|
|
List<OperationDescriptor> 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;
|
|
|
|
@ -623,7 +627,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
|
|
|
@ -656,13 +659,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|
|
|
|
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<String, Object> csvImportFileParameter(
|
|
|
|
|
String fileUrlOnStorage, FileUploadSession fileUploadSession,
|
|
|
|
|
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>();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -948,8 +948,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|
|
|
|
|
|
|
|
|
String fileUrlOnStorage = filesStorage.storageCSVTempFile(user,
|
|
|
|
|
fileUploadSession.getCsvFile());
|
|
|
|
|
logger.debug("File Url On Storage:"+fileUrlOnStorage);
|
|
|
|
|
|
|
|
|
|
logger.debug("File Url On Storage:" + fileUrlOnStorage);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> parameterInstance = csvImportFileParameter(
|
|
|
|
|
fileUrlOnStorage, fileUploadSession, csvImportSession);
|
|
|
|
@ -964,8 +963,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|
|
|
|
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();
|
|
|
|
@ -1019,14 +1020,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|
|
|
|
} 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<TRMetadata> getTableMetadata(TRId trId)
|
|
|
|
|
throws TDGWTServiceException {
|
|
|
|
@ -1167,71 +1177,94 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|
|
|
|
service = TabularDataServiceFactory.getService(aslSession
|
|
|
|
|
.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();
|
|
|
|
|
|
|
|
|
|
ArrayList<TRMetadata> listTRMetadata=new ArrayList<TRMetadata>();
|
|
|
|
|
ArrayList<TRMetadata> listTRMetadata = new ArrayList<TRMetadata>();
|
|
|
|
|
|
|
|
|
|
for(TableMetadata tMetadata:cMeta){
|
|
|
|
|
if(tMetadata instanceof DescriptionsMetadata){
|
|
|
|
|
TRDescriptionsMetadata trDescriptionsMetadata=new TRDescriptionsMetadata();
|
|
|
|
|
ArrayList<TRLocalizedText> listTRLocalizedText=new ArrayList<TRLocalizedText>();
|
|
|
|
|
List<LocalizedText> lLocalizedText=((DescriptionsMetadata) tMetadata).getTexts();
|
|
|
|
|
int i=0;
|
|
|
|
|
for(LocalizedText lt:lLocalizedText){
|
|
|
|
|
TRLocalizedText trLocalizedText=new TRLocalizedText();
|
|
|
|
|
for (TableMetadata tMetadata : cMeta) {
|
|
|
|
|
if (tMetadata instanceof DescriptionsMetadata) {
|
|
|
|
|
TRDescriptionsMetadata trDescriptionsMetadata = new TRDescriptionsMetadata();
|
|
|
|
|
ArrayList<TRLocalizedText> listTRLocalizedText = new ArrayList<TRLocalizedText>();
|
|
|
|
|
List<LocalizedText> 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<TRLocalizedText> listTRLocalizedText=new ArrayList<TRLocalizedText>();
|
|
|
|
|
List<LocalizedText> lLocalizedText=((NamesMetadata) tMetadata).getTexts();
|
|
|
|
|
int i=0;
|
|
|
|
|
for(LocalizedText lt:lLocalizedText){
|
|
|
|
|
TRLocalizedText trLocalizedText=new TRLocalizedText();
|
|
|
|
|
if (tMetadata instanceof NamesMetadata) {
|
|
|
|
|
TRNamesMetadata trNamesMetadata = new TRNamesMetadata();
|
|
|
|
|
ArrayList<TRLocalizedText> listTRLocalizedText = new ArrayList<TRLocalizedText>();
|
|
|
|
|
List<LocalizedText> 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 {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1242,15 +1275,194 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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<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());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|