|
|
|
@ -9,10 +9,10 @@ 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.accounting.accounting.summary.access.impl.ContextTreeProvider;
|
|
|
|
|
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
|
|
|
|
|
import org.gcube.common.portal.GCubePortalConstants;
|
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
|
|
|
@ -28,11 +28,21 @@ import com.liferay.portal.model.VirtualHost;
|
|
|
|
|
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.service.VirtualHostLocalServiceUtil;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Giancarlo Panichi
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
|
|
|
|
|
private static GroupManager groupsManager;
|
|
|
|
|
|
|
|
|
|
private static Logger log = LoggerFactory.getLogger(PortalContextTreeProvider.class);
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(PortalContextTreeProvider.class);
|
|
|
|
|
private AccountingServiceType accountingServiceType;
|
|
|
|
|
|
|
|
|
|
public PortalContextTreeProvider(AccountingServiceType accountingServiceType) {
|
|
|
|
|
this.accountingServiceType = accountingServiceType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
groupsManager = new LiferayGroupManager();
|
|
|
|
@ -44,12 +54,93 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
throw new Exception("Unable to get tree, Request is null.");
|
|
|
|
|
if (!(context instanceof HttpServletRequest))
|
|
|
|
|
throw new Exception("Invalid request object : " + context);
|
|
|
|
|
|
|
|
|
|
HttpServletRequest request = (HttpServletRequest) context;
|
|
|
|
|
|
|
|
|
|
// PARSE TREE
|
|
|
|
|
LinkedHashMap<VRECategory, ArrayList<VRE>> gatewayTree = getPortalSitesMappedToVRE(request);
|
|
|
|
|
if (accountingServiceType == null) {
|
|
|
|
|
logger.error("Invalid AccountingServiceType requested: null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.debug("Parsing tree from gateway. Size {} ", gatewayTree.size());
|
|
|
|
|
ScopeDescriptor root = null;
|
|
|
|
|
switch (accountingServiceType) {
|
|
|
|
|
case CurrentScope:
|
|
|
|
|
logger.debug("AccountingService: CurrentScope");
|
|
|
|
|
break;
|
|
|
|
|
case PortalContex:
|
|
|
|
|
logger.debug("AccountingService: PortalContext");
|
|
|
|
|
root = recreateTreeForPortalContext(request);
|
|
|
|
|
break;
|
|
|
|
|
case Infrastructure:
|
|
|
|
|
logger.debug("AccountingService: Infrastructure");
|
|
|
|
|
root = recreateTreeForInfrastructure(request);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
logger.debug("AccountingService: CurrentScope");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return root;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request)
|
|
|
|
|
throws Exception, PortalException, SystemException {
|
|
|
|
|
ScopeDescriptor infra = null;
|
|
|
|
|
PortalContext portalContext = PortalContext.getConfiguration();
|
|
|
|
|
String infrastructureName = portalContext.getInfrastructureName();
|
|
|
|
|
String infrastructureScope = portalContext.getCurrentScope(request);
|
|
|
|
|
infra = new ScopeDescriptor(infrastructureName, infrastructureScope);
|
|
|
|
|
|
|
|
|
|
LinkedList<ScopeDescriptor> infraChildren = new LinkedList<>();
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
GCubeUser currUser = pContext.getCurrentUser(request);
|
|
|
|
|
|
|
|
|
|
List<GCubeGroup> theGateways = new LiferayGroupManager().getGateways();
|
|
|
|
|
for (GCubeGroup gCubeGroup : theGateways) {
|
|
|
|
|
logger.debug("Gateway: [id=" + gCubeGroup.getGroupId() + ", name=" + gCubeGroup.getGroupName() + "]");
|
|
|
|
|
}
|
|
|
|
|
for (GCubeGroup gCubeGroup : theGateways) {
|
|
|
|
|
logger.debug("Gateway: [id=" + gCubeGroup.getGroupId() + ", name=" + gCubeGroup.getGroupName() + "]");
|
|
|
|
|
|
|
|
|
|
LinkedList<ScopeDescriptor> gatewayChildren = retrieveGatewayChildren(request, gCubeGroup.getGroupId(),
|
|
|
|
|
currUser);
|
|
|
|
|
ScopeDescriptor gatewayScopeDescriptor = new ScopeDescriptor(gCubeGroup.getGroupName(),
|
|
|
|
|
gCubeGroup.getGroupId() + "");
|
|
|
|
|
gatewayScopeDescriptor.setChildren(gatewayChildren);
|
|
|
|
|
infraChildren.add(gatewayScopeDescriptor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
infra.setChildren(infraChildren);
|
|
|
|
|
return infra;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ScopeDescriptor recreateTreeForPortalContext(HttpServletRequest request)
|
|
|
|
|
throws Exception, PortalException, SystemException {
|
|
|
|
|
ScopeDescriptor root;
|
|
|
|
|
|
|
|
|
|
long currentSiteGroupId = getSiteFromServletRequest(request).getGroupId();
|
|
|
|
|
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
GCubeUser currUser = pContext.getCurrentUser(request);
|
|
|
|
|
|
|
|
|
|
LinkedList<ScopeDescriptor> rootChildren = null;
|
|
|
|
|
rootChildren = retrieveGatewayChildren(request, currentSiteGroupId, currUser);
|
|
|
|
|
|
|
|
|
|
Group rootGroup = getSiteFromServletRequest(request);
|
|
|
|
|
root = new ScopeDescriptor(rootGroup.getDescriptiveName(), rootGroup.getGroupId() + "");
|
|
|
|
|
root.setChildren(rootChildren);
|
|
|
|
|
logger.debug("TREE IS {} ", root);
|
|
|
|
|
return root;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LinkedList<ScopeDescriptor> retrieveGatewayChildren(HttpServletRequest request, long currentSiteGroupId,
|
|
|
|
|
GCubeUser currUser) throws Exception, PortalException, SystemException {
|
|
|
|
|
|
|
|
|
|
// PARSE TREE
|
|
|
|
|
LinkedHashMap<VRECategory, ArrayList<VRE>> gatewayTree = getPortalSitesMappedToVRE(currUser,
|
|
|
|
|
currentSiteGroupId);
|
|
|
|
|
|
|
|
|
|
logger.debug("Parsing tree from gateway. Size {} ", gatewayTree.size());
|
|
|
|
|
|
|
|
|
|
LinkedList<ScopeDescriptor> rootChildren = new LinkedList<>();
|
|
|
|
|
for (Entry<VRECategory, ArrayList<VRE>> entry : gatewayTree.entrySet()) {
|
|
|
|
@ -59,12 +150,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
rootChildren.add(rootChild);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Group rootGroup = getSiteFromServletRequest(request);
|
|
|
|
|
ScopeDescriptor root = new ScopeDescriptor(rootGroup.getDescriptiveName(), rootGroup.getGroupId() + "");
|
|
|
|
|
root.setChildren(rootChildren);
|
|
|
|
|
log.debug("TREE IS {} ", root);
|
|
|
|
|
|
|
|
|
|
return root;
|
|
|
|
|
return rootChildren;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -74,12 +160,11 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
* @throws SystemException
|
|
|
|
|
* @throws PortalException
|
|
|
|
|
*/
|
|
|
|
|
private LinkedHashMap<VRECategory, ArrayList<VRE>> getPortalSitesMappedToVRE(HttpServletRequest request)
|
|
|
|
|
throws Exception {
|
|
|
|
|
private LinkedHashMap<VRECategory, ArrayList<VRE>> getPortalSitesMappedToVRE(GCubeUser currUser,
|
|
|
|
|
long currentSiteGroupId) throws Exception {
|
|
|
|
|
|
|
|
|
|
LinkedHashMap<VRECategory, ArrayList<VRE>> toReturn = new LinkedHashMap<VRECategory, ArrayList<VRE>>();
|
|
|
|
|
|
|
|
|
|
long currentSiteGroupId = getSiteFromServletRequest(request).getGroupId();
|
|
|
|
|
List<VirtualGroup> currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId);
|
|
|
|
|
|
|
|
|
|
for (VirtualGroup vg : currentSiteVGroups) {
|
|
|
|
@ -91,17 +176,16 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
GCubeGroup rootGroupVO = groupsManager.getRootVO();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
log.debug("root: " + rootGroupVO.getGroupName());
|
|
|
|
|
logger.debug("root: " + rootGroupVO.getGroupName());
|
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
|
log.error(
|
|
|
|
|
logger.error(
|
|
|
|
|
"Cannot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder, unless your installing the Bundle");
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
List<GCubeGroup> currUserGroups = new ArrayList<GCubeGroup>();
|
|
|
|
|
GCubeUser currUser = pContext.getCurrentUser(request);
|
|
|
|
|
|
|
|
|
|
if (currUser != null) {
|
|
|
|
|
currUserGroups = groupsManager.listGroupsByUser(currUser.getUserId());
|
|
|
|
|
}
|
|
|
|
@ -124,29 +208,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
for (VRECategory vre : toReturn.keySet()) {
|
|
|
|
|
if (vre.getName().compareTo(vreGroup.getName()) == 0) {
|
|
|
|
|
ArrayList<VRE> toUpdate = toReturn.get(vre);
|
|
|
|
|
// UserBelonging belongs =
|
|
|
|
|
// UserBelonging.NOT_BELONGING;
|
|
|
|
|
// VRE toAdd = new VRE(vreID,vreName,
|
|
|
|
|
// vreDescription, vreLogoURL, groupName,
|
|
|
|
|
// friendlyURL, belongs,
|
|
|
|
|
// getVREMembershipType(vreSite.getMembershipType()));
|
|
|
|
|
VRE toAdd = new VRE(vreName, vreDescription, vreID, friendlyURL, infraScope);
|
|
|
|
|
// if
|
|
|
|
|
// (GroupLocalServiceUtil.getGroup(vreID).getPublicLayoutsPageCount()
|
|
|
|
|
// > 0) {
|
|
|
|
|
// String publicURL =
|
|
|
|
|
// PREFIX_PUBLIC_URL+vreSite.getFriendlyURL();
|
|
|
|
|
// toAdd.setPublicURL(publicURL);
|
|
|
|
|
// }
|
|
|
|
|
// 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);
|
|
|
|
|
// }
|
|
|
|
|
toUpdate.add(toAdd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -164,17 +226,17 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
|
|
|
|
|
private Group getSiteFromServletRequest(final HttpServletRequest request) throws PortalException, SystemException {
|
|
|
|
|
String serverName = request.getServerName();
|
|
|
|
|
log.debug("currentHost is " + serverName);
|
|
|
|
|
logger.debug("currentHost is " + serverName);
|
|
|
|
|
Group site = null;
|
|
|
|
|
List<VirtualHost> vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0,
|
|
|
|
|
VirtualHostLocalServiceUtil.getVirtualHostsCount());
|
|
|
|
|
for (VirtualHost virtualHost : vHosts) {
|
|
|
|
|
log.debug("Found " + virtualHost.getHostname());
|
|
|
|
|
logger.debug("Found " + virtualHost.getHostname());
|
|
|
|
|
if (virtualHost.getHostname().compareTo("localhost") != 0 && 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());
|
|
|
|
|
logger.debug("Found match! Your site is " + site.getName());
|
|
|
|
|
return site;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|