Francesco Mangiacrapa 2019-10-29 09:57:57 +00:00
parent 347692bb5b
commit 913cfdc407
4 changed files with 79 additions and 62 deletions

View File

@ -1389,40 +1389,21 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
try { try {
List<InfoContactModel> listSharedContact = new ArrayList<InfoContactModel>(); List<InfoContactModel> listSharedContact = new ArrayList<InfoContactModel>();
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub(); NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub();
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem sourceShared = workspace org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem sourceShared = workspace.getRootSharedFolder(wsItem.getId());
.getRootSharedFolder(wsItem.getId());
// NotificationsManager nManager = // NotificationsManager nManager =
// WsUtil.getNotificationManager(this.getThreadLocalRequest()); // WsUtil.getNotificationManager(this.getThreadLocalRequest());
listSharedContact = NotificationStorageHubUtil.getListUserSharedByFolderSharedId(sourceShared, listSharedContact = NotificationStorageHubUtil.getListUserSharedByFolderSharedId(sourceShared,
workspace); workspace);
// IS A SHARED FOLDER
if (NotificationStorageHubUtil.isASharedFolder(wsItem)) { // THE ITEM RENAMED IS A SHARED FOLDER
if (NotificationStorageHubUtil.isFolderAndShared(wsItem)) {
np.notifyFolderRenamed(listSharedContact, wsItem, previousName, newName, sourceShared.getId()); np.notifyFolderRenamed(listSharedContact, wsItem, previousName, newName, sourceShared.getId());
// NotificationStorageHubUtil.checkNotifyAddItemToShare(movedItem,
// sourceRootSharedFolderId, folderDestination,
// workspace, np);
// NotificationStorageHubUtil.checkNotifyMoveItemFromShare(sourceItemIsShared,
// sourceItem, sourceRootSharedFolderId,
// folderDestination, workspace, np);
} else { } else {
// IS AN SHARED ITEM // THE ITEM RENAMED IS A SHARED ITEM
if (sourceShared instanceof org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder) //if (sourceShared instanceof org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder)
np.notifyItemRenamed(listSharedContact, previousName, wsItem, np.notifyItemRenamed(listSharedContact, previousName, wsItem,
(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder) sourceShared, (org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) sourceShared,
workspace); workspace);
// //TWO CASES: EITHER ROOT FOLDER AS
// WorkspaceSharedFolder OR DOESN'T.
// WorkspaceItem sharedFolder =
// workspace.getItem(wsItem.getIdSharedFolder());
// if(sharedFolder instanceof WorkspaceSharedFolder)
// notification.notifyItemRenamed(listSharedContact,
// previousName, wsItem, (WorkspaceSharedFolder)
// sharedFolder);
// else
// workspaceLogger.trace("Notifies for rename item
// itemId: "+itemId+" doesn't sent because:
// "+sharedFolder+" is not an instance of
// WorkspaceSharedFolder");
} }
} catch (Exception e) { } catch (Exception e) {
workspaceLogger.error("An error occurred in checkNotify ", e); workspaceLogger.error("An error occurred in checkNotify ", e);

View File

@ -5,8 +5,8 @@ package org.gcube.portlets.user.workspace.server.notifications.tostoragehub;
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem; import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder; import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -26,10 +26,12 @@ public class NotificationMapperToStorageHub {
* @param sharedFolder the shared folder * @param sharedFolder the shared folder
* @return the social shared folder * @return the social shared folder
*/ */
public static SocialSharedFolder toSocialSharedFolder(WorkspaceSharedFolder sharedFolder) { public static SocialSharedFolder toSocialSharedFolder(WorkspaceFolder sharedFolder) {
boolean isVREFolder = NotificationStorageHubUtil.isVREFolder(sharedFolder);
return new SocialSharedFolder(sharedFolder.getId(), sharedFolder.getName(), sharedFolder.getTitle(), return new SocialSharedFolder(sharedFolder.getId(), sharedFolder.getName(), sharedFolder.getTitle(),
sharedFolder.getName(), sharedFolder.getPath(), sharedFolder.getParentId(), sharedFolder.isVreFolder()); sharedFolder.getName(), sharedFolder.getPath(), sharedFolder.getParentId(), isVREFolder);
} }
/** /**
@ -50,8 +52,11 @@ public class NotificationMapperToStorageHub {
} }
// //
SocialSharedFolder parent = null; SocialSharedFolder parent = null;
if (theParentFolder != null && theParentFolder instanceof WorkspaceSharedFolder)
parent = toSocialSharedFolder((WorkspaceSharedFolder) theParentFolder); boolean isFolderAndShared = NotificationStorageHubUtil.isFolderAndShared(theParentFolder);
if (theParentFolder != null && isFolderAndShared)
parent = toSocialSharedFolder((WorkspaceFolder) theParentFolder);
// //
return new SocialFileItem(item.getId(), item.getName(), item.getTitle(), item.getPath(), parent); return new SocialFileItem(item.getId(), item.getName(), item.getTitle(), item.getPath(), parent);
} }

View File

@ -12,6 +12,7 @@ import org.gcube.common.storagehub.model.types.WorkspaceItemType;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceVREFolder;
import org.gcube.portlets.user.workspace.server.tostoragehub.StorageHubToWorkpaceConverter; import org.gcube.portlets.user.workspace.server.tostoragehub.StorageHubToWorkpaceConverter;
import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
@ -64,8 +65,8 @@ public class NotificationStorageHubUtil {
//WorkspaceItem destinationSharedFolder = workspace.getItem(rootSharedFolder.getId()); //WorkspaceItem destinationSharedFolder = workspace.getItem(rootSharedFolder.getId());
WorkspaceItem destinationSharedFolder = rootSharedFolder; WorkspaceItem destinationSharedFolder = rootSharedFolder;
if(destinationSharedFolder instanceof WorkspaceSharedFolder){ if(isFolderAndShared(destinationSharedFolder)){
np.notifyAddedItemToSharing(workspace, listContacts, workspaceItem, (WorkspaceSharedFolder) destinationSharedFolder); np.notifyAddedItemToSharing(workspace, listContacts, workspaceItem, (WorkspaceFolder) destinationSharedFolder);
logger.trace("The notifies sent correctly"); logger.trace("The notifies sent correctly");
} }
else else
@ -129,8 +130,8 @@ public class NotificationStorageHubUtil {
WorkspaceItem sourceRootSharedFolder = workspace.getItem(sourceRootSharedFolderId); WorkspaceItem sourceRootSharedFolder = workspace.getItem(sourceRootSharedFolderId);
if(sourceRootSharedFolder instanceof WorkspaceSharedFolder){ if(isFolderAndShared(sourceRootSharedFolder)){
np.notifyMovedItemToSharing(workspace, listContacts, sourceItem, (WorkspaceSharedFolder) sourceRootSharedFolder); np.notifyMovedItemToSharing(workspace, listContacts, sourceItem, (WorkspaceFolder) sourceRootSharedFolder);
logger.trace("The notifies was sent correctly"); logger.trace("The notifies was sent correctly");
}else }else
logger.warn("Notifies moved item: "+sourceItem+ "from share doesn't sent because "+sourceRootSharedFolder+" is not istance of WorkspaceSharedFolder"); logger.warn("Notifies moved item: "+sourceItem+ "from share doesn't sent because "+sourceRootSharedFolder+" is not istance of WorkspaceSharedFolder");
@ -157,7 +158,7 @@ public class NotificationStorageHubUtil {
try { try {
if(isASharedFolder(rootSharedFolder)){ //JUST TO BE SURE if(isFolderAndShared(rootSharedFolder)){ //JUST TO BE SURE
List<String> listPortalLogin = workspace.getSharedFolderMembers(rootSharedFolder.getId()); List<String> listPortalLogin = workspace.getSharedFolderMembers(rootSharedFolder.getId());
logger.debug("StorageHub returned "+ listPortalLogin.size() + " user/s"); logger.debug("StorageHub returned "+ listPortalLogin.size() + " user/s");
@ -206,11 +207,11 @@ public class NotificationStorageHubUtil {
} }
String idSharedFolder = sourceFolderSharedId!=null?sourceFolderSharedId:""; String idSharedFolder = sourceFolderSharedId!=null?sourceFolderSharedId:"";
boolean isRootFolderShared = checkIsRootFolderShared(oldItemId, idSharedFolder); boolean isRootFolderShared = checkIsRootSharedFolder(oldItemId, idSharedFolder);
logger.trace("isRootFolderShared is: "+ isRootFolderShared); logger.trace("isRootFolderShared is: "+ isRootFolderShared);
WorkspaceItem sourceSharedFolder = workspace.getItem(idSharedFolder); WorkspaceItem sourceSharedFolder = workspace.getItem(idSharedFolder);
boolean isSharedFolder = isASharedFolder(sourceSharedFolder); boolean isSharedFolder = isFolderAndShared(sourceSharedFolder);
if(isSharedFolder){ if(isSharedFolder){
logger.trace("idSharedFolder is: "+ idSharedFolder +" is shared folder: "+isSharedFolder); logger.trace("idSharedFolder is: "+ idSharedFolder +" is shared folder: "+isSharedFolder);
@ -219,12 +220,12 @@ public class NotificationStorageHubUtil {
//Notify Removed Item To Sharing? //Notify Removed Item To Sharing?
if(!isRootFolderShared){ if(!isRootFolderShared){
if(sourceSharedFolder instanceof org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder){ //if(isFolderAndShared(sourceSharedFolder)){
np.notifyRemovedItemToSharing(listContacts, oldItemName, (org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder) sourceSharedFolder); np.notifyRemovedItemToSharing(listContacts, oldItemName, (org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder) sourceSharedFolder);
logger.debug("Notification was sent correctly"); logger.debug("Notification was sent correctly");
} //}
else //else
logger.debug("The notifies doesn't sent because "+sourceSharedFolder+ " is not instance of WorkspaceSharedFolder"); // logger.debug("The notifies doesn't sent because "+sourceSharedFolder+ " is not instance of WorkspaceSharedFolder");
}else{ }else{
//Case removed shared folder //Case removed shared folder
@ -272,26 +273,54 @@ public class NotificationStorageHubUtil {
/** /**
* Checks if is a shared folder. * Checks if is folder and shared.
* *
* @param wsItem the ws item * @param wsItem the ws item
* @return true, if is a shared folder * @return true, if is folder and shared
*/ */
public static boolean isASharedFolder(WorkspaceItem wsItem){ public static boolean isFolderAndShared(WorkspaceItem wsItem){
if(wsItem!=null)
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER); if(wsItem!=null) {
if (wsItem.isFolder() && wsItem.isShared()) {
return true;
}
}
return false; return false;
} }
/** /**
* Check is root folder shared. * Checks if is VRE folder.
*
* @param folder the folder
* @return true, if is VRE folder
*/
public static boolean isVREFolder(WorkspaceFolder folder) {
try {
if(folder instanceof WorkspaceVREFolder) {
return true;
}
if(folder instanceof WorkspaceSharedFolder) {
WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) folder;
return sharedFolder.isVreFolder();
}
}catch (Exception e) {
//silent
}
return false;
}
/**
* Check is root shared folder.
* *
* @param itemId the item id * @param itemId the item id
* @param rootFolderSharedId the root folder shared id * @param rootFolderSharedId the root folder shared id
* @return true, if successful * @return true, if successful
*/ */
public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) { public static boolean checkIsRootSharedFolder(String itemId, String rootFolderSharedId) {
logger.trace("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]"); logger.trace("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]");
if(itemId==null) if(itemId==null)
@ -306,4 +335,6 @@ public class NotificationStorageHubUtil {
return false; return false;
} }
} }

View File

@ -12,8 +12,8 @@ import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem; import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder; import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
import org.gcube.portlets.user.workspace.server.util.PortalContextInfo; import org.gcube.portlets.user.workspace.server.util.PortalContextInfo;
import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
@ -58,7 +58,7 @@ public class NotificationsProducerToStorageHub {
* @param workspaceItem the workspace item * @param workspaceItem the workspace item
* @param sharedFolder the shared folder * @param sharedFolder the shared folder
*/ */
public void notifyAddedItemToSharing(final org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace, final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) { public void notifyAddedItemToSharing(final org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace, final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceFolder sharedFolder) {
new Thread() { new Thread() {
@Override @Override
@ -101,9 +101,9 @@ public class NotificationsProducerToStorageHub {
* @param workspace the workspace * @param workspace the workspace
* @param listContacts the list contacts * @param listContacts the list contacts
* @param workspaceItem the workspace item * @param workspaceItem the workspace item
* @param sourceRootSharedFolder the shared folder * @param sourceRootSharedFolder the source root shared folder
*/ */
public void notifyMovedItemToSharing(final org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace, final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sourceRootSharedFolder) { public void notifyMovedItemToSharing(final org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace, final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceFolder sourceRootSharedFolder) {
new Thread() { new Thread() {
@ -159,7 +159,7 @@ public class NotificationsProducerToStorageHub {
logger.trace("Send notifies shared folder was renamed is running..."); logger.trace("Send notifies shared folder was renamed is running...");
if(NotificationStorageHubUtil.checkIsRootFolderShared(folderItem.getId(), idRootSharedFolder)){ if(NotificationStorageHubUtil.checkIsRootSharedFolder(folderItem.getId(), idRootSharedFolder)){
logger.info("Notification not sent because the event is on root shared folder"); logger.info("Notification not sent because the event is on root shared folder");
return; return;
} }
@ -189,7 +189,6 @@ public class NotificationsProducerToStorageHub {
} }
/** /**
* Notify item renamed. * Notify item renamed.
* *
@ -199,7 +198,7 @@ public class NotificationsProducerToStorageHub {
* @param sharedFolder the shared folder * @param sharedFolder the shared folder
* @param workspace the workspace * @param workspace the workspace
*/ */
public void notifyItemRenamed(final List<InfoContactModel> listSharedContact, final String previousName, final WorkspaceItem item, final WorkspaceSharedFolder sharedFolder, final org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace) { public void notifyItemRenamed(final List<InfoContactModel> listSharedContact, final String previousName, final WorkspaceItem item, final WorkspaceFolder sharedFolder, final org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace) {
new Thread(){ new Thread(){
@Override @Override
@ -231,6 +230,7 @@ public class NotificationsProducerToStorageHub {
} }
/** /**
* Notify removed item to sharing. * Notify removed item to sharing.
* *
@ -238,7 +238,7 @@ public class NotificationsProducerToStorageHub {
* @param itemName the item name * @param itemName the item name
* @param sharedFolder the shared folder * @param sharedFolder the shared folder
*/ */
public void notifyRemovedItemToSharing(final List<InfoContactModel> listContacts, final String itemName, final WorkspaceSharedFolder sharedFolder) { public void notifyRemovedItemToSharing(final List<InfoContactModel> listContacts, final String itemName, final WorkspaceFolder sharedFolder) {
new Thread() { new Thread() {