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:
parent
da3b17c9c1
commit
7465bb2c39
|
@ -1,4 +1,7 @@
|
|||
<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"
|
||||
date="2016-09-28">
|
||||
<Change>Added efficient method to retireve VRE logo URLs</Change>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.dvos</groupId>
|
||||
<artifactId>usermanagement-core</artifactId>
|
||||
<version>2.1.0-SNAPSHOT</version>
|
||||
<version>2.2.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>User Management API</name>
|
||||
|
|
|
@ -100,7 +100,7 @@ public interface GroupManager {
|
|||
* @return the virtual group name associated to this group
|
||||
* @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
|
||||
|
|
|
@ -51,6 +51,9 @@ import com.liferay.portlet.expando.model.ExpandoBridge;
|
|||
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
|
||||
|
||||
public class LiferayGroupManager implements GroupManager {
|
||||
|
||||
private static final String DEFAULT_INFRA_NAME = "gcube";
|
||||
public static final String INFRASTRUCTURE_NAME = "infrastructure";
|
||||
/**
|
||||
* logger
|
||||
*/
|
||||
|
@ -136,28 +139,32 @@ public class LiferayGroupManager implements GroupManager {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException {
|
||||
VirtualGroup toReturn = new VirtualGroup();
|
||||
public List<VirtualGroup> getVirtualGroups(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) {
|
||||
String[] splits = values[0].split("\\|");
|
||||
toReturn.setName(splits[0]);
|
||||
toReturn.setDescription(splits[1]);
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
toReturn.setName("NoVirtualGroupAssigned");
|
||||
toReturn.setDescription("NoVirtualGroupDescription");
|
||||
toAdd.setName("NoVirtualGroupAssigned");
|
||||
toAdd.setDescription("NoVirtualGroupDescription");
|
||||
}
|
||||
}
|
||||
} 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 {
|
||||
Set<GCubeGroup> toReturn = new HashSet<>();
|
||||
try {
|
||||
List<VirtualGroup> currSiteVirtualGroups = ManagementUtils.getVirtualGroupsBySiteGroupId(ManagementUtils.getSiteGroupIdFromServletRequest(serverName));
|
||||
List<VirtualGroup> currSiteVirtualGroups = getVirtualGroups(ManagementUtils.getSiteGroupIdFromServletRequest(serverName));
|
||||
for (GCubeGroup userGroup : listGroupsByUser(userId)) {
|
||||
if (isVRE(userGroup.getGroupId())) {
|
||||
for (VirtualGroup vg : currSiteVirtualGroups)
|
||||
|
@ -609,8 +616,37 @@ public class LiferayGroupManager implements GroupManager {
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
package org.gcube.vomanagement.usermanagement.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.LoggerFactory;
|
||||
|
||||
|
@ -18,14 +12,8 @@ import com.liferay.portal.kernel.util.PropsUtil;
|
|||
import com.liferay.portal.model.Company;
|
||||
import com.liferay.portal.model.Group;
|
||||
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.GroupLocalServiceUtil;
|
||||
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
import com.liferay.portal.service.VirtualHostLocalServiceUtil;
|
||||
|
||||
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");
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue