Implemented support for Feature #4877 remove VRE association to single Category constraint

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@134344 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-11-17 17:24:24 +00:00
parent da3b17c9c1
commit 7465bb2c39
5 changed files with 53 additions and 67 deletions

View File

@ -1,4 +1,7 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.vo-management.usermanagement-core.2-2-0" date="2016-11-17">
<Change>Added method to read VirtualGroups associated to sites</Change>
</Changeset>
<Changeset component="org.gcube.vo-management.usermanagement-core.2-1-0" <Changeset component="org.gcube.vo-management.usermanagement-core.2-1-0"
date="2016-09-28"> date="2016-09-28">
<Change>Added efficient method to retireve VRE logo URLs</Change> <Change>Added efficient method to retireve VRE logo URLs</Change>

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.dvos</groupId> <groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId> <artifactId>usermanagement-core</artifactId>
<version>2.1.0-SNAPSHOT</version> <version>2.2.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>User Management API</name> <name>User Management API</name>

View File

@ -100,7 +100,7 @@ public interface GroupManager {
* @return the virtual group name associated to this group * @return the virtual group name associated to this group
* @throws GroupRetrievalFault * @throws GroupRetrievalFault
*/ */
VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException; List<VirtualGroup> getVirtualGroups(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException;
/* /*
* *
* @param scope the infrastructure scope e.g. /gcube/devsec * @param scope the infrastructure scope e.g. /gcube/devsec

View File

@ -51,6 +51,9 @@ import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil; import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
public class LiferayGroupManager implements GroupManager { public class LiferayGroupManager implements GroupManager {
private static final String DEFAULT_INFRA_NAME = "gcube";
public static final String INFRASTRUCTURE_NAME = "infrastructure";
/** /**
* logger * logger
*/ */
@ -136,28 +139,32 @@ public class LiferayGroupManager implements GroupManager {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException { public List<VirtualGroup> getVirtualGroups(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException {
VirtualGroup toReturn = new VirtualGroup(); List<VirtualGroup> toReturn = new ArrayList<VirtualGroup>();
try { try {
long userId = LiferayUserManager.getAdmin().getUserId(); long userId = LiferayUserManager.getAdmin().getUserId();
PrincipalThreadLocal.setName(userId); PrincipalThreadLocal.setName(userId);
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId)); PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId));
PermissionThreadLocal.setPermissionChecker(permissionChecker); PermissionThreadLocal.setPermissionChecker(permissionChecker);
Group site = GroupLocalServiceUtil.getGroup(actualGroupId); Group site = GroupLocalServiceUtil.getGroup(actualGroupId);
_log.debug("Set Thread Permission done, getVirtual Group of " + site.getName());
if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) { if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) {
String warningMessage = String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()); String warningMessage = String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
_log.warn(warningMessage); _log.warn(warningMessage);
throw new VirtualGroupNotExistingException(warningMessage); throw new VirtualGroupNotExistingException(warningMessage);
} else { } else {
String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()); String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
VirtualGroup toAdd = new VirtualGroup();
if (values != null && values.length > 0) { if (values != null && values.length > 0) {
String[] splits = values[0].split("\\|"); for (int i = 0; i < values.length; i++) {
toReturn.setName(splits[0]); toAdd = new VirtualGroup();
toReturn.setDescription(splits[1]); String[] splits = values[i].split("\\|");
toAdd.setName(splits[0]);
toAdd.setDescription(splits[1]);
toReturn.add(toAdd);
}
} else { } else {
toReturn.setName("NoVirtualGroupAssigned"); toAdd.setName("NoVirtualGroupAssigned");
toReturn.setDescription("NoVirtualGroupDescription"); toAdd.setDescription("NoVirtualGroupDescription");
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -414,7 +421,7 @@ public class LiferayGroupManager implements GroupManager {
public Set<GCubeGroup> listGroupsByUserAndSite(long userId, final String serverName) throws UserRetrievalFault, UserManagementSystemException, GroupRetrievalFault, VirtualGroupNotExistingException { public Set<GCubeGroup> listGroupsByUserAndSite(long userId, final String serverName) throws UserRetrievalFault, UserManagementSystemException, GroupRetrievalFault, VirtualGroupNotExistingException {
Set<GCubeGroup> toReturn = new HashSet<>(); Set<GCubeGroup> toReturn = new HashSet<>();
try { try {
List<VirtualGroup> currSiteVirtualGroups = ManagementUtils.getVirtualGroupsBySiteGroupId(ManagementUtils.getSiteGroupIdFromServletRequest(serverName)); List<VirtualGroup> currSiteVirtualGroups = getVirtualGroups(ManagementUtils.getSiteGroupIdFromServletRequest(serverName));
for (GCubeGroup userGroup : listGroupsByUser(userId)) { for (GCubeGroup userGroup : listGroupsByUser(userId)) {
if (isVRE(userGroup.getGroupId())) { if (isVRE(userGroup.getGroupId())) {
for (VirtualGroup vg : currSiteVirtualGroups) for (VirtualGroup vg : currSiteVirtualGroups)
@ -609,8 +616,37 @@ public class LiferayGroupManager implements GroupManager {
e.printStackTrace(); e.printStackTrace();
} }
} }
private static final String DEFAULT_INFRA_NAME = "gcube";
public static final String INFRASTRUCTURE_NAME = "infrastructure"; private VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException {
VirtualGroup toReturn = new VirtualGroup();
try {
long userId = LiferayUserManager.getAdmin().getUserId();
PrincipalThreadLocal.setName(userId);
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId));
PermissionThreadLocal.setPermissionChecker(permissionChecker);
Group site = GroupLocalServiceUtil.getGroup(actualGroupId);
_log.debug("Set Thread Permission done, getVirtual Group of " + site.getName());
if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) {
String warningMessage = String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
_log.warn(warningMessage);
throw new VirtualGroupNotExistingException(warningMessage);
} else {
String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
if (values != null && values.length > 0) {
String[] splits = values[0].split("\\|");
toReturn.setName(splits[0]);
toReturn.setDescription(splits[1]);
} else {
toReturn.setName("NoVirtualGroupAssigned");
toReturn.setDescription("NoVirtualGroupDescription");
}
}
} catch (Exception e) {
e.printStackTrace();
}
return toReturn;
}
/** /**
* read the infrastructure name from a property file and returns it * read the infrastructure name from a property file and returns it
*/ */

View File

@ -1,13 +1,7 @@
package org.gcube.vomanagement.usermanagement.util; package org.gcube.vomanagement.usermanagement.util;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys;
import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -18,14 +12,8 @@ import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.model.Company; import com.liferay.portal.model.Company;
import com.liferay.portal.model.Group; import com.liferay.portal.model.Group;
import com.liferay.portal.model.VirtualHost; import com.liferay.portal.model.VirtualHost;
import com.liferay.portal.security.auth.PrincipalThreadLocal;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.service.CompanyLocalServiceUtil; import com.liferay.portal.service.CompanyLocalServiceUtil;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.LayoutSetLocalServiceUtil; import com.liferay.portal.service.LayoutSetLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.service.VirtualHostLocalServiceUtil; import com.liferay.portal.service.VirtualHostLocalServiceUtil;
public class ManagementUtils { public class ManagementUtils {
@ -81,46 +69,5 @@ public class ManagementUtils {
_log.warn("serverName is " + serverName + " but i could not find any virtualHost associated to it"); _log.warn("serverName is " + serverName + " but i could not find any virtualHost associated to it");
return -1; return -1;
} }
/**
* read the list of virtual groups the current site (i-marine, services etc. ) should show up
* @param actualGroupId
* @return he list of virtual groups the current site (i-marine, services etc. ) should show up
* @throws GroupRetrievalFault
* @throws VirtualGroupNotExistingException
*/
public static List<VirtualGroup> getVirtualGroupsBySiteGroupId(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException {
List<VirtualGroup> toReturn = new ArrayList<VirtualGroup>();
try {
long userId = LiferayUserManager.getAdmin().getUserId();
PrincipalThreadLocal.setName(userId);
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId));
PermissionThreadLocal.setPermissionChecker(permissionChecker);
Group site = GroupLocalServiceUtil.getGroup(actualGroupId);
// _log.debug("Set Thread Permission done, getVirtual Group of " + site.getName());
if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) {
String warningMessage = String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
_log.warn(warningMessage);
throw new VirtualGroupNotExistingException(warningMessage);
} else {
String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
VirtualGroup toAdd = new VirtualGroup();
if (values != null && values.length > 0) {
for (int i = 0; i < values.length; i++) {
toAdd = new VirtualGroup();
String[] splits = values[i].split("\\|");
toAdd.setName(splits[0]);
toAdd.setDescription(splits[1]);
toReturn.add(toAdd);
//_log.debug("VirtualGroup selected found for " + site.getName() + " -> " + toAdd.getName());
}
} else {
toAdd.setName("NoVirtualGroupAssigned");
toAdd.setDescription("NoVirtualGroupDescription");
}
}
} catch (Exception e) {
e.printStackTrace();
}
return toReturn;
}
} }