From b0b7c1c5acf2e08bd85e131cb6e794c56c9eac08 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 5 Feb 2016 16:34:44 +0000 Subject: [PATCH] started implementing git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@122874 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 6 + .project | 13 + .settings/org.eclipse.wst.common.component | 6 + ....eclipse.wst.common.project.facet.core.xml | 5 + pom.xml | 33 +- .../usermanagement/UserManager.java | 92 +- .../impl/LiferayUserManager.java | 301 ++++++ .../impl/liferay/LiferayGroupManager.java | 509 --------- .../impl/liferay/LiferayRoleManager.java | 788 -------------- .../impl/liferay/LiferayUserManager.java | 969 ------------------ .../usermanagement/impl/liferay/ParseXML.java | 144 --- .../usermanagement/impl/liferay/Settings.java | 57 -- .../utils/ExpandoClassCodeManager.java | 47 - .../utils/ExpandoDefaultTableManager.java | 86 -- .../impl/voms/VOMSGroupManager.java | 129 --- .../impl/voms/VOMSRoleManager.java | 135 --- .../impl/voms/VOMSUserManager.java | 155 --- .../usermanagement/model/Email.java | 45 + .../usermanagement/model/UserModel.java | 240 +++-- 19 files changed, 641 insertions(+), 3119 deletions(-) create mode 100644 .settings/org.eclipse.wst.common.component create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java delete mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayGroupManager.java delete mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayRoleManager.java delete mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayUserManager.java delete mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/ParseXML.java delete mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/Settings.java delete mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoClassCodeManager.java delete mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoDefaultTableManager.java delete mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSGroupManager.java delete mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSRoleManager.java delete mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSUserManager.java create mode 100644 src/main/java/org/gcube/vomanagement/usermanagement/model/Email.java diff --git a/.classpath b/.classpath index f3dfa12..1628860 100644 --- a/.classpath +++ b/.classpath @@ -24,6 +24,12 @@ + + + + + + diff --git a/.project b/.project index ab558ba..35f1980 100644 --- a/.project +++ b/.project @@ -5,6 +5,11 @@ + + org.eclipse.wst.common.project.facet.core.builder + + + org.eclipse.jdt.core.javabuilder @@ -20,10 +25,18 @@ + + org.eclipse.wst.validation.validationbuilder + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.m2e.core.maven2Nature org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature + org.eclipse.wst.common.project.facet.core.nature diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..2ff2051 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,6 @@ + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c78d932 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/pom.xml b/pom.xml index ece847b..2829f5d 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.dvos usermanagement-core - 1.4.1-SNAPSHOT + 2.0.0-SNAPSHOT jar User Management API @@ -24,18 +24,16 @@ distro - 1.6 - 1.6 - + 1.7 + 1.7 UTF-8 UTF-8 - com.liferay.portal portal-service - 6.0.6 + 6.2.5 javax.portlet @@ -43,13 +41,34 @@ 2.0 provided + + javax.servlet + servlet-api + 2.4 + provided + + + javax.servlet.jsp + jsp-api + 2.0 + provided + junit junit 3.8.1 test - + + org.slf4j + slf4j-log4j12 + 1.6.4 + + + org.slf4j + slf4j-api + 1.6.4 + diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java index 17deb05..1d5f10d 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java @@ -14,56 +14,82 @@ import org.gcube.vomanagement.usermanagement.model.UserModel; /** - * This interface defines the class that manages the users. * - * @author Giulio Galiero + * + * @author Massimiliano Assante, CNR-ISTI * */ -public interface UserManager { + public interface UserManager { + /** + * + * @param username the username of the user you want to get + * @return the instance of the user + * @throws UserManagementSystemException + * @throws UserRetrievalFault + */ + UserModel getUserByUsername(String username) throws UserManagementSystemException, UserRetrievalFault ; + /** + * + * @param username the email of the user you want to get + * @return the instance of the user + * @throws UserManagementSystemException + * @throws UserRetrievalFault + */ + UserModel getUserByEmail(String email) throws UserManagementSystemException, UserRetrievalFault; + /** + * + * @return a list of all portal active users no matter if the belong or not to a VRE, if a user is deactived is not returned + * @throws UserManagementSystemException + */ + List listUsers() throws UserManagementSystemException; + /** + * + * @param groupId the LR groupId + * @return + * @throws UserManagementSystemException + * @throws GroupRetrievalFault + * @throws UserRetrievalFault + */ + List listUsersByGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + /** + * + * @param the name of the VO or VRE (e.g. devVRE, or gcube etc.) + * @return + * @throws UserManagementSystemException + * @throws GroupRetrievalFault + * @throws UserRetrievalFault + */ + List listUsersByGroupName(String name) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; - public void createUser(UserModel usermodel) throws UserManagementSystemException, UserRetrievalFault; + List listPendingUsersByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; - public void deleteUser(String userId) throws UserManagementSystemException, UserRetrievalFault; + String getMembershipRequestComment(String userId, String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; - public void updateUser(UserModel user) throws UserRetrievalFault, UserManagementSystemException, UserManagementPortalException; + HashMap> listUsersAndRolesByGroup(String groupId) throws GroupRetrievalFault, UserManagementSystemException, UserRetrievalFault ; - public UserModel getUser(String userId) throws UserManagementSystemException, UserRetrievalFault ; - - public List listUsers() throws UserManagementSystemException, UserRetrievalFault; + HashMap> listUsersAndGroupsByRole(String roleId) throws UserManagementSystemException, RoleRetrievalFault, UserRetrievalFault ; - public List listUsersByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; - - public List listPendingUsersByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + List listUsersByGroupAndRole(String groupId, String roleId) throws UserManagementSystemException, RoleRetrievalFault, GroupRetrievalFault, UserRetrievalFault; - public String getMembershipRequestComment(String userId, String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; - - public HashMap> listUsersAndRolesByGroup(String groupId) throws GroupRetrievalFault, UserManagementSystemException, UserRetrievalFault ; - - public HashMap> listUsersAndGroupsByRole(String roleId) throws UserManagementSystemException, RoleRetrievalFault, UserRetrievalFault ; - - public List listUsersByGroupAndRole(String groupId, String roleId) throws UserManagementSystemException, RoleRetrievalFault, GroupRetrievalFault, UserRetrievalFault; - - public void assignUserToGroup(String groupId, String userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault, UserManagementPortalException; + void assignUserToGroup(String groupId, String userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault, UserManagementPortalException; - public void dismissUserFromGroup(String groupId, String userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + void dismissUserFromGroup(String groupId, String userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; - public void requestMembership(String userId, String groupId, String comment) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + void requestMembership(String userId, String groupId, String comment) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; - public List listUnregisteredUsersByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + List listUnregisteredUsersByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; - public String getUserId(String screenName) throws UserManagementSystemException; + Long getUserId(String screenName) throws UserManagementSystemException; - public List getMembershipRequests(String groupId) throws UserManagementSystemException,GroupRetrievalFault, UserRetrievalFault; + List getMembershipRequests(String groupId) throws UserManagementSystemException,GroupRetrievalFault, UserRetrievalFault; - public UserModel getUserByScreenName(String screenName) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException; - - public HashMap getUserCustomAttributes(String userId) throws UserManagementSystemException, UserRetrievalFault; + HashMap getUserCustomAttributes(String userId) throws UserManagementSystemException, UserRetrievalFault; - public void setUserCustomAttributes(String userId, HashMap hMap) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException; + void setUserCustomAttributes(String userId, HashMap hMap) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException; - public String getUserCustomAttributeByName(String userId, String attrName)throws UserManagementSystemException, UserRetrievalFault; + String getUserCustomAttributeByName(String userId, String attrName)throws UserManagementSystemException, UserRetrievalFault; - public void setUserCustomAttributeByName(String userId, String attrName, String attrValue) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException; + void setUserCustomAttributeByName(String userId, String attrName, String attrValue) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException; - public void denyMembershipRequest(String userId,String groupId)throws UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException; + void denyMembershipRequest(String userId,String groupId)throws UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException; } diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java new file mode 100644 index 0000000..49ddb49 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayUserManager.java @@ -0,0 +1,301 @@ +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 emails = new ArrayList(); + 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 listUsers() throws UserManagementSystemException { + List toReturn = new ArrayList(); + try { + List 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 listUsersByGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault { + List toReturn = new ArrayList(); + 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 listUsersByGroupName(String name) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault { + List toReturn = new ArrayList(); + 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 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> listUsersAndRolesByGroup( + String groupId) throws GroupRetrievalFault, + UserManagementSystemException, UserRetrievalFault { + // TODO Auto-generated method stub + return null; + } + + @Override + public HashMap> listUsersAndGroupsByRole( + String roleId) throws UserManagementSystemException, + RoleRetrievalFault, UserRetrievalFault { + // TODO Auto-generated method stub + return null; + } + + @Override + public List 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 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 getMembershipRequests(String groupId) + throws UserManagementSystemException, GroupRetrievalFault, + UserRetrievalFault { + // TODO Auto-generated method stub + return null; + } + + @Override + public HashMap getUserCustomAttributes(String userId) + throws UserManagementSystemException, UserRetrievalFault { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setUserCustomAttributes(String userId, + HashMap 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 + + } + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayGroupManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayGroupManager.java deleted file mode 100644 index 4e17084..0000000 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayGroupManager.java +++ /dev/null @@ -1,509 +0,0 @@ -package org.gcube.vomanagement.usermanagement.impl.liferay; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.gcube.vomanagement.usermanagement.GroupManager; -import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; -import org.gcube.vomanagement.usermanagement.exception.UserManagementNameException; -import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; -import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; -import org.gcube.vomanagement.usermanagement.model.GroupModel; -import org.gcube.vomanagement.usermanagement.model.RoleModel; - - - -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.MembershipRequest; -import com.liferay.portal.model.Organization; -import com.liferay.portal.model.Role; - -import com.liferay.portal.service.CompanyLocalServiceUtil; -import com.liferay.portal.service.MembershipRequestLocalServiceUtil; -import com.liferay.portal.service.OrganizationLocalServiceUtil; -import com.liferay.portal.service.RoleLocalServiceUtil; -import com.liferay.portal.service.ServiceContext; - - -/** - * Liferay plugin for the GroupManager interface, this implementation interacts with Liferay through a LocalService. - * - * @author Giulio Galiero - * - */ -public class LiferayGroupManager implements GroupManager { - - private static final String DEFAULT_COMPANY_WEB_ID = "liferay.com"; - private final String REG_EX_MATCH = "^[A-Za-z0-9]+([-\\.\\_\\-ε]([A-Za-z0-9]+))*"; - - private long getLongId(String groupId) throws NumberFormatException{ - - long groupIdL = Long.parseLong(groupId); - return groupIdL; - } - /** - * return the companyId - * @param webId . - * @return the company bean - * @throws PortalException . - * @throws SystemException . - */ - 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) { - System.out.println("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; - } - - - - protected long getCompanyId() throws UserManagementSystemException, UserManagementPortalException{ - Company company = null; - try { - company = getCompany(); - } catch (PortalException e) { - throw new UserManagementPortalException("Error retrieving companyId ", e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving companyId ", e); - } - return company.getCompanyId(); - } - - /* public GroupModel.GROUP_TYPE getGroupType(GroupModel gm){ - if(gm.getGroupName().startsWith("VO")){ - return GroupModel.GROUP_TYPE.VO; - }else if(gm.getGroupName().contains("ROOT_VO")){ - return GroupModel.GROUP_TYPE.ROOT_VO; - }else if(gm.getGroupName().contains("VRE")){ - return GroupModel.GROUP_TYPE.ROOT_VO; - } - return GroupModel.GROUP_TYPE.VO; - }*/ - - public String getScope(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ - StringBuilder scope = new StringBuilder("/"); - Organization org; - - try{ - long groupIdL = this.getLongId(groupId); - org = OrganizationLocalServiceUtil.getOrganization(groupIdL); - }catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving scope for group ", groupId , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group name ",groupId, e); - } - if (isRootVO(groupId)) - scope.append(org.getName()); - else if (isVO(groupId)){ - long rootVOId = getGroupParentId(groupId); - Organization rootVO = null; - try { - rootVO = OrganizationLocalServiceUtil.getOrganization(rootVOId); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group name ",String.valueOf(rootVOId), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving scope for group ", groupId , e); - } - scope.append(rootVO.getName()).append("/").append(org.getName()); - } - else if (isVRE(groupId)){ - long voId = getGroupParentId(groupId); - Organization vo = null; - try { - vo = OrganizationLocalServiceUtil.getOrganization(voId); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group name ",String.valueOf(voId), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving scope for group ", groupId , e); - } - long rootVOId = getGroupParentId(String.valueOf(voId)); - Organization rootVO = null; - try { - rootVO = OrganizationLocalServiceUtil.getOrganization(rootVOId); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group name ",String.valueOf(rootVOId), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving scope for group ", groupId , e); - } - scope.append(rootVO.getName()).append("/").append(vo.getName()).append("/").append(org.getName()); - } - - return scope.toString(); - - } - - public Boolean isRootVO(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ - if(this.getLongId(groupId)!=0){ - if (getGroupParentId(groupId) == 0) - return true; - } - return false; - } - - public Boolean isVO(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ - if(this.getLongId(groupId)!=0){ - long parentId = getGroupParentId(groupId); - if (isRootVO(String.valueOf(parentId))) - return true; - } - return false; - } - - public Boolean isVRE(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ - long parentId = getGroupParentId(groupId); - if (isVO(String.valueOf(parentId))) - return true; - else - return false; - } - - /* - Already available in UserManager as listUsersByGroup! - - public List getGroupUsers(long groupId){ - List orgUsers = null; - try { - orgUsers = UserLocalServiceUtil.getOrganizationUsers(groupId); - } catch (SystemException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - List userModels = new ArrayList(); - for(User user : orgUsers){ - UserModel um = new UserModel(user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName()); - userModels.add(um); - } - return userModels; - } - */ - - public String getGroupId(String groupName) throws UserManagementSystemException, GroupRetrievalFault{ - List organizations = null; - long orgId = 0; - try { - organizations = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving Id for group ", groupName , e); - } - for(Organization organization: organizations){ - if(organization.getName().equalsIgnoreCase(groupName)){ - orgId = organization.getOrganizationId(); - break; - } - } - if(orgId == 0){ - throw new GroupRetrievalFault("No group exists with group name ",groupName); - } - return String.valueOf(orgId); - } - - public GroupModel getGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ - Organization group = null; - GroupModel gm = null; - try { - group = OrganizationLocalServiceUtil.getOrganization(this.getLongId(groupId)); - if(group!=null){ - gm = new GroupModel(String.valueOf(group.getOrganizationId()),String.valueOf(group.getParentOrganizationId()),group.getName(),group.getComments(),group.getLogoId()); - }else{ - // throw new UserManagementException("No Group Found with Id " + groupId); - } - - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving group ", groupId , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group name ",groupId, e); - } - return gm; - } - - public List listGroups() throws UserManagementSystemException { - List groups = null; - List orgModels = new ArrayList(); - try { - groups = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount()); - if(groups!=null){ - for(Organization group:groups){ - GroupModel gm = new GroupModel(String.valueOf(group.getOrganizationId()),String.valueOf(group.getParentOrganizationId()),group.getName(),group.getComments(),group.getLogoId()); - orgModels.add(gm); - } - }else{ - // throw new UserManagementException("No Groups found "); - } - - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving list of groups ", e); - } - return orgModels; - } - - public HashMap> listGroupsAndRolesByUser(String userId) throws UserManagementSystemException { - long userIdn = Long.parseLong(userId); - HashMap> hMap = new HashMap>(); - List groups = null; - List roles = null; - String roleName; - String completeRoleName; - LiferayRoleManager roleMan = new LiferayRoleManager(); - try { - groups = OrganizationLocalServiceUtil.getUserOrganizations(userIdn); - roles = RoleLocalServiceUtil.getUserRoles(userIdn); - } catch (Exception e) { - throw new UserManagementSystemException("Error listing groups and roles of user ", userId , e); - } - Iterator groupIter = groups.iterator(); - while(groupIter.hasNext()){ - Organization group = (Organization)groupIter.next(); - List userGroupRoles = new ArrayList(); - for(Role role : roles){ - if(role.getName().contains(group.getName())){ - completeRoleName = role.getName(); - roleName = roleMan.getRoleName(completeRoleName); - RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); - rm.setCompleteName(completeRoleName); - userGroupRoles.add(rm); - } - } - hMap.put(group.getName(), userGroupRoles); - } - return hMap; - } - - public List listGroupsByUser(String userId) throws UserManagementSystemException { - List groups = null; - List orgModels = new ArrayList(); - try { - groups = OrganizationLocalServiceUtil.getUserOrganizations(getLongId(userId)); - for(Organization group:groups){ - GroupModel gm = new GroupModel(String.valueOf(group.getOrganizationId()),String.valueOf(group.getParentOrganizationId()),group.getName(),group.getComments(),group.getLogoId()); - orgModels.add(gm); - } - }catch (Exception e) { - throw new UserManagementSystemException("Error retrieving groups of user ", userId , e); - } - return orgModels; - } - - public List listSubGroupsByGroup(String groupIdn) throws UserManagementSystemException, GroupRetrievalFault{ - long groupId = getLongId(groupIdn); - List org = new ArrayList(); - List subOrgs = null; - List subOrgModels = new ArrayList(); - try { - org.add(OrganizationLocalServiceUtil.getOrganization(groupId)); - subOrgs = OrganizationLocalServiceUtil.getSuborganizations(org); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving sub groups of group ", groupIdn , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group name ",groupIdn, e); - } - - if(subOrgs!=null){ - for(Organization suborg : subOrgs){ - GroupModel gm = new GroupModel(String.valueOf(suborg.getOrganizationId()),String.valueOf(suborg.getParentOrganizationId()),suborg.getName(),suborg.getComments(),suborg.getLogoId()); - subOrgModels.add(gm); - } - }else{ - // throw new UserManagementException("No SubGroups present for the group " + groupIdn); - } - - return subOrgModels; - } - - public void assignSubGrouptoParentGroup(String subGroupId, - String parentGroupId) throws UserManagementSystemException, GroupRetrievalFault{ - Organization subOrg = null; - try { - subOrg = OrganizationLocalServiceUtil.getOrganization(this.getLongId(subGroupId)); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning subGroup to Parent group ", e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group Id ", subGroupId, e); - } - subOrg.setParentOrganizationId(this.getLongId(parentGroupId)); - this.updateOrganization(subOrg); - - } - - private GroupModel createGroup(String groupName, String parentGroupId , String userId, String description) throws UserManagementNameException, UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException{ - /*Status Id is hard coded - ATTENTION*/ - ServiceContext serviceContext = new ServiceContext(); - Organization org = null; - GroupModel gm = null; - // Check for character, -, _, . which are valid characters for a group Name - requirement by Massi - Pattern p = Pattern.compile(REG_EX_MATCH); - Matcher m = p.matcher(groupName); - if(m.matches()){ - try { - org = OrganizationLocalServiceUtil.addOrganization(getLongId(userId), this.getLongId(parentGroupId), groupName, "regular-organization", true, 0L, 0L, 12017, description, serviceContext); - org.setCompanyId(getCompanyId()); - gm = new GroupModel(String.valueOf(org.getOrganizationId()),String.valueOf(org.getParentOrganizationId()),org.getName(),org.getComments(),org.getLogoId()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error creating group ", groupName , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("Check the groupName and the parent groupId ", groupName, e); - } - }else{ - throw new UserManagementNameException("Not a valid group Name. The valid characters are only A-Z a-z - _ ."); - } - return gm; - } - - public void deleteGroup(String groupName) throws UserManagementSystemException, GroupRetrievalFault{ - long organizationId = this.getLongId(groupName); - Organization organization; - try { - organization = OrganizationLocalServiceUtil.getOrganization(organizationId); - OrganizationLocalServiceUtil.deleteOrganization(organization); - }catch (SystemException e) { - throw new UserManagementSystemException("Error deleting group ", groupName , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group name ",groupName, e); - } - - List roles; - try { - roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); - for(Role role:roles){ - if(role.getName().contains(groupName)){ - RoleLocalServiceUtil.deleteRole(role); - } - } - } catch (SystemException e) { - throw new UserManagementSystemException("Error deleting group ", groupName , e); - } - - - } - - public void dismissSubGroupFromParentGroup(String subGroupId, - String parentGroupId) throws UserManagementSystemException, GroupRetrievalFault{ - long subOrgId = this.getLongId(subGroupId); - Organization org = null; - try { - org = OrganizationLocalServiceUtil.getOrganization(subOrgId); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing subGroup from Parent Group ", e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group Id ",subGroupId, e); - } - org.setParentOrganizationId(0); - this.updateOrganization(org); - } - - public GroupModel createRootVO(String rootVOName, String userId, String description) throws UserManagementNameException, UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException { - return createGroup(rootVOName,"0",userId, description); - } - - public GroupModel createVO(String VOName, String rootVOGroupId , String userId, String description) throws UserManagementNameException, UserManagementSystemException, UserManagementPortalException, GroupRetrievalFault { - return createGroup(VOName,rootVOGroupId,userId,description); - } - - public GroupModel createVRE(String VREName, String VOGroupId, String userId, String description) throws UserManagementNameException, UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException { - return createGroup(VREName,VOGroupId,userId,description); - } - - public GroupModel getRootVO() throws UserManagementSystemException, GroupRetrievalFault { - - List orgs = null; - GroupModel gm = null; - try { - orgs = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount()); - } catch (SystemException e) { - e.printStackTrace(); - } - for(Organization org : orgs){ - if(this.isRootVO(String.valueOf(org.getOrganizationId()))){ - gm = new GroupModel(String.valueOf(org.getOrganizationId()),String.valueOf(org.getParentOrganizationId()),org.getName(),org.getComments(),org.getLogoId()); - break; - } - } - return gm; - } - - public String getRootVOName() throws UserManagementSystemException, GroupRetrievalFault { - GroupModel gm = getRootVO(); - return gm.getGroupName(); - - } - - public List listPendingGroupsByUser(String userId) throws UserManagementSystemException { - List memberRequests = null; - List groupModels = new ArrayList(); - long userIdL = this.getLongId(userId); - try { - memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); - for(MembershipRequest memberRequest: memberRequests){ - if(memberRequest.getUserId() == userIdL){ - long groupId = memberRequest.getGroupId(); - List orgs = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount()); - for(Organization org : orgs){ - if(org.getGroup().getGroupId()==groupId){ - GroupModel gm = new GroupModel(String.valueOf(org.getOrganizationId()),String.valueOf(org.getParentOrganizationId()),org.getName(),org.getComments(),org.getLogoId()); - groupModels.add(gm); - break; - } - } - } - } - }catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving pending groups for user ", userId , e); - } - return groupModels; - } - - public void updateGroup(GroupModel group) throws UserManagementSystemException, GroupRetrievalFault{ - Organization org = null; - try { - org = OrganizationLocalServiceUtil.getOrganization(Long.parseLong(group.getGroupId())); - }catch (SystemException e) { - throw new UserManagementSystemException("Error updating group ", group.getGroupName() , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with groupId ",group.getGroupId(), e); - } - this.updateOrganization(org); - } - - private void updateOrganization(Organization org) throws UserManagementSystemException{ - try { - OrganizationLocalServiceUtil.updateOrganization(org); - } catch (SystemException e) { - throw new UserManagementSystemException("Error updating group " , e); - } - } - - public long getGroupParentId(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ - long groupIdL = this.getLongId(groupId); - Organization org = null; - long parentOrgId = 0; - try { - org = OrganizationLocalServiceUtil.getOrganization(groupIdL); - - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving parent Group Id for group ", groupId , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with groupId ",groupId, e); - } - parentOrgId = org.getParentOrganizationId(); - return parentOrgId; - } -} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayRoleManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayRoleManager.java deleted file mode 100644 index 8f3d2dd..0000000 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayRoleManager.java +++ /dev/null @@ -1,788 +0,0 @@ -package org.gcube.vomanagement.usermanagement.impl.liferay; - - - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Set; - -import org.gcube.vomanagement.usermanagement.GroupManager; -import org.gcube.vomanagement.usermanagement.RoleManager; -import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; -import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; -import org.gcube.vomanagement.usermanagement.exception.UserManagementFileNotFoundException; -import org.gcube.vomanagement.usermanagement.exception.UserManagementIOException; -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.GroupModel; -import org.gcube.vomanagement.usermanagement.model.RoleModel; - -import com.liferay.portal.kernel.exception.PortalException; -import com.liferay.portal.kernel.exception.SystemException; -import com.liferay.portal.model.Organization; -import com.liferay.portal.model.Role; -import com.liferay.portal.model.UserModel; -import com.liferay.portal.service.OrganizationLocalServiceUtil; -import com.liferay.portal.service.RoleLocalServiceUtil; -import com.liferay.portal.service.UserLocalServiceUtil; - - -/** - * Liferay plugin for the RoleManager interface, this implementation interacts with Liferay through a LocalService. - * - * @author Giulio Galiero - * - */ -public class LiferayRoleManager implements RoleManager { - - private static final String ADMIN_ROLE = "Administrator"; - protected static final String PRODUCTION_SUPPORT = "Production-Support"; - public static final String VRE = "vre"; - public static final String VO = "vo"; - public static final String ROOT_VO = "root-vo"; - - /** - * @return true if the user is a portal administrator, false otherwise - */ - public boolean isAdmin(String userId) { - LiferayGroupManager gm = new LiferayGroupManager(); - try { - com.liferay.portal.model.User currUser = UserLocalServiceUtil.getUserByScreenName(gm.getCompanyId(), userId); - for (Role role : currUser.getRoles()) - if (role.getName().compareTo(ADMIN_ROLE) == 0 ) - return true; - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - long convertType(String stringId){ - return Long.parseLong(stringId); - } - - protected String getRoleName(String roleNameFull){ - List orgs; - String roleName = null; - try { - orgs = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount()); - for(Organization org : orgs){ - if(roleNameFull.contains(org.getName())){ - roleName = roleNameFull.substring(0, roleNameFull.indexOf(org.getName())-1); - break; - } - } - } catch (SystemException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return roleName; - } - - public HashMap listAllowedRoles (String groupName) throws UserManagementSystemException, GroupRetrievalFault, UserManagementFileNotFoundException, UserManagementIOException - { - GroupManager gm = new LiferayGroupManager(); - String groupId = gm.getGroupId(groupName); - HashMap hMap = new HashMap(); - // Code changed to remove hardcoded role names to external config file as requested by Leonordo and Manzi - /* List vreRoles = Arrays.asList("VRE-Manager", "VRE-User"); - List voRoles = Arrays.asList("VO-Admin", "VRE-Designer", "VRE-Manager", "Data-Manager"); - List rootVoRoles = Arrays.asList("Infrastructure-Manager", "Site-Manager");*/ - - if(gm.isRootVO(groupId)){ - hMap = ParseXML.getRoles(ROOT_VO); - }else if (gm.isVO(groupId)){ - hMap = ParseXML.getRoles(VO); - }else if (gm.isVRE(groupId)){ - hMap = ParseXML.getRoles(VRE); - } - return hMap; - } - - - - - - public String getRoleId(String roleName, String groupName) throws UserManagementSystemException{ - List roles = null; - String rolenameLR = null; - long roleId = 0; - try { - roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving roles ", e); - } - if(!roleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ - roleName = roleName + "-" + groupName; - } - - for(Role role: roles){ - rolenameLR = role.getName(); - if(rolenameLR.equalsIgnoreCase(roleName)){ - roleId = role.getRoleId(); - break; - } - } - return String.valueOf(roleId); - } - - public void assignRoleToUser(String groupIdn, String roleIdn, - String userIdn) throws UserManagementSystemException, GroupRetrievalFault, RoleRetrievalFault, UserRetrievalFault{ - long[] roleIds; - long roleId = this.convertType(roleIdn); - long userId = this.convertType(userIdn); - long groupId = this.convertType(groupIdn); - int i = 0; - String orgName = null; - Role role = null; - Organization org; - List roles; - try { - org = OrganizationLocalServiceUtil.getOrganization(groupId); - roles = RoleLocalServiceUtil.getUserRoles(userId); - }catch (PortalException e){ - throw new GroupRetrievalFault("No group exists with groupId ",groupIdn, e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning role to user ", e); - } - - roleIds = new long[roles.size()+1]; - for(Role userRole : roles){ - roleIds[i++] = userRole.getRoleId(); - } - roleIds[i]= this.convertType(roleIdn); - orgName = org.getName(); - try { - role = RoleLocalServiceUtil.getRole(roleId); - } catch (PortalException e) { - throw new RoleRetrievalFault("No Role exists with roleId",roleIdn,e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning role to user ", e); - } - String roleName = role.getName(); - if(!roleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ - if(roleName.contains(orgName)){ - try { - if(UserLocalServiceUtil.hasOrganizationUser(groupId, userId)){ - RoleLocalServiceUtil.setUserRoles(userId, roleIds); - } - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning role to user ", e); - } catch (PortalException e) { - throw new UserRetrievalFault("No User exists with userId ",userIdn,e); - } - } - }else{ - try { - RoleLocalServiceUtil.setUserRoles(userId, roleIds); - } catch (PortalException e) { - throw new UserRetrievalFault("Error assigning role to user with userId ",userIdn,e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning role to user ", e); - } - } - - } - - private RoleModel createRoleUtil(String roleName,String roleDesc) throws UserManagementSystemException, RoleRetrievalFault, UserManagementPortalException { - Role role = null; - RoleModel rm = null; - LiferayGroupManager gm = new LiferayGroupManager(); - //List allowedRoles = getAllowedRoles(groupName); - boolean roleExists = false; - - long companyId = gm.getCompanyId(); - - //roleName = roleName + "-" + groupName; - List roles; - try { - roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error creating role ", e); - } - for(Role existingRole : roles){ - if(existingRole.getName().equals(roleName)){ - roleExists = true; - break; - } - } - if(!roleExists){ - try { - Locale english = new Locale("en"); - HashMap roleNames = new HashMap(); - roleNames.put(english, roleName); - role = RoleLocalServiceUtil.addRole(0L, companyId, roleName, roleNames, roleDesc, 1); - } catch (PortalException e) { - throw new RoleRetrievalFault("Cannot create new role, check the roleName already exists",roleName,e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error creating role ", e); - } - if(!roleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ - roleName = roleName.substring(0, roleName.lastIndexOf("-")); - } - - rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); - }else{ - throw new RoleRetrievalFault("Cannot create new role, check the roleName already exists",roleName); - } - return rm; - } - - public boolean createRole(String roleName,String roleDescription, String groupName) throws UserManagementSystemException, GroupRetrievalFault, RoleRetrievalFault, UserManagementPortalException { - List roleModels = new ArrayList(); - //String roleDesc = validateRoleName(roleName, groupId); - if(!roleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ - roleName = roleName +"-"+groupName; - } - - roleModels.add(this.createRoleUtil(roleName, roleDescription)); - return true; - } - - public void createRole(String groupName) throws UserManagementSystemException, GroupRetrievalFault, RoleRetrievalFault, UserManagementPortalException, UserManagementFileNotFoundException, UserManagementIOException{ - GroupManager gm = new LiferayGroupManager(); - Organization org; - HashMap allowedRolesConfig; - try { - String groupId = gm.getGroupId(groupName); - allowedRolesConfig = listAllowedRoles(groupName); - org = OrganizationLocalServiceUtil.getOrganization(this.convertType(groupId)); - }catch (SystemException e) { - throw new UserManagementSystemException("Error creating roles for group ", groupName , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group Name ", groupName, e); - } - String orgName = org.getName(); - Set allowedRoles = allowedRolesConfig.keySet(); - Collection allowedRolesDesc = allowedRolesConfig.values(); - Iterator rolesDescIter = allowedRolesDesc.iterator(); - - for(String allowedRole : allowedRoles){ - if(!allowedRole.equalsIgnoreCase(PRODUCTION_SUPPORT)){ - allowedRole = allowedRole+ "-"+ orgName; - } - this.createRoleUtil(allowedRole, rolesDescIter.next()); - } - } - - - - public void deleteRole(String roleName, String groupName)throws UserManagementSystemException, RoleRetrievalFault{ - try { - String roleId = this.getRoleId(roleName, groupName); - RoleLocalServiceUtil.deleteRole(this.convertType(roleId)); - } catch (SystemException e) { - throw new UserManagementSystemException("Error deleting role ", roleName , e); - } catch (PortalException e) { - throw new RoleRetrievalFault("No role exists with role name ", roleName, e); - } - } - - public void dismissRoleFromUser(String groupIdn, String roleIdn, - String userIdn) throws UserManagementSystemException, RoleRetrievalFault, GroupRetrievalFault, UserRetrievalFault{ - //boolean isMember = false; - long roleId = this.convertType(roleIdn); - long[] roleIds = {roleId}; - long userId = this.convertType(userIdn); - long groupId = this.convertType(groupIdn); - String orgName; - Role role; - try { - role = RoleLocalServiceUtil.getRole(roleId); - }catch (PortalException e) { - throw new RoleRetrievalFault("No role exists with roleId ", roleIdn, e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing roles from userc", userIdn, e); - } - Organization org; - try { - org = OrganizationLocalServiceUtil.getOrganization(groupId); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group Name ", groupIdn, e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing roles from userc", userIdn, e); - } - orgName = org.getName(); - if(!role.getName().equalsIgnoreCase(PRODUCTION_SUPPORT)){ - if(role.getName().contains(orgName)){ - try { - if(UserLocalServiceUtil.hasRoleUser(roleId, userId)){ - RoleLocalServiceUtil.unsetUserRoles(userId, roleIds); - } - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing roles from user ", userIdn, e); - } catch (PortalException e) { - throw new UserRetrievalFault("No User exists with userId ",userIdn,e); - } - } - }else{ - try { - if(UserLocalServiceUtil.hasRoleUser(roleId, userId)){ - RoleLocalServiceUtil.unsetUserRoles(userId, roleIds); - } - }catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing roles from user ", userIdn, e); - } catch (PortalException e) { - throw new UserRetrievalFault("No User exists with userId ",userIdn,e); - } - } - - //remove user from VO if no roles relevant to the VO are present - // removed as requested by massi as this removes the Organization-member role for the user - /* List userRoles = RoleLocalServiceUtil.getUserRoles(userId); - for(Role userRole : userRoles){ - if(userRole.getName().contains(orgName)){ - isMember = true; - break; - } - }*/ - // if the user does nt have other roles in the group, remove the user from the group - /* if(!isMember){ - long[] userIds = {userId}; - UserLocalServiceUtil.unsetOrganizationUsers(groupId, userIds); - }*/ - - } - - public RoleModel getRole(String roleId) throws UserManagementSystemException, RoleRetrievalFault{ - Role role = null; - RoleModel rm = null; - String roleName; - String completeRoleName; - try { - role = RoleLocalServiceUtil.getRole(this.convertType(roleId)); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving role ", roleId , e); - } catch (PortalException e) { - throw new RoleRetrievalFault("No role exists with roleId ", roleId, e); - } - completeRoleName = role.getName(); - roleName = getRoleName(completeRoleName); - rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); - rm.setCompleteName(completeRoleName); - - return rm; - } - - @Deprecated - public List listRoles() throws UserManagementSystemException { - List roles = null; - String roleName; - List roleNames = new ArrayList(); - try { - roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); - for(Role role:roles){ - roleName = role.getName(); - if(roleName.contains("-")){ - roleName = getRoleName(roleName); - if(!roleNames.contains(roleName)){ - roleNames.add(roleName); - } - } - } - } catch (SystemException e) { - throw new UserManagementSystemException("Error listing roles ", e); - } - return roleNames; - } - - public List listAllRoles() throws UserManagementSystemException { - List roles = null; - String roleName; - String completeRoleName; - List roleModels = new ArrayList(); - try { - roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); - for(Role role:roles){ - completeRoleName = role.getName(); - if(!completeRoleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ - roleName = getRoleName(completeRoleName); - } - else roleName = completeRoleName; - - RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); - rm.setCompleteName(completeRoleName); - roleModels.add(rm); - } - } catch (SystemException e) { - throw new UserManagementSystemException("Error listing roles ", e); - } - return roleModels; - } - - public List listRolesByUser(String userId) throws UserManagementSystemException { - List roles = null; - List roleModels = new ArrayList(); - String roleName; - String completeRoleName; - try { - roles = RoleLocalServiceUtil.getUserRoles(this.convertType(userId)); - for(Role role:roles){ - completeRoleName = role.getName(); - if(!completeRoleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ - roleName = getRoleName(completeRoleName); - } - else roleName = completeRoleName; - - RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); - rm.setCompleteName(completeRoleName); - roleModels.add(rm); - - } - } catch (SystemException e) { - throw new UserManagementSystemException("Error listing roles for user ",userId, e); - } - return roleModels; - } - - public List listRolesByUserAndGroup(String groupId, String userId) throws UserManagementSystemException, GroupRetrievalFault{ - List userRoles = new ArrayList(); - List userRoleModels = new ArrayList(); - List roles = null; - String roleName; - String completeRoleName; - String orgName; - Organization org = null; - try { - roles = RoleLocalServiceUtil.getUserRoles(this.convertType(userId)); - }catch (SystemException e) { - throw new UserManagementSystemException("Error listing roles by user and group ", e); - } - - try { - org = OrganizationLocalServiceUtil.getOrganization(this.convertType(groupId)); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group Id ", groupId, e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error listing roles by user and group ", e); - } - orgName = org.getName(); - for(Role role : roles){ - if(role.getName().contains(orgName)){ - userRoles.add(role); - completeRoleName = role.getName(); - roleName = getRoleName(completeRoleName); - RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); - rm.setCompleteName(completeRoleName); - userRoleModels.add(rm); - - } - } - - return userRoleModels; - } - - public List listRolesByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserManagementFileNotFoundException, UserManagementIOException{ - - List groupRoles = new ArrayList(); - List groupRoleModels = new ArrayList(); - GroupManager gm = new LiferayGroupManager(); - List roles = null; - String orgName; - String roleName; - String completeRoleName; - String groupType = null; - try { - roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); - - } catch (SystemException e) { - - throw new UserManagementSystemException("Error listing roles for group ", groupId , e); - } - Organization org; - try { - org = OrganizationLocalServiceUtil.getOrganization(this.convertType(groupId)); - - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with group Id ", groupId, e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error listing roles for group ", groupId , e); - } - orgName = org.getName(); - if(gm.isRootVO(groupId)){ - groupType = ROOT_VO; - }else if(gm.isVO(groupId)){ - groupType = VO; - }else if(gm.isVRE(groupId)){ - groupType = VRE; - } - for(Role role : roles){ - if(role.getName().endsWith(orgName)){ - groupRoles.add(role); - completeRoleName = role.getName(); - roleName = getRoleName(completeRoleName); - if(ParseXML.getRoles(groupType).containsKey(roleName)){ - String roleDesc; - if(role.getDescription()==""){ - roleDesc = ParseXML.getRoles(groupType).get(roleName); - role.setDescription(roleDesc); - try { - RoleLocalServiceUtil.updateRole(role); - }catch (SystemException e) { - e.printStackTrace(); - throw new UserManagementSystemException("Error updating role ",role.getName(), e); - } - }else{ - roleDesc = role.getDescription(); - } - RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),roleDesc); - rm.setCompleteName(completeRoleName); - groupRoleModels.add(rm); - }else{ - - RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); - groupRoleModels.add(rm); - } - - - } - } - Role role = this.getCommonRole(); - if(role!=null){ - String roleDesc; - try { - if(role.getDescription()==""){ - roleDesc = ParseXML.getRoles(VO).get(role.getName()); - role.setDescription(roleDesc); - RoleLocalServiceUtil.updateRole(role); - }else{ - roleDesc = role.getDescription(); - } - - } catch (SystemException e) { - throw new UserManagementSystemException("Error updating role Production-Support", e); - } - groupRoleModels.add(new RoleModel(role.getName(),String.valueOf(role.getRoleId()),roleDesc)); - } - - return groupRoleModels; - } - - protected Role getCommonRole() throws UserManagementSystemException{ - List roles; - try { - roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error listing roles ", e); - } - - for(Role role : roles){ - if(role.getName().equalsIgnoreCase(PRODUCTION_SUPPORT)){ - return role; - } - } - return null; - } - - private List getGroupsByType(String groupType) throws UserManagementSystemException, GroupRetrievalFault{ - LiferayGroupManager gm = new LiferayGroupManager(); - List groups = gm.listGroups(); - List groupsByType = new ArrayList(); - - if(groupType.equals(VO)){ - for(GroupModel group:groups){ - if(gm.isVO(group.getGroupId())){ - groupsByType.add(group); - } - } - }else if(groupType.equals(VRE)){ - for(GroupModel group:groups){ - if(gm.isVRE(group.getGroupId())){ - groupsByType.add(group); - } - } - }else if(groupType.equals(ROOT_VO)){ - for(GroupModel group:groups){ - if(gm.isRootVO(group.getGroupId())){ - groupsByType.add(group); - } - } - - } - return groupsByType; - } - - - - public void updateRole(String initialRoleName, String newRoleName, String roleDescription, String groupName) throws UserManagementSystemException, RoleRetrievalFault, NumberFormatException, UserManagementFileNotFoundException, UserManagementIOException, GroupRetrievalFault, UserManagementPortalException { - - Role role = null; - boolean isSystemRole = false; - String roleId; - String[] groupTypes = {VO,VRE,ROOT_VO}; - if(!initialRoleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ - roleId = this.getRoleId(initialRoleName, groupName); - }else{ - roleId = String.valueOf(this.getCommonRole().getRoleId()); - for(String groupType : groupTypes){ - HashMap hMap = ParseXML.getRoles(groupType); - hMap.put(initialRoleName, roleDescription); - ParseXML.updateRoles(hMap, groupType); - } - Role prod_supp_role; - try { - prod_supp_role = RoleLocalServiceUtil.getRole(Long.parseLong(roleId)); - prod_supp_role.setDescription(roleDescription); - RoleLocalServiceUtil.updateRole(prod_supp_role); - } catch (PortalException e1) { - throw new UserManagementPortalException("Error retrieving role ", initialRoleName , e1); - } catch (SystemException e1) { - throw new UserManagementSystemException("Error updating role ", initialRoleName , e1); - } - - - return; - - } - - try { - role = RoleLocalServiceUtil.getRole(Long.parseLong(roleId)); - } catch (PortalException e2) { - throw new UserManagementPortalException("Error retrieving role ", initialRoleName , e2); - } catch (SystemException e2) { - throw new UserManagementSystemException("Error updating role ", initialRoleName , e2); - } - - - if(ParseXML.getRoles(VO).containsKey(initialRoleName)){ - isSystemRole = true; - // update the predefined config file - HashMap hMap = ParseXML.getRoles(VO); - if(hMap.containsKey(initialRoleName)){ - hMap.put(initialRoleName, roleDescription); - - ParseXML.updateRoles(hMap, VO); - // update the actual roles - List voGroups = this.getGroupsByType(VO); - - for(GroupModel group:voGroups){ - List rm = this.listRolesByGroup(group.getGroupId()); - for(RoleModel roleModel : rm){ - if(roleModel.getRoleName().equals(initialRoleName)){ - String voroleId = this.getRoleId(initialRoleName, group.getGroupName()); - Role affectedRole; - try { - try { - affectedRole = RoleLocalServiceUtil.getRole(Long.parseLong(voroleId)); - } catch (SystemException e) { - throw new UserManagementSystemException("Error updating role ", initialRoleName , e); - } - } catch (PortalException e) { - throw new RoleRetrievalFault("Error retrieving role with name ", initialRoleName, e); - } - affectedRole.setDescription(roleDescription); - try { - RoleLocalServiceUtil.updateRole(affectedRole); - } catch (SystemException e) { - throw new UserManagementSystemException("Error updating role ", initialRoleName , e); - //break; - } - } - } - } - } - } if(ParseXML.getRoles(VRE).containsKey(initialRoleName)){ - isSystemRole = true; - HashMap hMap = ParseXML.getRoles(VRE); - if(hMap.containsKey(initialRoleName)){ - hMap.put(initialRoleName, roleDescription); - ParseXML.updateRoles(hMap, VRE); - - List vreGroups = this.getGroupsByType(VRE); - - for(GroupModel group:vreGroups){ - List rm = this.listRolesByGroup(group.getGroupId()); - for(RoleModel roleModel : rm){ - if(roleModel.getRoleName().equals(initialRoleName)){ - if(this.listRolesByGroup(group.getGroupId()).contains(initialRoleName)){ - String vreroleId = this.getRoleId(initialRoleName, group.getGroupName()); - Role affectedRole; - try { - try { - affectedRole = RoleLocalServiceUtil.getRole(Long.parseLong(vreroleId)); - } catch (SystemException e) { - throw new UserManagementSystemException("Error updating role ", initialRoleName , e); - } - } catch (PortalException e) { - throw new RoleRetrievalFault("Error retrieving role with name ", initialRoleName, e); - } - affectedRole.setDescription(roleDescription); - try { - RoleLocalServiceUtil.updateRole(affectedRole); - } catch (SystemException e) { - throw new UserManagementSystemException("Error updating role ", initialRoleName , e); - } - } - } - } - } - } - } if(ParseXML.getRoles(ROOT_VO).containsKey(initialRoleName)){ - isSystemRole = true; - HashMap hMap = ParseXML.getRoles(ROOT_VO); - if(hMap.containsKey(initialRoleName)){ - ParseXML.updateRoles(hMap, ROOT_VO); - - List rootvoGroups = this.getGroupsByType(ROOT_VO); - for(GroupModel group:rootvoGroups){ - List rm = this.listRolesByGroup(group.getGroupId()); - for(RoleModel roleModel : rm){ - if(roleModel.getRoleName().equals(initialRoleName)){ - String rootVoroleId = this.getRoleId(initialRoleName, group.getGroupName()); - Role affectedRole; - try { - try { - affectedRole = RoleLocalServiceUtil.getRole(Long.parseLong(rootVoroleId)); - } catch (SystemException e) { - throw new UserManagementSystemException("Error updating role ", initialRoleName , e); - } - } catch (PortalException e) { - throw new RoleRetrievalFault("Error retrieving role with name ", initialRoleName, e); - } - affectedRole.setDescription(roleDescription); - try { - RoleLocalServiceUtil.updateRole(affectedRole); - } catch (SystemException e) { - throw new UserManagementSystemException("Error updating role ", initialRoleName , e); - } - } - } - } - } - }if(!isSystemRole){ - role.setDescription(roleDescription); - newRoleName = newRoleName + "-" + groupName; - role.setName(newRoleName); - try { - RoleLocalServiceUtil.updateRole(role); - } catch (SystemException e) { - throw new UserManagementSystemException("Error updating role ", initialRoleName , e); - } - } - - /* role.setName(roleModel.getRoleName()); - role.setDescription(roleModel.getDescription());*/ - - - } - - - - public void updatePredefinedRoles(HashMap rolesMap, String groupType) - throws UserManagementIOException, UserManagementFileNotFoundException { - if(groupType.equals(VRE)){ - ParseXML.updateRoles(rolesMap, VRE); - }else if (groupType.equals(VO)){ - ParseXML.updateRoles(rolesMap, VO); - }else if(groupType.equals(ROOT_VO)){ - ParseXML.updateRoles(rolesMap, ROOT_VO); - } - - } - -} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayUserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayUserManager.java deleted file mode 100644 index 4f2407d..0000000 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayUserManager.java +++ /dev/null @@ -1,969 +0,0 @@ -package org.gcube.vomanagement.usermanagement.impl.liferay; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; - -import org.gcube.vomanagement.usermanagement.GroupManager; -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.impl.liferay.utils.ExpandoClassCodeManager; -import org.gcube.vomanagement.usermanagement.impl.liferay.utils.ExpandoDefaultTableManager; -import org.gcube.vomanagement.usermanagement.model.GroupModel; -import org.gcube.vomanagement.usermanagement.model.RoleModel; -import org.gcube.vomanagement.usermanagement.model.UserModel; - - -import com.liferay.portal.kernel.exception.PortalException; -import com.liferay.portal.kernel.exception.SystemException; -import com.liferay.portal.model.MembershipRequest; -import com.liferay.portal.model.Organization; -import com.liferay.portal.model.Role; -import com.liferay.portal.model.User; -import com.liferay.portal.service.MembershipRequestLocalServiceUtil; -import com.liferay.portal.service.OrganizationLocalServiceUtil; -import com.liferay.portal.service.RoleLocalServiceUtil; -import com.liferay.portal.service.ServiceContext; -import com.liferay.portal.service.UserLocalServiceUtil; -import com.liferay.portlet.expando.model.ExpandoColumn; -import com.liferay.portlet.expando.model.ExpandoTable; -import com.liferay.portlet.expando.model.ExpandoValue; -import com.liferay.portlet.expando.service.ExpandoColumnLocalServiceUtil; -import com.liferay.portlet.expando.service.ExpandoValueLocalServiceUtil; - -/** - * Liferay plugin for the UserManager interface, this implementation interacts with Liferay through a LocalService. - * - * @author Giulio Galiero - * - */ - - -public class LiferayUserManager implements UserManager { - - private final String DEFAULT_STRING = "_"; - - private long convertStringToLong(String id){ - return Long.parseLong(id); - } - - - public List getAllUsers () throws UserManagementSystemException, UserRetrievalFault - { - List users = null; - List response = new ArrayList(); - - try { - users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error getting the user list",e); - } - for(User user: users) - { - - response.add(new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(), user.getCreateDate().getTime() ,this.getUserCustomAttributes(String.valueOf(user.getUserId())))); - - } - - return response; - } - - public String getUserId(String userName) throws UserManagementSystemException{ - List users = null; - long userId = 0; - try { - users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error getting the User Id of user ",userName, e); - } - for(User user: users){ - if(user.getScreenName().equalsIgnoreCase(userName)){ - userId = user.getUserId(); - break; - } - } - return String.valueOf(userId); - } - - public void assignUserToGroup(String groupIdn, String userIdn) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault, UserManagementPortalException { - long userId = this.convertStringToLong(userIdn); - List memberRequests = null; - long groupId = this.convertStringToLong(groupIdn); - long[] userIds = {userId}; - GroupManager groupManager = new LiferayGroupManager(); - Organization org = null; - - // Add the user to Parent Organization if they are not already added - try { - org = OrganizationLocalServiceUtil.getOrganization(groupId); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with groupId ",groupIdn, e); - } - User user = null; - List orgs = null; - try { - user = UserLocalServiceUtil.getUser(userId); - orgs = user.getOrganizations(); - } catch (PortalException e) { - throw new UserRetrievalFault("No user exists with userId ",userIdn, e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } - - if(groupManager.isRootVO(groupIdn)){ - //RootVO - try { - UserLocalServiceUtil.addOrganizationUsers(groupId, userIds); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } catch (PortalException e) { - throw new UserManagementPortalException("Check if user already exists in group ", groupIdn , e); - } - - }else if (groupManager.isVO(groupIdn)){ - //VO - try { - UserLocalServiceUtil.addOrganizationUsers(groupId, userIds); - } catch (PortalException e) { - throw new UserManagementPortalException("Check if user already exists in group ", groupIdn , e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } - long parentOrgId = org.getParentOrganizationId(); - Organization parentOrg = null; - try { - parentOrg = OrganizationLocalServiceUtil.getOrganization(parentOrgId); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with groupId ",String.valueOf(parentOrgId), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } - if(!orgs.contains(parentOrg)){ - try { - UserLocalServiceUtil.addOrganizationUsers(parentOrgId, userIds); - } catch (PortalException e) { - throw new UserManagementPortalException("Check if user already exists in group ", String.valueOf(parentOrgId) , e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } - } - - }else if (groupManager.isVRE(groupIdn)){ - //VRE - try { - UserLocalServiceUtil.addOrganizationUsers(groupId, userIds); - } catch (PortalException e) { - throw new UserManagementPortalException("Check if user already exists in group ", String.valueOf(groupId) , e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } - long parentOrgId = org.getParentOrganizationId(); - Organization parentOrg = null; - try { - parentOrg = OrganizationLocalServiceUtil.getOrganization(parentOrgId); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with groupId ",String.valueOf(parentOrgId), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } - if(!orgs.contains(parentOrg)){ - try { - UserLocalServiceUtil.addOrganizationUsers(parentOrgId, userIds); - } catch (PortalException e) { - throw new GroupRetrievalFault("Check if user already exists in group ",String.valueOf(parentOrgId), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } - } - - try { - parentOrgId = org.getParentOrganization().getParentOrganizationId(); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with groupId ",String.valueOf(parentOrgId), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } - try { - parentOrg = OrganizationLocalServiceUtil.getOrganization(parentOrgId); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with groupId ",String.valueOf(parentOrgId), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } - if(!orgs.contains(parentOrg)){ - try { - UserLocalServiceUtil.addOrganizationUsers(parentOrgId, userIds); - } catch (PortalException e) { - throw new GroupRetrievalFault("Check if user already exists in group ",String.valueOf(parentOrgId), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); - } - } - - - } - //delete the corresponding member request from the MembershipRequest table - try { - memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error getting membership request ", e); - } - for(MembershipRequest memberRequest: memberRequests){ - if(memberRequest.getUserId()==userId && memberRequest.getGroupId()==org.getGroup().getGroupId()){ - try { - MembershipRequestLocalServiceUtil.deleteMembershipRequest(memberRequest); - } catch (SystemException e) { - throw new UserManagementSystemException("Error deleting membership request ", String.valueOf(memberRequest.getMembershipRequestId()) , e); - } - } - } - - - } - - public void requestMembership(String userIdn, String groupIdn,String comment) throws UserManagementSystemException, GroupRetrievalFault{ - long userId = this.convertStringToLong(userIdn); - long organizationId = this.convertStringToLong(groupIdn); - Organization org = null; - try { - org = OrganizationLocalServiceUtil.getOrganization(organizationId); - } catch (SystemException e) { - throw new UserManagementSystemException("Error adding membership request to group ", groupIdn , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with groupId ",groupIdn, e); - } - try { - if (!checkString(comment)) comment = DEFAULT_STRING; - MembershipRequest mr = MembershipRequestLocalServiceUtil.addMembershipRequest(userId, org.getGroup().getGroupId(), comment); - } catch (PortalException e) { - throw new GroupRetrievalFault("error adding membership request for user id ",userIdn, e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error adding membership request to group ", groupIdn , e); - } - - } - - /** - * - * If the string is null, empty or a digit returns false - * - * @param string - * @return false if the string is empty, null or a digit, true otherwise - */ - private boolean checkString (String string) - { - boolean response = true; - - try - { - Double.parseDouble(string); - response = false; - - } catch (NullPointerException e) - { - response = false; - } catch (NumberFormatException e) - { - if (string.trim().length() ==0) return false; - } - - return response; - } - - - public List getMembershipRequests(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault{ - List memberRequests = null; - List users = new ArrayList(); - Organization org = null; - UserModel um = null; - try { - memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving Membership requests of group ",groupId, e); - } - try { - org = OrganizationLocalServiceUtil.getOrganization(convertStringToLong(groupId)); - } catch (PortalException e) { - throw new GroupRetrievalFault("error retrieving group for group Id ",groupId, e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving Membership requests of group ",groupId, e); - } - for(MembershipRequest memberRequest: memberRequests){ - if(memberRequest.getGroupId() == org.getGroup().getGroupId()){ - long userId = memberRequest.getUserId(); - User user = null; - try { - user = UserLocalServiceUtil.getUser(userId); - } catch (PortalException e) { - throw new UserRetrievalFault("Error retrieving user for user Id ",String.valueOf(userId),e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving Membership requests of group ",groupId, e); - } - um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); - users.add(um); - break; - } - } - - return users; - - } - - - public void createUser(UserModel userModel) throws UserManagementSystemException, UserRetrievalFault { - String password1 = null; - Locale locale = new Locale("en_US"); - ServiceContext serviceContext = new ServiceContext(); - String password2 = null; - try { - UserLocalServiceUtil.addUser(0L, 1L, true, password1,password2, false, userModel.getScreenName(),userModel.getEmail(), 0L,"", - locale, userModel.getFirstname(), "mn", userModel.getLastname(), 0, 0, true, 1, 1, 1940, "", null, null, null, null, true, serviceContext); - }catch (SystemException e) { - throw new UserManagementSystemException("Error creating user ",userModel.getScreenName(), e); - } catch (PortalException e) { - throw new UserRetrievalFault("Error adding user with screen name ",userModel.getScreenName(),e); - } - } - - public void deleteUser(String userId)throws UserManagementSystemException, UserRetrievalFault { - try { - UserLocalServiceUtil.deleteUser(this.convertStringToLong(userId)); - }catch (SystemException e) { - throw new UserManagementSystemException("Error deleting user ",userId, e); - } catch (PortalException e) { - throw new UserRetrievalFault("Error deleting user with user Id ",userId,e); - } - - } - - - public void dismissUserFromGroup(String groupId, String userId) throws UserManagementSystemException, NumberFormatException, GroupRetrievalFault, UserRetrievalFault { - long[] userIds = {this.convertStringToLong(userId)}; - GroupManager groupManager = new LiferayGroupManager(); - long groupIdL = this.convertStringToLong(groupId); - List dismissedGroups = new ArrayList(); - List userOrgs = null; - try{ - - userOrgs = OrganizationLocalServiceUtil.getUserOrganizations(this.convertStringToLong(userId)); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); - } catch (PortalException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // Remove the user from sub organizations - if(groupManager.isRootVO(groupId)){ - //RootVO - // Remove the user from all groups - for(Organization userOrg : userOrgs){ - try { - UserLocalServiceUtil.unsetOrganizationUsers(userOrg.getOrganizationId(), userIds); - } catch (PortalException e) { - throw new UserRetrievalFault("Check the validity userId /Group Id ",e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); - } - dismissedGroups.add(userOrg); - } - - }else if (groupManager.isVO(groupId)){ - //VO - //Remove user from VREs under the VO - //Remove user from VO - try { - UserLocalServiceUtil.unsetOrganizationUsers(groupIdL, userIds); - } catch (PortalException e) { - throw new UserRetrievalFault("Check the validity of userId /Group Id ",e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); - } - try { - dismissedGroups.add(OrganizationLocalServiceUtil.getOrganization(groupIdL)); - } catch (PortalException e) { - throw new GroupRetrievalFault("Error retrieving group with group Id ",String.valueOf(groupIdL), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); - } - //Remove user from subgroups - List VREGroups = groupManager.listSubGroupsByGroup(groupId); - for(GroupModel VREGroup : VREGroups){ - try { - UserLocalServiceUtil.unsetOrganizationUsers(Long.parseLong(VREGroup.getGroupId()), userIds); - } catch (PortalException e) { - throw new UserRetrievalFault("Check the validity of userId /Group Id ",e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); - } - try { - dismissedGroups.add(OrganizationLocalServiceUtil.getOrganization(Long.parseLong(VREGroup.getGroupId()))); - } catch (PortalException e) { - throw new GroupRetrievalFault("Error retrieving group with group Id ",VREGroup.getGroupId(), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); - } - } - }else if(groupManager.isVRE(groupId)){ - //VRE - //Remove user from the VRE - try { - UserLocalServiceUtil.unsetOrganizationUsers(groupIdL, userIds); - } catch (PortalException e) { - throw new UserRetrievalFault("Check the validity of userId /Group Id ",e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); - } - try { - dismissedGroups.add(OrganizationLocalServiceUtil.getOrganization(groupIdL)); - } catch (PortalException e) { - throw new GroupRetrievalFault("Error retrieving group with group Id ",String.valueOf(groupIdL), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); - } - } - - // Remove all roles from the user that is relevant to the group - List userRoles = null; - try { - userRoles = RoleLocalServiceUtil.getUserRoles(this.convertStringToLong(userId)); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); - } - for(Organization dismissedGroup : dismissedGroups){ - String dismissedGroupName = dismissedGroup.getName(); - for(Role userRole : userRoles){ - if(userRole.getName().contains(dismissedGroupName)){ - long[] roleIds ={userRole.getRoleId()}; - try { - RoleLocalServiceUtil.unsetUserRoles(this.convertStringToLong(userId), roleIds); - } catch (PortalException e) { - throw new UserRetrievalFault("Error unsetting user roles for user ",userId, e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); - } - } - } - } - } - - - public UserModel getUser(String userId) throws UserManagementSystemException, UserRetrievalFault { - User user = null; - UserModel um = new UserModel(); - try { - user = UserLocalServiceUtil.getUser(this.convertStringToLong(userId)); - }catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving user ",userId, e); - } catch (PortalException e) { - throw new UserRetrievalFault("Error retrieving user for user Id ",userId, e); - } - um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); - return um; - } - - - public List listUsers() throws UserManagementSystemException, UserRetrievalFault { - List users = null; - List userModels = new ArrayList(); - try { - users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount()); - for(User user : users){ - UserModel um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); - userModels.add(um); - } - }catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving list of users ", e); - } - return userModels; - } - - - public HashMap> listUsersAndGroupsByRole(String roleIdn) throws UserManagementSystemException, RoleRetrievalFault, UserRetrievalFault { - List users; - long userId; - HashMap> hMap = new HashMap>(); - HashMap> hMapCustom = new HashMap>(); - UserModel um = null; - long roleId = this.convertStringToLong(roleIdn); - try { - users = UserLocalServiceUtil.getRoleUsers(roleId); - for(User user : users){ - userId = user.getUserId(); - um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); - Role role = null; - List group = new ArrayList(); - List groupModel = new ArrayList(); - List orgs = null; - try { - role = RoleLocalServiceUtil.getRole(roleId); - orgs = OrganizationLocalServiceUtil.getUserOrganizations(userId); - } catch (PortalException e) { - throw new RoleRetrievalFault("Error retrieving role for role Id",String.valueOf(roleId),e); - } - String roleName = role.getName(); - for(Organization org : orgs){ - if(roleName.contains(org.getName())){ - group.add(org); - GroupModel gm = new GroupModel(String.valueOf(org.getOrganizationId()),String.valueOf(org.getParentOrganizationId()),org.getName(),org.getComments(),org.getLogoId()); - groupModel.add(gm); - hMap.put(user, group); - - } - } - hMapCustom.put(um, groupModel); - } - }catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving list of users and groups for role ",roleIdn, e); - } - return hMapCustom; - } - - - public HashMap> listUsersAndRolesByGroup(String orgIdn) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault { - List users = null; - List roles = null; - UserModel um = null; - String orgName = null; - String roleName = null; - String completeRoleName = null; - HashMap> hMap = new HashMap>(); - long orgId = this.convertStringToLong(orgIdn); - LiferayRoleManager roleMan = new LiferayRoleManager(); - try { - users = UserLocalServiceUtil.getOrganizationUsers(orgId); - Organization org = OrganizationLocalServiceUtil.getOrganization(orgId); - orgName = org.getName(); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving list of users for group Id ",orgIdn, e); - } catch (PortalException e) { - throw new GroupRetrievalFault("Error retrieving group with group Id ",orgIdn, e); - } - for(User user : users){ - List userRoles = new ArrayList(); - um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); - try { - roles = user.getRoles(); - } catch (SystemException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Role Prod_Supp_role = roleMan.getCommonRole(); - if(Prod_Supp_role!=null){ - if(roles.contains(Prod_Supp_role)){ - RoleModel rm = new RoleModel(Prod_Supp_role.getName(),String.valueOf(Prod_Supp_role.getRoleId()),Prod_Supp_role.getDescription()); - userRoles.add(rm); - } - } - - - for(Role role : roles){ - if(role.getName().contains(orgName)){ - completeRoleName = role.getName(); - roleName = roleMan.getRoleName(completeRoleName); - RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); - rm.setCompleteName(completeRoleName); - userRoles.add(rm); - } - } - hMap.put(um,userRoles); - } - return hMap; - } - - - public List listUsersByGroup(String groupId) throws UserManagementSystemException, UserRetrievalFault { - List users = null; - List userModels = new ArrayList(); - try { - users = UserLocalServiceUtil.getOrganizationUsers(this.convertStringToLong(groupId)); - for(User user : users){ - UserModel um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); - userModels.add(um); - } - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving list of group users for group Id ",groupId, e); - } - return userModels; - } - - - public List listUsersByGroupAndRole(String groupIdn, String roleIdn) throws UserManagementSystemException, UserRetrievalFault { - List users = new ArrayList(); - List userModels = new ArrayList(); - List groupUsers = null; - long userId; - long roleId = this.convertStringToLong(roleIdn); - long groupId = this.convertStringToLong(groupIdn); - try { - groupUsers = UserLocalServiceUtil.getOrganizationUsers(groupId); - for(User user : groupUsers){ - userId = user.getUserId(); - if(RoleLocalServiceUtil.hasUserRole(userId, roleId)){ - if(OrganizationLocalServiceUtil.hasUserOrganization(userId, groupId)){ - users.add(user); - UserModel um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); - userModels.add(um); - } - } - } - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving list of users by group and role", e); - } - return userModels; - } - - - public List listPendingUsersByGroup(String groupIdn) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault { - List userModels = new ArrayList(); - List memberRequests = null; - //List usermodels = new HashMap (); - long groupId = this.convertStringToLong(groupIdn); - Organization org; - try { - org = OrganizationLocalServiceUtil.getOrganization(groupId); - memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); - }catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving pending users for group ",groupIdn, e); - } catch (PortalException e) { - throw new GroupRetrievalFault("Error retrieving group with group Id ",groupIdn, e); - } - - for(MembershipRequest memberRequest: memberRequests){ - if(memberRequest.getGroupId()==org.getGroup().getGroupId()){ - long userId = memberRequest.getUserId(); - User user = null; - try { - user = UserLocalServiceUtil.getUser(userId); - } catch (PortalException e) { - throw new UserRetrievalFault("Error retrieving user for user Id ",String.valueOf(userId), e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving pending users for group ",groupIdn, e); - } - UserModel um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); - userModels.add(um); - } - } - return userModels; - } - - - public void updateUser(UserModel usermodel) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { - try { - User user = null; - LiferayGroupManager gm = new LiferayGroupManager(); - long companyId = gm.getCompanyId(); - try { - user = UserLocalServiceUtil.getUserByScreenName(companyId, usermodel.getScreenName()); - user.setEmailAddress(usermodel.getEmail()); - user.setFirstName(usermodel.getFirstname()); - user.setLastName(usermodel.getLastname()); - }catch (PortalException e) { - throw new UserRetrievalFault("Error retrieving user by screen name ",usermodel.getScreenName(), e); - } - UserLocalServiceUtil.updateUser(user); - } catch (SystemException e) { - throw new UserManagementSystemException("Error updating user ",usermodel.getScreenName(), e); - } - - } - - - public List listUnregisteredUsersByGroup(String groupIdn) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault{ - List users = new ArrayList(); - List unregisteredUsers = new ArrayList(); - List unregisteredUserModels = new ArrayList(); - - long groupId = this.convertStringToLong(groupIdn); - Organization org; - try { - org = OrganizationLocalServiceUtil.getOrganization(groupId); - users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving unregistered users for group ",groupIdn, e); - } catch (PortalException e) { - throw new GroupRetrievalFault("Error retrieving group with group Id ",groupIdn, e); - } - - for(User user : users){ - boolean isRegistered = false; - //System.out.println(user.getFirstName()); - List userOrgs = null; - try { - userOrgs = user.getOrganizations(); - } catch (PortalException e) { - e.printStackTrace(); - } catch (SystemException e) { - e.printStackTrace(); - } - for(Organization userOrg : userOrgs){ - if(userOrg.getOrganizationId()==org.getOrganizationId()){ - isRegistered = true; - } - } - if(!isRegistered){ - unregisteredUsers.add(user); - UserModel um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); - unregisteredUserModels.add(um); - } - } - return unregisteredUserModels; - } - - public String getMembershipRequestComment(String userId, String groupId) throws UserManagementSystemException, GroupRetrievalFault { - long userIdL = convertStringToLong(userId); - long groupIdL = convertStringToLong(groupId); - String comment = null; - List memberRequests = null; - try { - Organization org = OrganizationLocalServiceUtil.getOrganization(groupIdL); - memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); - for(MembershipRequest memberRequest: memberRequests){ - if(memberRequest.getGroupId()==org.getGroup().getGroupId() && memberRequest.getUserId() == userIdL){ - comment = memberRequest.getComments(); - break; - } - } - }catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving membership request comment ", e); - } catch (PortalException e) { - throw new GroupRetrievalFault("Error retrieving group with group Id ",groupId, e); - } - return comment; - } - - public UserModel getUserByScreenName(String screenName) throws UserManagementSystemException, UserManagementPortalException, UserRetrievalFault { - User user = null; - UserModel um = null; - LiferayGroupManager gm = new LiferayGroupManager(); - long companyId = gm.getCompanyId(); - try { - user = UserLocalServiceUtil.getUserByScreenName(companyId, screenName); - um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving user by screename ",screenName, e); - } catch (PortalException e) { - throw new UserManagementPortalException("Error retrieving user by screename ",screenName, e); - } - return um; - } - - - - public HashMap getUserCustomAttributes(String userId) throws UserManagementSystemException, UserRetrievalFault{ - - User user = null; - HashMap hMap = new HashMap(); - try { - user = UserLocalServiceUtil.getUser(Long.parseLong(userId)); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving custom attributes of user ",userId, e); - } catch (PortalException e) { - throw new UserRetrievalFault("Error retrieving user for user Id ",userId, e); - } - - try { - - long id = ExpandoClassCodeManager.getInstance().getClassCode(User.class); - ExpandoTable table = ExpandoDefaultTableManager.getInstance().getExpandoDefaultTable(id); - - if (table != null) - { - long tableID = table.getTableId(); - List columns = ExpandoColumnLocalServiceUtil.getColumns(tableID); - - for (ExpandoColumn column : columns) - { - ExpandoValue value = ExpandoValueLocalServiceUtil.getValue(tableID, column.getColumnId(), user.getUserId()); - String valueString = ""; - - if (value != null && value.getString() != null) valueString = value.getString(); - - //System.out.println(valueString); - - hMap.put(column.getName(), valueString); - } - - } - - } catch (Exception e) - { - e.printStackTrace(); - } - return hMap; - } - - - public String getUserCustomAttributeByName(String userId, String attrName) throws UserManagementSystemException, UserRetrievalFault{ - User user = null; - try { - user = UserLocalServiceUtil.getUser(this.convertStringToLong(userId)); - }catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving custom attributes of user ",userId, e); - } catch (PortalException e) { - throw new UserRetrievalFault("Error retrieving user for user Id ",userId, e); - } - - String response = null; - - long id = ExpandoClassCodeManager.getInstance().getClassCode(User.class); - ExpandoTable table = ExpandoDefaultTableManager.getInstance().getExpandoDefaultTable(id); - - - if (table != null) - { - long tableID = table.getTableId(); - try { - - ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(tableID, attrName); - - if (column != null) - { - ExpandoValue value = ExpandoValueLocalServiceUtil.getValue(tableID, column.getColumnId(), user.getUserId()); - - if (value != null) response = value.getString(); - - } - } catch (SystemException e) - { - throw new UserManagementSystemException("Error retriving custom attributes",userId, e); - } catch (PortalException e) - { - throw new UserRetrievalFault("Error retriving custom attributes ",userId, e); - } - } - - - return response; - } - - public void setUserCustomAttributeByName(String userId, String attrName, String attrValue) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException{ - User user = null; - boolean attrPresent = false; - try { - user = UserLocalServiceUtil.getUser(this.convertStringToLong(userId)); - }catch (SystemException e) { - throw new UserManagementSystemException("Error setting custom attributes of user ",userId, e); - } catch (PortalException e) { - throw new UserRetrievalFault("Error retrieving user for user Id ",userId, e); - } - Enumeration attrNamesExist = user.getExpandoBridge().getAttributeNames(); - while(attrNamesExist.hasMoreElements()){ - if(attrNamesExist.nextElement().equals(attrName)){ - attrPresent = true; - break; - } - } - if(attrPresent){ - user.getExpandoBridge().setAttribute(attrName, attrValue); - }else{ - try { - user.getExpandoBridge().addAttribute(attrName); - user.getExpandoBridge().setAttribute(attrName, attrValue); - } catch (PortalException e) { - throw new UserManagementPortalException("Error setting custom attributes of user ",userId, e); - } - - } - - } - - public void setUserCustomAttributes(String userId, HashMap hMap) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException{ - User user = null; - String attrName = null ; - boolean attrPresent = false; - try { - user = UserLocalServiceUtil.getUser(this.convertStringToLong(userId)); - }catch (SystemException e) { - throw new UserManagementSystemException("Error setting custom attributes of user ",userId, e); - } catch (PortalException e) { - throw new UserRetrievalFault("Error retrieving user for user Id ",userId, e); - } - - Iterator customAttributesIterNew = hMap.keySet().iterator(); - Enumeration attrNamesExist = user.getExpandoBridge().getAttributeNames(); - while(customAttributesIterNew.hasNext()){ - attrPresent = false; - String customAttribute = customAttributesIterNew.next(); - while(attrNamesExist.hasMoreElements()){ - attrName = attrNamesExist.nextElement(); - if(attrName.equals(customAttribute)){ - attrPresent = true; - break; - } - } - if(attrPresent){ - user.getExpandoBridge().setAttribute(attrName ,hMap.get(attrName) ); - }else{ - try { - user.getExpandoBridge().addAttribute(customAttribute); - user.getExpandoBridge().setAttribute(customAttribute, hMap.get(customAttribute)); - } catch (PortalException e) { - throw new UserManagementPortalException("Error setting custom attributes of user ",userId, e); - } - } - - } - - } - - public void denyMembershipRequest(String userId, String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException { - List memberRequests; - Organization org; - try { - memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); - } catch (SystemException e) { - throw new UserManagementSystemException("Error retrieving Membership requests ", e); - } - try { - org = OrganizationLocalServiceUtil.getOrganization(this.convertStringToLong(groupId)); - } catch (SystemException e) { - throw new UserManagementSystemException("Error deleting membership request of user ", userId , e); - } catch (PortalException e) { - throw new GroupRetrievalFault("No group exists with groupId ",groupId, e); - } - for(MembershipRequest memberRequest:memberRequests){ - if(memberRequest.getGroupId()==org.getGroup().getGroupId() && memberRequest.getUserId() == this.convertStringToLong(userId)){ - try { - MembershipRequestLocalServiceUtil.deleteMembershipRequest(memberRequest.getMembershipRequestId()); - } catch (PortalException e) { - throw new UserManagementPortalException("Error deleting membership request of user ", userId , e); - } catch (SystemException e) { - throw new UserManagementSystemException("Error deleting membership request of user ", userId , e); - } - break; - } - } - //MembershipRequestLocalServiceUtil.updateStatus(replierUserId, membershipRequestId, replyComments, statusId) - } - -// public List getUserCustomAttributes(String userId) -// throws UserManagementSystemException, UserRetrievalFault -// { -// HashMap map = internalGetUserCustomAttributes(userId); -// List response = new ArrayList(); -// -// if (map != null) -// { -// Iterator keys = map.keySet().iterator(); -// -// while (keys.hasNext()) -// { -// String key = keys.next(); -// response.add(new CustomFieldModel(key, map.get(key))); -// } -// } -// -// return response; -// } - - -} \ No newline at end of file diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/ParseXML.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/ParseXML.java deleted file mode 100644 index 2f74066..0000000 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/ParseXML.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.gcube.vomanagement.usermanagement.impl.liferay; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import java.io.FileWriter; -import java.io.IOException; - -import java.util.HashMap; -import java.util.Iterator; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.gcube.vomanagement.usermanagement.exception.UserManagementFileNotFoundException; -import org.gcube.vomanagement.usermanagement.exception.UserManagementIOException; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; - -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; - -public class ParseXML { - - - private static Document convertStringToDocument (FileInputStream inputFile) throws IOException { - - InputSource in = null; - try { - in = new InputSource (inputFile); - } catch (Exception e) { - e.printStackTrace(); - } - DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); - Document doc = null; - try { - doc = dfactory.newDocumentBuilder().parse(in); - } catch (Exception e) { - e.printStackTrace(); - } - inputFile.close(); - return doc; - } - - private static String document2String(Document document) throws Exception { - ByteArrayOutputStream baos; - Transformer t; - - baos = new ByteArrayOutputStream(); - t = TransformerFactory.newInstance().newTransformer(); - t.transform(new DOMSource(document), new StreamResult(baos)); - return baos.toString(); - - } - - protected static HashMap getRoles(String groupType) throws UserManagementFileNotFoundException, UserManagementIOException { - HashMap hMap = new HashMap(); - File file = new File (Settings.getInstance().getProperty("sharedDir")+ File.separator + "roles-config.xml"); - - Document dom = null; - try { - FileInputStream in = new FileInputStream(file); - dom = convertStringToDocument(in); - in.close(); - } catch (FileNotFoundException e) { - throw new UserManagementFileNotFoundException("Roles config file not found. Check if the config file exists", e); - } catch (IOException e) { - throw new UserManagementIOException("Error writing to the roles config file", e); - } - Element elem = dom.getDocumentElement(); - - NodeList nl = elem.getElementsByTagName(groupType); - for(int i=0;i rolesMap, String groupType) throws UserManagementIOException, UserManagementFileNotFoundException{ - File file = new File (Settings.getInstance().getProperty("sharedDir")+ File.separator + "roles-config.xml"); - Document dom; - Iterator keyIter = rolesMap.keySet().iterator(); - try { - dom = convertStringToDocument(new FileInputStream(file)); - } catch (FileNotFoundException e) { - throw new UserManagementFileNotFoundException("Roles config file not found. Check if the config file exists", e); - } catch (IOException e) { - throw new UserManagementIOException("Error writing to the roles config file", e); - } - Element elem = dom.getDocumentElement(); - NodeList nl = elem.getElementsByTagName(groupType); - for(int i=0;i0){ - Element el2 = (Element)nl2.item(nl2.getLength()-1); - el.removeChild(el2); - } - - while(keyIter.hasNext()){ - Element role = dom.createElement("role"); - - Element roleNode = (Element)el.appendChild(role); - String roleName = keyIter.next(); - roleNode.setAttribute("name", roleName); - - roleNode.setAttribute("description", rolesMap.get(roleName)); - } - } - FileWriter out = null; - try { - out = new FileWriter(file); - } catch (IOException e) { - throw new UserManagementIOException("Error writing to the roles config file", e); - } - try { - out.write(document2String(dom)); - out.flush(); - out.close(); - } catch (IOException e) { - throw new UserManagementIOException("Error writing to the roles config file", e); - } catch (Exception e) { - e.printStackTrace(); - } - - } -} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/Settings.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/Settings.java deleted file mode 100644 index 8322b39..0000000 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/Settings.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.gcube.vomanagement.usermanagement.impl.liferay; - -import java.io.*; -import java.util.*; - -public class Settings { - - static Properties props = new Properties(); - static Settings settings = null; - - Settings() - { - try - { - props.load(Settings.class.getResourceAsStream("/etc/settings.properties")); - - } - catch (FileNotFoundException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - catch (IOException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public static Settings getInstance() - { - if (settings == null) - settings = new Settings(); - return settings; - } - - /** - * @return the props - */ - public String getProperty(String key) { - String value = props.getProperty(key); - if(value.contains("${")) - { - int start = 0; - int i; - while((i= value.indexOf("${", start)) != -1) - { - start = value.indexOf("}", i) +1; - String reg = value.substring(i, start); - //System.out.println(reg); - //System.out.println(reg.substring(2, reg.length() -1)); - value = value.replace(reg, (System.getProperty(reg.substring(2, reg.length() -1)) != null)?System.getProperty(reg.substring(2, reg.length() -1)):""); - } - } - return value; - } -} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoClassCodeManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoClassCodeManager.java deleted file mode 100644 index 4fc9846..0000000 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoClassCodeManager.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.gcube.vomanagement.usermanagement.impl.liferay.utils; - -import java.util.HashMap; -import java.util.Map; - -import com.liferay.portal.service.ClassNameLocalServiceUtil; - -/** - * - * Utility class to load the classes of custom field - * - * @author Ciro Formisano - * - */ -public class ExpandoClassCodeManager -{ - private Map map; - - private static ExpandoClassCodeManager instance; - - public static ExpandoClassCodeManager getInstance () - { - if (instance == null) instance = new ExpandoClassCodeManager(); - - return instance; - } - - public ExpandoClassCodeManager() - { - this.map = new HashMap (); - } - - public long getClassCode (Class type) - { - String className = type.getName(); - Long code = this.map.get(className); - - if (code == null) - { - code = ClassNameLocalServiceUtil.getClassNameId(type); - this.map.put(className, code); - } - - return code; - } - -} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoDefaultTableManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoDefaultTableManager.java deleted file mode 100644 index aaa86d8..0000000 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoDefaultTableManager.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.gcube.vomanagement.usermanagement.impl.liferay.utils; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import com.liferay.portlet.expando.model.ExpandoTable; -import com.liferay.portlet.expando.service.ExpandoTableLocalServiceUtil; - - -/** - * - * Utility class to load the table of custom fields - * - * @author Ciro Formisano - * - */ -public class ExpandoDefaultTableManager -{ - - private Map tableMap; - private final String DEFAULT_TABLE_NAME = "DEFAULT_TABLE"; - - private static ExpandoDefaultTableManager instance; - - public static ExpandoDefaultTableManager getInstance () - { - if (instance == null) - { - instance = new ExpandoDefaultTableManager(); - } - - return instance; - } - - public ExpandoDefaultTableManager() - { - this.tableMap = new HashMap (); - } - - public ExpandoTable getExpandoDefaultTable (long classId) - { - ExpandoTable response = this.tableMap.get(classId); - - if (response == null) - { - try - { - response = getExpandoDefaultTableFromDatabase(classId); - - if (response != null) this.tableMap.put(classId, response); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - return response; - } - - private ExpandoTable getExpandoDefaultTableFromDatabase (long classId) throws Exception - { - int numberOfTables = ExpandoTableLocalServiceUtil.getExpandoTablesCount(); - List tables = ExpandoTableLocalServiceUtil .getExpandoTables(0, numberOfTables); - ExpandoTable response = null; - - if (tables != null) - { - Iterator tableIterator = tables.iterator(); - - - while (tableIterator.hasNext() && response == null) - { - ExpandoTable currentTable = tableIterator.next(); - - if (currentTable.getName().equals(DEFAULT_TABLE_NAME) && currentTable.getClassNameId() == classId) response = currentTable; - } - } - - return response; - - } - -} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSGroupManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSGroupManager.java deleted file mode 100644 index 135e59a..0000000 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSGroupManager.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.gcube.vomanagement.usermanagement.impl.voms; - -import java.util.HashMap; -import java.util.List; - -import org.gcube.vomanagement.usermanagement.GroupManager; -import org.gcube.vomanagement.usermanagement.model.GroupModel; -import org.gcube.vomanagement.usermanagement.model.RoleModel; - -/** - * VOMS plugin for the GroupManager interface. - * - * @author Giulio Galiero - * - */ -public class VOMSGroupManager implements GroupManager { - - public void assignSubGrouptoParentGroup(String subGroupId, - String parentGroupId) { - // TODO Auto-generated method stub - - } - - public GroupModel createRootVO(String RootVOName, String userId, String description) { - // TODO Auto-generated method stub - return null; - } - - public GroupModel createVO(String VOName, String rootVOGroupId, - String userId, String description) { - // TODO Auto-generated method stub - return null; - } - - public GroupModel createVRE(String VREName, String VOGroupId, String userId, String description) { - // TODO Auto-generated method stub - return null; - } - - public void deleteGroup(String groupId) { - // TODO Auto-generated method stub - - } - - public void dismissSubGroupFromParentGroup(String subGroupId, - String parentGroupId) { - // TODO Auto-generated method stub - - } - - public GroupModel getGroup(String groupId) { - // TODO Auto-generated method stub - return null; - } - - public String getGroupId(String groupName) { - // TODO Auto-generated method stub - return null; - } - - public long getGroupParentId(String groupId) { - // TODO Auto-generated method stub - return 0; - } - - public GroupModel getRootVO() { - // TODO Auto-generated method stub - return null; - } - - public String getRootVOName() { - // TODO Auto-generated method stub - return null; - } - - public String getScope(String groupId) { - // TODO Auto-generated method stub - return null; - } - - public Boolean isRootVO(String groupId) { - // TODO Auto-generated method stub - return null; - } - - public Boolean isVO(String groupId) { - // TODO Auto-generated method stub - return null; - } - - public Boolean isVRE(String groupId) { - // TODO Auto-generated method stub - return null; - } - - public List listGroups() { - // TODO Auto-generated method stub - return null; - } - - public HashMap> listGroupsAndRolesByUser( - String userId) { - // TODO Auto-generated method stub - return null; - } - - public List listGroupsByUser(String userId) { - // TODO Auto-generated method stub - return null; - } - - public List listPendingGroupsByUser(String userId) { - // TODO Auto-generated method stub - return null; - } - - public List listSubGroupsByGroup(String groupId) { - // TODO Auto-generated method stub - return null; - } - - public void updateGroup(GroupModel group) { - // TODO Auto-generated method stub - - } - - - -} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSRoleManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSRoleManager.java deleted file mode 100644 index 9daf67f..0000000 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSRoleManager.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.gcube.vomanagement.usermanagement.impl.voms; - -import java.util.HashMap; -import java.util.List; - -import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; -import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; -import org.gcube.vomanagement.usermanagement.exception.UserManagementFileNotFoundException; -import org.gcube.vomanagement.usermanagement.exception.UserManagementIOException; -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.RoleModel; - - - -/** - * VOMS plugin for the RoleManager interface. - * - * @author Giulio Galiero - * - */ -public class VOMSRoleManager implements - org.gcube.vomanagement.usermanagement.RoleManager { - - public void assignRoleToUser(String groupId, String roleId, String userId) - throws UserManagementSystemException, UserRetrievalFault, - GroupRetrievalFault, RoleRetrievalFault { - // TODO Auto-generated method stub - - } - - public void createRole(String groupName) - throws UserManagementSystemException, GroupRetrievalFault, - RoleRetrievalFault, UserManagementPortalException, - UserManagementFileNotFoundException, UserManagementIOException { - // TODO Auto-generated method stub - - } - - public boolean createRole(String roleName, String roleDescription, - String groupName) throws UserManagementSystemException, - RoleRetrievalFault, GroupRetrievalFault, - UserManagementPortalException { - // TODO Auto-generated method stub - return false; - } - - public void deleteRole(String roleName, String groupName) - throws UserManagementSystemException, RoleRetrievalFault { - // TODO Auto-generated method stub - - } - - public void dismissRoleFromUser(String groupId, String roleId, String userId) - throws UserManagementSystemException, UserRetrievalFault, - GroupRetrievalFault, RoleRetrievalFault { - // TODO Auto-generated method stub - - } - - public RoleModel getRole(String roleId) - throws UserManagementSystemException, RoleRetrievalFault { - // TODO Auto-generated method stub - return null; - } - - public String getRoleId(String roleName, String groupName) - throws UserManagementSystemException { - // TODO Auto-generated method stub - return null; - } - - public HashMap listAllowedRoles(String groupName) - throws UserManagementSystemException, GroupRetrievalFault, - UserManagementFileNotFoundException, UserManagementIOException { - // TODO Auto-generated method stub - return null; - } - - @Deprecated - public List listRoles() throws UserManagementSystemException { - // TODO Auto-generated method stub - return null; - } - - public List listRolesByGroup(String groupId) - throws UserManagementSystemException, GroupRetrievalFault { - // TODO Auto-generated method stub - return null; - } - - public List listRolesByUser(String userId) - throws UserManagementSystemException { - // TODO Auto-generated method stub - return null; - } - - public List listRolesByUserAndGroup(String groupId, String userId) - throws UserManagementSystemException, GroupRetrievalFault, - UserRetrievalFault { - // TODO Auto-generated method stub - return null; - } - - public void updatePredefinedRoles(HashMap rolesMap, - String groupType) throws UserManagementIOException, - UserManagementFileNotFoundException { - // TODO Auto-generated method stub - - } - - public void updateRole(String initialRoleName, String newRoleName, - String roleDescription, String groupName) - throws UserManagementSystemException, RoleRetrievalFault, - NumberFormatException, UserManagementFileNotFoundException, - UserManagementIOException, GroupRetrievalFault, - UserManagementPortalException { - // TODO Auto-generated method stub - - } - - public List listAllRoles() throws UserManagementSystemException { - // TODO Auto-generated method stub - return null; - } - - public boolean isAdmin(String userId) { - // TODO Auto-generated method stub - return false; - } - - - -} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSUserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSUserManager.java deleted file mode 100644 index 79d0904..0000000 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSUserManager.java +++ /dev/null @@ -1,155 +0,0 @@ -package org.gcube.vomanagement.usermanagement.impl.voms; - -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.UserManagementPortalException; -import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; -import org.gcube.vomanagement.usermanagement.model.GroupModel; -import org.gcube.vomanagement.usermanagement.model.RoleModel; -import org.gcube.vomanagement.usermanagement.model.UserModel; - -/** - * VOMS plugin for the UserManager interface. - * - * @author Giulio Galiero - * - */ -public class VOMSUserManager implements UserManager { - - public void assignUserToGroup(String groupName, String userId) { - // TODO Auto-generated method stub - - } - - public void createUser(UserModel usermodel) { - // TODO Auto-generated method stub - - } - - public void deleteUser(String userId) { - // TODO Auto-generated method stub - - } - - public void dismissUserFromGroup(String groupName, String userId) { - // TODO Auto-generated method stub - - } - - public UserModel getUser(String userId) { - // TODO Auto-generated method stub - return null; - } - - public List listPendingUsersByGroup(String groupId) { - // TODO Auto-generated method stub - return null; - } - - public List listUsers() { - // TODO Auto-generated method stub - return null; - } - - public HashMap> listUsersAndGroupsByRole( - String roleName) { - // TODO Auto-generated method stub - return null; - } - - public HashMap> listUsersAndRolesByGroup( - String groupName) { - // TODO Auto-generated method stub - return null; - } - - public List listUsersByGroup(String groupId) { - // TODO Auto-generated method stub - return null; - } - - public List listUsersByGroupAndRole(String groupName, - String roleName) { - // TODO Auto-generated method stub - return null; - } - - public void updateUser(UserModel user) { - // TODO Auto-generated method stub - - } - - public List listUnregisteredUsersByGroup(String groupId) { - // TODO Auto-generated method stub - return null; - } - - public void requestMembership(String userId, String groupId, String comment) { - // TODO Auto-generated method stub - - } - - public String getUserId(String userName) { - // TODO Auto-generated method stub - return null; - } - - public List getMembershipRequests(String groupId) { - // TODO Auto-generated method stub - return null; - } - - public String getMembershipRequestComment(String userId, String groupId) { - // TODO Auto-generated method stub - return null; - } - - public UserModel getUserByScreenName(String screenName) { - // TODO Auto-generated method stub - return null; - } - - public HashMap getCustomAttributes(String userId) { - // TODO Auto-generated method stub - return null; - } - - public String getUserCustomAttributeByName(String userId, String attrName) - throws UserManagementSystemException { - // TODO Auto-generated method stub - return null; - } - - public HashMap getUserCustomAttributes(String userId) - throws UserManagementSystemException { - // TODO Auto-generated method stub - return null; - } - - public void setUserCustomAttributeByName(String userId, String attrName, - String attrValue) throws UserManagementSystemException, - UserManagementPortalException { - // TODO Auto-generated method stub - - } - - public void setUserCustomAttributes(String userId, - HashMap hMap) throws UserManagementSystemException, - UserManagementPortalException { - // TODO Auto-generated method stub - - } - - public void denyMembershipRequest(String userId, String groupId) - throws UserManagementSystemException, GroupRetrievalFault, - UserManagementPortalException { - // TODO Auto-generated method stub - - } - - - -} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/model/Email.java b/src/main/java/org/gcube/vomanagement/usermanagement/model/Email.java new file mode 100644 index 0000000..d3f38b7 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/model/Email.java @@ -0,0 +1,45 @@ +package org.gcube.vomanagement.usermanagement.model; + +import java.io.Serializable; + +@SuppressWarnings("serial") +public class Email implements Serializable { + private String email; + private String type; + boolean primary; + + public Email() { + super(); + } + public Email(String email, String type, boolean primary) { + super(); + this.email = email; + this.type = type; + this.primary = primary; + } + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public boolean isPrimary() { + return primary; + } + public void setPrimary(boolean primary) { + this.primary = primary; + } + @Override + public String toString() { + return "Email [email=" + email + ", type=" + type + ", primary=" + + primary + "]"; + } + + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/model/UserModel.java b/src/main/java/org/gcube/vomanagement/usermanagement/model/UserModel.java index 2b65294..6dca2d7 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/model/UserModel.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/model/UserModel.java @@ -1,94 +1,214 @@ package org.gcube.vomanagement.usermanagement.model; +import java.io.Serializable; +import java.util.Date; import java.util.HashMap; +import java.util.List; +import java.util.Map; /** - * Liferay User Object Model + * @author Massimiliano Assante, CNR-ISTI * */ -public class UserModel{ - - private String fullname; - +@SuppressWarnings("serial") +public class UserModel implements Serializable { + private long userId; + private String username; private String email; - - private String screenName; - - private String firstname; - - private String lastname; - - private String userId; - + private String firstName; + private String middleName; + private String lastName; + private String fullname; private long registrationDate; - - private HashMap customAttrsMap; - - public HashMap getCustomAttrsMap() { - return customAttrsMap; - } - public void setCustomAttrsMap(HashMap customAttrsMap) { + private String userAvatarId; + private boolean male; + private String jobTitle; + private Map customAttrsMap; + private List emailAddresses; + /** + * constructor without custom attrs + * @param userId + * @param username + * @param email + * @param firstName + * @param middleName + * @param lastName + * @param fullname + * @param registrationDate + * @param userAvatarId + * @param male + * @param jobTitle + * @param customAttrsMap + * @param emailAddresses + */ + public UserModel(long userId, String username, String email, + String firstName, String middleName, String lastName, + String fullname, long registrationDate, String userAvatarId, + boolean male, String jobTitle, Map customAttrsMap, + List emailAddresses) { + super(); + this.userId = userId; + this.username = username; + this.email = email; + this.firstName = firstName; + this.middleName = middleName; + this.lastName = lastName; + this.fullname = fullname; + this.registrationDate = registrationDate; + this.userAvatarId = userAvatarId; + this.male = male; + this.jobTitle = jobTitle; this.customAttrsMap = customAttrsMap; + this.emailAddresses = emailAddresses; } - public String getUserId() { + /** + * constructor without custom attrs + * @param userId + * @param username + * @param email + * @param firstName + * @param middleName + * @param lastName + * @param fullname + * @param registrationDate + * @param userAvatarId + * @param male + * @param jobTitle + * @param emailAddresses + */ + public UserModel(long userId, String username, String email, + String firstName, String middleName, String lastName, + String fullname, long registrationDate, String userAvatarId, + boolean male, String jobTitle, + List emailAddresses) { + super(); + this.userId = userId; + this.username = username; + this.email = email; + this.firstName = firstName; + this.middleName = middleName; + this.lastName = lastName; + this.fullname = fullname; + this.registrationDate = registrationDate; + this.userAvatarId = userAvatarId; + this.male = male; + this.jobTitle = jobTitle; + this.emailAddresses = emailAddresses; + } + + public long getUserId() { return userId; } - public void setUserId(String userId) { + + public void setUserId(long userId) { this.userId = userId; } - public String getFirstname() { - return firstname; - } - public void setFirstname(String firstname) { - this.firstname = firstname; - } - public String getLastname() { - return lastname; - } - public void setLastname(String lastname) { - this.lastname = lastname; + + public String getUsername() { + return username; } + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getMiddleName() { + return middleName; + } + + public void setMiddleName(String middleName) { + this.middleName = middleName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } public String getFullname() { return fullname; } + public void setFullname(String fullname) { this.fullname = fullname; } - public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } - public String getScreenName() { - return screenName; - } - public void setScreenName(String screenName) { - this.screenName = screenName; - } - public UserModel() { - - } - public long getRegistrationDate() { return registrationDate; } + public void setRegistrationDate(long registrationDate) { this.registrationDate = registrationDate; } - public UserModel(String userId, String firstname, String lastname, String fullname,String email,String screenname,long registrationDate,HashMap customAttrsMap) { - this.userId = userId; - this.firstname=firstname; - this.lastname=lastname; - this.fullname= fullname; - this.email = email; - this.screenName = screenname; - this.customAttrsMap = customAttrsMap; - this.registrationDate = registrationDate; - + + public String getUserAvatarId() { + return userAvatarId; } + + public void setUserAvatarId(String userAvatarId) { + this.userAvatarId = userAvatarId; + } + + public boolean isMale() { + return male; + } + + public void setMale(boolean male) { + this.male = male; + } + + public String getJobTitle() { + return jobTitle; + } + + public void setJobTitle(String jobTitle) { + this.jobTitle = jobTitle; + } + + public Map getCustomAttrsMap() { + return customAttrsMap; + } + public void setCustomAttrsMap(Map customAttrsMap) { + this.customAttrsMap = customAttrsMap; + } + public List getEmailAddresses() { + return emailAddresses; + } + + public void setEmailAddresses(List emailAddresses) { + this.emailAddresses = emailAddresses; + } + + @Override + public String toString() { + return "UserModel [userId=" + userId + ", username=" + username + + ", email=" + email + ", firstName=" + firstName + + ", middleName=" + middleName + ", lastName=" + lastName + + ", fullname=" + fullname + ", registrationDate=" + + new Date(registrationDate) + ", userAvatarId=" + userAvatarId + + ", male=" + male + ", jobTitle=" + jobTitle + + ", customAttrsMap=" + customAttrsMap + ", emailAddresses=" + + emailAddresses + "]"; + } + } \ No newline at end of file