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,7 +63,10 @@ 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);
protected static ASLSession getAslSession(HttpSession httpSession) {
@ -442,6 +445,22 @@ public class SessionUtil {
httpSession.removeAttribute(CSV_EXPORT_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) {
Task monitor = (Task) httpSession.getAttribute(SDMX_EXPORT_TASK);
@ -450,7 +469,7 @@ public class SessionUtil {
}
return monitor;
}
public static void setSDMXExportTask(HttpSession httpSession, Task task) {
Task monitor = (Task) httpSession.getAttribute(SDMX_EXPORT_TASK);
if (monitor != null)

View File

@ -195,12 +195,13 @@ 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);
TabResource currentTR=new TabResource();
TabResource currentTR = new TabResource();
currentTR.setTrId(trId);
ArrayList<TRMetadata> trMetadatas = getTRMetadata(currentTR
.getTrId());
@ -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);
@ -1714,8 +1708,7 @@ 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) {
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()+"]");
storage.createItemOnWorkspace(exportMetadata.getUri(), user,
exportSession.getFileName(),
exportSession.getFileDescription(), "text/csv",
exportSession.getItemId());
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() + "]");
storage.createItemOnWorkspace(exportMetadata.getUri(), user,
exportSession.getFileName(),
exportSession.getFileDescription(), "text/csv",
exportSession.getItemId());
}
} else {
}

View File

@ -38,7 +38,7 @@ public class FilesStorage {
IClient client = new StorageClient(user, AccessType.PUBLIC,
MemoryType.VOLATILE).getClient();
String remotePath = "/CSVimport/" + file.getName();
logger.debug("remotePath: "+remotePath);
logger.debug("remotePath: " + remotePath);
client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
String url = client.getUrl().RFile(remotePath);
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);
Handler.activateProtocol();
URL smsHome = null;
smsHome = new URL(null, gcubeItem.getPublicLink(), new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
return new SMPURLConnection(u);
}
});
// new URL(gcubeItem.getPublicLink());
smsHome = new URL(null, gcubeItem.getPublicLink(),
new URLStreamHandler() {
@Override
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()
+ " userinfo:" + smsHome.getUserInfo() + " ]");
@ -144,8 +145,7 @@ public class FilesStorage {
return is;
}
/**
*
* @param user
@ -163,14 +163,15 @@ public class FilesStorage {
Handler.activateProtocol();
URL smsHome = null;
smsHome = new URL(null, uri, new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
return new SMPURLConnection(u);
}
});
@Override
protected URLConnection openConnection(URL u)
throws IOException {
return new SMPURLConnection(u);
}
});
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef()
+ " userinfo:" + smsHome.getUserInfo() + " ]");
@ -188,8 +189,7 @@ public class FilesStorage {
return is;
}
/**
*
* @param user
@ -199,45 +199,43 @@ public class FilesStorage {
* @return InputStream back to read the file
* @throws TDGWTServiceException
*/
public void createItemOnWorkspace(String uri,String user,
String item_name,String item_description,
String item_mimetype, String item_folder)
throws TDGWTServiceException {
public void createItemOnWorkspace(String uri, String user,
String item_name, String item_description, String item_mimetype,
String item_folder) throws TDGWTServiceException {
InputStream is = null;
try {
Handler.activateProtocol();
URL smsHome = null;
smsHome = new URL(null, uri, new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
return new SMPURLConnection(u);
}
});
@Override
protected URLConnection openConnection(URL u)
throws IOException {
return new SMPURLConnection(u);
}
});
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
+ smsHome.getPath() + " ref:" + smsHome.getRef()
+ " userinfo:" + smsHome.getUserInfo() + " ]");
URLConnection uc = null;
uc = (URLConnection) smsHome.openConnection();
is = uc.getInputStream();
logger.debug("ws.createExternalFile [name: "+item_name
+ " ,description: "+ item_description
+ " ,mimetype:" + item_mimetype
+ " ,is:" +is
+ " ,folder:" +item_folder
logger.debug("ws.createExternalFile [name: " + item_name
+ " ,description: " + item_description + " ,mimetype:"
+ item_mimetype + " ,is:" + is + " ,folder:" + item_folder
+ " ]");
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(user).getWorkspace() ;
ws.createExternalFile(item_name, item_description, item_mimetype, is, item_folder);
is.close();
Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager()
.getHome(user).getWorkspace();
ws.createExternalFile(item_name, item_description, item_mimetype,
is, item_folder);
is.close();
} catch (Exception e) {
logger.error("Error creating item on workspace", e);
throw new TDGWTServiceException(
@ -245,9 +243,6 @@ public class FilesStorage {
+ e.getLocalizedMessage(), e);
}
}
}