From 4da6326f0b643913c2e48da95c7aab130ef58d30 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Wed, 25 May 2016 10:37:32 +0000 Subject: [PATCH] Group of people is now supported. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/social-networking/social-util-library@128818 82a268e6-3cf1-43bd-a215-b396298e98cf --- .project | 4 +- .settings/org.eclipse.wst.validation.prefs | 2 + .../socialutillibrary/Utils.java | 105 +++++++++++++----- 3 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 .settings/org.eclipse.wst.validation.prefs diff --git a/.project b/.project index 753e8c7..5483214 100644 --- a/.project +++ b/.project @@ -16,12 +16,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/src/main/java/org/gcube/social_networking/socialutillibrary/Utils.java b/src/main/java/org/gcube/social_networking/socialutillibrary/Utils.java index b66e05d..8de43f7 100644 --- a/src/main/java/org/gcube/social_networking/socialutillibrary/Utils.java +++ b/src/main/java/org/gcube/social_networking/socialutillibrary/Utils.java @@ -17,9 +17,13 @@ import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.portal.databook.client.GCubeSocialNetworking; import org.gcube.portlets.widgets.pickitem.shared.ItemBean; import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.RoleManager; import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.GCubeTeam; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.htmlparser.beans.StringBean; import org.slf4j.Logger; @@ -31,7 +35,7 @@ public class Utils { * logger */ private static final Logger logger = LoggerFactory.getLogger(Utils.class); - + /** * * @param preview @@ -47,51 +51,75 @@ public class Utils { * * @param session the Asl Session * @param withinPortal true when is on Liferay portal - * @return the users belonging to the current organization (scope) + * @return the users plus the groups belonging to the current organization (scope) */ - public static ArrayList getOrganizationUsers(String scope, String currUser, boolean withinPortal) { - ArrayList portalUsers = new ArrayList(); + public static ArrayList getDisplayableItemBeans(String scope, String currUser, boolean withinPortal) { + ArrayList portalBeans = new ArrayList(); try { if (withinPortal) { UserManager um = new LiferayUserManager(); GroupManager gm = new LiferayGroupManager(); + RoleManager rm = new LiferayRoleManager(); ScopeBean sb = new ScopeBean(scope); List users = null; + List teams = null; - if (sb.is(Type.INFRASTRUCTURE)) + if (sb.is(Type.INFRASTRUCTURE)){ users = um.listUsersByGroup(gm.getRootVO().getGroupId()); + + // we need to retrieve vres to whom the current user belongs and then retrieve their teams + List groupsOfCurrentUser = gm.listGroupsByUser(um.getUserId(currUser)); + + teams = new ArrayList(); + + // retrieve the teams of each group + for (GCubeGroup gCubeGroup : groupsOfCurrentUser) { + List partialTeamList = rm.listTeamsByGroup(gCubeGroup.getGroupId()); + if(partialTeamList != null && !partialTeamList.isEmpty()) + teams.addAll(partialTeamList); + } + + logger.debug("Teams retrieved are " + teams); + + } 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 users = um.listUsersByGroup(gm.getGroupId(orgName)); + // ask the teams + teams = rm.listTeamsByGroup(gm.getGroupId(orgName)); + logger.debug("Teams retrieved are " + teams); } else { logger.error("Error, you must be in SCOPE VRE OR INFRASTURCTURE, you are in VO SCOPE returning no users"); - return portalUsers; + return portalBeans; } for (GCubeUser user : users) { if (user.getUsername().compareTo("test.user") != 0 && user.getUsername().compareTo(currUser) != 0) { //skip test.user & current user - portalUsers.add(new ItemBean(user.getUserId()+"", user.getUsername(), user.getFullname(), user.getUserAvatarURL())); + portalBeans.add(new ItemBean(user.getUserId()+"", user.getUsername(), user.getFullname(), user.getUserAvatarURL())); } } + for (GCubeTeam gCubeTeam : teams) { + portalBeans.add(new ItemBean(gCubeTeam.getTeamId()+"", gCubeTeam.getTeamName())); + } } else { //test users - portalUsers.add(new ItemBean("12111", "massimiliano.assante", "Test User #1", "")); - portalUsers.add(new ItemBean("14111", "massimiliano.assante", "Test Second User #2", "")); - portalUsers.add(new ItemBean("11511", "massimiliano.assante", "Test Third User", "")); - portalUsers.add(new ItemBean("11611", "massimiliano.assante", "Test Fourth User", "")); - portalUsers.add(new ItemBean("11711", "massimiliano.assante", "Test Fifth User", "")); - portalUsers.add(new ItemBean("11811", "massimiliano.assante", "Test Sixth User", "")); - portalUsers.add(new ItemBean("15811", "massimiliano.assante", "Ninth Testing User", "")); - portalUsers.add(new ItemBean("15811", "massimiliano.assante", "Eighth Testing User", "")); - portalUsers.add(new ItemBean("11211", "giogio.giorgi", "Seventh Test User", "")); - portalUsers.add(new ItemBean("2222", "pino.pinetti", "Tenth Testing User", "")); + portalBeans.add(new ItemBean("12111", "massimiliano.assante", "Test User #1", "")); + portalBeans.add(new ItemBean("14111", "massimiliano.assante", "Test Second User #2", "")); + portalBeans.add(new ItemBean("11511", "massimiliano.assante", "Test Third User", "")); + portalBeans.add(new ItemBean("11611", "massimiliano.assante", "Test Fourth User", "")); + portalBeans.add(new ItemBean("11711", "massimiliano.assante", "Test Fifth User", "")); + portalBeans.add(new ItemBean("11811", "massimiliano.assante", "Test Sixth User", "")); + portalBeans.add(new ItemBean("15811", "massimiliano.assante", "Ninth Testing User", "")); + portalBeans.add(new ItemBean("15811", "massimiliano.assante", "Eighth Testing User", "")); + portalBeans.add(new ItemBean("11211", "giogio.giorgi", "Seventh Test User", "")); + portalBeans.add(new ItemBean("2222", "pino.pinetti", "Tenth Testing User", "")); } } catch (Exception e) { logger.error("Error in server get all contacts ", e); } - return portalUsers; + return portalBeans; } /** @@ -108,7 +136,7 @@ public class Utils { } return hashtags; } - + /** * utility method that extract an url ina text when you paste a link * @param feedText @@ -156,7 +184,7 @@ public class Utils { toReturn = toReturn.replaceAll("\\s\\s","  "); return toReturn; } - + /** * Escape an html string. Escaping data received from the client helps to * prevent cross-site script vulnerabilities. @@ -219,25 +247,46 @@ public class Utils { } return null; } - /** + + /** * convert the mentioned people in HTML anchor and also Encode the params Base64 * @param escapedFeedText * @param taggedPeople * @return */ public static String convertMentionPeopleAnchorHTML(String escapedFeedText, ArrayList taggedPeople, HttpServletRequest request) { - String userProfilePageURL = ""; - userProfilePageURL = PortalContext.getConfiguration().getSiteLandingPagePath(request)+GCubePortalConstants.USER_PROFILE_FRIENDLY_URL; + String pageToRedirectURL = ""; + String httpGETAttrName = ""; + String httpGETAttrValue =""; + for (ItemBean tagged : taggedPeople) { - String taggedHTML = ""+tagged.getAlternativeName()+" "; + new String(Base64.encodeBase64(httpGETAttrName.getBytes()))+"="+ + new String(Base64.encodeBase64(httpGETAttrValue.getBytes()))+"\">"+tagged.getAlternativeName()+" "; escapedFeedText = escapedFeedText.replace(tagged.getAlternativeName(), taggedHTML); } return escapedFeedText; } - + /** * convert the hashtag in HTML anchor and also Encode the params Base64 * @param escapedFeedText @@ -259,7 +308,7 @@ public class Utils { } return escapedFeedText; } - + /** * generate the description parsing the content (Best Guess) * @param link the link to check