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
This commit is contained in:
Massimiliano Assante 2017-02-23 17:24:59 +00:00
parent d2e809610b
commit 58e656caf6
6 changed files with 96 additions and 6 deletions

View File

@ -1,4 +1,7 @@
<ReleaseNotes>
<Changeset component="org.gcube.portal.plugins.VREFolder-hook.6-4-0" date="2017-02-23">
<Change>Feature #6680, added hook to keep in sync VRE Managers and Workspace VRE Folder Managers</Change>
</Changeset>
<Changeset component="org.gcube.portal.plugins.VREFolder-hook.6-3-0" date="2016-03-16">
<Change>First Release</Change>
</Changeset>

View File

@ -11,7 +11,7 @@
<groupId>org.gcube.portal.plugins</groupId>
<artifactId>VREFolder-hook</artifactId>
<name>VREFolder-hook Hook</name>
<version>6.3.0-SNAPSHOT</version>
<version>6.4.0-SNAPSHOT</version>
<packaging>war</packaging>
<description>
VREFolder-hook handles the user adding/removal from the related Home Library VRE Folder

View File

@ -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<com.liferay.portal.model.UserGroupRole> addUserGroupRoles(
long userId, long groupId, long[] roleIds)
throws com.liferay.portal.kernel.exception.SystemException {
List<UserGroupRole> 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);
}
}

View File

@ -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<com.liferay.portal.model.User> 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());
}

View File

@ -10,4 +10,13 @@
org.gcube.portal.plugins.GCubeHookUserLocalService
</service-impl>
</service>
<service>
<service-type>
com.liferay.portal.service.UserGroupRoleLocalService
</service-type>
<service-impl>
org.gcube.portal.plugins.GCubeHookSiteRoleLocalService
</service-impl>
</service>
</hook>

View File

@ -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
licenses=LGPL