fix on upload archive

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@171509 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-09-18 15:42:00 +00:00
parent 19a6deac59
commit 471cb428a9
1 changed files with 19 additions and 27 deletions

View File

@ -32,7 +32,6 @@ import org.apache.commons.fileupload.util.Streams;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.Validate;
import org.gcube.common.homelibrary.util.MimeTypeUtil;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
@ -103,6 +102,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
public static final String FILE = "File";
public static final String ARCHIVE = "Archive";
// public static final String D4ST = Extensions.REPORT_TEMPLATE.getName(); //extension of Report Template type
// public static final String D4SR = Extensions.REPORT.getName(); //extension of Report type
@ -539,7 +540,23 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
String contentType = null; //It's set into HL
if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
if(uploadType.compareTo(ARCHIVE)==0){ //UPLOAD ARCHIVE
//TODO UPLOAD ARCHIVE
logger.debug("Archive content type: "+uploadItem.getContentType());
workspaceUploader = WorkspaceUploaderMng.uploadArchive(storageHubWrapper, user, scopeGroupId, workspaceUploader, request, itemName, inputStream, destinationFolder, size);
// if (MimeTypeUtil.isZipContentType(uploadItem.getContentType())){ //UNZIP??
// logger.debug("Unziping content");
// //THE WORKSPACE HAS BEEN INSTANCIED ABOVE
if(workspaceUploader==null)
throw new Exception("Error when creating uploader, it is null!");
sendMessage(response, workspaceUploader.getIdentifier());
}else{ //UPLOAD FILE. IT IS DEFAULT CASE
//I don't need to check this if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
workspaceUploader = WorkspaceUploaderMng.uploadFile(storageHubWrapper, user, scopeGroupId, request, workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
@ -548,33 +565,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
sendMessage(response, workspaceUploader.getIdentifier());
}else {//IS ARCHIVE UPLOAD
//TODO UPLOAD ARCHIVE
logger.debug("Archive content type: "+uploadItem.getContentType());
if (MimeTypeUtil.isZipContentType(uploadItem.getContentType())){ //UNZIP??
logger.debug("Unziping content");
//THE WORKSPACE HAS BEEN INSTANCIED ABOVE
workspaceUploader = WorkspaceUploaderMng.uploadArchive(storageHubWrapper, user, scopeGroupId, workspaceUploader, request, itemName, inputStream, destinationFolder, size);
if(workspaceUploader==null)
throw new Exception("Error when creating uploader, it is null!");
sendMessage(response, workspaceUploader.getIdentifier());
} else{
//THE WORKSPACE HAS BEEN INSTANCIED ABOVE. DEFAULT CASE IS UPLOADING A FILE
workspaceUploader = WorkspaceUploaderMng.uploadFile(storageHubWrapper, user, scopeGroupId, request, workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
if(workspaceUploader==null)
throw new Exception("Error when creating uploader, it is null!");
sendMessage(response, workspaceUploader.getIdentifier());
}
}
//saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
// file.delete();
} catch (InsufficientPrivilegesException e) {
logger.error("Error creating elements", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred in the upload. Insufficient privileges", request.getSession());