From be265c4147bf0f6f03ed183d54930d882ac4e0d2 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Mon, 3 Aug 2015 10:10:59 +0000 Subject: [PATCH] 401: Tabular Data Manager Portlet allows to Share Tabular Data Resources with the whole set of portal users Task-Url: https://support.d4science.org/issues/401 Added code to read users for organization git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@117631 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/WorkspaceSharingServiceImpl.java | 159 ++++++++++++------ .../server/util/UserUtil.java | 67 +++++++- 2 files changed, 173 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java index e99a38a..428b1e8 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java @@ -34,10 +34,7 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.SessionExpiredEx import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL; import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO; import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE; -import org.gcube.vomanagement.usermanagement.GroupManager; -import org.gcube.vomanagement.usermanagement.UserManager; -import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; -import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager; +import org.gcube.vomanagement.usermanagement.model.UserModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,6 +42,9 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet; /** * The server side implementation of the RPC service. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Aug 3, 2015 */ @SuppressWarnings("serial") public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements @@ -53,40 +53,68 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements protected static Logger logger = LoggerFactory.getLogger(WorkspaceSharingServiceImpl.class); + /** + * Gets the GWT workspace builder. + * + * @return the GWT workspace builder + */ protected GWTWorkspaceSharingBuilder getGWTWorkspaceBuilder() { return WsUtil.getGWTWorkspaceSharingBuilder(this.getThreadLocalRequest().getSession()); } + /** + * Gets the workspace. + * + * @return the workspace + * @throws InternalErrorException the internal error exception + * @throws HomeNotFoundException the home not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ protected Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException { return WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); } + /** + * Gets the notification producer. + * + * @return the notification producer + */ protected NotificationsProducer getNotificationProducer(){ return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession())); } + /** + * Gets the scope util filter. + * + * @return the scope util filter + */ protected ScopeUtility getScopeUtilFilter(){ return WsUtil.getScopeUtilFilter(this.getThreadLocalRequest().getSession()); } + /** + * Checks if is test mode. + * + * @return true, if is test mode + */ protected boolean isTestMode(){ return !WsUtil.isWithinPortal(); //IS NOT INTO PORTAL } + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getAllContacts(boolean, boolean) + */ @Override public List getAllContacts(boolean readGroupsFromHL, boolean readGroupsFromPortal) throws Exception { try { ASLSession aslSession = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()); //THIS FORCE THE SESSION CREATION logger.info("Get all contacts"); - -// WorkspaceItem parent = workspace.getItem(parentFileModel.getIdentifier()); //get item from workspace -// workspace.getAllScope(); - + GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder(); if(isTestMode()){ @@ -97,32 +125,26 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements InfoContactModel contact = GWTWorkspaceSharingBuilder.getHashTestUsers().get(key); listContactsModel.add(contact); } - -// -// listContactsModel.add(new InfoContactModel("antonio.gioia", "antonio.gioia", "Antonio Gioia", false)); -// listContactsModel.add(new InfoContactModel("fabio.sinibaldi", "fabio.sinibaldi", "Fabio Sinibaldi", false)); -// listContactsModel.add(new InfoContactModel("pasquale.pagano", "pasquale.pagano", "Pasquale Pagano", false)); -//// listContactsModel.add(new InfoContactModel(WsUtil.TEST_USER, WsUtil.TEST_USER, WsUtil.TEST_USER_FULL_NAME)); -// listContactsModel.add(new InfoContactModel("francesco.mangiacrapa", "francesco.mangiacrapa", "Francesco Mangiacrapa", false)); -// listContactsModel.add(new InfoContactModel("massimiliano.assante", "massimiliano.assante", "Massimiliano Assante", false)); -// listContactsModel.add(new InfoContactModel("valentina.marioli", "valentina.marioli", "Valentina Marioli", false)); -// listContactsModel.add(new InfoContactModel("leonardo.candela", "leonardo.candela", "Leonardo Candela", false)); -// -// listContactsModel.add(new InfoContactModel("/gube/devsec/devVRE", "/gube/devsec/devVRE", "devVRE", true)); - -// listContactsModel.addAll(getFakeGroups()); - return listContactsModel; - } - - UserManager userManag = new LiferayUserManager(); + //READING USERS FROM VRE + /*UserManager userManag = new LiferayUserManager(); GroupManager gm = new LiferayGroupManager(); - String groupId = gm.getRootVO().getGroupId(); - - logger.trace("Liferay User Manager getting list users by group: "+groupId); + String aslSessionGN = aslSession.getGroupName(); + logger.info("aslSession.getGroupName(): "+ aslSessionGN); + String groupId = gm.getGroupId(aslSessionGN); + logger.info("groupId from GroupManager: "+ groupId); + logger.info("Liferay User Manager getting list users by group: "+groupId); List listContactsModel = builder.buildGXTListContactsModelFromUserModel(userManag.listUsersByGroup(groupId)); + */ + List users = UserUtil.getOrganizationUsers(aslSession.toString()); + + if(users==null) + throw new Exception("An error occurred on recovering users from Portal, try again later"); + + List listContactsModel = builder.buildGXTListContactsModelFromUserModel(users); + if(readGroupsFromHL){ logger.info("Reading group names from HL.."); org.gcube.common.homelibrary.home.workspace.usermanager.UserManager hlUserManager = HomeLibrary.getHomeManagerFactory().getUserManager(); @@ -167,9 +189,10 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements throw new Exception(e.getMessage()); } } - - + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getListUserSharedByFolderSharedId(java.lang.String) + */ @Override public List getListUserSharedByFolderSharedId(String folderSharedId) throws Exception{ @@ -213,6 +236,9 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } } + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getOwnerByItemId(java.lang.String) + */ @Override public InfoContactModel getOwnerByItemId(String itemId) throws Exception { @@ -234,9 +260,10 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } /** - * - * @return - * @throws Exception + * Gets the AC ls. + * + * @return the AC ls + * @throws Exception the exception */ @Override public List getACLs() throws Exception{ @@ -251,12 +278,18 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } } + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getMyLogin() + */ @Override public String getMyLogin(){ ASLSession asl = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()); return asl.getUsername(); } + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getFileModelByWorkpaceItemId(java.lang.String) + */ @Override public FileModel getFileModelByWorkpaceItemId(String itemId) throws Exception { @@ -320,6 +353,11 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements // DEBUG + /** + * Prints the contacts. + * + * @param listContacts the list contacts + */ private void printContacts(List listContacts) { boolean testMode = isTestMode(); @@ -337,6 +375,9 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#shareFolder(org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel, java.util.List, boolean, org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL) + */ @Override public boolean shareFolder(FileModel folder, List listContacts, boolean isNewFolder, WorkspaceACL acl) throws Exception { @@ -430,11 +471,12 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } /** - * - * @param folderId - * @param listLogins - * @param aclType - * @throws Exception + * Sets the ac ls. + * + * @param folderId the folder id + * @param listLogins the list logins + * @param aclType the acl type + * @throws Exception the exception */ public void setACLs(String folderId, List listLogins, String aclType) throws Exception{ try { @@ -539,8 +581,9 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements /** - * DEBUG - * @return + * DEBUG. + * + * @return the fake groups */ private List getFakeGroups(){ @@ -563,6 +606,11 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements return listContactsModel; } + /** + * The main method. + * + * @param args the arguments + */ public static void main(String[] args) { WorkspaceSharingServiceImpl impl = new WorkspaceSharingServiceImpl(); @@ -642,9 +690,11 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } /** - * + * Gets the AC ls description for shared folder id. + * + * @param folderId the folder id * @return Formatted HTML DIV containing ACLs description for folderId - * @throws Exception + * @throws Exception the exception */ @Override public String getACLsDescriptionForSharedFolderId(String folderId) throws Exception{ @@ -661,10 +711,11 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } /** - * - * @param folderId - * @return - * @throws Exception + * Gets the shared folder for id. + * + * @param folderId the folder id + * @return the shared folder for id + * @throws Exception the exception */ private WorkspaceFolder getSharedFolderForId(String folderId) throws Exception{ @@ -708,10 +759,11 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } /** - * - * @param itemID + * Checks if is a shared folder. + * + * @param itemID the item id * @param asRoot true check if itemID is root, not otherwise - * @return + * @return true, if is a shared folder */ public boolean isASharedFolder(String itemID, boolean asRoot){ @@ -731,6 +783,13 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements } } + /** + * Checks if is a shared folder. + * + * @param item the item + * @param asRoot the as root + * @return true, if is a shared folder + */ public boolean isASharedFolder(WorkspaceItem item, boolean asRoot){ try { diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java index e36d385..9c3efd8 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java @@ -3,11 +3,15 @@ package org.gcube.portlets.widgets.workspacesharingwidget.server.util; import java.util.ArrayList; import java.util.List; +import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; +import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager; import org.gcube.vomanagement.usermanagement.model.UserModel; import org.slf4j.Logger; @@ -15,6 +19,12 @@ import org.slf4j.LoggerFactory; +/** + * The Class UserUtil. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Aug 3, 2015 + */ public class UserUtil { static UserManager um = new LiferayUserManager(); @@ -22,9 +32,10 @@ public class UserUtil { /** - * - * @param user - * @return + * Gets the user full name. + * + * @param portalLogin the portal login + * @return the user full name */ public static String getUserFullName(String portalLogin){ // return user.getPortalLogin(); //for testing in eclipse @@ -73,6 +84,44 @@ public class UserUtil { return portalLogin; } + + /** + * Gets the organization users. + * + * @param scope the scope + * @return the organization users + */ + public static List getOrganizationUsers(String scope) { + try { + UserManager um = new LiferayUserManager(); + GroupManager gm = new LiferayGroupManager(); + ScopeBean sb = new ScopeBean(scope); + + if (sb.is(Type.INFRASTRUCTURE)){ + logger.info("Returning users by group for INFRASTRUCTURE: "+gm.getRootVO().getGroupId()); + return um.listUsersByGroup(gm.getRootVO().getGroupId()); + }else if (sb.is(Type.VRE)) { //must be in VRE + //get the name from the scope + String orgName = scope.substring(scope.lastIndexOf("/")+1, scope.length()); + //ask the users + logger.info("Returning users by group for VRE: "+orgName); + return um.listUsersByGroup(gm.getGroupId(orgName)); + }else { + logger.error("Error, you must be in SCOPE VRE OR INFRASTURCTURE, you are in VO SCOPE returning no users"); + return null; + } + } catch (Exception e) { + logger.error("Error in server get all contacts ", e); + } + return null; + } + + /** + * 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){ List listUsers = new ArrayList(); @@ -84,6 +133,12 @@ public class UserUtil { return listUsers; } + /** + * Separate users names to comma. + * + * @param listContacts the list contacts + * @return the string + */ public static String separateUsersNamesToComma(List listContacts){ String users = ""; @@ -99,6 +154,12 @@ public class UserUtil { } + /** + * Separate full name to comma for portal login. + * + * @param listLogin the list login + * @return the string + */ public static String separateFullNameToCommaForPortalLogin(List listLogin){ String users = "";