|
|
|
@ -13,8 +13,16 @@ 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.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;
|
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.server.is.BuildInfraNode;
|
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.server.util.CocktailSort;
|
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.server.util.CocktailSort.Order;
|
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.env.AccountingServiceType;
|
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.is.InfraNode;
|
|
|
|
|
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
|
|
|
@ -42,8 +50,15 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(PortalContextTreeProvider.class);
|
|
|
|
|
private AccountingServiceType accountingServiceType;
|
|
|
|
|
|
|
|
|
|
private TreeOptions treeOptions;
|
|
|
|
|
|
|
|
|
|
public PortalContextTreeProvider(AccountingServiceType accountingServiceType) {
|
|
|
|
|
this.accountingServiceType = accountingServiceType;
|
|
|
|
|
this.treeOptions = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTreeOptions(TreeOptions treeOptions) {
|
|
|
|
|
this.treeOptions = treeOptions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
@ -110,19 +125,19 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
currUser);
|
|
|
|
|
|
|
|
|
|
if (infraNode != null) {
|
|
|
|
|
String scopeGroup="";
|
|
|
|
|
if(gCubeGroup.getGroupName().toUpperCase().endsWith(" GATEWAY")){
|
|
|
|
|
int l=gCubeGroup.getGroupName().length();
|
|
|
|
|
scopeGroup=gCubeGroup.getGroupName().substring(0, l-8);
|
|
|
|
|
String scopeGroup = "";
|
|
|
|
|
if (gCubeGroup.getGroupName().toUpperCase().endsWith(" GATEWAY")) {
|
|
|
|
|
int l = gCubeGroup.getGroupName().length();
|
|
|
|
|
scopeGroup = gCubeGroup.getGroupName().substring(0, l - 8);
|
|
|
|
|
} else {
|
|
|
|
|
scopeGroup=gCubeGroup.getGroupName();
|
|
|
|
|
scopeGroup = gCubeGroup.getGroupName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder gatewayScope=new StringBuilder();
|
|
|
|
|
|
|
|
|
|
StringBuilder gatewayScope = new StringBuilder();
|
|
|
|
|
gatewayScope.append(infrastructureScope);
|
|
|
|
|
gatewayScope.append("/");
|
|
|
|
|
gatewayScope.append(scopeGroup);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, gatewayScope.toString());
|
|
|
|
|
if (gatewayChildren != null) {
|
|
|
|
|
gatewayChildren.addFirst(infraNodeScopeDescriptor);
|
|
|
|
@ -138,10 +153,68 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
infraChildren.add(gatewayScopeDescriptor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()) {
|
|
|
|
|
ArrayList<Gateway> gatewaysList = new ArrayList<Gateway>(detachedREs.getGateways().values());
|
|
|
|
|
Collections.sort(gatewaysList);
|
|
|
|
|
for (Gateway gateway : gatewaysList) {
|
|
|
|
|
ScopeDescriptor getewaySD = new ScopeDescriptor(gateway.getName(), gateway.getScope());
|
|
|
|
|
LinkedList<ScopeDescriptor> voChildren = retrieveVOChildren(infraNode, gateway);
|
|
|
|
|
getewaySD.setChildren(voChildren);
|
|
|
|
|
infraChildren.add(getewaySD);
|
|
|
|
|
}
|
|
|
|
|
CocktailSort.sort(infraChildren,Order.DESC);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
logger.debug("DetachedREs is disabled");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
infra.setChildren(infraChildren);
|
|
|
|
|
return infra;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LinkedList<ScopeDescriptor> retrieveVOChildren(InfraNode infraNode, Gateway gateway) {
|
|
|
|
|
LinkedList<ScopeDescriptor> vos = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
if (infraNode != null) {
|
|
|
|
|
ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, gateway.getScope());
|
|
|
|
|
vos.add(infraNodeScopeDescriptor);
|
|
|
|
|
}
|
|
|
|
|
if (gateway.getVos() != null && !gateway.getVos().isEmpty()) {
|
|
|
|
|
ArrayList<VO> vosList = new ArrayList<VO>(gateway.getVos().values());
|
|
|
|
|
Collections.sort(vosList);
|
|
|
|
|
for (VO vo : vosList) {
|
|
|
|
|
ScopeDescriptor voSD = new ScopeDescriptor(vo.getName(), vo.getScope());
|
|
|
|
|
LinkedList<ScopeDescriptor> voChildren = retrieveVREChildren(vo);
|
|
|
|
|
voSD.setChildren(voChildren);
|
|
|
|
|
vos.add(voSD);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return vos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LinkedList<ScopeDescriptor> retrieveVREChildren(VO vo) {
|
|
|
|
|
LinkedList<ScopeDescriptor> vres = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
if (vo.getVres() != null && !vo.getVres().isEmpty()) {
|
|
|
|
|
ArrayList<org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE> vresList = new ArrayList<org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE>(
|
|
|
|
|
vo.getVres().values());
|
|
|
|
|
Collections.sort(vresList);
|
|
|
|
|
for (org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE vre : vresList) {
|
|
|
|
|
ScopeDescriptor vreSD = new ScopeDescriptor(vre.getName(), vre.getScope());
|
|
|
|
|
vres.add(vreSD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return vres;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope) {
|
|
|
|
|
StringBuilder absoluteScope = new StringBuilder();
|
|
|
|
|
absoluteScope.append(scope);
|
|
|
|
@ -164,28 +237,28 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
throws Exception, PortalException, SystemException {
|
|
|
|
|
ScopeDescriptor root;
|
|
|
|
|
|
|
|
|
|
Group group=getSiteFromServletRequest(request);
|
|
|
|
|
Group group = getSiteFromServletRequest(request);
|
|
|
|
|
long currentSiteGroupId = group.getGroupId();
|
|
|
|
|
String gatewayName=group.getName();
|
|
|
|
|
|
|
|
|
|
String gatewayName = group.getName();
|
|
|
|
|
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
GCubeUser currUser = pContext.getCurrentUser(request);
|
|
|
|
|
String portalScope = pContext.getCurrentScope(currentSiteGroupId + "");
|
|
|
|
|
|
|
|
|
|
String scopeGroup="";
|
|
|
|
|
if(gatewayName.toUpperCase().endsWith(" GATEWAY")){
|
|
|
|
|
int l=gatewayName.length();
|
|
|
|
|
scopeGroup=gatewayName.substring(0, l-8);
|
|
|
|
|
|
|
|
|
|
String scopeGroup = "";
|
|
|
|
|
if (gatewayName.toUpperCase().endsWith(" GATEWAY")) {
|
|
|
|
|
int l = gatewayName.length();
|
|
|
|
|
scopeGroup = gatewayName.substring(0, l - 8);
|
|
|
|
|
} else {
|
|
|
|
|
scopeGroup=gatewayName;
|
|
|
|
|
scopeGroup = gatewayName;
|
|
|
|
|
}
|
|
|
|
|
StringBuilder gatewayScope=new StringBuilder();
|
|
|
|
|
StringBuilder gatewayScope = new StringBuilder();
|
|
|
|
|
gatewayScope.append(portalScope);
|
|
|
|
|
gatewayScope.append("/");
|
|
|
|
|
gatewayScope.append(scopeGroup);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InfraNode infraNode = BuildInfraNode.build(portalScope);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LinkedList<ScopeDescriptor> rootChildren = null;
|
|
|
|
|
rootChildren = retrieveGatewayChildren(request, currentSiteGroupId, currUser);
|
|
|
|
|
|
|
|
|
|