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_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);
@ -443,6 +446,22 @@ public class SessionUtil {
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) {
Task monitor = (Task) httpSession.getAttribute(SDMX_EXPORT_TASK);
if (monitor == null) {

View File

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

View File

@ -116,16 +116,17 @@ public class FilesStorage {
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi);
Handler.activateProtocol();
URL smsHome = null;
smsHome = new URL(null, gcubeItem.getPublicLink(), new URLStreamHandler() {
smsHome = new URL(null, gcubeItem.getPublicLink(),
new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
protected URLConnection openConnection(URL u)
throws IOException {
return new SMPURLConnection(u);
}
});
// new URL(gcubeItem.getPublicLink());
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef()
@ -145,7 +146,6 @@ public class FilesStorage {
}
/**
*
* @param user
@ -165,7 +165,8 @@ public class FilesStorage {
smsHome = new URL(null, uri, new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
protected URLConnection openConnection(URL u)
throws IOException {
return new SMPURLConnection(u);
}
@ -189,7 +190,6 @@ public class FilesStorage {
}
/**
*
* @param user
@ -200,9 +200,8 @@ public class FilesStorage {
* @throws TDGWTServiceException
*/
public void createItemOnWorkspace(String uri, String user,
String item_name,String item_description,
String item_mimetype, String item_folder)
throws TDGWTServiceException {
String item_name, String item_description, String item_mimetype,
String item_folder) throws TDGWTServiceException {
InputStream is = null;
try {
@ -211,7 +210,8 @@ public class FilesStorage {
smsHome = new URL(null, uri, new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
protected URLConnection openConnection(URL u)
throws IOException {
return new SMPURLConnection(u);
}
@ -225,17 +225,15 @@ public class FilesStorage {
is = uc.getInputStream();
logger.debug("ws.createExternalFile [name: " + item_name
+ " ,description: "+ item_description
+ " ,mimetype:" + item_mimetype
+ " ,is:" +is
+ " ,folder:" +item_folder
+ " ,description: " + item_description + " ,mimetype:"
+ item_mimetype + " ,is:" + is + " ,folder:" + item_folder
+ " ]");
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager()
.getHome(user).getWorkspace();
ws.createExternalFile(item_name, item_description, item_mimetype, is, item_folder);
ws.createExternalFile(item_name, item_description, item_mimetype,
is, item_folder);
is.close();
} catch (Exception e) {
@ -245,9 +243,6 @@ public class FilesStorage {
+ e.getLocalizedMessage(), e);
}
}
}