diff --git a/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/WorkspaceUploadServletStream.java b/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/WorkspaceUploadServletStream.java index cfd740e..3f6b19d 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/WorkspaceUploadServletStream.java +++ b/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/WorkspaceUploadServletStream.java @@ -240,7 +240,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet }catch(Exception e){ //Silent exception; } - } 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"); 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) { logger.error("Error in notifyUploadInSharedFolder", e); diff --git a/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/notification/NotificationsWorkspaceUploader.java b/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/notification/NotificationsWorkspaceUploader.java index 447f8be..2197863 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/notification/NotificationsWorkspaceUploader.java +++ b/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/notification/NotificationsWorkspaceUploader.java @@ -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.Item; 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.storagehubwrapper.server.StorageHubWrapper; import org.gcube.common.storagehubwrapper.server.tohl.Workspace; @@ -52,18 +53,19 @@ public class NotificationsWorkspaceUploader { * @param folderDestinationItem the folder destination item * @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){ - + try{ 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()); //share condition is true if source shared folder is not null + 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){ @@ -88,9 +90,18 @@ public class NotificationsWorkspaceUploader { //TO folderDest or rootSharedFolder?? SocialSharedFolder socialFolder = NotificationMapper.toSocialFolder(rootSharedFolder); + + boolean isUpdate = false; + try { + List versions = storageWrapper.getStorageHubClientService().getListVersions(sourceItem.getId()); + isUpdate = versions.size()>1?true:false; + logger.debug("Is file updating? "+shareChangeCondition); + }catch (Exception e) { + //silent + } - //SWITCH BEETWEEN ADDED OR UPDATED - if(!isOverwrite) + //SWITCH BETWEEN ADDED OR UPDATED + if(!isUpdate) np.notifyAddedItemToSharing(listContacts, socialItem, socialFolder); else np.notifyUpdatedItemToSharing(listContacts, socialItem, socialFolder);