2018-07-06 12:30:27 +02:00
|
|
|
package org.gcube.portlets.user.accountingdashboard.server.accounting;
|
|
|
|
|
2018-07-09 14:18:29 +02:00
|
|
|
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;
|
|
|
|
|
2018-07-10 17:50:37 +02:00
|
|
|
import org.gcube.accounting.accounting.summary.access.impl.ContextTreeProvider;
|
|
|
|
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
|
2019-10-22 19:04:25 +02:00
|
|
|
import org.gcube.common.portal.GCubePortalConstants;
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
2020-04-07 17:34:45 +02:00
|
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.DetachedREsBuilder;
|
|
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs;
|
|
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway;
|
|
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VO;
|
2020-01-20 19:21:27 +01:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.server.is.BuildInfraNode;
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.is.InfraNode;
|
2020-04-07 17:34:45 +02:00
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
|
2018-07-06 12:30:27 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
2018-07-09 14:18:29 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
|
2018-07-09 14:30:56 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-07-09 14:18:29 +02:00
|
|
|
|
|
|
|
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;
|
2018-07-06 12:30:27 +02:00
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
|
|
|
*/
|
2018-07-06 12:30:27 +02:00
|
|
|
public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
|
|
|
private static GroupManager groupsManager;
|
2018-07-06 17:48:46 +02:00
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(PortalContextTreeProvider.class);
|
|
|
|
private AccountingServiceType accountingServiceType;
|
|
|
|
|
2020-04-07 17:34:45 +02:00
|
|
|
private TreeOptions treeOptions;
|
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
public PortalContextTreeProvider(AccountingServiceType accountingServiceType) {
|
|
|
|
this.accountingServiceType = accountingServiceType;
|
2020-04-07 17:34:45 +02:00
|
|
|
this.treeOptions = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTreeOptions(TreeOptions treeOptions){
|
|
|
|
this.treeOptions=treeOptions;
|
2019-10-22 19:04:25 +02:00
|
|
|
}
|
2018-07-09 14:30:56 +02:00
|
|
|
|
2018-07-06 12:30:27 +02:00
|
|
|
static {
|
|
|
|
groupsManager = new LiferayGroupManager();
|
|
|
|
}
|
2018-07-06 17:48:46 +02:00
|
|
|
|
2018-07-06 12:30:27 +02:00
|
|
|
@Override
|
|
|
|
public ScopeDescriptor getTree(Object context) throws Exception {
|
2018-07-17 19:15:10 +02:00
|
|
|
if (context == null)
|
|
|
|
throw new Exception("Unable to get tree, Request is null.");
|
|
|
|
if (!(context instanceof HttpServletRequest))
|
|
|
|
throw new Exception("Invalid request object : " + context);
|
2019-10-22 19:04:25 +02:00
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
HttpServletRequest request = (HttpServletRequest) context;
|
2018-07-06 17:48:46 +02:00
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
if (accountingServiceType == null) {
|
|
|
|
logger.error("Invalid AccountingServiceType requested: null");
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2020-04-07 17:34:45 +02:00
|
|
|
root = recreateTreeForInfrastructure(request, treeOptions);
|
2019-10-22 19:04:25 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
logger.debug("AccountingService: CurrentScope");
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
2020-04-07 17:34:45 +02:00
|
|
|
private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request, TreeOptions treeOptions2)
|
2019-10-22 19:04:25 +02:00
|
|
|
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);
|
2020-01-21 11:28:33 +01:00
|
|
|
|
|
|
|
InfraNode infraNode = BuildInfraNode.build(infrastructureScope);
|
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
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);
|
2020-01-21 11:28:33 +01:00
|
|
|
|
|
|
|
if (infraNode != null) {
|
2020-04-07 17:34:45 +02:00
|
|
|
String scopeGroup = "";
|
|
|
|
if (gCubeGroup.getGroupName().toUpperCase().endsWith(" GATEWAY")) {
|
|
|
|
int l = gCubeGroup.getGroupName().length();
|
|
|
|
scopeGroup = gCubeGroup.getGroupName().substring(0, l - 8);
|
2020-02-14 15:04:07 +01:00
|
|
|
} else {
|
2020-04-07 17:34:45 +02:00
|
|
|
scopeGroup = gCubeGroup.getGroupName();
|
2020-02-14 15:04:07 +01:00
|
|
|
}
|
2020-04-07 17:34:45 +02:00
|
|
|
|
|
|
|
StringBuilder gatewayScope = new StringBuilder();
|
2020-01-21 18:57:27 +01:00
|
|
|
gatewayScope.append(infrastructureScope);
|
|
|
|
gatewayScope.append("/");
|
2020-02-14 15:04:07 +01:00
|
|
|
gatewayScope.append(scopeGroup);
|
2020-04-07 17:34:45 +02:00
|
|
|
|
2020-01-21 18:57:27 +01:00
|
|
|
ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, gatewayScope.toString());
|
2020-01-21 11:28:33 +01:00
|
|
|
if (gatewayChildren != null) {
|
2020-01-20 19:21:27 +01:00
|
|
|
gatewayChildren.addFirst(infraNodeScopeDescriptor);
|
|
|
|
} else {
|
2020-01-21 11:28:33 +01:00
|
|
|
gatewayChildren = new LinkedList<>();
|
2020-01-20 19:21:27 +01:00
|
|
|
gatewayChildren.add(infraNodeScopeDescriptor);
|
|
|
|
}
|
|
|
|
}
|
2020-01-21 11:28:33 +01:00
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
ScopeDescriptor gatewayScopeDescriptor = new ScopeDescriptor(gCubeGroup.getGroupName(),
|
|
|
|
gCubeGroup.getGroupId() + "");
|
|
|
|
gatewayScopeDescriptor.setChildren(gatewayChildren);
|
|
|
|
infraChildren.add(gatewayScopeDescriptor);
|
|
|
|
}
|
|
|
|
|
2020-04-07 17:34:45 +02:00
|
|
|
if (treeOptions != null && treeOptions.isShowDetachedREs()) {
|
|
|
|
logger.debug("Show DestachedREs");
|
|
|
|
DetachedREs detachedREs = DetachedREsBuilder.build(infrastructureScope);
|
|
|
|
if (detachedREs != null && detachedREs.isEnabled()) {
|
|
|
|
logger.debug("DetachedREs is enabled");
|
|
|
|
if (detachedREs.getGateways() != null && !detachedREs.getGateways().isEmpty()) {
|
|
|
|
for (String key : detachedREs.getGateways().keySet()) {
|
|
|
|
Gateway gateway = detachedREs.getGateways().get(key);
|
|
|
|
ScopeDescriptor getewaySD = new ScopeDescriptor(gateway.getName(), key);
|
|
|
|
LinkedList<ScopeDescriptor> voChildren = retrieveVOChildren(gateway);
|
|
|
|
getewaySD.setChildren(voChildren);
|
|
|
|
infraChildren.add(getewaySD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.debug("DetachedREs is disabled");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
infra.setChildren(infraChildren);
|
|
|
|
return infra;
|
|
|
|
}
|
2020-01-21 11:28:33 +01:00
|
|
|
|
2020-04-07 17:34:45 +02:00
|
|
|
private LinkedList<ScopeDescriptor> retrieveVOChildren(Gateway gateway) {
|
|
|
|
if (gateway.getVos() != null && !gateway.getVos().isEmpty()) {
|
|
|
|
LinkedList<ScopeDescriptor> vos = new LinkedList<>();
|
|
|
|
for (String key : gateway.getVos().keySet()) {
|
|
|
|
VO vo = gateway.getVos().get(key);
|
|
|
|
ScopeDescriptor voSD = new ScopeDescriptor(vo.getName(), key);
|
|
|
|
LinkedList<ScopeDescriptor> voChildren = retrieveVREChildren(vo);
|
|
|
|
voSD.setChildren(voChildren);
|
|
|
|
vos.add(voSD);
|
|
|
|
}
|
|
|
|
return vos;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private LinkedList<ScopeDescriptor> retrieveVREChildren(VO vo) {
|
|
|
|
if (vo.getVres() != null && !vo.getVres().isEmpty()) {
|
|
|
|
LinkedList<ScopeDescriptor> vres = new LinkedList<>();
|
|
|
|
for (String key : vo.getVres().keySet()) {
|
|
|
|
org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE vre = vo.getVres().get(key);
|
|
|
|
ScopeDescriptor vreSD = new ScopeDescriptor(vre.getName(), key);
|
|
|
|
vres.add(vreSD);
|
|
|
|
}
|
|
|
|
return vres;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-21 11:28:33 +01:00
|
|
|
private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope) {
|
|
|
|
StringBuilder absoluteScope = new StringBuilder();
|
|
|
|
absoluteScope.append(scope);
|
|
|
|
absoluteScope.append("/");
|
|
|
|
absoluteScope.append(infraNode.getScope());
|
|
|
|
ScopeDescriptor scopeDescriptor = new ScopeDescriptor(infraNode.getName(), absoluteScope.toString());
|
|
|
|
if (infraNode.getChildren() != null && !infraNode.getChildren().isEmpty()) {
|
|
|
|
LinkedList<ScopeDescriptor> childsScopeDescriptor = new LinkedList<>();
|
|
|
|
for (InfraNode child : infraNode.getChildren()) {
|
2020-01-22 10:49:22 +01:00
|
|
|
ScopeDescriptor childScopeDescriptor = createRelativeInfraNode(child, scope);
|
2020-01-21 11:28:33 +01:00
|
|
|
childsScopeDescriptor.add(childScopeDescriptor);
|
2020-01-20 19:21:27 +01:00
|
|
|
}
|
2020-01-21 11:28:33 +01:00
|
|
|
scopeDescriptor.setChildren(childsScopeDescriptor);
|
|
|
|
}
|
|
|
|
|
2020-01-20 19:21:27 +01:00
|
|
|
return scopeDescriptor;
|
|
|
|
}
|
2019-10-22 19:04:25 +02:00
|
|
|
|
|
|
|
private ScopeDescriptor recreateTreeForPortalContext(HttpServletRequest request)
|
|
|
|
throws Exception, PortalException, SystemException {
|
|
|
|
ScopeDescriptor root;
|
|
|
|
|
2020-04-07 17:34:45 +02:00
|
|
|
Group group = getSiteFromServletRequest(request);
|
2020-01-21 18:57:27 +01:00
|
|
|
long currentSiteGroupId = group.getGroupId();
|
2020-04-07 17:34:45 +02:00
|
|
|
String gatewayName = group.getName();
|
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
GCubeUser currUser = pContext.getCurrentUser(request);
|
2020-01-21 12:09:14 +01:00
|
|
|
String portalScope = pContext.getCurrentScope(currentSiteGroupId + "");
|
2020-04-07 17:34:45 +02:00
|
|
|
|
|
|
|
String scopeGroup = "";
|
|
|
|
if (gatewayName.toUpperCase().endsWith(" GATEWAY")) {
|
|
|
|
int l = gatewayName.length();
|
|
|
|
scopeGroup = gatewayName.substring(0, l - 8);
|
2020-02-14 15:04:07 +01:00
|
|
|
} else {
|
2020-04-07 17:34:45 +02:00
|
|
|
scopeGroup = gatewayName;
|
2020-02-14 15:04:07 +01:00
|
|
|
}
|
2020-04-07 17:34:45 +02:00
|
|
|
StringBuilder gatewayScope = new StringBuilder();
|
2020-01-21 18:57:27 +01:00
|
|
|
gatewayScope.append(portalScope);
|
|
|
|
gatewayScope.append("/");
|
2020-02-14 15:04:07 +01:00
|
|
|
gatewayScope.append(scopeGroup);
|
2020-04-07 17:34:45 +02:00
|
|
|
|
2020-01-21 12:09:14 +01:00
|
|
|
InfraNode infraNode = BuildInfraNode.build(portalScope);
|
2020-04-07 17:34:45 +02:00
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
LinkedList<ScopeDescriptor> rootChildren = null;
|
|
|
|
rootChildren = retrieveGatewayChildren(request, currentSiteGroupId, currUser);
|
2020-01-21 11:28:33 +01:00
|
|
|
|
|
|
|
if (infraNode != null) {
|
2020-01-21 18:57:27 +01:00
|
|
|
ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, gatewayScope.toString());
|
2020-01-21 11:28:33 +01:00
|
|
|
if (rootChildren != null) {
|
2020-01-20 19:21:27 +01:00
|
|
|
rootChildren.addFirst(infraNodeScopeDescriptor);
|
|
|
|
} else {
|
2020-01-21 11:28:33 +01:00
|
|
|
rootChildren = new LinkedList<>();
|
2020-01-20 19:21:27 +01:00
|
|
|
rootChildren.add(infraNodeScopeDescriptor);
|
|
|
|
}
|
|
|
|
}
|
2020-01-21 11:28:33 +01:00
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
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 {
|
2020-01-21 11:28:33 +01:00
|
|
|
logger.info("Retrieve Gateway Children: currentSiteGroupId=" + currentSiteGroupId);
|
|
|
|
|
2018-07-06 12:30:27 +02:00
|
|
|
// PARSE TREE
|
2019-10-22 19:04:25 +02:00
|
|
|
LinkedHashMap<VRECategory, ArrayList<VRE>> gatewayTree = getPortalSitesMappedToVRE(currUser,
|
|
|
|
currentSiteGroupId);
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2019-10-22 19:04:25 +02:00
|
|
|
logger.debug("Parsing tree from gateway. Size {} ", gatewayTree.size());
|
2018-07-17 19:15:10 +02:00
|
|
|
|
|
|
|
LinkedList<ScopeDescriptor> rootChildren = new LinkedList<>();
|
2020-01-21 11:28:33 +01:00
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
for (Entry<VRECategory, ArrayList<VRE>> entry : gatewayTree.entrySet()) {
|
|
|
|
ScopeDescriptor rootChild = new ScopeDescriptor(entry.getKey().name, entry.getKey().categoryID + "");
|
|
|
|
for (VRE vre : entry.getValue())
|
2018-07-09 14:18:29 +02:00
|
|
|
rootChild.getChildren().add(new ScopeDescriptor(vre.name, vre.scope));
|
2018-07-09 15:06:01 +02:00
|
|
|
rootChildren.add(rootChild);
|
2018-07-09 14:18:29 +02:00
|
|
|
}
|
2019-10-22 19:04:25 +02:00
|
|
|
return rootChildren;
|
2018-07-06 12:30:27 +02:00
|
|
|
}
|
2018-07-06 17:48:46 +02:00
|
|
|
|
2018-07-09 14:18:29 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return the Virtual groups with their VREs in the order estabilished in
|
2018-07-17 19:15:10 +02:00
|
|
|
* the LR Control Panel
|
2018-07-09 14:18:29 +02:00
|
|
|
* @throws SystemException
|
|
|
|
* @throws PortalException
|
|
|
|
*/
|
2019-10-22 19:04:25 +02:00
|
|
|
private LinkedHashMap<VRECategory, ArrayList<VRE>> getPortalSitesMappedToVRE(GCubeUser currUser,
|
|
|
|
long currentSiteGroupId) throws Exception {
|
2018-07-09 14:18:29 +02:00
|
|
|
|
|
|
|
LinkedHashMap<VRECategory, ArrayList<VRE>> toReturn = new LinkedHashMap<VRECategory, ArrayList<VRE>>();
|
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
List<VirtualGroup> currentSiteVGroups = groupsManager.getVirtualGroups(currentSiteGroupId);
|
2018-07-09 14:18:29 +02:00
|
|
|
|
|
|
|
for (VirtualGroup vg : currentSiteVGroups) {
|
|
|
|
ArrayList<VRE> toCreate = new ArrayList<VRE>();
|
|
|
|
VRECategory cat = new VRECategory(1L, vg.getName(), vg.getDescription());
|
|
|
|
toReturn.put(cat, toCreate);
|
|
|
|
}
|
|
|
|
|
|
|
|
GCubeGroup rootGroupVO = groupsManager.getRootVO();
|
|
|
|
|
|
|
|
try {
|
2019-10-22 19:04:25 +02:00
|
|
|
logger.debug("root: " + rootGroupVO.getGroupName());
|
2018-07-09 14:18:29 +02:00
|
|
|
} catch (NullPointerException e) {
|
2019-10-22 19:04:25 +02:00
|
|
|
logger.error(
|
2018-07-17 19:15:10 +02:00
|
|
|
"Cannot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder, unless your installing the Bundle");
|
2018-07-09 14:18:29 +02:00
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
2018-07-09 15:00:51 +02:00
|
|
|
@SuppressWarnings("unused")
|
2018-07-09 14:18:29 +02:00
|
|
|
List<GCubeGroup> currUserGroups = new ArrayList<GCubeGroup>();
|
2019-10-22 19:04:25 +02:00
|
|
|
|
2018-07-09 14:18:29 +02:00
|
|
|
if (currUser != null) {
|
|
|
|
currUserGroups = groupsManager.listGroupsByUser(currUser.getUserId());
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
// for each root sub organizations (VO)
|
2018-07-09 14:18:29 +02:00
|
|
|
for (GCubeGroup vOrg : rootGroupVO.getChildren()) {
|
|
|
|
for (GCubeGroup vreSite : vOrg.getChildren()) {
|
2018-07-17 19:15:10 +02:00
|
|
|
long vreID = vreSite.getGroupId();
|
2018-07-09 14:18:29 +02:00
|
|
|
String vreName = vreSite.getGroupName();
|
|
|
|
String vreDescription = vreSite.getDescription();
|
|
|
|
|
|
|
|
long logoId = vreSite.getLogoId();
|
2018-07-23 17:17:06 +02:00
|
|
|
@SuppressWarnings("unused")
|
2018-07-09 14:18:29 +02:00
|
|
|
String vreLogoURL = groupsManager.getGroupLogoURL(logoId);
|
|
|
|
String infraScope = groupsManager.getInfrastructureScope(vreSite.getGroupId());
|
2018-07-17 19:15:10 +02:00
|
|
|
String friendlyURL = GCubePortalConstants.PREFIX_GROUP_URL + vreSite.getFriendlyURL();
|
2018-07-09 14:18:29 +02:00
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
List<VirtualGroup> vreGroups = groupsManager.getVirtualGroups(vreID);
|
2018-07-09 14:18:29 +02:00
|
|
|
for (VirtualGroup vreGroup : vreGroups) {
|
|
|
|
for (VRECategory vre : toReturn.keySet()) {
|
2018-07-17 19:15:10 +02:00
|
|
|
if (vre.getName().compareTo(vreGroup.getName()) == 0) {
|
2018-07-09 14:18:29 +02:00
|
|
|
ArrayList<VRE> toUpdate = toReturn.get(vre);
|
2018-07-17 19:15:10 +02:00
|
|
|
VRE toAdd = new VRE(vreName, vreDescription, vreID, friendlyURL, infraScope);
|
2018-07-09 14:18:29 +02:00
|
|
|
toUpdate.add(toAdd);
|
|
|
|
}
|
2018-07-17 19:15:10 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-09 14:18:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
// sort the vres in the groups
|
2018-07-09 14:18:29 +02:00
|
|
|
for (VRECategory cat : toReturn.keySet()) {
|
|
|
|
ArrayList<VRE> toSort = toReturn.get(cat);
|
|
|
|
Collections.sort(toSort);
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
private Group getSiteFromServletRequest(final HttpServletRequest request) throws PortalException, SystemException {
|
2018-07-09 14:18:29 +02:00
|
|
|
String serverName = request.getServerName();
|
2019-10-22 19:04:25 +02:00
|
|
|
logger.debug("currentHost is " + serverName);
|
2018-07-09 14:18:29 +02:00
|
|
|
Group site = null;
|
|
|
|
List<VirtualHost> vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0,
|
|
|
|
VirtualHostLocalServiceUtil.getVirtualHostsCount());
|
|
|
|
for (VirtualHost virtualHost : vHosts) {
|
2019-10-22 19:04:25 +02:00
|
|
|
logger.debug("Found " + virtualHost.getHostname());
|
2018-07-17 19:15:10 +02:00
|
|
|
if (virtualHost.getHostname().compareTo("localhost") != 0 && virtualHost.getLayoutSetId() != 0
|
|
|
|
&& virtualHost.getHostname().compareTo(serverName) == 0) {
|
2018-07-09 14:18:29 +02:00
|
|
|
long layoutSetId = virtualHost.getLayoutSetId();
|
|
|
|
site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup();
|
2019-10-22 19:04:25 +02:00
|
|
|
logger.debug("Found match! Your site is " + site.getName());
|
2018-07-09 14:18:29 +02:00
|
|
|
return site;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-09 14:30:56 +02:00
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
private class VRECategory {
|
2018-07-09 14:30:56 +02:00
|
|
|
private long categoryID;
|
|
|
|
private String name;
|
|
|
|
private String description;
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-09 14:30:56 +02:00
|
|
|
public VRECategory(long categoryID, String name, String description) {
|
|
|
|
super();
|
|
|
|
this.categoryID = categoryID;
|
|
|
|
this.name = name;
|
|
|
|
this.description = description;
|
|
|
|
}
|
|
|
|
|
2018-07-23 17:17:06 +02:00
|
|
|
@SuppressWarnings("unused")
|
2018-07-09 14:30:56 +02:00
|
|
|
public long getCategoryID() {
|
|
|
|
return categoryID;
|
|
|
|
}
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-23 17:17:06 +02:00
|
|
|
@SuppressWarnings("unused")
|
2018-07-09 14:30:56 +02:00
|
|
|
public String getDescription() {
|
|
|
|
return description;
|
|
|
|
}
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-09 14:30:56 +02:00
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
2018-07-09 14:54:53 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "VRECategory [categoryID=" + categoryID + ", name=" + name + ", description=" + description + "]";
|
|
|
|
}
|
2018-07-09 14:30:56 +02:00
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
}
|
2018-07-09 14:30:56 +02:00
|
|
|
|
2018-07-17 19:15:10 +02:00
|
|
|
private class VRE implements Comparable<VRE> {
|
2018-07-09 14:30:56 +02:00
|
|
|
private String name;
|
2018-07-17 19:15:10 +02:00
|
|
|
private String description;
|
2018-07-09 14:30:56 +02:00
|
|
|
private long id;
|
|
|
|
private String url;
|
|
|
|
private String scope;
|
|
|
|
|
|
|
|
public VRE(String name, String description, long id, String url, String scope) {
|
|
|
|
super();
|
|
|
|
this.name = name;
|
|
|
|
this.description = description;
|
|
|
|
this.id = id;
|
|
|
|
this.url = url;
|
|
|
|
this.scope = scope;
|
|
|
|
}
|
|
|
|
|
2018-07-23 17:17:06 +02:00
|
|
|
@SuppressWarnings("unused")
|
2018-07-09 14:30:56 +02:00
|
|
|
public String getDescription() {
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
2018-07-23 17:17:06 +02:00
|
|
|
@SuppressWarnings("unused")
|
2018-07-09 14:30:56 +02:00
|
|
|
public long getId() {
|
|
|
|
return id;
|
|
|
|
}
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-09 14:30:56 +02:00
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-23 17:17:06 +02:00
|
|
|
@SuppressWarnings("unused")
|
2018-07-09 14:30:56 +02:00
|
|
|
public String getScope() {
|
|
|
|
return scope;
|
|
|
|
}
|
2018-07-17 19:15:10 +02:00
|
|
|
|
2018-07-23 17:17:06 +02:00
|
|
|
@SuppressWarnings("unused")
|
2018-07-09 14:30:56 +02:00
|
|
|
public String getUrl() {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2018-07-09 14:54:53 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "VRE [name=" + name + ", description=" + description + ", id=" + id + ", url=" + url + ", scope="
|
|
|
|
+ scope + "]";
|
|
|
|
}
|
|
|
|
|
2018-07-09 14:30:56 +02:00
|
|
|
@Override
|
|
|
|
public int compareTo(VRE vre) {
|
|
|
|
return this.getName().compareTo(vre.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 12:30:27 +02:00
|
|
|
}
|