From 58e656caf60de8a291003e0a6e8ff3eee886e3ae Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 23 Feb 2017 17:24:59 +0000 Subject: [PATCH] Feature #6680, added hook to keep in sync VRE Managers and Workspace VRE Folder Managers git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/liferay62-plugins/VREFolder-hook@144224 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 3 + pom.xml | 2 +- .../GCubeHookSiteRoleLocalService.java | 81 +++++++++++++++++++ .../plugins/GCubeHookUserLocalService.java | 3 - src/main/webapp/WEB-INF/liferay-hook.xml | 9 +++ .../WEB-INF/liferay-plugin-package.properties | 4 +- 6 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java diff --git a/distro/changelog.xml b/distro/changelog.xml index 2b49370..399c168 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,7 @@ + + Feature #6680, added hook to keep in sync VRE Managers and Workspace VRE Folder Managers + First Release diff --git a/pom.xml b/pom.xml index a549493..e5fa452 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.gcube.portal.plugins VREFolder-hook VREFolder-hook Hook - 6.3.0-SNAPSHOT + 6.4.0-SNAPSHOT war VREFolder-hook handles the user adding/removal from the related Home Library VRE Folder diff --git a/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java b/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java new file mode 100644 index 0000000..e501ead --- /dev/null +++ b/src/main/java/org/gcube/portal/plugins/GCubeHookSiteRoleLocalService.java @@ -0,0 +1,81 @@ +package org.gcube.portal.plugins; + +import java.util.List; + +import org.gcube.common.homelibrary.home.HomeLibrary; +import org.gcube.common.homelibrary.home.workspace.usermanager.UserManager; +import org.gcube.common.portal.PortalContext; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.model.GCubeRole; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.liferay.portal.model.Role; +import com.liferay.portal.model.UserGroupRole; +import com.liferay.portal.service.RoleLocalServiceUtil; +import com.liferay.portal.service.UserGroupRoleLocalService; +import com.liferay.portal.service.UserGroupRoleLocalServiceWrapper; +import com.liferay.portal.service.UserLocalServiceUtil; + +public class GCubeHookSiteRoleLocalService extends UserGroupRoleLocalServiceWrapper { + /** + * logger + */ + private static final Logger _log = LoggerFactory.getLogger(GCubeHookSiteRoleLocalService.class); + private GroupManager gm; + public GCubeHookSiteRoleLocalService(UserGroupRoleLocalService userGroupRoleLocalService) { + super(userGroupRoleLocalService); + gm = new LiferayGroupManager(); + System.out.println("GCubeHookSiteRoleLocalService hook is UP & Listening ..."); + } + + @Override + public java.util.List addUserGroupRoles( + long userId, long groupId, long[] roleIds) + throws com.liferay.portal.kernel.exception.SystemException { + List toReturn = super.addUserGroupRoles(userId, groupId, roleIds); + try { + _log.debug("Check if addUserGroupRoles is done in a VRE"); + if (gm.isVRE(groupId)) { + _log.debug("addUserGroupRoles performed in a VRE, groupId=" + groupId); + boolean vreManagerRolePresent = false; + for (int i = 0; i < roleIds.length; i++) { + Role role = RoleLocalServiceUtil.getRole(roleIds[i]); + if (role.getName().compareTo(GCubeRole.VRE_MANAGER_LABEL) == 0) { + _log.info("User is being promoted (or was) as VREFolder Administrator, userId=" + userId + " on Site groupId="+groupId); + vreManagerRolePresent = true; + break; + } + } + setVREFolderAdministrator(userId, groupId, vreManagerRolePresent); + } else { + _log.debug("addUserGroupRoles NOT done in a VRE, groupId=" + groupId); + } + } + catch (Exception e) { + e.printStackTrace(); + } + return toReturn; + } + + private void setVREFolderAdministrator(long userId, long groupId, boolean enable) throws Exception { + + String scopeVREFolder = gm.getInfrastructureScope(groupId); + + String currScope = ScopeProvider.instance.get(); + String scopeToset = "/"+PortalContext.getConfiguration().getInfrastructureName(); + ScopeProvider.instance.set(scopeToset); + + String username = UserLocalServiceUtil.getUser(userId).getScreenName(); + _log.debug("User " + username + " is going to be VRE Folder Admin?" + enable); + UserManager hlUm = HomeLibrary.getHomeManagerFactory().getUserManager(); + if (enable) + hlUm.setAdministrator(scopeVREFolder, username); + else + hlUm.removeAdministrator(scopeVREFolder, username); + + ScopeProvider.instance.set(currScope); + } +} diff --git a/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java b/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java index eafcb18..d6083f6 100644 --- a/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java +++ b/src/main/java/org/gcube/portal/plugins/GCubeHookUserLocalService.java @@ -74,19 +74,16 @@ public class GCubeHookUserLocalService extends UserLocalServiceWrapper { @Override public void deleteGroupUser(long groupId, com.liferay.portal.model.User user) throws com.liferay.portal.kernel.exception.SystemException { super.deleteGroupUser(groupId, user); - System.out.println("Non ci entra proprio deleteGroupUser"); removeUserFromHLVREFolder(groupId, user.getUserId()); } @Override public void deleteGroupUsers(long groupId, long[] userIds) throws com.liferay.portal.kernel.exception.SystemException { super.deleteGroupUsers(groupId, userIds); - System.out.println("Non ci entra proprio"); removeUsersFromHLVREFolder(groupId, userIds); } @Override public void deleteGroupUsers(long groupId, java.util.List Users) throws com.liferay.portal.kernel.exception.SystemException { super.deleteGroupUsers(groupId, Users); - System.out.println("Non ci entra proprio"); for (User user : Users) { removeUserFromHLVREFolder(groupId, user.getUserId()); } diff --git a/src/main/webapp/WEB-INF/liferay-hook.xml b/src/main/webapp/WEB-INF/liferay-hook.xml index 4b979d4..86429ea 100644 --- a/src/main/webapp/WEB-INF/liferay-hook.xml +++ b/src/main/webapp/WEB-INF/liferay-hook.xml @@ -10,4 +10,13 @@ org.gcube.portal.plugins.GCubeHookUserLocalService + + + + com.liferay.portal.service.UserGroupRoleLocalService + + + org.gcube.portal.plugins.GCubeHookSiteRoleLocalService + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/liferay-plugin-package.properties b/src/main/webapp/WEB-INF/liferay-plugin-package.properties index 169a8a1..4b2043e 100644 --- a/src/main/webapp/WEB-INF/liferay-plugin-package.properties +++ b/src/main/webapp/WEB-INF/liferay-plugin-package.properties @@ -1,9 +1,9 @@ name=VREFolder-hook module-group-id=liferay -module-incremental-version=1 +module-incremental-version=2 tags= short-description= change-log= page-url=http://www.liferay.com author=Liferay, Inc. -licenses=LGPL \ No newline at end of file +licenses=LGPL