diff --git a/CHANGELOG.md b/CHANGELOG.md index c2761be..286ebe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,24 +3,31 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v2.1.0-SNAPSHOT] - 2022-05-02 + +#### Enhancements + +- [#23225] Updated the method to read the members of VREs + + ## [v2.0.6] - 2020-07-15 -[#19317] Just to include the storagehub-client-wrapper at 1.0.0 version +- [#19317] Just to include the storagehub-client-wrapper at 1.0.0 version #### Fixes -[#19243] upload archive facility does not work properly with Windows OS +- [#19243] upload archive facility does not work properly with Windows OS -[#19232] manage file names that use special characters +- [#19232] manage file names that use special characters ## [v2.0.5] - 2020-05-14 #### Fixes -[#19243] upload archive facility does not work properly with Windows OS +- [#19243] upload archive facility does not work properly with Windows OS -[#19232] manage file names that use special characters +- [#19232] manage file names that use special characters ## [v2.0.4] - 2019-12-19 diff --git a/pom.xml b/pom.xml index fdaeb80..4e91257 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.widgets workspace-uploader jar - 2.0.6 + 2.1.0-SNAPSHOT Workspace Uploader Widget Workspace Uploader Widget allows your application to upload file/s in the gCube Workspace @@ -37,7 +37,7 @@ org.gcube.distribution maven-portal-bom - 3.6.0 + 3.6.3 pom import 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 2197863..9ed67a4 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 @@ -18,6 +18,7 @@ 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; +import org.gcube.common.storagehubwrapper.shared.Member; import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem; import org.gcube.portlets.widgets.workspaceuploader.server.util.UserUtil; import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel; @@ -25,96 +26,97 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - - /** * The Class NotificationsWorkspaceUploader. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) - * Jul 2, 2018 + * Jul 2, 2018 */ public class NotificationsWorkspaceUploader { - protected static Logger logger = LoggerFactory.getLogger(NotificationsWorkspaceUploader.class); - /** * Check send notify changed item to share. * - * @param storageWrapper the storage wrapper - * @param request the request - * @param currUser the curr user - * @param scopeGroupId the scope group id - * @param np the np - * @param httpSession the http session - * @param sourceItem the source item - * @param sourceSharedId the source shared id + * @param storageWrapper the storage wrapper + * @param request the request + * @param currUser the curr user + * @param scopeGroupId the scope group id + * @param np the np + * @param httpSession the http session + * @param sourceItem the source item + * @param sourceSharedId the source shared id * @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) { + 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.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.debug("shareChangeCondition add item: "+shareChangeCondition); + if (folderDestinationItem != null) { - //if shareChangeCondition is true.. notifies added item to sharing - if(shareChangeCondition){ + 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.debug("shareChangeCondition add item: " + shareChangeCondition); + + // if shareChangeCondition is true.. notifies added item to sharing + if (shareChangeCondition) { FolderItem folderDest = (FolderItem) folderDestinationItem; SharedFolder rootSharedFolder = null; - try{ - FolderItem sharedFolder = storageWrapper.getStorageHubClientService().getRootSharedFolder(folderDest.getId()); + try { + FolderItem sharedFolder = storageWrapper.getStorageHubClientService() + .getRootSharedFolder(folderDest.getId()); rootSharedFolder = (SharedFolder) sharedFolder; - }catch(Exception e){ - //silent - } - - //Reading memmbers from rootSharedFolder - List listLogins = storageWrapper.getWorkspace().getSharedFolderMembers(rootSharedFolder.getId()); - List listContacts = new ArrayList(listLogins.size()); - for (String login : listLogins) { - listContacts.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login))); + } catch (Exception e) { + // silent } + // Reading members from rootSharedFolder + List listMemebers = storageWrapper.getWorkspace() + .getSharedFolderMembers(rootSharedFolder.getId()); + + List listContacts = UserUtil.listMembersToListContact(listMemebers); + SocialFileItem socialItem = NotificationMapper.toSocialItem(storageWrapper, sourceItem); - //TO folderDest or rootSharedFolder?? + // 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 + List 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) + // SWITCH BETWEEN ADDED OR UPDATED + if (!isUpdate) np.notifyAddedItemToSharing(listContacts, socialItem, socialFolder); else np.notifyUpdatedItemToSharing(listContacts, socialItem, socialFolder); } - } - else + } else logger.trace("folder destination is not shared"); - }catch (Exception e) { - logger.error("An error occurred in checkSendNotifyAddItemToShare ",e); + } catch (Exception e) { + logger.error("An error occurred in checkSendNotifyAddItemToShare ", e); } - }else - logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null"); + } else + logger.warn( + "The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null"); } /** @@ -123,30 +125,29 @@ public class NotificationsWorkspaceUploader { * @param wsItem the ws item * @return true, if is a shared folder */ - public static boolean isASharedFolder(WorkspaceItem wsItem){ - if(wsItem!=null) + public static boolean isASharedFolder(WorkspaceItem wsItem) { + if (wsItem != null) return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER); return false; } - /** * Checks if is a shared folder for id. * * @param workspace the workspace - * @param itemId the item id + * @param itemId the item id * @return true, if is a shared folder for id */ - public static boolean isASharedFolderForId(Workspace workspace, String itemId){ + public static boolean isASharedFolderForId(Workspace workspace, String itemId) { - if(itemId==null || itemId.isEmpty()) + if (itemId == null || itemId.isEmpty()) return false; try { WorkspaceItem wsItem = workspace.getItem(itemId); - if(wsItem!=null) + if (wsItem != null) return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER); return false; @@ -156,24 +157,24 @@ public class NotificationsWorkspaceUploader { } } - /** * Check is root folder shared. * - * @param itemId the item id + * @param itemId the item id * @param rootFolderSharedId the root folder shared id * @return true, if successful */ public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) { - logger.trace("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]"); - if(itemId==null) + logger.trace("checkIsRootFolderShared between [itemid: " + itemId + ", rootFolderSharedId: " + + rootFolderSharedId + "]"); + if (itemId == null) return false; - if(rootFolderSharedId==null) + if (rootFolderSharedId == null) return false; - if(itemId.compareTo(rootFolderSharedId)==0) + if (itemId.compareTo(rootFolderSharedId) == 0) return true; return false; diff --git a/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/util/UserUtil.java b/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/util/UserUtil.java index 5542b4f..a50b6f9 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/util/UserUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/workspaceuploader/server/util/UserUtil.java @@ -3,8 +3,10 @@ package org.gcube.portlets.widgets.workspaceuploader.server.util; import java.util.ArrayList; import java.util.List; +import org.gcube.common.storagehubwrapper.shared.Member; import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel; import org.gcube.vomanagement.usermanagement.UserManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; @@ -12,31 +14,27 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - - /** * The Class UserUtil. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Aug 3, 2015 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Aug 3, 2015 */ public class UserUtil { static UserManager um = new LiferayUserManager(); protected static Logger logger = LoggerFactory.getLogger(UserUtil.class); - /** * Gets the user full name. * * @param portalLogin the portal login * @return the user full name */ - public static String getUserFullName(String portalLogin){ - if(portalLogin==null) + public static String getUserFullName(String portalLogin) { + if (portalLogin == null) return ""; - if (WsUtil.isWithinPortal()) { //INTO PORTAL + if (WsUtil.isWithinPortal()) { // INTO PORTAL GCubeUser curr = null; @@ -46,38 +44,80 @@ public class UserUtil { } catch (UserManagementSystemException e) { - logger.error("An error occurred in getUserByUsername "+e,e); + logger.error("An error occurred in getUserByUsername " + e, e); } catch (UserRetrievalFault e) { - logger.error("An error occurred in getUserByUsername "+e,e); + logger.error("An error occurred in getUserByUsername " + e, e); } - }catch (Exception e) { - logger.error("An error occurred in getUserByUsername "+e,e); - logger.warn("Return portal login "+portalLogin); + } catch (Exception e) { + logger.error("An error occurred in getUserByUsername " + e, e); + logger.warn("Return portal login " + portalLogin); return portalLogin; } - if (curr != null){ + if (curr != null) { // logger.trace("Return "+curr.getFullname() +" full name for: "+portalLogin); return curr.getFullname(); } - }else{ + } else { logger.trace("DEVELOPEMENT MODE ON"); } - logger.trace("Return portal login as full name for: "+portalLogin); + logger.trace("Return portal login as full name for: " + portalLogin); return portalLogin; } + public static List listMembersToListContact(List members) { + logger.info("listMembersToListContact called for " + members.size() + " member/s"); + + List listContacts = new ArrayList(); + UserManager userManager = new LiferayUserManager(); + + for (Member member : members) { + logger.debug("Resolving member: " + member); + boolean isGroup = member.getMemberType().equals(Member.TYPE.GROUP) ? true : false; + + if (!isGroup) { + // HE/SHE IS A USER + listContacts.add(new ContactModel(member.getIdentity(), member.getIdentity(), false, + UserUtil.getUserFullName(member.getIdentity()))); + } else { + // HE/SHE IS A GROUP + logger.debug("The member: " + member + + " is a group, resolving list of Users from "+LiferayUserManager.class.getSimpleName()+" for the group name: " + + member.getName()); + try { + List listUsers = userManager.listUsersByGroupName(member.getName()); + + if (listUsers != null) { + logger.debug("List of user for groupName are: " + listUsers.size()); + for (GCubeUser user : listUsers) { + listContacts.add(new ContactModel(user.getUsername(), user.getUsername(), false, + user.getFullname())); + } + } else { + logger.warn("List of user for groupName: " + member.getName() + " is null"); + } + } catch (UserManagementSystemException | GroupRetrievalFault | UserRetrievalFault e) { + logger.warn("Error occurrend on resolving the member: " + member.getName(), e); + } + } + } + + logger.info("Returning " + listContacts.size() + " from members"); + return listContacts; + + } + /** * Gets the list login by info contact model. * * @param listContacts the list contacts * @return the list login by info contact model */ - public static List getListLoginByInfoContactModel(List listContacts){ + public static List getListLoginByInfoContactModel(List listContacts) { List listUsers = new ArrayList(); @@ -94,46 +134,45 @@ public class UserUtil { * @param listContacts the list contacts * @return the string */ - public static String separateUsersNamesToComma(List listContacts){ + public static String separateUsersNamesToComma(List listContacts) { String users = ""; - for (int i = 0; i < listContacts.size()-1; i++) { - users+= listContacts.get(i).getFullName() + ", "; + for (int i = 0; i < listContacts.size() - 1; i++) { + users += listContacts.get(i).getFullName() + ", "; } - if(listContacts.size()>1) - users += listContacts.get(listContacts.size()-1).getFullName(); + if (listContacts.size() > 1) + users += listContacts.get(listContacts.size() - 1).getFullName(); return users; } - /** * Separate full name to comma for portal login. * * @param listLogin the list login * @return the string */ - public static String separateFullNameToCommaForPortalLogin(List listLogin){ + public static String separateFullNameToCommaForPortalLogin(List listLogin) { String users = ""; - logger.trace("SeparateFullNameToCommaForPortalLogin converting: "+listLogin); + logger.trace("SeparateFullNameToCommaForPortalLogin converting: " + listLogin); - //N-1 MEMBERS - for (int i = 0; i < listLogin.size()-1; i++) { + // N-1 MEMBERS + for (int i = 0; i < listLogin.size() - 1; i++) { // logger.trace("Converting: "+i+") "+listLogin.get(i)); - users+= getUserFullName(listLogin.get(i)) + ", "; + users += getUserFullName(listLogin.get(i)) + ", "; } - //LAST MEMBER - if(listLogin.size()>=1){ + // LAST MEMBER + if (listLogin.size() >= 1) { // logger.trace("Converting: "+(listLogin.size()-1)+") " +listLogin.get(listLogin.size()-1)); - users += getUserFullName(listLogin.get(listLogin.size()-1)); + users += getUserFullName(listLogin.get(listLogin.size() - 1)); } - logger.trace("SeparateFullNameToCommaForPortalLogin returning: "+users); + logger.trace("SeparateFullNameToCommaForPortalLogin returning: " + users); return users; }