This commit is contained in:
Fabio Sinibaldi 2018-07-09 12:18:29 +00:00
parent 7c747ed998
commit 1c57cea4d7
1 changed files with 174 additions and 127 deletions

View File

@ -1,5 +1,16 @@
package org.gcube.portlets.user.accountingdashboard.server.accounting; package org.gcube.portlets.user.accountingdashboard.server.accounting;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.common.portal.PortalContext;
import org.gcube.data.access.accounting.summary.access.impl.ContextTreeProvider; import org.gcube.data.access.accounting.summary.access.impl.ContextTreeProvider;
import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor; import org.gcube.data.access.accounting.summary.access.model.ScopeDescriptor;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
@ -7,7 +18,18 @@ import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.VirtualHost;
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
import com.liferay.portal.service.VirtualHostLocalServiceUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@ -15,23 +37,57 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
private static GroupManager groupsManager; private static GroupManager groupsManager;
@AllArgsConstructor
@Getter
private class VRECategory{
private long categoryID;
private String name;
private String description;
}
@AllArgsConstructor
@Getter
private class VRE implements Comparable<VRE>{
private String name;
private String description;
private long id;
private String url;
private String scope;
@Override
public int compareTo(VRE vre) {
return this.getName().compareTo(vre.getName());
}
}
static { static {
groupsManager = new LiferayGroupManager(); groupsManager = new LiferayGroupManager();
} }
@Override @Override
public ScopeDescriptor getTree(Object context) throws Exception { public ScopeDescriptor getTree(Object context) throws Exception {
// if(context == null) throw new Exception("Unable to get tree, Request if(context == null) throw new Exception("Unable to get tree, Request is null.");
// is null."); if(!(context instanceof HttpServletRequest)) throw new
// if(!(context instanceof HttpServletRequest)) throw new Exception("Invalid request object : "+context);
// Exception("Invalid request object : "+context); HttpServletRequest request=(HttpServletRequest) context;
// HttpServletRequest request=(HttpServletRequest) context;
// PARSE TREE // PARSE TREE
LinkedHashMap<VRECategory,ArrayList<VRE>> gatewayTree=getPortalSitesMappedToVRE(request);
LinkedList<ScopeDescriptor> rootChildren=new LinkedList<>();
for(Entry<VRECategory,ArrayList<VRE>> entry:gatewayTree.entrySet()) {
ScopeDescriptor rootChild=new ScopeDescriptor(entry.getKey().name, entry.getKey().categoryID+"");
for(VRE vre:entry.getValue())
rootChild.getChildren().add(new ScopeDescriptor(vre.name, vre.scope));
}
Group rootGroup=getSiteFromServletRequest(request);
ScopeDescriptor root=new ScopeDescriptor(rootGroup.getDescriptiveName(),rootGroup.getGroupId()+"");
root.setChildren(rootChildren);
GCubeGroup rootGroupVO = groupsManager.getRootVO(); return root;
return asScopeDescriptor(rootGroupVO);
} }
private ScopeDescriptor asScopeDescriptor(GCubeGroup group) private ScopeDescriptor asScopeDescriptor(GCubeGroup group)
@ -46,123 +102,114 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
return toReturn; return toReturn;
} }
//
//
// /** /**
// * *
// * @return the Virtual groups with their VREs in the order estabilished in * @return the Virtual groups with their VREs in the order estabilished in
// the LR Control Panel the LR Control Panel
// * @throws SystemException * @throws SystemException
// * @throws PortalException * @throws PortalException
// */ */
// private LinkedHashMap<VRECategory, ArrayList<VRE>> private LinkedHashMap<VRECategory, ArrayList<VRE>>
// getPortalSitesMappedToVRE(HttpServletRequest request) throws Exception { getPortalSitesMappedToVRE(HttpServletRequest request) throws Exception {
//
// Group site=getSiteFromServletRequest(request); LinkedHashMap<VRECategory, ArrayList<VRE>> toReturn = new LinkedHashMap<VRECategory, ArrayList<VRE>>();
//
// ScopeDescriptor root=new long currentSiteGroupId = getSiteFromServletRequest(request).getGroupId();
// ScopeDescriptor(site.getDescriptiveName(),site.getUuid()); List<VirtualGroup> currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId);
//
// LinkedList<ScopeDescriptor> groups=new LinkedList<>(); for (VirtualGroup vg : currentSiteVGroups) {
// ArrayList<VRE> toCreate = new ArrayList<VRE>();
// long currentSiteGroupId = site.getGroupId(); VRECategory cat = new VRECategory(1L, vg.getName(), vg.getDescription());
// toReturn.put(cat, toCreate);
//// List<VirtualGroup> currentSiteVGroups = }
// groupsManager.getVirtualGroups(currentSiteGroupId);
//// GCubeGroup rootGroupVO = groupsManager.getRootVO();
//// for (VirtualGroup vg : currentSiteVGroups) {
//// ScopeDescriptor groupDescriptor=new ScopeDescriptor(vg.getName(),); try {
//// VRECategory cat = new VRECategory(1L, vg.getName(), log.debug("root: " + rootGroupVO.getGroupName() );
// vg.getDescription()); } catch (NullPointerException e) {
//// toReturn.put(cat, toCreate); log.error("Cannot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder, unless your installing the Bundle");
//// } return toReturn;
// }
// GCubeGroup rootGroupVO = groupsManager.getRootVO(); PortalContext pContext = PortalContext.getConfiguration();
////
//// try { List<GCubeGroup> currUserGroups = new ArrayList<GCubeGroup>();
//// log.debug("root: " + rootGroupVO.getGroupName() ); GCubeUser currUser = pContext.getCurrentUser(request);
//// } catch (NullPointerException e) { if (currUser != null) {
//// log.error("Cannot find root organziation, please check currUserGroups = groupsManager.listGroupsByUser(currUser.getUserId());
// gcube-data.properties file in $CATALINA_HOME/conf folder, unless your }
// installing the Bundle");
//// return toReturn; //for each root sub organizations (VO)
//// } for (GCubeGroup vOrg : rootGroupVO.getChildren()) {
//// PortalContext pContext = PortalContext.getConfiguration(); for (GCubeGroup vreSite : vOrg.getChildren()) {
//// long vreID = vreSite.getGroupId();
//// List<GCubeGroup> currUserGroups = new ArrayList<GCubeGroup>(); String vreName = vreSite.getGroupName();
//// GCubeUser currUser = pContext.getCurrentUser(request); String vreDescription = vreSite.getDescription();
//// if (currUser != null) {
//// currUserGroups = groupsManager.listGroupsByUser(currUser.getUserId()); long logoId = vreSite.getLogoId();
//// } String vreLogoURL = groupsManager.getGroupLogoURL(logoId);
// String infraScope = groupsManager.getInfrastructureScope(vreSite.getGroupId());
// //for each root sub organizations (VO) String friendlyURL = GCubePortalConstants.PREFIX_GROUP_URL+vreSite.getFriendlyURL();
// for (GCubeGroup vOrg : rootGroupVO.getChildren()) {
// for (GCubeGroup vreSite : vOrg.getChildren()) { List<VirtualGroup> vreGroups = groupsManager.getVirtualGroups(vreID);
// long vreID = vreSite.getGroupId(); for (VirtualGroup vreGroup : vreGroups) {
// String vreName = vreSite.getGroupName(); for (VRECategory vre : toReturn.keySet()) {
// String vreDescription = vreSite.getDescription(); if (vre.getName().compareTo(vreGroup.getName())==0) {
// ArrayList<VRE> toUpdate = toReturn.get(vre);
// String groupName = // UserBelonging belongs = UserBelonging.NOT_BELONGING;
// groupsManager.getInfrastructureScope(vreSite.getGroupId()); // VRE toAdd = new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName, friendlyURL, belongs, getVREMembershipType(vreSite.getMembershipType()));
// VRE toAdd= new VRE(vreName,vreDescription,vreID,friendlyURL,infraScope);
// List<VirtualGroup> vreGroups = groupsManager.getVirtualGroups(vreID); // if (GroupLocalServiceUtil.getGroup(vreID).getPublicLayoutsPageCount() > 0) {
// for (VirtualGroup vreGroup : vreGroups) { // String publicURL = PREFIX_PUBLIC_URL+vreSite.getFriendlyURL();
// for (VRECategory vre : toReturn.keySet()) { // toAdd.setPublicURL(publicURL);
// if (vre.getName().compareTo(vreGroup.getName())==0) { // }
// ArrayList<VRE> toUpdate = toReturn.get(vre); // if (currUser != null) {
// UserBelonging belongs = UserBelonging.NOT_BELONGING; // //check if the user belongs to it
// VRE toAdd = new VRE(vreID,vreName, vreDescription, vreLogoURL, groupName, // if (currUserGroups.contains(vreSite)) {
// friendlyURL, belongs, getVREMembershipType(vreSite.getMembershipType())); // toAdd.setUserBelonging(UserBelonging.BELONGING);
//// if (GroupLocalServiceUtil.getGroup(vreID).getPublicLayoutsPageCount() > // }
// 0) { // else if (checkPending(currUser.getUsername(), vreSite.getGroupId()))
//// String publicURL = PREFIX_PUBLIC_URL+vreSite.getFriendlyURL(); // toAdd.setUserBelonging(UserBelonging.PENDING);
//// toAdd.setPublicURL(publicURL); // }
//// } toUpdate.add(toAdd);
//// if (currUser != null) { }
//// //check if the user belongs to it }
//// if (currUserGroups.contains(vreSite)) { }
//// toAdd.setUserBelonging(UserBelonging.BELONGING); }
//// } }
//// else if (checkPending(currUser.getUsername(), vreSite.getGroupId()))
//// toAdd.setUserBelonging(UserBelonging.PENDING); //sort the vres in the groups
//// } for (VRECategory cat : toReturn.keySet()) {
// toUpdate.add(toAdd); ArrayList<VRE> toSort = toReturn.get(cat);
// } Collections.sort(toSort);
// } }
// } return toReturn;
// } }
// }
//
// //sort the vres in the groups
// for (VRECategory cat : toReturn.keySet()) {
// ArrayList<VRE> toSort = toReturn.get(cat);
// Collections.sort(toSort); private Group getSiteFromServletRequest(final HttpServletRequest request)
// } throws PortalException, SystemException {
// return toReturn; String serverName = request.getServerName();
// } log.debug("currentHost is " + serverName);
// Group site = null;
// List<VirtualHost> vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0,
// VirtualHostLocalServiceUtil.getVirtualHostsCount());
// for (VirtualHost virtualHost : vHosts) {
// log.debug("Found " + virtualHost.getHostname());
// private Group getSiteFromServletRequest(final HttpServletRequest request) if (virtualHost.getHostname().compareTo("localhost") != 0 &&
// throws PortalException, SystemException { virtualHost.getLayoutSetId() != 0 &&
// String serverName = request.getServerName(); virtualHost.getHostname().compareTo(serverName) == 0) {
// log.debug("currentHost is " + serverName); long layoutSetId = virtualHost.getLayoutSetId();
// Group site = null; site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup();
// List<VirtualHost> vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, log.debug("Found match! Your site is " + site.getName());
// VirtualHostLocalServiceUtil.getVirtualHostsCount()); return site;
// for (VirtualHost virtualHost : vHosts) { }
// log.debug("Found " + virtualHost.getHostname()); }
// if (virtualHost.getHostname().compareTo("localhost") != 0 && return null;
// virtualHost.getLayoutSetId() != 0 && }
// virtualHost.getHostname().compareTo(serverName) == 0) {
// long layoutSetId = virtualHost.getLayoutSetId();
// site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup();
// log.debug("Found match! Your site is " + site.getName());
// return site;
// }
// }
// return null;
// }
} }