Catched the UserNotAuthorizedException in case of upload file and archive
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@179250 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
21e013bb90
commit
b9379a457c
|
@ -4,6 +4,8 @@
|
|||
date="${buildDate}">
|
||||
<Change>[Incident #16285] Bug fixing
|
||||
</Change>
|
||||
<Change>[Feature #13327] Checking permission before uploading
|
||||
</Change>
|
||||
</Changeset>
|
||||
<Changeset
|
||||
component="org.gcube.portlets-widgets.workspace-uploader.2-0-1"
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.gcube.common.portal.PortalContext;
|
|||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
||||
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InsufficientPrivilegesException;
|
||||
|
@ -45,6 +46,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorEx
|
|||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemAlreadyExistException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceSharedFolder;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploader;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploaderProducer;
|
||||
|
@ -449,9 +451,11 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
}
|
||||
|
||||
WorkspaceItem destinationItem = null;
|
||||
Workspace workspace = null;
|
||||
try {
|
||||
logger.debug("getWorkspaceItem destination id: "+destinationId+" from HL");
|
||||
destinationItem = storageHubWrapper.getWorkspace().getItem(destinationId);
|
||||
workspace = storageHubWrapper.getWorkspace();
|
||||
destinationItem = workspace.getItem(destinationId);
|
||||
} catch (ItemNotFoundException | InternalErrorException e) {
|
||||
logger.error("Error, no destination folder found", e);
|
||||
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". No destination folder found", request.getSession());
|
||||
|
@ -473,6 +477,23 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
|
||||
final WorkspaceFolder destinationFolder = (WorkspaceFolder) destinationItem;
|
||||
|
||||
if(destinationFolder.isShared()) {
|
||||
try {
|
||||
WorkspaceItem rootSharedFolder = workspace.getRootSharedFolder(destinationFolder.getId());
|
||||
|
||||
//TODO RETRIEVE USERS BELONGING TO SHARE
|
||||
//TODO RETRIEVE ACL
|
||||
|
||||
if(rootSharedFolder instanceof WorkspaceSharedFolder) {
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
//Removing path from fileName
|
||||
String itemName = fileName;
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.io.InputStream;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||
|
@ -73,15 +74,9 @@ public class WorkspaceUploaderMng {
|
|||
WorkspaceItem createdItem = null;
|
||||
|
||||
try{
|
||||
Long startTime = WorkspaceUploadServletStream.printStartTime();
|
||||
// if(!isOvewrite){
|
||||
// logger.debug("Calling HL createExternalFile - [itemName: "+itemName+", contentType: "+contentType+"]");
|
||||
// createdItem = wa.createExternalFile(destinationFolder, itemName, "", contentType, uploadFile);
|
||||
// }
|
||||
// else{
|
||||
// createdItem = overwriteItem(wa, itemName, uploadFile, destinationFolder); //CASE OVERWRITE
|
||||
// }
|
||||
|
||||
Long startTime = WorkspaceUploadServletStream.printStartTime();
|
||||
//UPLOAD
|
||||
createdItem = storageWrapper.getWorkspace().uploadFile(destinationFolder.getId(), uploadFile, itemName, "");
|
||||
|
||||
if(createdItem!=null){
|
||||
|
@ -119,6 +114,7 @@ public class WorkspaceUploaderMng {
|
|||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
//TODO TO BE REMOVED
|
||||
} catch (InternalErrorException e) {
|
||||
logger.error("Error during upload: ",e);
|
||||
workspaceUploader.setStatusDescription("Error on uploading: "+itemName+". "+e.getMessage());
|
||||
|
@ -128,7 +124,7 @@ public class WorkspaceUploaderMng {
|
|||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
|
||||
//TODO TO BE REMOVED
|
||||
} catch (InsufficientPrivilegesException | ItemAlreadyExistException | WorkspaceFolderNotFoundException | WrongDestinationException e) {
|
||||
logger.error("Error during file uploading: ",e);
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
|
@ -156,6 +152,22 @@ public class WorkspaceUploaderMng {
|
|||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
|
||||
//TO STORAGEHUB EXCEPTION
|
||||
}catch(Exception e){
|
||||
logger.error("Error occurred uploading the file: ",e);
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
workspaceUploader.setStatusDescription("An error occurred uploading the file: "+itemName+". "+e.getMessage());
|
||||
|
||||
if (e instanceof UserNotAuthorizedException){
|
||||
String folderName = destinationFolder.getName();
|
||||
workspaceUploader.setStatusDescription("You have not permission to upload in the folder: "+folderName);
|
||||
}
|
||||
try {
|
||||
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
}finally{
|
||||
try {
|
||||
// StreamUtils.deleteTempFile(uploadFile);
|
||||
|
@ -231,6 +243,7 @@ public class WorkspaceUploaderMng {
|
|||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
//TODO TO BE REMOVED
|
||||
} catch (InternalErrorException e) {
|
||||
logger.error("Error during upload: ",e);
|
||||
workspaceUploader.setStatusDescription("Error on uploading: "+itemName+". "+e.getMessage());
|
||||
|
@ -240,7 +253,7 @@ public class WorkspaceUploaderMng {
|
|||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
|
||||
//TODO TO BE REMOVED
|
||||
} catch (InsufficientPrivilegesException | ItemAlreadyExistException | WorkspaceFolderNotFoundException | WrongDestinationException e) {
|
||||
logger.error("Error during file uploading: ",e);
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
|
@ -256,7 +269,7 @@ public class WorkspaceUploaderMng {
|
|||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
//IS unreachable
|
||||
//IS unreachable
|
||||
}catch(UploadCanceledException e){
|
||||
logger.info("UploadCanceledException thrown by client..");
|
||||
workspaceUploader.setStatusDescription("Aborted upload: "+itemName);
|
||||
|
@ -268,6 +281,22 @@ public class WorkspaceUploaderMng {
|
|||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
|
||||
//TO STORAGEHUB EXCEPTION
|
||||
}catch(Exception e){
|
||||
logger.error("Error occurred uploading the archive: ",e);
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
workspaceUploader.setStatusDescription("An error occurred uploading the archive: "+itemName+". "+e.getMessage());
|
||||
|
||||
if (e instanceof UserNotAuthorizedException){
|
||||
String folderName = destinationFolder.getName();
|
||||
workspaceUploader.setStatusDescription("You have not permission to upload in the folder: "+folderName);
|
||||
}
|
||||
try {
|
||||
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
}finally{
|
||||
try {
|
||||
// StreamUtils.deleteTempFile(uploadFile);
|
||||
|
@ -300,12 +329,7 @@ public class WorkspaceUploaderMng {
|
|||
*/
|
||||
public static WorkspaceUploaderItem uploadFile(StorageHubWrapper storageWrapper, GCubeUser currUser, String scopeGroupId, HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, String itemName, InputStream file, WorkspaceFolder destinationFolder, String contentType, boolean isOverwrite, long totolaBytes) throws Exception {
|
||||
|
||||
try {
|
||||
return createWorkspaceUploaderFile(storageWrapper, currUser, scopeGroupId, request, workspaceUploader, httpSession, isOverwrite, file, itemName, destinationFolder, contentType, totolaBytes);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error when uploading file to HL : ",e);
|
||||
throw new Exception("An error occurred during upload: "+itemName+". Try again");
|
||||
}
|
||||
return createWorkspaceUploaderFile(storageWrapper, currUser, scopeGroupId, request, workspaceUploader, httpSession, isOverwrite, file, itemName, destinationFolder, contentType, totolaBytes);
|
||||
}
|
||||
|
||||
|
||||
|
@ -326,13 +350,7 @@ public class WorkspaceUploaderMng {
|
|||
*/
|
||||
public static WorkspaceUploaderItem uploadArchive(StorageHubWrapper storageWrapper, GCubeUser currUser, String scopeGroupId, WorkspaceUploaderItem workspaceUploader, HttpServletRequest request, String itemName, InputStream file, WorkspaceFolder destinationFolder, long totalBytes) throws Exception {
|
||||
|
||||
try {
|
||||
return createWorkspaceUploaderArchive(storageWrapper, currUser, scopeGroupId, workspaceUploader, request, file, itemName, destinationFolder, totalBytes);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error when uploading Archive to HL creation: ",e);
|
||||
throw new Exception("An error occurred during upload: "+itemName+". Try again");
|
||||
}
|
||||
return createWorkspaceUploaderArchive(storageWrapper, currUser, scopeGroupId, workspaceUploader, request, file, itemName, destinationFolder, totalBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue