download folder modified
This commit is contained in:
parent
50124d8a49
commit
bfa702bf0f
|
@ -99,6 +99,8 @@ import org.gcube.smartgears.utils.InnerMethodName;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.itextpdf.text.pdf.PdfStructTreeController.returnType;
|
||||||
|
|
||||||
|
|
||||||
@Path("items")
|
@Path("items")
|
||||||
@ManagedBy(StorageHubAppllicationManager.class)
|
@ManagedBy(StorageHubAppllicationManager.class)
|
||||||
|
@ -784,7 +786,6 @@ public class ItemsManager extends Impersonable{
|
||||||
public Response download(@QueryParam("exclude") List<String> excludes){
|
public Response download(@QueryParam("exclude") List<String> excludes){
|
||||||
InnerMethodName.instance.set("downloadById");
|
InnerMethodName.instance.set("downloadById");
|
||||||
Session ses = null;
|
Session ses = null;
|
||||||
Response response = null;
|
|
||||||
try{
|
try{
|
||||||
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||||
final Node node = ses.getNodeByIdentifier(id);
|
final Node node = ses.getNodeByIdentifier(id);
|
||||||
|
@ -793,9 +794,24 @@ public class ItemsManager extends Impersonable{
|
||||||
if (item instanceof AbstractFileItem){
|
if (item instanceof AbstractFileItem){
|
||||||
return downloadFileInternal(ses, (AbstractFileItem) item, currentUser, true);
|
return downloadFileInternal(ses, (AbstractFileItem) item, currentUser, true);
|
||||||
} else if (item instanceof FolderItem){
|
} else if (item instanceof FolderItem){
|
||||||
|
return downloadFolderInternal(ses, (FolderItem)item, true);
|
||||||
|
} else throw new InvalidItemException("item type not supported for download: "+item.getClass());
|
||||||
|
|
||||||
|
}catch(RepositoryException re ){
|
||||||
|
log.error("jcr error download", re);
|
||||||
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
||||||
|
}catch(StorageHubException she ){
|
||||||
|
log.error(she.getErrorMessage(), she);
|
||||||
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
||||||
|
} finally{
|
||||||
|
if (ses!=null) ses.logout();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response downloadFolderInternal(Session ses, FolderItem item, boolean withAccounting ) throws StorageHubException, RepositoryException {
|
||||||
try {
|
try {
|
||||||
final Deque<Item> allNodes = compressHandler.getAllNodesForZip((FolderItem)item, ses, currentUser, accountingHandler, excludes);
|
final Deque<Item> allNodes = compressHandler.getAllNodesForZip((FolderItem)item, ses, currentUser, accountingHandler, Excludes.GET_ONLY_CONTENT);
|
||||||
final org.gcube.common.storagehub.model.Path originalPath = Paths.getPath(item.getParentPath());
|
final org.gcube.common.storagehub.model.Path originalPath = Paths.getPath(item.getParentPath());
|
||||||
StreamingOutput so = new StreamingOutput() {
|
StreamingOutput so = new StreamingOutput() {
|
||||||
|
|
||||||
|
@ -815,31 +831,21 @@ public class ItemsManager extends Impersonable{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
response = Response
|
Response response = Response
|
||||||
.ok(so)
|
.ok(so)
|
||||||
.header("content-disposition","attachment; filename = "+item.getTitle()+".zip")
|
.header("content-disposition","attachment; filename = "+item.getTitle()+".zip")
|
||||||
.header("Content-Type", "application/zip")
|
.header("Content-Type", "application/zip")
|
||||||
.header("Content-Length", -1l)
|
.header("Content-Length", -1l)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
if (withAccounting)
|
||||||
accountingHandler.createReadObj(item.getTitle(), ses, (Node) item.getRelatedNode(), currentUser, false);
|
accountingHandler.createReadObj(item.getTitle(), ses, (Node) item.getRelatedNode(), currentUser, false);
|
||||||
|
return response;
|
||||||
}finally {
|
}finally {
|
||||||
if (ses!=null) ses.save();
|
if (ses!=null) ses.save();
|
||||||
}
|
}
|
||||||
} else throw new InvalidItemException("item type not supported for download: "+item.getClass());
|
|
||||||
|
|
||||||
}catch(RepositoryException re ){
|
|
||||||
log.error("jcr error download", re);
|
|
||||||
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
||||||
}catch(StorageHubException she ){
|
|
||||||
log.error(she.getErrorMessage(), she);
|
|
||||||
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
||||||
} finally{
|
|
||||||
if (ses!=null) ses.logout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Response downloadFileInternal(Session ses, AbstractFileItem fileItem, String login, boolean withAccounting) throws RepositoryException, PluginInitializationException, PluginNotFoundException, StorageHubException {
|
private Response downloadFileInternal(Session ses, AbstractFileItem fileItem, String login, boolean withAccounting) throws RepositoryException, PluginInitializationException, PluginNotFoundException, StorageHubException {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue