From 82d1c2d772b20f63a74afa3301084b57c8aaf989 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 22 Feb 2019 11:00:42 +0000 Subject: [PATCH] ref 13226:StorageHub - Update workspace-sharing-widget to SH https://support.d4science.org/issues/13226 Updated to StorageHub git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@177224 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/GWTWorkspaceServiceImpl.java | 491 +----------------- 1 file changed, 1 insertion(+), 490 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index 80d6653..4546f59 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -74,7 +74,6 @@ import org.gcube.portlets.user.workspace.server.reader.ApplicationProfile; import org.gcube.portlets.user.workspace.server.reader.ApplicationProfileReader; import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex; import org.gcube.portlets.user.workspace.server.tostoragehub.StorageHubToWorkpaceConverter; -import org.gcube.portlets.user.workspace.server.util.DifferenceBetweenInfoContactModel; import org.gcube.portlets.user.workspace.server.util.PortalContextInfo; import org.gcube.portlets.user.workspace.server.util.StringUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil; @@ -1085,18 +1084,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT try { Workspace workspace = getWorkspace(); -<<<<<<< .mine - // workspaceLogger.trace("######### SEND TO: "); - // workspaceLogger.trace("subject " + subject); - // workspaceLogger.trace("body " + body); - -||||||| .r176880 // workspaceLogger.trace("######### SEND TO: "); // workspaceLogger.trace("subject " + subject); // workspaceLogger.trace("body " + body); -======= ->>>>>>> .r177215 // DEBUG for (String contactId : listContactsId) workspaceLogger.trace("contactId " + contactId); @@ -1177,488 +1168,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } -<<<<<<< .mine - /** -||||||| .r176880 - /** - * Share folder. - * - * @param folder the folder - * @param listContacts the list contacts - * @param isNewFolder the is new folder - * @param acl the acl - * @return true, if successful - * @throws Exception the exception - */ - @Override - public boolean shareFolder(FileModel folder, List listContacts, boolean isNewFolder, WorkspaceACL acl) throws Exception { - if(isSessionExpired()) - throw new SessionExpiredException(); - - try { - - Workspace workspace = getWorkspace(); - - workspaceLogger.info("shareFolder "+ folder.getIdentifier() - + " name: "+ folder.getName() - + " parent is: " + folder.getParentFileModel() - + " listContacts size: " + listContacts.size() - +" ACL: "+acl); - - //DEBUG - //printContacts(listContacts); - - List listLogin = UserUtil.getListLoginByInfoContactModel(listContacts); - WorkspaceSharedFolder sharedFolder = null; - List listSharedContact = null; - - boolean sourceFolderIsShared = folder.isShared(); - - if(sourceFolderIsShared){ //if source folder is already share... retrieve old list of sharing to notify - listSharedContact = getListUserSharedByFolderSharedId(folder.getIdentifier()); - } - - if(listLogin.size()>0){ - - if(!isNewFolder){ - - sharedFolder = workspace.shareFolder(listLogin, folder.getIdentifier()); - sharedFolder.setDescription(folder.getDescription()); //SET NEW DESCRIPTION - - //USER REMOVED FROM SHARE - DifferenceBetweenInfoContactModel diff2 = new DifferenceBetweenInfoContactModel(listSharedContact, listContacts); - List listRemovedUsersFromShare = diff2.getDifferentsContacts(); - workspaceLogger.info("List removed user from share has size: "+listRemovedUsersFromShare.size()); - for (InfoContactModel userRemoved : listRemovedUsersFromShare) { - workspaceLogger.info("Unsharing user: "+userRemoved.getLogin()); - sharedFolder.unShare(userRemoved.getLogin()); - } - } - else{ - //IS NEW SHARED FOLDER - FileModel parent = folder.getParentFileModel(); - String parentId = ""; - if(parent!=null){ - parentId = parent.getIdentifier(); - }else{ - workspaceLogger.info("Parent is null, reading root ID from workspace"); - parentId = getWorkspace().getRoot().getId(); - } - - //CHECKING THAT THE PARENT IS NOT LOCKED - checkItemLocked(parentId); - - sharedFolder = workspace.createSharedFolder(folder.getName(), folder.getDescription(), listLogin, parentId); - } - } - - boolean created = sharedFolder==null?false:true; - - if(acl!=null) - setACLs(sharedFolder.getId(), listLogin, acl.getId().toString()); - - if(created){ - NotificationsProducer np = getNotificationProducer(); - if(!sourceFolderIsShared) //if source folder is not already shared - np.notifyFolderSharing(listContacts, sharedFolder); - else{ - // printContacts(listContacts); - np.notifyUpdatedUsersToSharing(listSharedContact, listContacts, sharedFolder); - } - } - - return created; - - }catch (WorkspaceFolderLocked e1){ - throw new Exception(e1.getMessage()); - - } catch (InsufficientPrivilegesException e) { - workspaceLogger.error("Error in shareFolder ", e); - String error = "An error occurred on creating shared folder. "+ e.getMessage(); - throw new Exception(error); - - } catch (ItemAlreadyExistException e) { - workspaceLogger.error("Error in shareFolder ", e); - String error = "An error occurred on creating shared folder. "+ e.getMessage(); - throw new Exception(error); - - } catch (WrongDestinationException e) { - workspaceLogger.error("Error in shareFolder ", e); - String error = "An error occurred on creating shared folder. "+ e.getMessage(); - throw new Exception(error); - - } catch (Exception e) { - workspaceLogger.error("Error in shareFolder ", e); - String error = ConstantsExplorer.SERVER_ERROR+" creating shared folder."; - throw new Exception(error); - } - } - - /* (non-Javadoc) - * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getListUserSharedByFolderSharedId(java.lang.String) - */ - /** - * Gets the list user shared by folder shared id. - * - * @param folderSharedId the folder shared id - * @return the list user shared by folder shared id - * @throws Exception the exception - */ - @Override - public List getListUserSharedByFolderSharedId(String folderSharedId) throws Exception{ - - workspaceLogger.debug("getListUserSharedByFolderSharedId "+ folderSharedId); - - try { - Workspace workspace = getWorkspace(); - - WorkspaceItem wsItem = workspace.getItem(folderSharedId); - - if(NotificationsUtil.isASharedFolder(wsItem)){ - - WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem; - //GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); - List listPortalLogin = wsFolder.getUsers(); - workspaceLogger.debug("HL return "+ listPortalLogin.size() + " user/s"); - - if(isTestMode()) - return GWTWorkspaceBuilder.buildGxtInfoContactFromPortalLoginTestMode(listPortalLogin); - - return GWTWorkspaceBuilder.buildGxtInfoContactsFromPortalLogins(listPortalLogin); - } - else - workspaceLogger.trace("the item with id: "+folderSharedId+ " is not "+WorkspaceItemType.SHARED_FOLDER); - - return new ArrayList(); - - } catch (Exception e) { - workspaceLogger.error("Error in getListUserSharedByItemId ", e); - throw new Exception(e.getMessage()); - } - } - - /* (non-Javadoc) - * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#unSharedFolderByFolderSharedId(java.lang.String) - */ - /** - * Un shared folder by folder shared id. - * - * @param folderSharedId the folder shared id - * @return true, if successful - * @throws Exception the exception - */ - @Override - public boolean unSharedFolderByFolderSharedId(String folderSharedId) throws Exception{ - - boolean unShared = false; - - if(isSessionExpired()) - throw new SessionExpiredException(); - - workspaceLogger.trace("unSharedFolderByFolderSharedId "+ folderSharedId); - - - try { - checkItemLocked(folderSharedId); - - if(isASharedFolder(folderSharedId, true)){ - Workspace workspace = getWorkspace(); - WorkspaceItem wsItem = workspace.getItem(folderSharedId); - workspaceLogger.trace("workspace return an item with name "+wsItem.getName()); - WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem; - - List contacts = getListUserSharedByFolderSharedId(folderSharedId); - String sharedFolderName = wsFolder.getName(); - - //RETURN A NEW FOLDER - wsFolder.unShare(); - workspaceLogger.trace("no error incoming on unsharing"); - unShared = true; - - NotificationsProducer np = getNotificationProducer(); - List purgeMyContact = new ArrayList(contacts.size()-1); - String myLogin = getMyLogin(null).getUsername(); - workspaceLogger.trace("Preparing list of contacts to send un share notification"); - for (InfoContactModel infoContactModel : contacts) { - if(infoContactModel.getLogin().compareToIgnoreCase(getMyLogin(null).getUsername())==0) - workspaceLogger.trace("skipping my login "+myLogin); - else - purgeMyContact.add(infoContactModel); - } - workspaceLogger.trace("UNSHARE WITH: "); - printContacts(purgeMyContact); - - np.notifyFolderUnSharing(purgeMyContact, folderSharedId, sharedFolderName); - } - else{ - String msg = "The item with id: "+folderSharedId+ "is not a base shared folder"; - workspaceLogger.warn("the item with id: "+folderSharedId+ "is not "+WorkspaceItemType.SHARED_FOLDER +" or root shared folder"); - throw new WorkspaceHandledException(msg); - } - - }catch (WorkspaceFolderLocked e1){ - throw new Exception(e1.getMessage()); - - } catch (InternalErrorException e) { - workspaceLogger.error("Error in unSharedFolderByFolderSharedId ", e); - String error = "An error occerred on unsharing folder. "+ e.getMessage(); - throw new Exception(error); - - } catch (WorkspaceHandledException e) { - String error = ConstantsExplorer.SERVER_ERROR+" unshare folder. "+e.getMessage(); - throw new Exception(error); - - } catch (Exception e) { - workspaceLogger.error("Error in unSharedFolderByFolderSharedId ", e); - String error = ConstantsExplorer.SERVER_ERROR+" unshare folder. Refresh folder and " +ConstantsExplorer.TRY_AGAIN; - throw new Exception(error); - } - - return unShared; - } - - /** -======= - @Override - public FileModel shareFolder(FileModel folder, List listContacts, boolean isNewFolder, WorkspaceACL acl) throws Exception { - - if(isSessionExpired()) - throw new SessionExpiredException(); - - try { - - Workspace workspace = getWorkspace(); - - workspaceLogger.info("shareFolder "+ folder.getIdentifier() - + " name: "+ folder.getName() - + " parent is: " + folder.getParentFileModel() - + " listContacts size: " + listContacts.size() - +" ACL: "+acl); - - //DEBUG - //printContacts(listContacts); - - List listLogin = UserUtil.getListLoginByInfoContactModel(listContacts); - WorkspaceSharedFolder sharedFolder = null; - List listSharedContact = null; - - boolean sourceFolderIsShared = folder.isShared(); - if(sourceFolderIsShared){ //if source folder is already share... retrieve old list of sharing to notify - listSharedContact = getListUserSharedByFolderSharedId(folder.getIdentifier()); - } - - if(listLogin.size()>0){ - - if(!isNewFolder){ - - sharedFolder = workspace.shareFolder(listLogin, folder.getIdentifier()); - sharedFolder.setDescription(folder.getDescription()); //SET NEW DESCRIPTION - - //USER REMOVED FROM SHARE - DifferenceBetweenInfoContactModel diff2 = new DifferenceBetweenInfoContactModel(listSharedContact, listContacts); - List listRemovedUsersFromShare = diff2.getDifferentsContacts(); - workspaceLogger.info("List removed user from share has size: "+listRemovedUsersFromShare.size()); - for (InfoContactModel userRemoved : listRemovedUsersFromShare) { - workspaceLogger.info("Unsharing user: "+userRemoved.getLogin()); - sharedFolder.unShare(userRemoved.getLogin()); - } - } - else{ - //IS NEW SHARED FOLDER - FileModel parent = folder.getParentFileModel(); - String parentId = ""; - if(parent!=null){ - parentId = parent.getIdentifier(); - }else{ - workspaceLogger.info("Parent is null, reading root ID from workspace"); - parentId = getWorkspace().getRoot().getId(); - } - - //CHECKING THAT THE PARENT IS NOT LOCKED - checkItemLocked(parentId); - - sharedFolder = workspace.createSharedFolder(folder.getName(), folder.getDescription(), listLogin, parentId); - } - } - - boolean created = sharedFolder==null?false:true; - - if(acl!=null) - setACLs(sharedFolder.getId(), listLogin, acl.getId().toString()); - - FileModel theSharedFolder = null; - - if(created){ - - GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); - WorkspaceFolder parent = sharedFolder.getParent(); - FileModel theParent = builder.buildGXTFileModelItem(parent, null); - theSharedFolder = builder.buildGXTFileModelItem(sharedFolder, theParent); - - NotificationsProducer np = getNotificationProducer(); - if(!sourceFolderIsShared) //if source folder is not already shared - np.notifyFolderSharing(listContacts, sharedFolder); - else{ - // printContacts(listContacts); - np.notifyUpdatedUsersToSharing(listSharedContact, listContacts, sharedFolder); - } - } - - - return theSharedFolder; - - }catch (WorkspaceFolderLocked e1){ - throw new Exception(e1.getMessage()); - - } catch (InsufficientPrivilegesException e) { - workspaceLogger.error("Error in shareFolder ", e); - String error = "An error occurred on creating shared folder. "+ e.getMessage(); - throw new Exception(error); - - } catch (ItemAlreadyExistException e) { - workspaceLogger.error("Error in shareFolder ", e); - String error = "An error occurred on creating shared folder. "+ e.getMessage(); - throw new Exception(error); - - } catch (WrongDestinationException e) { - workspaceLogger.error("Error in shareFolder ", e); - String error = "An error occurred on creating shared folder. "+ e.getMessage(); - throw new Exception(error); - - } catch (Exception e) { - workspaceLogger.error("Error in shareFolder ", e); - String error = ConstantsExplorer.SERVER_ERROR+" creating shared folder."; - throw new Exception(error); - } - } - - /* (non-Javadoc) - * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getListUserSharedByFolderSharedId(java.lang.String) - */ - /** - * Gets the list user shared by folder shared id. - * - * @param folderSharedId the folder shared id - * @return the list user shared by folder shared id - * @throws Exception the exception - */ - @Override - public List getListUserSharedByFolderSharedId(String folderSharedId) throws Exception{ - - workspaceLogger.debug("getListUserSharedByFolderSharedId "+ folderSharedId); - - try { - Workspace workspace = getWorkspace(); - - WorkspaceItem wsItem = workspace.getItem(folderSharedId); - - if(NotificationsUtil.isASharedFolder(wsItem)){ - - WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem; - //GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); - List listPortalLogin = wsFolder.getUsers(); - workspaceLogger.debug("HL return "+ listPortalLogin.size() + " user/s"); - - if(isTestMode()) - return GWTWorkspaceBuilder.buildGxtInfoContactFromPortalLoginTestMode(listPortalLogin); - - return GWTWorkspaceBuilder.buildGxtInfoContactsFromPortalLogins(listPortalLogin); - } - else - workspaceLogger.trace("the item with id: "+folderSharedId+ " is not "+WorkspaceItemType.SHARED_FOLDER); - - return new ArrayList(); - - } catch (Exception e) { - workspaceLogger.error("Error in getListUserSharedByItemId ", e); - throw new Exception(e.getMessage()); - } - } - - /* (non-Javadoc) - * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#unSharedFolderByFolderSharedId(java.lang.String) - */ - /** - * Un shared folder by folder shared id. - * - * @param folderSharedId the folder shared id - * @return true, if successful - * @throws Exception the exception - */ - @Override - public boolean unSharedFolderByFolderSharedId(String folderSharedId) throws Exception{ - - boolean unShared = false; - - if(isSessionExpired()) - throw new SessionExpiredException(); - - workspaceLogger.trace("unSharedFolderByFolderSharedId "+ folderSharedId); - - - try { - checkItemLocked(folderSharedId); - - if(isASharedFolder(folderSharedId, true)){ - Workspace workspace = getWorkspace(); - WorkspaceItem wsItem = workspace.getItem(folderSharedId); - workspaceLogger.trace("workspace return an item with name "+wsItem.getName()); - WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem; - - List contacts = getListUserSharedByFolderSharedId(folderSharedId); - String sharedFolderName = wsFolder.getName(); - - //RETURN A NEW FOLDER - wsFolder.unShare(); - workspaceLogger.trace("no error incoming on unsharing"); - unShared = true; - - NotificationsProducer np = getNotificationProducer(); - List purgeMyContact = new ArrayList(contacts.size()-1); - String myLogin = getMyLogin(null).getUsername(); - workspaceLogger.trace("Preparing list of contacts to send un share notification"); - for (InfoContactModel infoContactModel : contacts) { - if(infoContactModel.getLogin().compareToIgnoreCase(getMyLogin(null).getUsername())==0) - workspaceLogger.trace("skipping my login "+myLogin); - else - purgeMyContact.add(infoContactModel); - } - workspaceLogger.trace("UNSHARE WITH: "); - printContacts(purgeMyContact); - - np.notifyFolderUnSharing(purgeMyContact, folderSharedId, sharedFolderName); - } - else{ - String msg = "The item with id: "+folderSharedId+ "is not a base shared folder"; - workspaceLogger.warn("the item with id: "+folderSharedId+ "is not "+WorkspaceItemType.SHARED_FOLDER +" or root shared folder"); - throw new WorkspaceHandledException(msg); - } - - }catch (WorkspaceFolderLocked e1){ - throw new Exception(e1.getMessage()); - - } catch (InternalErrorException e) { - workspaceLogger.error("Error in unSharedFolderByFolderSharedId ", e); - String error = "An error occerred on unsharing folder. "+ e.getMessage(); - throw new Exception(error); - - } catch (WorkspaceHandledException e) { - String error = ConstantsExplorer.SERVER_ERROR+" unshare folder. "+e.getMessage(); - throw new Exception(error); - - } catch (Exception e) { - workspaceLogger.error("Error in unSharedFolderByFolderSharedId ", e); - String error = ConstantsExplorer.SERVER_ERROR+" unshare folder. Refresh folder and " +ConstantsExplorer.TRY_AGAIN; - throw new Exception(error); - } - - return unShared; - } - - /** ->>>>>>> .r177215 - * Gets the list parents by item identifier. + /** Gets the list parents by item identifier. * * @param itemIdentifier * the item identifier