added getGateways method, implemented other two methods in the WS version of the GroupManager

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@141592 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-01-16 17:16:36 +00:00
parent 8079834438
commit d3005a099c
4 changed files with 144 additions and 6 deletions

View File

@ -232,4 +232,10 @@ public interface GroupManager {
* @throws GroupRetrievalFault
*/
String getGroupLogoURL(long logoId);
/**
* Retrieve the list of GCubeGroups that are Gateways (i.e. groups with no father and children).
* @return a list of gateways
*/
List<GCubeGroup> getGateways();
}

View File

@ -51,7 +51,7 @@ 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";
/**
@ -434,7 +434,7 @@ public class LiferayGroupManager implements GroupManager {
Set<GCubeGroup> toReturn = new HashSet<>();
try {
List<VirtualGroup> currSiteVirtualGroups = getVirtualGroups(siteGroupId);
for (GCubeGroup userGroup : listGroupsByUser(userId)) {
if (isVRE(userGroup.getGroupId())) {
for (VirtualGroup currSiteVGroup : currSiteVirtualGroups) {
@ -446,7 +446,7 @@ public class LiferayGroupManager implements GroupManager {
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
@ -710,5 +710,26 @@ public class LiferayGroupManager implements GroupManager {
return layoutSetLogo;
}
@Override
public List<GCubeGroup> getGateways() {
List<GCubeGroup> gateways = new ArrayList<GCubeGroup>();
try{
List<Group> candidateGateways = GroupLocalServiceUtil.getGroups(ManagementUtils.getCompany().getCompanyId(), 0, true);
// real gateways have no children as well
for (Group group : candidateGateways) {
List<Group> children = group.getChildren(true);
if(children == null || children.isEmpty())
if(!group.getFriendlyURL().equals("/guest") && !group.getFriendlyURL().equals("/global")) // created by Liferay
gateways.add(mapLRGroup(group));
}
}catch(Exception e){
_log.error("Failed to retrieve the list of gateways", e);
return null;
}
return gateways;
}
}

View File

@ -27,6 +27,7 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalExcep
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.CustomAttributeKeys;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GroupMembershipType;
@ -63,6 +64,7 @@ public class LiferayWSGroupManager implements GroupManager {
private static final String GET_GROUP_BY_ID = "/group/get-group/group-id/$GROUP_ID";
private static final String GET_GROUPS_BY_PARENT_ID = "/group/get-groups/company-id/$COMPANY_ID/parent-group-id/$GROUP_PARENT_ID/site/$SITE";
private static final String GET_GROUPS_BY_USERID = "/group/get-user-sites-groups/user-id/$USER_ID/class-names/%5B%22com.liferay.portal.model.Group%22%5D/max/$MAX_GROUP";
private static final String GET_GROUP_CUSTOM_FIELDS = "/expandovalue/get-data/company-id/$COMPANY_ID/class-name/com.liferay.portal.model.Group/table-name/CUSTOM_FIELDS/column-name/$CUSTOM_KEY/class-pk/$GROUP_ID";
// logger
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(LiferayWSGroupManager.class);
@ -358,8 +360,36 @@ public class LiferayWSGroupManager implements GroupManager {
@Override
public List<VirtualGroup> getVirtualGroups(long actualGroupId)
throws GroupRetrievalFault, VirtualGroupNotExistingException {
// TODO Auto-generated method stub
List<VirtualGroup> toReturn = new ArrayList<VirtualGroup>();
try {
String jsonCustomFields =
executeHTTPGETRequest(API_BASE_URL + GET_GROUP_CUSTOM_FIELDS.replace("$COMPANY_ID", String.valueOf(companyId)).replace("$CUSTOM_KEY", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).replace("$GROUP_ID", String.valueOf(actualGroupId)),
credsProvider, localContext, target);
if(jsonCustomFields != null){
//parse this array
JSONParser parser = new JSONParser();
JSONArray array = (JSONArray)parser.parse(jsonCustomFields);
for (int i = 0; i < array.size(); i++) {
String obj = (String)array.get(i);
String[] splits = obj.split("\\|");
String gName = splits[0];
String gDescription = splits[1];
toReturn.add(new VirtualGroup(gName, gDescription));
}
}
return toReturn;
} catch (Exception e) {
logger.error("Failed to read Virtualgroups for this group", e);
}
return null;
}
@Override
@ -572,8 +602,15 @@ public class LiferayWSGroupManager implements GroupManager {
@Override
public Serializable readCustomAttr(long groupId, String attributeKey)
throws GroupRetrievalFault {
// TODO Auto-generated method stub
return null;
String result =
executeHTTPGETRequest(API_BASE_URL + GET_GROUP_CUSTOM_FIELDS.replace("$COMPANY_ID", String.valueOf(companyId)).replace("$GROUP_ID", String.valueOf(groupId)).replace("$CUSTOM_KEY", attributeKey),
credsProvider, localContext, target);
logger.debug("Data is " + result);
return result;
}
@Override
@ -596,4 +633,43 @@ public class LiferayWSGroupManager implements GroupManager {
return null;
}
@Override
public List<GCubeGroup> getGateways() {
List<GCubeGroup> gateways = new ArrayList<GCubeGroup>();
try{
String jsonGroups =
executeHTTPGETRequest(API_BASE_URL + GET_GROUPS_BY_PARENT_ID.replace("$COMPANY_ID", String.valueOf(companyId)).replace("$GROUP_PARENT_ID", String.valueOf(0))
.replace("$SITE", Boolean.toString(true)),
credsProvider, localContext, target);
JSONArray candidateGateways = (JSONArray)(new JSONParser().parse(jsonGroups));
List<Long> idsCandidateGateways = new ArrayList<Long>();
for (int i = 0; i < candidateGateways.size(); i++) {
idsCandidateGateways.add((Long) ((JSONObject)(candidateGateways.get(i))).get("groupId"));
}
// real gateways have no children as well
for (int i = 0; i < idsCandidateGateways.size(); i++) {
List<String> children = getChildren(idsCandidateGateways.get(i));
String friendlyUrl = (String) ((JSONObject)candidateGateways.get(i)).get("friendlyURL");
// check if it is not a group created by Liferay
boolean defaultGroup = friendlyUrl.equals("/guest") || friendlyUrl.equals("/global");
if(defaultGroup)
continue;
if(children == null || children.isEmpty())
gateways.add(mapLRGroup(((JSONObject)candidateGateways.get(i)).toJSONString()));
}
}catch(Exception e){
logger.error("Failed to retrieve the list of gateways", e);
return null;
}
return gateways;
}
}

View File

@ -5,8 +5,10 @@ import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
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.impl.ws.LiferayWSGroupManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
import org.slf4j.LoggerFactory;
/**
@ -76,4 +78,37 @@ public class LiferayWSGroupTest {
logger.debug("Retrieved groups " + groups);
}
//@Test
public void getGateways(){
List<GCubeGroup> gateways = groupManager.getGateways();
logger.debug("Retrieved gateways are " + gateways.size());
for (GCubeGroup gCubeGroup : gateways) {
logger.debug("Name is " + gCubeGroup.getGroupName());
}
}
//@Test
public void getVirtualGroups() throws GroupRetrievalFault, VirtualGroupNotExistingException{
// virtual groups of nextnext vre
List<VirtualGroup> virtualGroups = groupManager.getVirtualGroups(21660);
logger.debug("Retrieved vg " + virtualGroups);
// virtual groups of the gateway
List<VirtualGroup> virtualGroupsGateway = groupManager.getVirtualGroups(1142377);
logger.debug("Retrieved vg " + virtualGroupsGateway);
}
//@Test
public void getGatewayInfo() throws UserManagementSystemException, GroupRetrievalFault{
GCubeGroup getGroup = groupManager.getGroup(1142377);
logger.debug("Retrieved vg " + getGroup);
String result = (String)groupManager.readCustomAttr(getGroup.getGroupId(), "Emailsender");
logger.debug("Value is " + result);
}
}