[Feature #13327] Checking upload permission before the upload starting

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@181702 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2019-09-16 14:22:59 +00:00
parent dce66bf75c
commit ef5ab6adf4
2 changed files with 18 additions and 8 deletions

View File

@ -240,7 +240,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}catch(Exception e){ }catch(Exception e){
//Silent exception; //Silent exception;
} }
} }
if(item.isFormField() && CLIENT_UPLOAD_KEYS.equals(item.getFieldName())){ if(item.isFormField() && CLIENT_UPLOAD_KEYS.equals(item.getFieldName())){
@ -755,7 +754,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
Validate.notNull(folderDestination, "The folder destionation is null"); Validate.notNull(folderDestination, "The folder destionation is null");
logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName()); logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(storageWrapper, request, currUser, scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestination,isOverwrite); NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(storageWrapper, request, currUser, scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestination);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e); logger.error("Error in notifyUploadInSharedFolder", e);

View File

@ -14,6 +14,7 @@ import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
import org.gcube.common.storagehub.model.items.FolderItem; import org.gcube.common.storagehub.model.items.FolderItem;
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.service.Version;
import org.gcube.common.storagehub.model.types.WorkspaceItemType; import org.gcube.common.storagehub.model.types.WorkspaceItemType;
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper; import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace; import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
@ -52,9 +53,9 @@ public class NotificationsWorkspaceUploader {
* @param folderDestinationItem the folder destination item * @param folderDestinationItem the folder destination item
* @param isOverwrite the is overwrite * @param isOverwrite the is overwrite
*/ */
public static void checkSendNotifyChangedItemToShare(StorageHubWrapper storageWrapper, HttpServletRequest request, GCubeUser currUser, String scopeGroupId, NotificationsWorkspaceUploaderProducer np, HttpSession httpSession, final Item sourceItem, final String sourceSharedId, final FolderItem folderDestinationItem, boolean isOverwrite) { public static void checkSendNotifyChangedItemToShare(StorageHubWrapper storageWrapper, HttpServletRequest request, GCubeUser currUser, String scopeGroupId, NotificationsWorkspaceUploaderProducer np, HttpSession httpSession, final Item sourceItem, final String sourceSharedId, final FolderItem folderDestinationItem) {
logger.trace("checkSendNotifyAddItemToShare"); logger.debug("checkSendNotifyChangedItemToShare called");
if(folderDestinationItem!=null){ if(folderDestinationItem!=null){
@ -62,8 +63,9 @@ public class NotificationsWorkspaceUploader {
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing? if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination name: "+folderDestinationItem.getName() + " folder destination id: "+folderDestinationItem.getId()); logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination name: "+folderDestinationItem.getName() + " folder destination id: "+folderDestinationItem.getId());
//share condition is true if source shared folder is not null //share condition is true if source shared folder is not null
boolean shareChangeCondition = sourceSharedId==null?false:true; boolean shareChangeCondition = sourceSharedId==null?false:true;
logger.trace("shareChangeCondition add item: "+shareChangeCondition); logger.debug("shareChangeCondition add item: "+shareChangeCondition);
//if shareChangeCondition is true.. notifies added item to sharing //if shareChangeCondition is true.. notifies added item to sharing
if(shareChangeCondition){ if(shareChangeCondition){
@ -89,8 +91,17 @@ public class NotificationsWorkspaceUploader {
//TO folderDest or rootSharedFolder?? //TO folderDest or rootSharedFolder??
SocialSharedFolder socialFolder = NotificationMapper.toSocialFolder(rootSharedFolder); SocialSharedFolder socialFolder = NotificationMapper.toSocialFolder(rootSharedFolder);
//SWITCH BEETWEEN ADDED OR UPDATED boolean isUpdate = false;
if(!isOverwrite) try {
List<Version> versions = storageWrapper.getStorageHubClientService().getListVersions(sourceItem.getId());
isUpdate = versions.size()>1?true:false;
logger.debug("Is file updating? "+shareChangeCondition);
}catch (Exception e) {
//silent
}
//SWITCH BETWEEN ADDED OR UPDATED
if(!isUpdate)
np.notifyAddedItemToSharing(listContacts, socialItem, socialFolder); np.notifyAddedItemToSharing(listContacts, socialItem, socialFolder);
else else
np.notifyUpdatedItemToSharing(listContacts, socialItem, socialFolder); np.notifyUpdatedItemToSharing(listContacts, socialItem, socialFolder);