76 lines
3.5 KiB
Java
76 lines
3.5 KiB
Java
package org.gcube.portlets.user.newsfeed.server;
|
|
|
|
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.portal.custom.communitymanager.OrganizationsUtil;
|
|
import org.gcube.portlets.widgets.pickuser.shared.PickingUser;
|
|
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;
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
public class UsersUtil {
|
|
private static final Logger _log = LoggerFactory.getLogger(UsersUtil.class);
|
|
/**
|
|
*
|
|
* @param session the Asl Session
|
|
* @param withinPortal true when is on Liferay portal
|
|
* @return the users belonging to the current organization (scope)
|
|
*/
|
|
public static ArrayList<PickingUser> getOrganizationUsers(String scope, String currUser, boolean withinPortal) {
|
|
ArrayList<PickingUser> portalUsers = new ArrayList<PickingUser>();
|
|
try {
|
|
if (withinPortal) {
|
|
UserManager um = new LiferayUserManager();
|
|
GroupManager gm = new LiferayGroupManager();
|
|
ScopeBean sb = new ScopeBean(scope);
|
|
List<UserModel> users = null;
|
|
|
|
if (sb.is(Type.INFRASTRUCTURE))
|
|
users = 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
|
|
users = um.listUsersByGroup(gm.getGroupId(orgName));
|
|
}
|
|
else {
|
|
_log.error("Error, you must be in SCOPE VRE OR INFRASTURCTURE, you are in VO SCOPE returning no users");
|
|
return portalUsers;
|
|
}
|
|
for (UserModel user : users) {
|
|
if (user.getScreenName().compareTo("test.user") != 0 && user.getScreenName().compareTo(currUser) != 0) { //skip test.user & current user
|
|
String thumbnailURL = "";
|
|
com.liferay.portal.model.UserModel lifeUser = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), user.getScreenName());
|
|
thumbnailURL = "/image/user_male_portrait?img_id="+lifeUser.getPortraitId();
|
|
portalUsers.add(new PickingUser(user.getUserId(), user.getScreenName(), user.getFullname(), thumbnailURL));
|
|
}
|
|
}
|
|
}
|
|
else { //test users
|
|
portalUsers.add(new PickingUser("12111", "massimiliano.assante", "Test User #1", ""));
|
|
portalUsers.add(new PickingUser("14111", "massimiliano.assante", "Test Second User #2", ""));
|
|
portalUsers.add(new PickingUser("11511", "massimiliano.assante", "Test Third User", ""));
|
|
portalUsers.add(new PickingUser("11611", "massimiliano.assante", "Test Fourth User", ""));
|
|
portalUsers.add(new PickingUser("11711", "massimiliano.assante", "Test Fifth User", ""));
|
|
portalUsers.add(new PickingUser("11811", "massimiliano.assante", "Test Sixth User", ""));
|
|
portalUsers.add(new PickingUser("15811", "massimiliano.assante", "Ninth Testing User", ""));
|
|
portalUsers.add(new PickingUser("15811", "massimiliano.assante", "Eighth Testing User", ""));
|
|
portalUsers.add(new PickingUser("11211", "giogio.giorgi", "Seventh Test User", ""));
|
|
portalUsers.add(new PickingUser("2222", "pino.pinetti", "Tenth Testing User", ""));
|
|
}
|
|
} catch (Exception e) {
|
|
_log.error("Error in server get all contacts ", e);
|
|
}
|
|
return portalUsers;
|
|
}
|
|
}
|