patched download external image for version id

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@144265 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-02-24 13:49:09 +00:00
parent 40cb42d349
commit 7f631e7323
1 changed files with 38 additions and 3 deletions

View File

@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.common.homelibary.model.versioning.WorkspaceVersion;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
@ -255,7 +256,20 @@ public class DownloadServlet extends HttpServlet{
if(versionID!=null){ if(versionID!=null){
logger.info("Downloading version id: "+versionID); logger.info("Downloading version id: "+versionID);
//TODO MUST BE ADDED SIZE FOR VERSIONED FILE //TODO MUST BE ADDED SIZE FOR VERSIONED FILE
is = externalFile.downloadVersion(versionID); WorkspaceVersion vers = externalFile.getVersion(versionID);
if(vers!=null){
long versionSize = vers.getSize(); //just one read
versionSize = versionSize>0?versionSize:-1;
if(versionSize>0)
resp = setContentLength(resp, versionSize);
is = externalFile.downloadVersion(versionID);
}else{
logger.error("Error file version "+versionID+" not found in the server-side. Refresh and try again.");
handleError(urlRedirectOnError, req, resp, itemId, HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error file version "+versionID+" not found in the server-side. Refresh and try again.");
return;
}
}else{ }else{
resp = setContentLength(resp, externalFile.getLength()); resp = setContentLength(resp, externalFile.getLength());
is = externalFile.getData(); is = externalFile.getData();
@ -286,9 +300,30 @@ public class DownloadServlet extends HttpServlet{
String contentDisposition = viewContent?"inline":"attachment"; String contentDisposition = viewContent?"inline":"attachment";
resp.setHeader( "Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" ); resp.setHeader( "Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
resp.setContentType(externalImage.getMimeType()); resp.setContentType(externalImage.getMimeType());
resp = setContentLength(resp, externalImage.getLength()); InputStream is;
if(versionID!=null){
logger.info("Downloading version id: "+versionID);
//TODO MUST BE ADDED SIZE FOR VERSIONED FILE
WorkspaceVersion vers = externalImage.getVersion(versionID);
if(vers!=null){
long versionSize = vers.getSize(); //just one read
versionSize = versionSize>0?versionSize:-1;
if(versionSize>0)
resp = setContentLength(resp, versionSize);
is = externalImage.downloadVersion(versionID);
}else{
logger.error("Error file version "+versionID+" not found in the server-side. Refresh and try again.");
handleError(urlRedirectOnError, req, resp, itemId, HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error file version "+versionID+" not found in the server-side. Refresh and try again.");
return;
}
}else{
resp = setContentLength(resp, externalImage.getLength());
is = externalImage.getData();
}
OutputStream out = resp.getOutputStream(); OutputStream out = resp.getOutputStream();
InputStream is = externalImage.getData();
IOUtils.copy(is, out); IOUtils.copy(is, out);
is.close(); is.close();