302 lines
9.1 KiB
Java
302 lines
9.1 KiB
Java
|
package org.gcube.vomanagement.usermanagement.impl;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.List;
|
||
|
|
||
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||
|
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||
|
import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault;
|
||
|
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.model.Email;
|
||
|
import org.gcube.vomanagement.usermanagement.model.GroupModel;
|
||
|
import org.gcube.vomanagement.usermanagement.model.RoleModel;
|
||
|
import org.gcube.vomanagement.usermanagement.model.UserModel;
|
||
|
import org.slf4j.Logger;
|
||
|
import org.slf4j.LoggerFactory;
|
||
|
|
||
|
import com.liferay.portal.kernel.exception.PortalException;
|
||
|
import com.liferay.portal.kernel.exception.SystemException;
|
||
|
import com.liferay.portal.kernel.util.GetterUtil;
|
||
|
import com.liferay.portal.kernel.util.PropsUtil;
|
||
|
import com.liferay.portal.model.Company;
|
||
|
import com.liferay.portal.model.EmailAddress;
|
||
|
import com.liferay.portal.model.Group;
|
||
|
import com.liferay.portal.model.User;
|
||
|
import com.liferay.portal.service.CompanyLocalServiceUtil;
|
||
|
import com.liferay.portal.service.GroupLocalServiceUtil;
|
||
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||
|
import com.liferay.portlet.sites.util.SitesUtil;
|
||
|
|
||
|
public class LiferayUserManager implements UserManager {
|
||
|
/**
|
||
|
* logger
|
||
|
*/
|
||
|
private static final Logger _log = LoggerFactory.getLogger(LiferayUserManager.class);
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
public static final String DEFAULT_COMPANY_WEB_ID = "liferay.com";
|
||
|
|
||
|
public static Company getCompany() throws PortalException, SystemException {
|
||
|
return CompanyLocalServiceUtil.getCompanyByWebId(getDefaultCompanyWebId());
|
||
|
}
|
||
|
/**
|
||
|
*
|
||
|
* @return the default company web-id (e.g. iMarine.eu)
|
||
|
*/
|
||
|
public static String getDefaultCompanyWebId() {
|
||
|
String defaultWebId = "";
|
||
|
try {
|
||
|
defaultWebId = GetterUtil.getString(PropsUtil.get("company.default.web.id"));
|
||
|
}
|
||
|
catch (NullPointerException e) {
|
||
|
_log.info("Cound not find property company.default.web.id in portal.ext file returning default web id: " + DEFAULT_COMPANY_WEB_ID);
|
||
|
return DEFAULT_COMPANY_WEB_ID;
|
||
|
}
|
||
|
return defaultWebId;
|
||
|
}
|
||
|
|
||
|
private static UserModel mapLRUser(User u) throws PortalException, SystemException {
|
||
|
if (u != null) {
|
||
|
List<Email> emails = new ArrayList<Email>();
|
||
|
for (EmailAddress e : u.getEmailAddresses()) {
|
||
|
emails.add(new Email(e.getAddress(), e.getType().toString(), e.isPrimary()));
|
||
|
}
|
||
|
return new UserModel(
|
||
|
u.getUserId(),
|
||
|
u.getScreenName(),
|
||
|
u.getEmailAddress(),
|
||
|
u.getFirstName(),
|
||
|
u.getMiddleName(),
|
||
|
u.getLastName(),
|
||
|
u.getFullName(),
|
||
|
u.getCreateDate().getTime(),
|
||
|
u.getPortraitId()+"",
|
||
|
u.isMale(),
|
||
|
u.getJobTitle(),
|
||
|
emails);
|
||
|
}
|
||
|
else
|
||
|
return null;
|
||
|
}
|
||
|
/**
|
||
|
* {@inheritDoc}
|
||
|
*/
|
||
|
@Override
|
||
|
public UserModel getUserByUsername(String username) throws UserManagementSystemException, UserRetrievalFault {
|
||
|
User toGet = null;
|
||
|
UserModel toReturn = null;
|
||
|
try {
|
||
|
toGet = UserLocalServiceUtil.getUserByScreenName(getCompany().getCompanyId(), username);
|
||
|
toReturn = mapLRUser(toGet);
|
||
|
} catch (PortalException e) {
|
||
|
throw new UserRetrievalFault("User not existing", e);
|
||
|
} catch (SystemException e) {
|
||
|
throw new UserManagementSystemException(e.getMessage(), e);
|
||
|
}
|
||
|
return toReturn;
|
||
|
}
|
||
|
/**
|
||
|
* {@inheritDoc}
|
||
|
*/
|
||
|
@Override
|
||
|
public UserModel getUserByEmail(String emailAddress) throws UserManagementSystemException, UserRetrievalFault {
|
||
|
User toGet = null;
|
||
|
UserModel toReturn = null;
|
||
|
try {
|
||
|
toGet = UserLocalServiceUtil.getUserByEmailAddress(getCompany().getCompanyId(), emailAddress);
|
||
|
toReturn = mapLRUser(toGet);
|
||
|
} catch (PortalException e) {
|
||
|
throw new UserRetrievalFault("User not existing", e);
|
||
|
} catch (SystemException e) {
|
||
|
throw new UserManagementSystemException(e.getMessage(), e);
|
||
|
}
|
||
|
return toReturn;
|
||
|
}
|
||
|
/**
|
||
|
* {@inheritDoc}
|
||
|
*/
|
||
|
@Override
|
||
|
public List<UserModel> listUsers() throws UserManagementSystemException {
|
||
|
List<UserModel> toReturn = new ArrayList<UserModel>();
|
||
|
try {
|
||
|
List<User> lrUsers = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount());
|
||
|
for (User user : lrUsers) {
|
||
|
if (user.isActive())
|
||
|
toReturn.add(mapLRUser(user));
|
||
|
}
|
||
|
} catch (SystemException e) {
|
||
|
throw new UserManagementSystemException(e.getMessage(), e);
|
||
|
} catch (PortalException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
return toReturn;
|
||
|
}
|
||
|
/**
|
||
|
* {@inheritDoc}
|
||
|
*/
|
||
|
@Override
|
||
|
public List<UserModel> listUsersByGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault {
|
||
|
List<UserModel> toReturn = new ArrayList<UserModel>();
|
||
|
try {
|
||
|
for (User user : UserLocalServiceUtil.getGroupUsers(groupId)) {
|
||
|
if (user.isActive())
|
||
|
toReturn.add(mapLRUser(user));
|
||
|
}
|
||
|
} catch (PortalException e) {
|
||
|
e.printStackTrace();
|
||
|
} catch (SystemException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
return toReturn;
|
||
|
}
|
||
|
/**
|
||
|
* {@inheritDoc}
|
||
|
*/
|
||
|
@Override
|
||
|
public List<UserModel> listUsersByGroupName(String name) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault {
|
||
|
List<UserModel> toReturn = new ArrayList<UserModel>();
|
||
|
try {
|
||
|
Group g = (GroupLocalServiceUtil.getGroup(getCompany().getCompanyId(), name));
|
||
|
for (User user : UserLocalServiceUtil.getGroupUsers(g.getGroupId())) {
|
||
|
if (user.isActive())
|
||
|
toReturn.add(mapLRUser(user));
|
||
|
}
|
||
|
} catch (PortalException e) {
|
||
|
e.printStackTrace();
|
||
|
} catch (SystemException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
return toReturn;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public List<UserModel> listPendingUsersByGroup(String groupId)
|
||
|
throws UserManagementSystemException, GroupRetrievalFault,
|
||
|
UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getMembershipRequestComment(String userId, String groupId)
|
||
|
throws UserManagementSystemException, GroupRetrievalFault,
|
||
|
UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public HashMap<UserModel, List<RoleModel>> listUsersAndRolesByGroup(
|
||
|
String groupId) throws GroupRetrievalFault,
|
||
|
UserManagementSystemException, UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public HashMap<UserModel, List<GroupModel>> listUsersAndGroupsByRole(
|
||
|
String roleId) throws UserManagementSystemException,
|
||
|
RoleRetrievalFault, UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public List<UserModel> listUsersByGroupAndRole(String groupId, String roleId)
|
||
|
throws UserManagementSystemException, RoleRetrievalFault,
|
||
|
GroupRetrievalFault, UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void assignUserToGroup(String groupId, String userId)
|
||
|
throws UserManagementSystemException, GroupRetrievalFault,
|
||
|
UserRetrievalFault, UserManagementPortalException {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void dismissUserFromGroup(String groupId, String userId)
|
||
|
throws UserManagementSystemException, GroupRetrievalFault,
|
||
|
UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void requestMembership(String userId, String groupId, String comment)
|
||
|
throws UserManagementSystemException, GroupRetrievalFault,
|
||
|
UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public List<UserModel> listUnregisteredUsersByGroup(String groupId)
|
||
|
throws UserManagementSystemException, GroupRetrievalFault,
|
||
|
UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Long getUserId(String screenName)
|
||
|
throws UserManagementSystemException {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public List<UserModel> getMembershipRequests(String groupId)
|
||
|
throws UserManagementSystemException, GroupRetrievalFault,
|
||
|
UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public HashMap<String, String> getUserCustomAttributes(String userId)
|
||
|
throws UserManagementSystemException, UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setUserCustomAttributes(String userId,
|
||
|
HashMap<String, String> hMap) throws UserManagementSystemException,
|
||
|
UserRetrievalFault, UserManagementPortalException {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getUserCustomAttributeByName(String userId, String attrName)
|
||
|
throws UserManagementSystemException, UserRetrievalFault {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setUserCustomAttributeByName(String userId, String attrName,
|
||
|
String attrValue) throws UserManagementSystemException,
|
||
|
UserRetrievalFault, UserManagementPortalException {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void denyMembershipRequest(String userId, String groupId)
|
||
|
throws UserManagementSystemException, GroupRetrievalFault,
|
||
|
UserManagementPortalException {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|