ref 11724: SAI - Update to StorageHUB
https://support.d4science.org/issues/11724 Updated to StorageHub git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@171899 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
37f4e4d69e
commit
affcf404e3
|
@ -89,4 +89,6 @@ public interface StatAlgoImporterService extends RemoteService {
|
||||||
|
|
||||||
public void repackageSoftware() throws StatAlgoImporterServiceException;
|
public void repackageSoftware() throws StatAlgoImporterServiceException;
|
||||||
|
|
||||||
|
public ItemDescription getItemDescription(String itemId) throws StatAlgoImporterServiceException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,8 @@ public interface StatAlgoImporterServiceAsync {
|
||||||
|
|
||||||
void getDeployOperationLogs(String operationId, AsyncCallback<String> callback);
|
void getDeployOperationLogs(String operationId, AsyncCallback<String> callback);
|
||||||
|
|
||||||
|
void getItemDescription(String itemId, AsyncCallback<ItemDescription> asyncCallback);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package org.gcube.portlets.user.statisticalalgorithmsimporter.client.tools.explorer;
|
package org.gcube.portlets.user.statisticalalgorithmsimporter.client.tools.explorer;
|
||||||
|
|
||||||
import org.gcube.portal.clientcontext.client.GCubeClientContext;
|
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.BinaryCodeSetEvent;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.BinaryCodeSetEvent;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.DeleteItemEvent;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.DeleteItemEvent;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.MainCodeSetEvent;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.MainCodeSetEvent;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.ProjectStatusEvent;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.ProjectStatusEvent;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.resource.StatAlgoImporterResources;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.resource.StatAlgoImporterResources;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.utils.UtilsGXT3;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.utils.UtilsGXT3;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.workspace.DownloadWidget;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectSupportBashEdit;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectSupportBashEdit;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectSupportBlackBox;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectSupportBlackBox;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
||||||
|
@ -20,10 +19,7 @@ import org.gcube.portlets.widgets.wsexplorer.shared.Item;
|
||||||
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
|
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
|
||||||
|
|
||||||
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.event.shared.EventBus;
|
import com.google.gwt.event.shared.EventBus;
|
||||||
import com.google.gwt.http.client.URL;
|
|
||||||
import com.google.gwt.user.client.Window;
|
|
||||||
import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale;
|
import com.sencha.gxt.cell.core.client.ButtonCell.ButtonScale;
|
||||||
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
||||||
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
|
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
|
||||||
|
@ -364,62 +360,11 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
|
|
||||||
private void openFile() {
|
private void openFile() {
|
||||||
if (selectedItem != null) {
|
if (selectedItem != null) {
|
||||||
|
DownloadWidget downloadWidget = new DownloadWidget(eventBus);
|
||||||
if (selectedItem.isFolder()) {
|
downloadWidget.download(selectedItem.getId());
|
||||||
|
|
||||||
StringBuilder url = new StringBuilder();
|
|
||||||
url.append(GWT.getModuleBaseURL());
|
|
||||||
url.append(Constants.DOWNLOAD_FOLDER_SERVLET + "?" + Constants.DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER
|
|
||||||
+ "=" + selectedItem.getId() + "&" + Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER
|
|
||||||
+ "=" + selectedItem.getName() + "&" + Constants.CURR_GROUP_ID + "="
|
|
||||||
+ GCubeClientContext.getCurrentContextId());
|
|
||||||
|
|
||||||
Log.debug("Retrieved link: " + url);
|
|
||||||
Window.open(URL.encode(url.toString()), "_blank", "");
|
|
||||||
} else {
|
|
||||||
|
|
||||||
final ItemDescription itemDescription = new ItemDescription(selectedItem.getId(),
|
|
||||||
selectedItem.getName(), selectedItem.getOwner(), selectedItem.getPath(),
|
|
||||||
selectedItem.getType().name());
|
|
||||||
Log.debug("ItemDescription: " + itemDescription);
|
|
||||||
String currentContextId = GCubeClientContext.getCurrentContextId();
|
|
||||||
StringBuilder url = new StringBuilder();
|
|
||||||
url.append(GWT.getModuleBaseURL());
|
|
||||||
url.append(Constants.DOWNLOAD_FILE_SERVLET + "/" + itemDescription.getName() + "?itemId="
|
|
||||||
+ itemDescription.getId() + "&" + Constants.CURR_GROUP_ID + "=" + currentContextId);
|
|
||||||
|
|
||||||
Window.open(URL.encode(url.toString()), "_blank", "");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Used to fix the problem of the PortalContext that lost the
|
|
||||||
* scope
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* StatAlgoImporterServiceAsync.INSTANCE.getPublicLink(
|
|
||||||
* itemDescription, new AsyncCallback<String>() {
|
|
||||||
*
|
|
||||||
* @Override public void onFailure(Throwable caught) { if
|
|
||||||
* (caught instanceof StatAlgoImporterSessionExpiredException) {
|
|
||||||
* eventBus.fireEvent(new
|
|
||||||
* SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER)); }
|
|
||||||
* else { Log.error("Error open file: " +
|
|
||||||
* caught.getLocalizedMessage()); UtilsGXT3.alert("Error",
|
|
||||||
* caught.getLocalizedMessage()); } caught.printStackTrace();
|
|
||||||
*
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* @Override public void onSuccess(String link) {
|
|
||||||
* Log.debug("Retrieved link: " + link); Window.open(link,
|
|
||||||
* itemDescription.getName(), ""); }
|
|
||||||
*
|
|
||||||
* });
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
UtilsGXT3.info("Attention", "Select a file!");
|
UtilsGXT3.info("Attention", "Select a file!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
package org.gcube.portlets.user.statisticalalgorithmsimporter.client.workspace;
|
||||||
|
|
||||||
|
import org.gcube.portal.clientcontext.client.GCubeClientContext;
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.SessionExpiredEvent;
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterServiceAsync;
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.SessionExpiredType;
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.utils.UtilsGXT3;
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException;
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
||||||
|
|
||||||
|
import com.allen_sauer.gwt.log.client.Log;
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.event.shared.EventBus;
|
||||||
|
import com.google.gwt.http.client.URL;
|
||||||
|
import com.google.gwt.user.client.Window;
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Giancarlo Panichi
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DownloadWidget {
|
||||||
|
private EventBus eventBus;
|
||||||
|
|
||||||
|
public DownloadWidget(EventBus eventBus) {
|
||||||
|
this.eventBus=eventBus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void download(String itemId) {
|
||||||
|
|
||||||
|
StatAlgoImporterServiceAsync.INSTANCE.getItemDescription(itemId, new AsyncCallback<ItemDescription>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
if (caught instanceof StatAlgoImporterSessionExpiredException) {
|
||||||
|
eventBus.fireEvent(new SessionExpiredEvent(SessionExpiredType.EXPIREDONSERVER));
|
||||||
|
} else {
|
||||||
|
Log.error("Error open file: " + caught.getLocalizedMessage());
|
||||||
|
UtilsGXT3.alert("Error", caught.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
caught.printStackTrace();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(ItemDescription itemDownloadInfo) {
|
||||||
|
Log.debug("Retrieved item download info: " + itemDownloadInfo);
|
||||||
|
requestDownload(itemDownloadInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void requestDownload(ItemDescription itemDescription) {
|
||||||
|
switch (itemDescription.getType()) {
|
||||||
|
case "AbstractFileItem":
|
||||||
|
case "FolderItem":
|
||||||
|
executeDownload(itemDescription);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UtilsGXT3.info("Attention", "This item does not support download operation!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeDownload(ItemDescription itemDescription) {
|
||||||
|
StringBuilder url = new StringBuilder();
|
||||||
|
url.append(GWT.getModuleBaseURL());
|
||||||
|
url.append(Constants.DOWNLOAD_SERVLET + "/" + itemDescription.getName() + "?itemId=" + itemDescription.getId()
|
||||||
|
+ "&" + Constants.CURR_GROUP_ID + "=" + GCubeClientContext.getCurrentContextId());
|
||||||
|
|
||||||
|
Window.open(URL.encode(url.toString()), "_blank", "");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,111 +0,0 @@
|
||||||
package org.gcube.portlets.user.statisticalalgorithmsimporter.server;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServlet;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.servlet.http.HttpSession;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
|
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
|
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Giancarlo Panichi
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Download Folder Servlet
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class DownloadFolderServlet extends HttpServlet {
|
|
||||||
private static final long serialVersionUID = -1838255772767180518L;
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(DownloadFolderServlet.class);
|
|
||||||
|
|
||||||
|
|
||||||
public DownloadFolderServlet() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
|
|
||||||
* response)
|
|
||||||
*/
|
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
||||||
throws ServletException, IOException {
|
|
||||||
createResponse(request, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
|
|
||||||
* response)
|
|
||||||
*/
|
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
||||||
throws ServletException, IOException {
|
|
||||||
createResponse(request, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createResponse(HttpServletRequest request, HttpServletResponse response)
|
|
||||||
throws ServletException, IOException {
|
|
||||||
try {
|
|
||||||
logger.debug("DownloadFolderServlet");
|
|
||||||
|
|
||||||
HttpSession session = request.getSession();
|
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
ServiceCredentials serviceCredentials;
|
|
||||||
|
|
||||||
String scopeGroupId = request.getHeader(Constants.CURR_GROUP_ID);
|
|
||||||
if (scopeGroupId == null || scopeGroupId.isEmpty()) {
|
|
||||||
scopeGroupId = request.getParameter(Constants.CURR_GROUP_ID);
|
|
||||||
if (scopeGroupId == null || scopeGroupId.isEmpty()) {
|
|
||||||
logger.error(
|
|
||||||
"CURR_GROUP_ID is null, it is a mandatory parameter in custom servlet: " + scopeGroupId);
|
|
||||||
throw new ServletException(
|
|
||||||
"CURR_GROUP_ID is null, it is a mandatory parameter in custom servlet: " + scopeGroupId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
serviceCredentials = SessionUtil.getServiceCredentials(request, scopeGroupId);
|
|
||||||
|
|
||||||
String itemId = request.getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER);
|
|
||||||
String folderName = request.getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER);
|
|
||||||
logger.debug("Request: [itemId=" + itemId + ", folderName=" + folderName + "]");
|
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
|
||||||
File tmpZip = filesStorage.zipFolder(serviceCredentials.getUserName(), itemId);
|
|
||||||
|
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + folderName + ".zip\"");
|
|
||||||
response.setContentType("application/zip");
|
|
||||||
response.setHeader("Content-Length", String.valueOf(tmpZip.length()));
|
|
||||||
|
|
||||||
try (OutputStream out = response.getOutputStream();FileInputStream fileTmpZip = new FileInputStream(tmpZip)){
|
|
||||||
IOUtils.copy(fileTmpZip, response.getOutputStream());
|
|
||||||
}
|
|
||||||
|
|
||||||
Files.delete(tmpZip.toPath());
|
|
||||||
return;
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
|
||||||
logger.error("Error in DownloadFolderServlet: " + e.getLocalizedMessage(), e);
|
|
||||||
throw new ServletException("Download:" + e.getLocalizedMessage(), e);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -14,11 +14,12 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.ItemDownload;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -29,16 +30,16 @@ import org.slf4j.LoggerFactory;
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DownloadFileServlet extends HttpServlet {
|
public class DownloadServlet extends HttpServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = 5389118370656932343L;
|
private static final long serialVersionUID = 5389118370656932343L;
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(DownloadFileServlet.class);
|
private static Logger logger = LoggerFactory.getLogger(DownloadServlet.class);
|
||||||
|
|
||||||
public DownloadFileServlet() {
|
public DownloadServlet() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
|
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
|
||||||
* response)
|
* response)
|
||||||
|
@ -57,11 +58,10 @@ public class DownloadFileServlet extends HttpServlet {
|
||||||
createResponse(request, response);
|
createResponse(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createResponse(HttpServletRequest req, HttpServletResponse resp)
|
private void createResponse(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
throws ServletException, IOException {
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.debug("DownloadFileServlet()");
|
logger.debug("DownloadServlet()");
|
||||||
|
|
||||||
HttpSession session = req.getSession();
|
HttpSession session = req.getSession();
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class DownloadFileServlet extends HttpServlet {
|
||||||
"ERROR-Error getting the user session, no session found" + session);
|
"ERROR-Error getting the user session, no session found" + session);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug("DownloadFileServlet session id: " + session.getId());
|
logger.debug("DownloadServlet() session id: " + session.getId());
|
||||||
String scopeGroupId = req.getHeader(Constants.CURR_GROUP_ID);
|
String scopeGroupId = req.getHeader(Constants.CURR_GROUP_ID);
|
||||||
if (scopeGroupId == null || scopeGroupId.isEmpty()) {
|
if (scopeGroupId == null || scopeGroupId.isEmpty()) {
|
||||||
scopeGroupId = req.getParameter(Constants.CURR_GROUP_ID);
|
scopeGroupId = req.getParameter(Constants.CURR_GROUP_ID);
|
||||||
|
@ -82,26 +82,55 @@ public class DownloadFileServlet extends HttpServlet {
|
||||||
"CURR_GROUP_ID is null, it is a mandatory parameter in custom servlet: " + scopeGroupId);
|
"CURR_GROUP_ID is null, it is a mandatory parameter in custom servlet: " + scopeGroupId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String itemId = req.getParameter("itemId");
|
String itemId = req.getParameter("itemId");
|
||||||
logger.info("DownloadFileServlet(): [scopeGroupId=" + scopeGroupId + ",ItemId=" + itemId + "]");
|
logger.info("DownloadServlet(): [scopeGroupId=" + scopeGroupId + ",ItemId=" + itemId + "]");
|
||||||
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(req, scopeGroupId);
|
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(req, scopeGroupId);
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
ItemDescription itemDescription = filesStorage.getFileInfoOnWorkspace(serviceCredentials.getUserName(),
|
ItemDownload itemDownload = filesStorage.getItemDownload(serviceCredentials.getUserName(), itemId);
|
||||||
itemId);
|
if (itemDownload == null) {
|
||||||
logger.debug("Item retrieved: " + itemDescription);
|
logger.error("This type of item does not support download operation");
|
||||||
InputStream inputStream = filesStorage.getFileOnWorkspace(serviceCredentials.getUserName(), itemId);
|
throw new ServletException("This type of item does not support download operation");
|
||||||
|
|
||||||
resp.setHeader("Content-Disposition:", "attachment;filename=\"" + itemDescription.getName() + "\"");
|
} else {
|
||||||
resp.setHeader("Content-Type", "application/force-download");
|
if (itemDownload.getInputStream() == null) {
|
||||||
resp.setHeader("Content-Length", itemDescription.getLenght());
|
logger.error("This type of item does not support download operation");
|
||||||
|
throw new ServletException("This type of item does not support download operation");
|
||||||
|
} else {
|
||||||
|
String fileName;
|
||||||
|
if (itemDownload.getItemDescription() == null) {
|
||||||
|
fileName = "filename";
|
||||||
|
} else {
|
||||||
|
if (itemDownload.getItemDescription().getName() == null
|
||||||
|
|| itemDownload.getItemDescription().getName().isEmpty()) {
|
||||||
|
if (itemDownload.getItemDescription().getType() != null && itemDownload.getItemDescription()
|
||||||
|
.getType().compareTo(FolderItem.class.getSimpleName()) == 0) {
|
||||||
|
fileName = "folder.zip";
|
||||||
|
} else {
|
||||||
|
fileName = itemDownload.getItemDescription().getName();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (itemDownload.getItemDescription().getType() != null && itemDownload.getItemDescription()
|
||||||
|
.getType().compareTo(FolderItem.class.getSimpleName()) == 0) {
|
||||||
|
fileName = itemDownload.getItemDescription().getName() + ".zip";
|
||||||
|
} else {
|
||||||
|
fileName = itemDownload.getItemDescription().getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.setHeader("Content-Disposition:", "attachment;filename=\"" + fileName + "\"");
|
||||||
|
resp.setHeader("Content-Type", "application/force-download");
|
||||||
|
stream(itemDownload.getInputStream(), resp.getOutputStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stream(inputStream, resp.getOutputStream());
|
|
||||||
} catch (StatAlgoImporterServiceException e) {
|
} catch (StatAlgoImporterServiceException e) {
|
||||||
logger.error("DownloadFileServlet():"+e.getLocalizedMessage(), e);
|
logger.error("DownloadServlet():" + e.getLocalizedMessage(), e);
|
||||||
throw new ServletException(e.getLocalizedMessage(), e);
|
throw new ServletException(e.getLocalizedMessage(), e);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("DownloadFileServlet(): " + e.getLocalizedMessage(), e);
|
logger.error("DownloadServlet(): " + e.getLocalizedMessage(), e);
|
||||||
throw new ServletException("Download:" + e.getLocalizedMessage(), e);
|
throw new ServletException("Download item error: " + e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -442,7 +442,7 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
|
||||||
Project project = SessionUtil.getProjectSession(httpRequest, serviceCredentials);
|
Project project = SessionUtil.getProjectSession(httpRequest, serviceCredentials);
|
||||||
checkProjectInfoForDelete(itemDescription, httpRequest, serviceCredentials, project);
|
checkProjectInfoForDelete(itemDescription, httpRequest, serviceCredentials, project);
|
||||||
FilesStorage fileStorage = new FilesStorage();
|
FilesStorage fileStorage = new FilesStorage();
|
||||||
fileStorage.deleteItemOnFolder(serviceCredentials.getUserName(), itemDescription.getId());
|
fileStorage.deleteItem(serviceCredentials.getUserName(), itemDescription.getId());
|
||||||
return project;
|
return project;
|
||||||
|
|
||||||
} catch (StatAlgoImporterServiceException e) {
|
} catch (StatAlgoImporterServiceException e) {
|
||||||
|
@ -827,4 +827,23 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemDescription getItemDescription(String itemId) throws StatAlgoImporterServiceException {
|
||||||
|
try {
|
||||||
|
HttpServletRequest httpRequest = this.getThreadLocalRequest();
|
||||||
|
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(httpRequest);
|
||||||
|
logger.debug("getItemDescription(): [itemId=" + itemId + "]");
|
||||||
|
FilesStorage storageUtil = new FilesStorage();
|
||||||
|
ItemDescription itemDownloadInfo = storageUtil.getItemDescription(serviceCredentials.getUserName(), itemId);
|
||||||
|
logger.debug("ItemDescription info: " + itemDownloadInfo);
|
||||||
|
return itemDownloadInfo;
|
||||||
|
} catch (StatAlgoImporterServiceException e) {
|
||||||
|
logger.error(e.getLocalizedMessage(), e);
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.error("Error retrieving item description: " + e.getLocalizedMessage(), e);
|
||||||
|
throw new StatAlgoImporterServiceException("Error retrieving item description: " + e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class ProjectBuilder {
|
||||||
ItemDescription mainCodeItemDescription = project.getMainCode().getItemDescription();
|
ItemDescription mainCodeItemDescription = project.getMainCode().getItemDescription();
|
||||||
if (mainCodeItemDescription.getId() != null && !mainCodeItemDescription.getId().isEmpty()) {
|
if (mainCodeItemDescription.getId() != null && !mainCodeItemDescription.getId().isEmpty()) {
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
filesStorage.deleteItemOnFolder(serviceCredentials.getUserName(), mainCodeItemDescription.getId());
|
filesStorage.deleteItem(serviceCredentials.getUserName(), mainCodeItemDescription.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainGenerator mainGenerator = new MainGenerator();
|
MainGenerator mainGenerator = new MainGenerator();
|
||||||
|
@ -233,7 +233,7 @@ public class ProjectBuilder {
|
||||||
if (project.getProjectTarget().getProjectDeploy().getCodeJar() != null
|
if (project.getProjectTarget().getProjectDeploy().getCodeJar() != null
|
||||||
&& project.getProjectTarget().getProjectDeploy().getCodeJar().getId() != null
|
&& project.getProjectTarget().getProjectDeploy().getCodeJar().getId() != null
|
||||||
&& !project.getProjectTarget().getProjectDeploy().getCodeJar().getId().isEmpty()) {
|
&& !project.getProjectTarget().getProjectDeploy().getCodeJar().getId().isEmpty()) {
|
||||||
filesStorage.deleteItemOnFolder(serviceCredentials.getUserName(),
|
filesStorage.deleteItem(serviceCredentials.getUserName(),
|
||||||
project.getProjectTarget().getProjectDeploy().getCodeJar().getId());
|
project.getProjectTarget().getProjectDeploy().getCodeJar().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,10 +589,10 @@ public class ProjectBuilder {
|
||||||
Path packageHomeDir = packageHome.toPath();
|
Path packageHomeDir = packageHome.toPath();
|
||||||
|
|
||||||
Path ecologicalEngineJar = new File(tempDirectory.toFile(), ECOLOGICAL_ENGINE_JAR).toPath();
|
Path ecologicalEngineJar = new File(tempDirectory.toFile(), ECOLOGICAL_ENGINE_JAR).toPath();
|
||||||
storage.downloadInputFile(ECOLOGICAL_ENGINE_JAR_URL, ecologicalEngineJar);
|
storage.downloadExternalInputFile(ECOLOGICAL_ENGINE_JAR_URL, ecologicalEngineJar);
|
||||||
Path ecologicalEngineSmartExecutorJar = new File(tempDirectory.toFile(), ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR)
|
Path ecologicalEngineSmartExecutorJar = new File(tempDirectory.toFile(), ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR)
|
||||||
.toPath();
|
.toPath();
|
||||||
storage.downloadInputFile(ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR_URL, ecologicalEngineSmartExecutorJar);
|
storage.downloadExternalInputFile(ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR_URL, ecologicalEngineSmartExecutorJar);
|
||||||
|
|
||||||
Path algorithmTempFile = new File(packageHomeDir.toFile(),
|
Path algorithmTempFile = new File(packageHomeDir.toFile(),
|
||||||
project.getInputData().getProjectInfo().getAlgorithmNameToClassName() + ALGORITHM_EXTENTION).toPath();
|
project.getInputData().getProjectInfo().getAlgorithmNameToClassName() + ALGORITHM_EXTENTION).toPath();
|
||||||
|
|
|
@ -21,8 +21,10 @@ import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||||
import org.gcube.common.storagehub.model.Metadata;
|
import org.gcube.common.storagehub.model.Metadata;
|
||||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
|
import org.gcube.common.storagehub.model.items.GCubeItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.gcube.common.storagehub.model.items.SharedFolder;
|
import org.gcube.common.storagehub.model.items.SharedFolder;
|
||||||
|
import org.gcube.common.storagehub.model.items.TrashItem;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -95,7 +97,7 @@ public class FilesStorage {
|
||||||
FileContainer fileCreatedContainer = fileContainer.copy(folderContainer, fileContainer.get().getName());
|
FileContainer fileCreatedContainer = fileContainer.copy(folderContainer, fileContainer.get().getName());
|
||||||
AbstractFileItem item = fileCreatedContainer.get();
|
AbstractFileItem item = fileCreatedContainer.get();
|
||||||
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
||||||
item.getPath(), item.getClass().getSimpleName());
|
item.getPath(), getItemType(item));
|
||||||
return itemDescription;
|
return itemDescription;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Copy item on folder on workspace: " + e.getLocalizedMessage(), e);
|
logger.error("Copy item on folder on workspace: " + e.getLocalizedMessage(), e);
|
||||||
|
@ -134,8 +136,8 @@ public class FilesStorage {
|
||||||
FileContainer fileCreatedContainer = fileContainer.copy(folderContainer, newName);
|
FileContainer fileCreatedContainer = fileContainer.copy(folderContainer, newName);
|
||||||
AbstractFileItem item = fileCreatedContainer.get();
|
AbstractFileItem item = fileCreatedContainer.get();
|
||||||
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
||||||
item.getPath(), item.getClass().getSimpleName());
|
item.getPath(), getItemType(item));
|
||||||
|
|
||||||
logger.debug("File created: " + itemDescription);
|
logger.debug("File created: " + itemDescription);
|
||||||
return itemDescription;
|
return itemDescription;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -154,7 +156,7 @@ public class FilesStorage {
|
||||||
* @throws StatAlgoImporterServiceException
|
* @throws StatAlgoImporterServiceException
|
||||||
* exception
|
* exception
|
||||||
*/
|
*/
|
||||||
public void deleteItemOnFolder(String user, String itemId) throws StatAlgoImporterServiceException {
|
public void deleteItem(String user, String itemId) throws StatAlgoImporterServiceException {
|
||||||
try {
|
try {
|
||||||
logger.info("Delete Item: [User=" + user + ", ItemId=" + itemId + "]");
|
logger.info("Delete Item: [User=" + user + ", ItemId=" + itemId + "]");
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
@ -246,7 +248,7 @@ public class FilesStorage {
|
||||||
FolderItem folderCreated = folderContainerNew.get();
|
FolderItem folderCreated = folderContainerNew.get();
|
||||||
|
|
||||||
ItemDescription itemDescription = new ItemDescription(folderCreated.getId(), folderCreated.getName(),
|
ItemDescription itemDescription = new ItemDescription(folderCreated.getId(), folderCreated.getName(),
|
||||||
folderCreated.getOwner(), folderCreated.getPath(), folderCreated.getClass().getSimpleName());
|
folderCreated.getOwner(), folderCreated.getPath(), getItemType(folderCreated));
|
||||||
|
|
||||||
return itemDescription;
|
return itemDescription;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -287,7 +289,7 @@ public class FilesStorage {
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
logger.debug("Item Id=" + item.getId());
|
logger.debug("Item Id=" + item.getId());
|
||||||
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
||||||
item.getPath(), item.getClass().getSimpleName());
|
item.getPath(), getItemType(item));
|
||||||
|
|
||||||
return itemDescription;
|
return itemDescription;
|
||||||
} else {
|
} else {
|
||||||
|
@ -413,8 +415,8 @@ public class FilesStorage {
|
||||||
AbstractFileItem fileCreated = fileContainerNew.get();
|
AbstractFileItem fileCreated = fileContainerNew.get();
|
||||||
|
|
||||||
ItemDescription itemDescription = new ItemDescription(fileCreated.getId(), fileCreated.getName(),
|
ItemDescription itemDescription = new ItemDescription(fileCreated.getId(), fileCreated.getName(),
|
||||||
fileCreated.getOwner(), fileCreated.getPath(), fileCreated.getClass().getSimpleName());
|
fileCreated.getOwner(), fileCreated.getPath(), getItemType(fileCreated));
|
||||||
|
|
||||||
return itemDescription;
|
return itemDescription;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Create item on workspace: " + e.getLocalizedMessage(), e);
|
logger.error("Create item on workspace: " + e.getLocalizedMessage(), e);
|
||||||
|
@ -435,8 +437,7 @@ public class FilesStorage {
|
||||||
* Exception
|
* Exception
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public InputStream getProjectItemOnWorkspace(String user, String folderId)
|
public InputStream getProjectItemOnWorkspace(String user, String folderId) throws StatAlgoImporterServiceException {
|
||||||
throws StatAlgoImporterServiceException {
|
|
||||||
try {
|
try {
|
||||||
logger.info("Retrieve project item on workspace: [user=" + user + ", folderId=" + folderId + "]");
|
logger.info("Retrieve project item on workspace: [user=" + user + ", folderId=" + folderId + "]");
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
@ -517,67 +518,7 @@ public class FilesStorage {
|
||||||
* @throws StatAlgoImporterServiceException
|
* @throws StatAlgoImporterServiceException
|
||||||
* Exception
|
* Exception
|
||||||
*/
|
*/
|
||||||
public ItemDescription getItemInfoOnWorkspace(String user, String itemId)
|
public ItemDescription getFileInfoOnWorkspace(String user, String itemId) throws StatAlgoImporterServiceException {
|
||||||
throws StatAlgoImporterServiceException {
|
|
||||||
try {
|
|
||||||
logger.info("Retrieve item info on workspace: [user=" + user + ", itemId=" + itemId + "]");
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
|
||||||
OpenResolver openResolver = shc.open(itemId);
|
|
||||||
|
|
||||||
ItemContainer<Item> fileContainer = openResolver.asItem();
|
|
||||||
Item item = fileContainer.get();
|
|
||||||
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
|
||||||
item.getPath(), item.getClass().getSimpleName());
|
|
||||||
return itemDescription;
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
|
||||||
logger.error("Retrieve item info on workspace: " + e.getLocalizedMessage(), e);
|
|
||||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
* User
|
|
||||||
* @param itemId
|
|
||||||
* Item id
|
|
||||||
* @return Input stream
|
|
||||||
* @throws StatAlgoImporterServiceException
|
|
||||||
* Excetpion
|
|
||||||
*/
|
|
||||||
public InputStream getItemOnWorkspace(String user, String itemId) throws StatAlgoImporterServiceException {
|
|
||||||
|
|
||||||
try {
|
|
||||||
logger.info("Get item on workspace: [user=" + user + ", itemId=" + itemId + "]");
|
|
||||||
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
|
||||||
|
|
||||||
StreamDescriptor streamDescr = shc.open(itemId).asItem().download();
|
|
||||||
|
|
||||||
InputStream is = streamDescr.getStream();
|
|
||||||
return is;
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
|
||||||
logger.error("Get item on workspace: " + e.getLocalizedMessage(), e);
|
|
||||||
|
|
||||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
* User
|
|
||||||
* @param itemId
|
|
||||||
* Item id
|
|
||||||
* @return Item description
|
|
||||||
* @throws StatAlgoImporterServiceException
|
|
||||||
* Exception
|
|
||||||
*/
|
|
||||||
public ItemDescription getFileInfoOnWorkspace(String user, String itemId)
|
|
||||||
throws StatAlgoImporterServiceException {
|
|
||||||
try {
|
try {
|
||||||
logger.info("Retrieve file info on workspace: [user=" + user + ", itemId=" + itemId + "]");
|
logger.info("Retrieve file info on workspace: [user=" + user + ", itemId=" + itemId + "]");
|
||||||
StorageHubClient shc = new StorageHubClient();
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
@ -586,7 +527,7 @@ public class FilesStorage {
|
||||||
FileContainer fileContainer = openResolver.asFile();
|
FileContainer fileContainer = openResolver.asFile();
|
||||||
AbstractFileItem item = fileContainer.get();
|
AbstractFileItem item = fileContainer.get();
|
||||||
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
||||||
item.getPath(), item.getClass().getSimpleName());
|
item.getPath(), getItemType(item));
|
||||||
itemDescription.setMimeType(item.getContent().getMimeType());
|
itemDescription.setMimeType(item.getContent().getMimeType());
|
||||||
itemDescription.setLenght(String.valueOf(item.getContent().getSize()));
|
itemDescription.setLenght(String.valueOf(item.getContent().getSize()));
|
||||||
return itemDescription;
|
return itemDescription;
|
||||||
|
@ -597,8 +538,6 @@ public class FilesStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
|
@ -619,7 +558,7 @@ public class FilesStorage {
|
||||||
|
|
||||||
FolderItem item = openResolver.asFolder().get();
|
FolderItem item = openResolver.asFolder().get();
|
||||||
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
||||||
item.getPath(), item.getClass().getSimpleName());
|
item.getPath(), getItemType(item));
|
||||||
|
|
||||||
return itemDescription;
|
return itemDescription;
|
||||||
|
|
||||||
|
@ -730,46 +669,6 @@ public class FilesStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
* User
|
|
||||||
* @param folderId
|
|
||||||
* Folder Id
|
|
||||||
* @return Zip folder
|
|
||||||
* @throws StatAlgoImporterServiceException
|
|
||||||
* Exception
|
|
||||||
*/
|
|
||||||
public File zipFolder(String user, String folderId) throws StatAlgoImporterServiceException {
|
|
||||||
try {
|
|
||||||
logger.info("Zip folder: [user=" + user + ", folderId=" + folderId + "]");
|
|
||||||
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
|
||||||
|
|
||||||
StreamDescriptor streamDescr = shc.open(folderId).asFolder().download();
|
|
||||||
|
|
||||||
File fileZip = Files.createTempFile(streamDescr.getFileName(), "").toFile();
|
|
||||||
logger.debug("File zip: " + fileZip.getAbsolutePath());
|
|
||||||
|
|
||||||
try (FileOutputStream fos = new FileOutputStream(fileZip)) {
|
|
||||||
InputStream is = streamDescr.getStream();
|
|
||||||
byte[] buf = new byte[2048];
|
|
||||||
int read = -1;
|
|
||||||
while ((read = is.read(buf)) != -1) {
|
|
||||||
fos.write(buf, 0, read);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return fileZip;
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
|
||||||
logger.error("Zip folder on workspace: " + e.getLocalizedMessage(), e);
|
|
||||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
|
@ -822,7 +721,7 @@ public class FilesStorage {
|
||||||
* @throws StatAlgoImporterServiceException
|
* @throws StatAlgoImporterServiceException
|
||||||
* Exception
|
* Exception
|
||||||
*/
|
*/
|
||||||
public void downloadInputFile(String fileUrl, Path destination) throws StatAlgoImporterServiceException {
|
public void downloadExternalInputFile(String fileUrl, Path destination) throws StatAlgoImporterServiceException {
|
||||||
try {
|
try {
|
||||||
logger.info("Download input file: [fileUrl=" + fileUrl + ", destination=" + destination + "]");
|
logger.info("Download input file: [fileUrl=" + fileUrl + ", destination=" + destination + "]");
|
||||||
|
|
||||||
|
@ -899,4 +798,100 @@ public class FilesStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* User
|
||||||
|
* @param itemId
|
||||||
|
* Item id
|
||||||
|
* @return ItemDownload
|
||||||
|
* @throws StatAlgoImporterServiceException
|
||||||
|
* Exception
|
||||||
|
*/
|
||||||
|
public ItemDownload getItemDownload(String user, String itemId) throws StatAlgoImporterServiceException {
|
||||||
|
try {
|
||||||
|
logger.debug("getItemDownload: [user=" + user + ", itemId=" + itemId + "]");
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
OpenResolver openResolver = shc.open(itemId);
|
||||||
|
ItemContainer<Item> itemContainer = openResolver.asItem();
|
||||||
|
Item item = itemContainer.get();
|
||||||
|
|
||||||
|
StreamDescriptor streamDescriptor = null;
|
||||||
|
if (item instanceof AbstractFileItem) {
|
||||||
|
FileContainer fileContainer = openResolver.asFile();
|
||||||
|
streamDescriptor = fileContainer.download();
|
||||||
|
} else {
|
||||||
|
if (item instanceof FolderItem) {
|
||||||
|
FolderContainer folderContainer = openResolver.asFolder();
|
||||||
|
streamDescriptor = folderContainer.download();
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (streamDescriptor == null) {
|
||||||
|
logger.error("This type of item does not support download: " + itemId);
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
||||||
|
item.getPath(), getItemType(item));
|
||||||
|
ItemDownload itemDownload = new ItemDownload(itemDescription, streamDescriptor.getStream());
|
||||||
|
return itemDownload;
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.error("Error retrieving InputStream for item: " + e.getLocalizedMessage(), e);
|
||||||
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* User
|
||||||
|
* @param itemId
|
||||||
|
* Item id
|
||||||
|
* @return Item Description
|
||||||
|
* @throws StatAlgoImporterServiceException
|
||||||
|
* Exception
|
||||||
|
*/
|
||||||
|
public ItemDescription getItemDescription(String user, String itemId) throws StatAlgoImporterServiceException {
|
||||||
|
try {
|
||||||
|
logger.info("Retrieve file info on workspace: [user=" + user + ", itemId=" + itemId + "]");
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
OpenResolver openResolver = shc.open(itemId);
|
||||||
|
ItemContainer<Item> itemContainer = openResolver.asItem();
|
||||||
|
Item item = itemContainer.get();
|
||||||
|
ItemDescription itemDescription = new ItemDescription(item.getId(), item.getName(), item.getOwner(),
|
||||||
|
item.getPath(), getItemType(item));
|
||||||
|
return itemDescription;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.error("Retrieve file info on workspace: " + e.getLocalizedMessage(), e);
|
||||||
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param item
|
||||||
|
* Item
|
||||||
|
* @return Item type
|
||||||
|
*/
|
||||||
|
private String getItemType(Item item) {
|
||||||
|
if (item instanceof AbstractFileItem) {
|
||||||
|
return AbstractFileItem.class.getSimpleName();
|
||||||
|
} else {
|
||||||
|
if (item instanceof FolderItem) {
|
||||||
|
return FolderItem.class.getSimpleName();
|
||||||
|
} else {
|
||||||
|
if (item instanceof GCubeItem) {
|
||||||
|
return GCubeItem.class.getSimpleName();
|
||||||
|
} else {
|
||||||
|
if (item instanceof TrashItem) {
|
||||||
|
return TrashItem.class.getSimpleName();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Giancarlo Panichi
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ItemDownload {
|
||||||
|
private ItemDescription itemDescription;
|
||||||
|
private InputStream inputStream;
|
||||||
|
|
||||||
|
public ItemDownload(ItemDescription itemDescription, InputStream inputStream) {
|
||||||
|
super();
|
||||||
|
this.itemDescription = itemDescription;
|
||||||
|
this.inputStream = inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemDescription getItemDescription() {
|
||||||
|
return itemDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemDescription(ItemDescription itemDescription) {
|
||||||
|
this.itemDescription = itemDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream getInputStream() {
|
||||||
|
return inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInputStream(InputStream inputStream) {
|
||||||
|
this.inputStream = inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ItemDownload [itemDescription=" + itemDescription + ", inputStream=" + inputStream + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -27,14 +27,10 @@ public class Constants {
|
||||||
|
|
||||||
// Session
|
// Session
|
||||||
public static final String CURR_GROUP_ID = "CURR_GROUP_ID";
|
public static final String CURR_GROUP_ID = "CURR_GROUP_ID";
|
||||||
|
|
||||||
// Download
|
|
||||||
public static final String DOWNLOAD_FILE_SERVLET = "DownloadFileServlet";
|
|
||||||
|
|
||||||
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";
|
|
||||||
|
|
||||||
|
// Download
|
||||||
|
public static final String DOWNLOAD_SERVLET = "DownloadServlet";
|
||||||
|
|
||||||
// Upload
|
// Upload
|
||||||
public static final String LOCAL_UPLOAD_SERVLET = "LocalUploadServlet";
|
public static final String LOCAL_UPLOAD_SERVLET = "LocalUploadServlet";
|
||||||
|
|
||||||
|
|
|
@ -26,14 +26,9 @@
|
||||||
|
|
||||||
<!-- Download -->
|
<!-- Download -->
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>DownloadFileServlet</servlet-name>
|
<servlet-name>DownloadServlet</servlet-name>
|
||||||
<servlet-class>org.gcube.portlets.user.statisticalalgorithmsimporter.server.DownloadFileServlet</servlet-class>
|
<servlet-class>org.gcube.portlets.user.statisticalalgorithmsimporter.server.DownloadServlet</servlet-class>
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet>
|
|
||||||
<servlet-name>DownloadFolderServlet</servlet-name>
|
|
||||||
<servlet-class>org.gcube.portlets.user.statisticalalgorithmsimporter.server.DownloadFolderServlet</servlet-class>
|
|
||||||
</servlet>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Workspace Explorer -->
|
<!-- Workspace Explorer -->
|
||||||
|
@ -83,14 +78,9 @@
|
||||||
|
|
||||||
<!-- Download -->
|
<!-- Download -->
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>DownloadFileServlet</servlet-name>
|
<servlet-name>DownloadServlet</servlet-name>
|
||||||
<url-pattern>/statalgoimporter/DownloadFileServlet/*</url-pattern>
|
<url-pattern>/statalgoimporter/DownloadServlet/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>DownloadFolderServlet</servlet-name>
|
|
||||||
<url-pattern>/statalgoimporter/DownloadFolderServlet</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Workspace Explorer -->
|
<!-- Workspace Explorer -->
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
|
|
Loading…
Reference in New Issue