|
|
|
@ -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<ItemBean> getOrganizationUsers(String scope, String currUser, boolean withinPortal) {
|
|
|
|
|
ArrayList<ItemBean> portalUsers = new ArrayList<ItemBean>();
|
|
|
|
|
public static ArrayList<ItemBean> getDisplayableItemBeans(String scope, String currUser, boolean withinPortal) {
|
|
|
|
|
ArrayList<ItemBean> portalBeans = new ArrayList<ItemBean>();
|
|
|
|
|
try {
|
|
|
|
|
if (withinPortal) {
|
|
|
|
|
UserManager um = new LiferayUserManager();
|
|
|
|
|
GroupManager gm = new LiferayGroupManager();
|
|
|
|
|
RoleManager rm = new LiferayRoleManager();
|
|
|
|
|
ScopeBean sb = new ScopeBean(scope);
|
|
|
|
|
List<GCubeUser> users = null;
|
|
|
|
|
List<GCubeTeam> 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<GCubeGroup> groupsOfCurrentUser = gm.listGroupsByUser(um.getUserId(currUser));
|
|
|
|
|
|
|
|
|
|
teams = new ArrayList<GCubeTeam>();
|
|
|
|
|
|
|
|
|
|
// retrieve the teams of each group
|
|
|
|
|
for (GCubeGroup gCubeGroup : groupsOfCurrentUser) {
|
|
|
|
|
List<GCubeTeam> 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<ItemBean> 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 = "<a class=\"link\" href=\""+userProfilePageURL
|
|
|
|
|
if (! tagged.isItemGroup()) {
|
|
|
|
|
pageToRedirectURL = PortalContext.getConfiguration().getSiteLandingPagePath(request)+GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
|
|
|
|
|
httpGETAttrName = GCubeSocialNetworking.USER_PROFILE_OID;
|
|
|
|
|
httpGETAttrValue = tagged.getName();
|
|
|
|
|
} else {
|
|
|
|
|
long teamId = Long.parseLong(tagged.getId());
|
|
|
|
|
try {
|
|
|
|
|
GCubeTeam theTeam = new LiferayRoleManager().getTeam(teamId);
|
|
|
|
|
//returns the VRE url e.g. /group/devVRE
|
|
|
|
|
String vreURL = new LiferayGroupManager().getGroup(theTeam.getGroupId()).getFriendlyURL();
|
|
|
|
|
//append the members url
|
|
|
|
|
pageToRedirectURL= vreURL + GCubePortalConstants.GROUP_MEMBERS_FRIENDLY_URL;
|
|
|
|
|
httpGETAttrName = GCubeSocialNetworking.GROUP_MEMBERS_OID;
|
|
|
|
|
httpGETAttrValue = tagged.getId();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String taggedHTML = "<a class=\"link\" href=\""+pageToRedirectURL
|
|
|
|
|
+"?"+
|
|
|
|
|
new String(Base64.encodeBase64(GCubeSocialNetworking.USER_PROFILE_OID.getBytes()))+"="+
|
|
|
|
|
new String(Base64.encodeBase64(tagged.getName().getBytes()))+"\">"+tagged.getAlternativeName()+"</a> ";
|
|
|
|
|
new String(Base64.encodeBase64(httpGETAttrName.getBytes()))+"="+
|
|
|
|
|
new String(Base64.encodeBase64(httpGETAttrValue.getBytes()))+"\">"+tagged.getAlternativeName()+"</a> ";
|
|
|
|
|
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
|
|
|
|
|