added virtual groups management
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@125711 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
59a3786158
commit
321512e876
|
@ -9,8 +9,10 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementNameExcepti
|
|||
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.exception.VirtualGroupNotExistingException;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||
import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -86,12 +88,19 @@ public interface GroupManager {
|
|||
GCubeGroup getGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault;
|
||||
/**
|
||||
* Virtual Groups are handled as Custom attributes in Liferay Sites table
|
||||
* @param groupId the LR groupId
|
||||
* @param actualGroupId the LR groupId
|
||||
* @return the virtual group list available
|
||||
* @throws GroupRetrievalFault
|
||||
*/
|
||||
List<VirtualGroup> getVirtualGroups() throws VirtualGroupNotExistingException;
|
||||
/**
|
||||
* Virtual Groups are handled as Custom attributes in Liferay Sites table
|
||||
* @param actualGroupId the LR groupId
|
||||
* @return the virtual group name associated to this group
|
||||
* @throws GroupRetrievalFault
|
||||
*/
|
||||
String getVirtualGroupName(long groupId) throws GroupRetrievalFault;
|
||||
/**
|
||||
VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException;
|
||||
/*
|
||||
*
|
||||
* @param scope the infrastructure scope e.g. /gcube/devsec
|
||||
* @return the LR groupId, -1 otherwise
|
||||
|
|
|
@ -2,15 +2,8 @@ package org.gcube.vomanagement.usermanagement.exception;
|
|||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class GroupRetrievalFault extends Exception{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5809619725100397844L;
|
||||
|
||||
public GroupRetrievalFault(String errorMsg, String orgId ){
|
||||
System.out.println(errorMsg + orgId);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package org.gcube.vomanagement.usermanagement.exception;
|
||||
|
||||
import com.liferay.portal.kernel.exception.PortalException;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class VirtualGroupNotExistingException extends Exception {
|
||||
public VirtualGroupNotExistingException(String errorMsg, PortalException e){
|
||||
System.out.println(errorMsg);
|
||||
e.printStackTrace();
|
||||
}
|
||||
public VirtualGroupNotExistingException(String errorMsg){
|
||||
System.out.println(errorMsg);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package org.gcube.vomanagement.usermanagement.impl;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -14,8 +15,10 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementNameExcepti
|
|||
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.exception.VirtualGroupNotExistingException;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
||||
import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
|
||||
import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -39,6 +42,8 @@ import com.liferay.portal.service.LayoutSetLocalServiceUtil;
|
|||
import com.liferay.portal.service.RoleServiceUtil;
|
||||
import com.liferay.portal.service.ServiceContext;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
import com.liferay.portlet.expando.model.ExpandoBridge;
|
||||
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
|
||||
|
||||
public class LiferayGroupManager implements GroupManager {
|
||||
/**
|
||||
|
@ -109,29 +114,64 @@ public class LiferayGroupManager implements GroupManager {
|
|||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getVirtualGroupName(long groupId) throws GroupRetrievalFault {
|
||||
try {
|
||||
_log.debug("Setting Thread Permission");
|
||||
long userId = LiferayUserManager.getAdmin().getUserId();
|
||||
PrincipalThreadLocal.setName(userId);
|
||||
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId));
|
||||
PermissionThreadLocal.setPermissionChecker(permissionChecker);
|
||||
Group site = GroupLocalServiceUtil.getGroup(groupId);
|
||||
if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) {
|
||||
_log.warn(String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()));
|
||||
return null;
|
||||
} else {
|
||||
String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
|
||||
if (values != null)
|
||||
return values[0];
|
||||
else return "";
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public VirtualGroup getVirtualGroup(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException {
|
||||
VirtualGroup toReturn = new VirtualGroup();
|
||||
try {
|
||||
_log.debug("Setting Thread Permission");
|
||||
long userId = LiferayUserManager.getAdmin().getUserId();
|
||||
PrincipalThreadLocal.setName(userId);
|
||||
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId));
|
||||
PermissionThreadLocal.setPermissionChecker(permissionChecker);
|
||||
Group site = GroupLocalServiceUtil.getGroup(actualGroupId);
|
||||
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) {
|
||||
String[] splits = values[0].split("\\|");
|
||||
toReturn.setName(splits[0]);
|
||||
toReturn.setDescription(splits[1]);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "Exception ";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<VirtualGroup> getVirtualGroups() throws VirtualGroupNotExistingException {
|
||||
ExpandoBridge expandoBridge = null;
|
||||
List<VirtualGroup> toReturn = new ArrayList<VirtualGroup>();
|
||||
try {
|
||||
expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(ManagementUtils.getCompany().getCompanyId(), Group.class.getName());
|
||||
String[] groups = (String[]) expandoBridge.getAttributeDefault(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
|
||||
List<String> virtualGroups = Arrays.asList(groups);
|
||||
|
||||
for (String vg : virtualGroups) {
|
||||
String[] splits = vg.split("\\|");
|
||||
String gName = splits[0];
|
||||
String gDescription = splits[1];
|
||||
toReturn.add(new VirtualGroup(gName, gDescription));
|
||||
}
|
||||
} catch (PortalException e) {
|
||||
throw new VirtualGroupNotExistingException("", e);
|
||||
} catch (SystemException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public GCubeGroup createRootVO(String rootVOName, String description) throws UserManagementNameException, UserManagementSystemException, UserRetrievalFault, GroupRetrievalFault, UserManagementPortalException {
|
||||
Group group = null;
|
||||
|
@ -147,6 +187,9 @@ public class LiferayGroupManager implements GroupManager {
|
|||
return null;
|
||||
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public GCubeGroup createVO(String virtualOrgName, long rootVOGroupId, String description) throws UserManagementNameException,
|
||||
UserManagementSystemException, UserRetrievalFault,
|
||||
|
@ -163,6 +206,9 @@ public class LiferayGroupManager implements GroupManager {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public GCubeGroup createVRE(String virtualResearchEnvName, long virtualOrgGroupId, String description) throws UserManagementNameException,
|
||||
UserManagementSystemException, UserRetrievalFault,
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package org.gcube.vomanagement.usermanagement.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
/**
|
||||
*
|
||||
* @author Massimiliano Assante, CNR-ISTI
|
||||
* Virtual Groups are another way to group VREs indipendently from the scope,
|
||||
* they are modeled as Custom attributes in Liferay Sites table wtih
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class VirtualGroup implements Serializable{
|
||||
private String name;
|
||||
private String description;
|
||||
public VirtualGroup() {}
|
||||
public VirtualGroup(String name, String description) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VirtualGroup [name=" + name + ", description=" + description
|
||||
+ "]";
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
VirtualGroup other = (VirtualGroup) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue