Updated export CSV

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@86574 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2013-12-04 19:01:00 +00:00
parent a8295e93a6
commit 613d912845
3 changed files with 96 additions and 85 deletions

View File

@ -63,6 +63,9 @@ public class SessionUtil {
protected static final String CSV_EXPORT_SESSION = "CSV_EXPORT_SESSION"; protected static final String CSV_EXPORT_SESSION = "CSV_EXPORT_SESSION";
protected static final String CSV_EXPORT_TASK = "CSV_EXPORT_TASK"; protected static final String CSV_EXPORT_TASK = "CSV_EXPORT_TASK";
protected static final String CSV_EXPORT_END = "CSV_EXPORT_END";
protected static final String CSV_EXPORT_MONITOR = "CSV_EXPORT_MONITOR";
protected static Logger logger = LoggerFactory.getLogger(SessionUtil.class); protected static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
@ -443,6 +446,22 @@ public class SessionUtil {
httpSession.setAttribute(CSV_EXPORT_TASK, task); httpSession.setAttribute(CSV_EXPORT_TASK, task);
} }
public static void setCSVExportEnd(HttpSession httpSession, Boolean end) {
Boolean fin = (Boolean) httpSession.getAttribute(CSV_EXPORT_END);
if (fin != null)
httpSession.removeAttribute(CSV_EXPORT_END);
httpSession.setAttribute(CSV_EXPORT_END, end);
}
public static Boolean getCSVExportEnd(HttpSession httpSession) {
Boolean end = (Boolean) httpSession.getAttribute(CSV_EXPORT_END);
if (end == null) {
logger.error("CSV_EXPORT_END was not acquired");
}
return end;
}
public static Task getSDMXExportTask(HttpSession httpSession) { public static Task getSDMXExportTask(HttpSession httpSession) {
Task monitor = (Task) httpSession.getAttribute(SDMX_EXPORT_TASK); Task monitor = (Task) httpSession.getAttribute(SDMX_EXPORT_TASK);
if (monitor == null) { if (monitor == null) {

View File

@ -195,12 +195,13 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
public TabResource getTabResourceInformation(TRId trId) throws TDGWTServiceException { public TabResource getTabResourceInformation(TRId trId)
throws TDGWTServiceException {
try { try {
session = this.getThreadLocalRequest().getSession(); session = this.getThreadLocalRequest().getSession();
aslSession = SessionUtil.getAslSession(session); aslSession = SessionUtil.getAslSession(session);
TabResource currentTR=new TabResource(); TabResource currentTR = new TabResource();
currentTR.setTrId(trId); currentTR.setTrId(trId);
ArrayList<TRMetadata> trMetadatas = getTRMetadata(currentTR ArrayList<TRMetadata> trMetadatas = getTRMetadata(currentTR
.getTrId()); .getTrId());
@ -218,7 +219,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
} }
protected void updateTabResourceInformation(TabResource tabResource, protected void updateTabResourceInformation(TabResource tabResource,
ArrayList<TRMetadata> trMetadatas) { ArrayList<TRMetadata> trMetadatas) {
for (TRMetadata trMetadata : trMetadatas) { for (TRMetadata trMetadata : trMetadatas) {
@ -879,8 +879,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -1531,7 +1529,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
protected Map<String, Object> csvExportFileParameter( protected Map<String, Object> csvExportFileParameter(
CSVExportSession exportSession) { CSVExportSession exportSession) {
Map<String, Object> parameterInstances = new HashMap<String, Object>(); Map<String, Object> parameterInstances = new HashMap<String, Object>();
parameterInstances.put(Constants.PARAMETER_ENCODING, exportSession.getEncoding()); parameterInstances.put(Constants.PARAMETER_ENCODING,
exportSession.getEncoding());
parameterInstances.put(Constants.PARAMETER_SEPARATOR, parameterInstances.put(Constants.PARAMETER_SEPARATOR,
exportSession.getSeparator()); exportSession.getSeparator());
parameterInstances.put(Constants.PARAMETER_COLUMNS, parameterInstances.put(Constants.PARAMETER_COLUMNS,
@ -1539,8 +1538,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
return parameterInstances; return parameterInstances;
} }
/** /**
* *
* @param exportSession * @param exportSession
@ -1549,17 +1546,14 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
protected Map<String, Object> sdmxExportParameter( protected Map<String, Object> sdmxExportParameter(
SDMXExportSession exportSession) { SDMXExportSession exportSession) {
Map<String, Object> parameterInstances = new HashMap<String, Object>(); Map<String, Object> parameterInstances = new HashMap<String, Object>();
parameterInstances.put(Constants.PARAMETER_REGISTRYBASEURL, "http://pc-fortunati.isti.cnr.it:8080/FusionRegistry/ws/rest/"); parameterInstances.put(Constants.PARAMETER_REGISTRYBASEURL,
"http://pc-fortunati.isti.cnr.it:8080/FusionRegistry/ws/rest/");
parameterInstances.put(Constants.PARAMETER_AGENCY, "SDMX"); parameterInstances.put(Constants.PARAMETER_AGENCY, "SDMX");
parameterInstances.put(Constants.PARAMETER_ID, "NEW_CL_DIVISION"); parameterInstances.put(Constants.PARAMETER_ID, "NEW_CL_DIVISION");
parameterInstances.put(Constants.PARAMETER_VERSION, "2.0"); parameterInstances.put(Constants.PARAMETER_VERSION, "2.0");
return parameterInstances; return parameterInstances;
} }
/** /**
* *
* @param exportSession * @param exportSession
@ -1631,12 +1625,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
SessionUtil.setSDMXExportTask(session, trTask); SessionUtil.setSDMXExportTask(session, trTask);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public SDMXExportMonitor getSDMXExportMonitor() throws TDGWTServiceException { public SDMXExportMonitor getSDMXExportMonitor()
throws TDGWTServiceException {
try { try {
session = this.getThreadLocalRequest().getSession(); session = this.getThreadLocalRequest().getSession();
aslSession = SessionUtil.getAslSession(session); aslSession = SessionUtil.getAslSession(session);
@ -1715,7 +1709,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
/** /**
* *
* {@inheritDoc} * {@inheritDoc}
@ -1783,11 +1776,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
} }
logger.debug("Start Task on service: TaskId " + trTask.getId()); logger.debug("Start Task on service: TaskId " + trTask.getId());
SessionUtil.setCSVExportEnd(session, false);
SessionUtil.setCSVExportTask(session, trTask); SessionUtil.setCSVExportTask(session, trTask);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -1828,6 +1821,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
exportMonitor.setProgress(task.getProgress()); exportMonitor.setProgress(task.getProgress());
break; break;
case SUCCEDED: case SUCCEDED:
SessionUtil.setCSVExportEnd(session, true);
logger.debug("Task Result:" + task.getResult()); logger.debug("Task Result:" + task.getResult());
exportMonitor.setProgress(task.getProgress()); exportMonitor.setProgress(task.getProgress());
Table table = task.getResult().getPrimaryTable(); Table table = task.getResult().getPrimaryTable();
@ -1844,7 +1838,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
trExportMetadata.setExportDate(sdf trExportMetadata.setExportDate(sdf
.format(exportMetadata.getExportDate())); .format(exportMetadata.getExportDate()));
exportMonitor.setTrExportMetadata(trExportMetadata); exportMonitor.setTrExportMetadata(trExportMetadata);
saveInDestination(aslSession.getUsername(), saveInDestination(aslSession.getUsername(),
exportMetadata, exportSession); exportMetadata, exportSession);
@ -1881,17 +1874,21 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
ExportMetadata exportMetadata, CSVExportSession exportSession) ExportMetadata exportMetadata, CSVExportSession exportSession)
throws TDGWTServiceException { throws TDGWTServiceException {
if (exportSession.getDestination().getId().compareTo("Workspace") == 0) { if (exportSession.getDestination().getId().compareTo("Workspace") == 0) {
FilesStorage storage = new FilesStorage(); if (SessionUtil.getCSVExportEnd(session) == false) {
logger.debug("Create Item On Workspace: [ uri: "+exportMetadata.getUri()+ SessionUtil.setCSVExportEnd(session, true);
" ,user: "+user+ FilesStorage storage = new FilesStorage();
" ,fileName: "+exportSession.getFileName()+ logger.debug("Create Item On Workspace: [ uri: "
" ,fileDescription: "+exportSession.getFileDescription()+ + exportMetadata.getUri() + " ,user: " + user
" ,mimetype: text/csv"+ + " ,fileName: " + exportSession.getFileName()
" ,folder: "+exportSession.getItemId()+"]"); + " ,fileDescription: "
storage.createItemOnWorkspace(exportMetadata.getUri(), user, + exportSession.getFileDescription()
exportSession.getFileName(), + " ,mimetype: text/csv" + " ,folder: "
exportSession.getFileDescription(), "text/csv", + exportSession.getItemId() + "]");
exportSession.getItemId()); storage.createItemOnWorkspace(exportMetadata.getUri(), user,
exportSession.getFileName(),
exportSession.getFileDescription(), "text/csv",
exportSession.getItemId());
}
} else { } else {
} }

View File

@ -38,7 +38,7 @@ public class FilesStorage {
IClient client = new StorageClient(user, AccessType.PUBLIC, IClient client = new StorageClient(user, AccessType.PUBLIC,
MemoryType.VOLATILE).getClient(); MemoryType.VOLATILE).getClient();
String remotePath = "/CSVimport/" + file.getName(); String remotePath = "/CSVimport/" + file.getName();
logger.debug("remotePath: "+remotePath); logger.debug("remotePath: " + remotePath);
client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath); client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
String url = client.getUrl().RFile(remotePath); String url = client.getUrl().RFile(remotePath);
return url; return url;
@ -116,17 +116,18 @@ public class FilesStorage {
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi); org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi);
Handler.activateProtocol(); Handler.activateProtocol();
URL smsHome = null; URL smsHome = null;
smsHome = new URL(null, gcubeItem.getPublicLink(), new URLStreamHandler() { smsHome = new URL(null, gcubeItem.getPublicLink(),
new URLStreamHandler() {
@Override @Override
protected URLConnection openConnection(URL u) throws IOException { protected URLConnection openConnection(URL u)
return new SMPURLConnection(u); throws IOException {
} return new SMPURLConnection(u);
}
}); });
// new URL(gcubeItem.getPublicLink());
// new URL(gcubeItem.getPublicLink());
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:" logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef() + smsHome.getPath() + " ref:" + smsHome.getRef()
+ " userinfo:" + smsHome.getUserInfo() + " ]"); + " userinfo:" + smsHome.getUserInfo() + " ]");
@ -145,7 +146,6 @@ public class FilesStorage {
} }
/** /**
* *
* @param user * @param user
@ -164,10 +164,11 @@ public class FilesStorage {
URL smsHome = null; URL smsHome = null;
smsHome = new URL(null, uri, new URLStreamHandler() { smsHome = new URL(null, uri, new URLStreamHandler() {
@Override @Override
protected URLConnection openConnection(URL u) throws IOException { protected URLConnection openConnection(URL u)
return new SMPURLConnection(u); throws IOException {
} return new SMPURLConnection(u);
}
}); });
@ -189,7 +190,6 @@ public class FilesStorage {
} }
/** /**
* *
* @param user * @param user
@ -199,10 +199,9 @@ public class FilesStorage {
* @return InputStream back to read the file * @return InputStream back to read the file
* @throws TDGWTServiceException * @throws TDGWTServiceException
*/ */
public void createItemOnWorkspace(String uri,String user, public void createItemOnWorkspace(String uri, String user,
String item_name,String item_description, String item_name, String item_description, String item_mimetype,
String item_mimetype, String item_folder) String item_folder) throws TDGWTServiceException {
throws TDGWTServiceException {
InputStream is = null; InputStream is = null;
try { try {
@ -210,10 +209,11 @@ public class FilesStorage {
URL smsHome = null; URL smsHome = null;
smsHome = new URL(null, uri, new URLStreamHandler() { smsHome = new URL(null, uri, new URLStreamHandler() {
@Override @Override
protected URLConnection openConnection(URL u) throws IOException { protected URLConnection openConnection(URL u)
return new SMPURLConnection(u); throws IOException {
} return new SMPURLConnection(u);
}
}); });
@ -224,19 +224,17 @@ public class FilesStorage {
uc = (URLConnection) smsHome.openConnection(); uc = (URLConnection) smsHome.openConnection();
is = uc.getInputStream(); is = uc.getInputStream();
logger.debug("ws.createExternalFile [name: "+item_name logger.debug("ws.createExternalFile [name: " + item_name
+ " ,description: "+ item_description + " ,description: " + item_description + " ,mimetype:"
+ " ,mimetype:" + item_mimetype + item_mimetype + " ,is:" + is + " ,folder:" + item_folder
+ " ,is:" +is
+ " ,folder:" +item_folder
+ " ]"); + " ]");
Workspace ws = HomeLibrary Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager()
.getHomeManagerFactory() .getHome(user).getWorkspace();
.getHomeManager() ws.createExternalFile(item_name, item_description, item_mimetype,
.getHome(user).getWorkspace() ; is, item_folder);
ws.createExternalFile(item_name, item_description, item_mimetype, is, item_folder);
is.close(); is.close();
} catch (Exception e) { } catch (Exception e) {
logger.error("Error creating item on workspace", e); logger.error("Error creating item on workspace", e);
@ -245,9 +243,6 @@ public class FilesStorage {
+ e.getLocalizedMessage(), e); + e.getLocalizedMessage(), e);
} }
} }
} }