refs 2521: Explore the possibility to port the StatMan interface onto Dataminer

https://support.d4science.org/issues/2521

Added Folder Download

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/data-miner-manager@128772 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-05-23 10:14:00 +00:00
parent 109423f1c0
commit 6193c8c1c8
7 changed files with 317 additions and 189 deletions

View File

@ -16,6 +16,7 @@ import org.gcube.portlets.user.dataminermanager.client.events.UIStateEvent;
import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletServiceAsync; import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletServiceAsync;
import org.gcube.portlets.user.dataminermanager.client.type.DataMinerWorkAreaElementType; import org.gcube.portlets.user.dataminermanager.client.type.DataMinerWorkAreaElementType;
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3; import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
import org.gcube.portlets.user.dataminermanager.shared.Constants;
import org.gcube.portlets.user.dataminermanager.shared.exception.ExpiredSessionServiceException; import org.gcube.portlets.user.dataminermanager.shared.exception.ExpiredSessionServiceException;
import org.gcube.portlets.user.dataminermanager.shared.workspace.ItemDescription; import org.gcube.portlets.user.dataminermanager.shared.workspace.ItemDescription;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
@ -27,6 +28,7 @@ import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item; import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale;
@ -144,7 +146,8 @@ public class ComputationsExecutedPanel extends FramedPanel {
private void manageDataMinerWorkAreaEvents(DataMinerWorkAreaEvent event) { private void manageDataMinerWorkAreaEvents(DataMinerWorkAreaEvent event) {
Log.debug("ComputationsExecutedPanel recieved DataMinerWorkAreaEvent: " + event); Log.debug("ComputationsExecutedPanel recieved DataMinerWorkAreaEvent: "
+ event);
if (event == null) { if (event == null) {
Log.error("DataMinerWorkAreaEvent null"); Log.error("DataMinerWorkAreaEvent null");
return; return;
@ -227,7 +230,8 @@ public class ComputationsExecutedPanel extends FramedPanel {
wsResourcesExplorerPanel = new WorkspaceResourcesExplorerPanel( wsResourcesExplorerPanel = new WorkspaceResourcesExplorerPanel(
event.getDataMinerWorkArea().getComputations().getFolder() event.getDataMinerWorkArea().getComputations().getFolder()
.getId(), false, showProperties, filterCriteria, true); .getId(), false, showProperties, filterCriteria,
true);
WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() { WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() {
@Override @Override
public void onSelectedItem(Item item) { public void onSelectedItem(Item item) {
@ -462,7 +466,24 @@ public class ComputationsExecutedPanel extends FramedPanel {
} }
private void downloadFile() { private void downloadFile() {
if (selectedItem != null && !selectedItem.isFolder()) { if (selectedItem != null) {
if (selectedItem.isFolder()) {
StringBuilder actionUrl = new StringBuilder();
actionUrl.append(GWT.getModuleBaseURL());
actionUrl
.append(Constants.DOWNLOAD_FOLDER_SERVLET
+ "?"
+ Constants.DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER
+ "="
+ selectedItem.getId()
+ "&"
+ Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER
+ "=" + selectedItem.getName());
Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), selectedItem.getName(), "");
} else {
final ItemDescription itemDescription = new ItemDescription( final ItemDescription itemDescription = new ItemDescription(
selectedItem.getId(), selectedItem.getName(), selectedItem.getId(), selectedItem.getName(),
@ -494,7 +515,7 @@ public class ComputationsExecutedPanel extends FramedPanel {
} }
}); });
}
} else { } else {
UtilsGXT3.info("Attention", "Select a file!"); UtilsGXT3.info("Attention", "Select a file!");
} }

View File

@ -14,6 +14,7 @@ import org.gcube.portlets.user.dataminermanager.client.events.UIStateEvent;
import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletServiceAsync; import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletServiceAsync;
import org.gcube.portlets.user.dataminermanager.client.type.DataMinerWorkAreaElementType; import org.gcube.portlets.user.dataminermanager.client.type.DataMinerWorkAreaElementType;
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3; import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
import org.gcube.portlets.user.dataminermanager.shared.Constants;
import org.gcube.portlets.user.dataminermanager.shared.exception.ExpiredSessionServiceException; import org.gcube.portlets.user.dataminermanager.shared.exception.ExpiredSessionServiceException;
import org.gcube.portlets.user.dataminermanager.shared.workspace.ItemDescription; import org.gcube.portlets.user.dataminermanager.shared.workspace.ItemDescription;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
@ -25,6 +26,7 @@ import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item; import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale;
@ -221,7 +223,8 @@ public class InputDataSetsPanel extends FramedPanel {
wsResourcesExplorerPanel = new WorkspaceResourcesExplorerPanel( wsResourcesExplorerPanel = new WorkspaceResourcesExplorerPanel(
event.getDataMinerWorkArea().getInputDataSets().getFolder() event.getDataMinerWorkArea().getInputDataSets().getFolder()
.getId(), false, showProperties, filterCriteria, true); .getId(), false, showProperties, filterCriteria,
true);
WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() { WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() {
@Override @Override
public void onSelectedItem(Item item) { public void onSelectedItem(Item item) {
@ -393,7 +396,23 @@ public class InputDataSetsPanel extends FramedPanel {
} }
private void downloadFile() { private void downloadFile() {
if (selectedItem != null && !selectedItem.isFolder()) { if (selectedItem != null) {
if (selectedItem.isFolder()) {
StringBuilder actionUrl = new StringBuilder();
actionUrl.append(GWT.getModuleBaseURL());
actionUrl
.append(Constants.DOWNLOAD_FOLDER_SERVLET
+ "?"
+ Constants.DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER
+ "="
+ selectedItem.getId()
+ "&"
+ Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER
+ "=" + selectedItem.getName());
Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), selectedItem.getName(), "");
} else {
final ItemDescription itemDescription = new ItemDescription( final ItemDescription itemDescription = new ItemDescription(
selectedItem.getId(), selectedItem.getName(), selectedItem.getId(), selectedItem.getName(),
@ -425,7 +444,7 @@ public class InputDataSetsPanel extends FramedPanel {
} }
}); });
}
} else { } else {
UtilsGXT3.info("Attention", "Select a file!"); UtilsGXT3.info("Attention", "Select a file!");
} }

View File

@ -14,6 +14,7 @@ import org.gcube.portlets.user.dataminermanager.client.events.UIStateEvent;
import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletServiceAsync; import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletServiceAsync;
import org.gcube.portlets.user.dataminermanager.client.type.DataMinerWorkAreaElementType; import org.gcube.portlets.user.dataminermanager.client.type.DataMinerWorkAreaElementType;
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3; import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
import org.gcube.portlets.user.dataminermanager.shared.Constants;
import org.gcube.portlets.user.dataminermanager.shared.exception.ExpiredSessionServiceException; import org.gcube.portlets.user.dataminermanager.shared.exception.ExpiredSessionServiceException;
import org.gcube.portlets.user.dataminermanager.shared.workspace.ItemDescription; import org.gcube.portlets.user.dataminermanager.shared.workspace.ItemDescription;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
@ -25,6 +26,7 @@ import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item; import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale; import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale;
@ -394,8 +396,23 @@ public class OutputDataSetsPanel extends FramedPanel {
} }
private void downloadFile() { private void downloadFile() {
if (selectedItem != null && !selectedItem.isFolder()) { if (selectedItem != null) {
if (selectedItem.isFolder()) {
StringBuilder actionUrl = new StringBuilder();
actionUrl.append(GWT.getModuleBaseURL());
actionUrl
.append(Constants.DOWNLOAD_FOLDER_SERVLET
+ "?"
+ Constants.DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER
+ "="
+ selectedItem.getId()
+ "&"
+ Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER
+ "=" + selectedItem.getName());
Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), selectedItem.getName(), "");
} else {
final ItemDescription itemDescription = new ItemDescription( final ItemDescription itemDescription = new ItemDescription(
selectedItem.getId(), selectedItem.getName(), selectedItem.getId(), selectedItem.getName(),
selectedItem.getOwner(), selectedItem.getPath(), selectedItem.getOwner(), selectedItem.getPath(),
@ -426,6 +443,7 @@ public class OutputDataSetsPanel extends FramedPanel {
} }
}); });
}
} else { } else {
UtilsGXT3.info("Attention", "Select a file!"); UtilsGXT3.info("Attention", "Select a file!");

View File

@ -1,18 +1,35 @@
package org.gcube.portlets.user.dataminermanager.server; package org.gcube.portlets.user.dataminermanager.server;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.IOUtils;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.user.dataminermanager.server.storage.StorageUtil;
import org.gcube.portlets.user.dataminermanager.shared.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* DownloadFolder Servlet *
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
* Download Folder Servlet
*
*/ */
@WebServlet("/DownloadFolderServlet")
public class DownloadFolderServlet extends HttpServlet { public class DownloadFolderServlet extends HttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = -1838255772767180518L;
private static Logger logger = LoggerFactory
.getLogger(DownloadFolderServlet.class);
/** /**
* @see HttpServlet#HttpServlet() * @see HttpServlet#HttpServlet()
@ -23,45 +40,74 @@ public class DownloadFolderServlet extends HttpServlet {
} }
/** /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/ */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
createResponse(request, response); createResponse(request, response);
} }
/** /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/ */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
createResponse(request, response); createResponse(request, response);
} }
private void createResponse(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
try {
logger.info("DownloadFolderServlet");
private void createResponse(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ HttpSession session = request.getSession();
/*try {
request.getParameter("c") if (session == null) {
logger.error("Error getting the session, no session valid found: "
+ session);
response.sendError(
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"ERROR-Error getting the user session, no session found "
+ session);
return;
}
logger.debug("DownloadFolderServlet session id: " + session.getId());
File tmpZip = ZipUtil.zipFolder((WorkspaceFolder) item); ASLSession aslSession = SessionUtil.getASLSession(session);
resp.setHeader( "Content-Disposition", "attachment; filename=\"" + item.getName() + ".zip\"" );
resp.setContentType("application/zip"); String itemId = request.getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER);
resp = setContentLength(resp, tmpZip.length()); String folderName = request.getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER);
OutputStream out = resp.getOutputStream(); logger.debug("Request: [itemId=" + itemId + ", folderName="
+ folderName + "]");
File tmpZip = StorageUtil.zipFolder(aslSession.getUsername(),
itemId);
response.setHeader("Content-Disposition", "attachment; filename=\""
+ folderName + ".zip\"");
response.setContentType("application/zip");
response.setHeader("Content-Length",
String.valueOf(tmpZip.length()));
OutputStream out = response.getOutputStream();
FileInputStream fileTmpZip = new FileInputStream(tmpZip); FileInputStream fileTmpZip = new FileInputStream(tmpZip);
IOUtils.copy(fileTmpZip, resp.getOutputStream()); IOUtils.copy(fileTmpZip, response.getOutputStream());
fileTmpZip.close(); out.flush();
out.close(); out.close();
fileTmpZip.close();
tmpZip.delete(); tmpZip.delete();
return; return;
} catch (Exception e) { } catch (Throwable e) {
logger.error("Error during folder compression "+itemId,e); logger.error("Error in DownloadFolderServlet: "
handleError(urlRedirectOnError, req, resp, itemId, HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error during folder compression: "+e.getMessage()); + e.getLocalizedMessage());
return; e.printStackTrace();
throw new ServletException("Error:"
+ e.getLocalizedMessage(), e);
} }
}*/
} }
} }

View File

@ -219,10 +219,18 @@ public class StorageUtil {
} }
} }
public File zipFolder(String user, String folderId) /**
*
* @param user
* @param folderId
* @return
* @throws ServiceException
*/
public static File zipFolder(String user, String folderId)
throws ServiceException { throws ServiceException {
Workspace ws; Workspace ws;
try { try {
logger.debug("zipFolder: [user="+user+", folderId="+folderId+"]");
ws = HomeLibrary.getUserWorkspace(user); ws = HomeLibrary.getUserWorkspace(user);
WorkspaceItem workSpaceItem = ws.getItem(folderId); WorkspaceItem workSpaceItem = ws.getItem(folderId);

View File

@ -51,6 +51,11 @@ public class Constants {
//public static final String WPSToken = "45943442-74ef-408b-be64-d26b42cf4c08 "; //public static final String WPSToken = "45943442-74ef-408b-be64-d26b42cf4c08 ";
//public static final String WPSUser = "statistical.manager@gmail.com"; //public static final String WPSUser = "statistical.manager@gmail.com";
//DownloadFolderServlet
public static final String DOWNLOAD_FOLDER_SERVLET= "DownloadFolderServlet";
public static final String DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER = "itemId";
public static final String DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER = "folderName";
} }

View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet> <servlet>
<servlet-name>DataMinerManagerServlet</servlet-name> <servlet-name>DataMinerManagerServlet</servlet-name>
<servlet-class>org.gcube.portlets.user.dataminermanager.server.DataMinerManagerServiceImpl</servlet-class> <servlet-class>org.gcube.portlets.user.dataminermanager.server.DataMinerManagerServiceImpl</servlet-class>
@ -12,6 +15,10 @@
<servlet-name>DownloadService</servlet-name> <servlet-name>DownloadService</servlet-name>
<servlet-class>org.gcube.portlets.user.dataminermanager.server.DownloadServlet</servlet-class> <servlet-class>org.gcube.portlets.user.dataminermanager.server.DownloadServlet</servlet-class>
</servlet> </servlet>
<servlet>
<servlet-name>DownloadFolderServlet</servlet-name>
<servlet-class>org.gcube.portlets.user.dataminermanager.server.DownloadFolderServlet</servlet-class>
</servlet>
<servlet> <servlet>
<servlet-name>workspaceExplorer</servlet-name> <servlet-name>workspaceExplorer</servlet-name>
<servlet-class>org.gcube.portlets.widgets.wsexplorer.server.WorkspaceExplorerServiceImpl</servlet-class> <servlet-class>org.gcube.portlets.widgets.wsexplorer.server.WorkspaceExplorerServiceImpl</servlet-class>
@ -44,6 +51,10 @@
<servlet-name>DownloadService</servlet-name> <servlet-name>DownloadService</servlet-name>
<url-pattern>/dataminermanager/DownloadService</url-pattern> <url-pattern>/dataminermanager/DownloadService</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet-mapping>
<servlet-name>DownloadFolderServlet</servlet-name>
<url-pattern>/dataminermanager/DownloadFolderServlet</url-pattern>
</servlet-mapping>
<servlet-mapping> <servlet-mapping>
<servlet-name>workspaceExplorer</servlet-name> <servlet-name>workspaceExplorer</servlet-name>
<url-pattern>/dataminermanager/WorkspaceExplorerService</url-pattern> <url-pattern>/dataminermanager/WorkspaceExplorerService</url-pattern>