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:
parent
a8295e93a6
commit
613d912845
|
@ -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) {
|
||||||
|
|
|
@ -195,7 +195,8 @@ 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);
|
||||||
|
@ -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) {
|
||||||
|
if (SessionUtil.getCSVExportEnd(session) == false) {
|
||||||
|
SessionUtil.setCSVExportEnd(session, true);
|
||||||
FilesStorage storage = new FilesStorage();
|
FilesStorage storage = new FilesStorage();
|
||||||
logger.debug("Create Item On Workspace: [ uri: "+exportMetadata.getUri()+
|
logger.debug("Create Item On Workspace: [ uri: "
|
||||||
" ,user: "+user+
|
+ exportMetadata.getUri() + " ,user: " + user
|
||||||
" ,fileName: "+exportSession.getFileName()+
|
+ " ,fileName: " + exportSession.getFileName()
|
||||||
" ,fileDescription: "+exportSession.getFileDescription()+
|
+ " ,fileDescription: "
|
||||||
" ,mimetype: text/csv"+
|
+ exportSession.getFileDescription()
|
||||||
" ,folder: "+exportSession.getItemId()+"]");
|
+ " ,mimetype: text/csv" + " ,folder: "
|
||||||
|
+ exportSession.getItemId() + "]");
|
||||||
storage.createItemOnWorkspace(exportMetadata.getUri(), user,
|
storage.createItemOnWorkspace(exportMetadata.getUri(), user,
|
||||||
exportSession.getFileName(),
|
exportSession.getFileName(),
|
||||||
exportSession.getFileDescription(), "text/csv",
|
exportSession.getFileDescription(), "text/csv",
|
||||||
exportSession.getItemId());
|
exportSession.getItemId());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
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)
|
||||||
|
throws IOException {
|
||||||
return new SMPURLConnection(u);
|
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()
|
||||||
|
@ -145,7 +146,6 @@ public class FilesStorage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
|
@ -165,7 +165,8 @@ public class FilesStorage {
|
||||||
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)
|
||||||
|
throws IOException {
|
||||||
return new SMPURLConnection(u);
|
return new SMPURLConnection(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +190,6 @@ public class FilesStorage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
|
@ -200,9 +200,8 @@ public class FilesStorage {
|
||||||
* @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 {
|
||||||
|
|
||||||
|
@ -211,7 +210,8 @@ public class FilesStorage {
|
||||||
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)
|
||||||
|
throws IOException {
|
||||||
return new SMPURLConnection(u);
|
return new SMPURLConnection(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,17 +225,15 @@ public class FilesStorage {
|
||||||
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()
|
|
||||||
.getHomeManager()
|
|
||||||
.getHome(user).getWorkspace();
|
.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();
|
is.close();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -245,9 +243,6 @@ public class FilesStorage {
|
||||||
+ e.getLocalizedMessage(), e);
|
+ e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue