|
|
|
@ -13,8 +13,13 @@ 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.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 +47,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 {
|
|
|
|
@ -74,7 +86,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
break;
|
|
|
|
|
case Infrastructure:
|
|
|
|
|
logger.debug("AccountingService: Infrastructure");
|
|
|
|
|
root = recreateTreeForInfrastructure(request);
|
|
|
|
|
root = recreateTreeForInfrastructure(request, treeOptions);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
logger.debug("AccountingService: CurrentScope");
|
|
|
|
@ -85,7 +97,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|
|
|
|
return root;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request)
|
|
|
|
|
private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request, TreeOptions treeOptions2)
|
|
|
|
|
throws Exception, PortalException, SystemException {
|
|
|
|
|
ScopeDescriptor infra = null;
|
|
|
|
|
PortalContext portalContext = PortalContext.getConfiguration();
|
|
|
|
@ -110,19 +122,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 +150,59 @@ 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()) {
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
infra.setChildren(infraChildren);
|
|
|
|
|
return infra;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope) {
|
|
|
|
|
StringBuilder absoluteScope = new StringBuilder();
|
|
|
|
|
absoluteScope.append(scope);
|
|
|
|
@ -164,28 +225,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);
|
|
|
|
|
|
|
|
|
|