ref 18815: Accounting Dashboard Reminiscence

https://support.d4science.org/issues/18815

Updated detached REs support
This commit is contained in:
Giancarlo Panichi 2020-04-08 12:30:28 +02:00
parent e368c174dd
commit 2081513f2f
2 changed files with 107 additions and 25 deletions

View File

@ -18,6 +18,8 @@ import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Detache
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway; import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VO; 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.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.is.InfraNode; import org.gcube.portlets.user.accountingdashboard.shared.is.InfraNode;
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions; import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
@ -53,9 +55,9 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
this.accountingServiceType = accountingServiceType; this.accountingServiceType = accountingServiceType;
this.treeOptions = null; this.treeOptions = null;
} }
public void setTreeOptions(TreeOptions treeOptions){ public void setTreeOptions(TreeOptions treeOptions) {
this.treeOptions=treeOptions; this.treeOptions = treeOptions;
} }
static { static {
@ -86,7 +88,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
break; break;
case Infrastructure: case Infrastructure:
logger.debug("AccountingService: Infrastructure"); logger.debug("AccountingService: Infrastructure");
root = recreateTreeForInfrastructure(request, treeOptions); root = recreateTreeForInfrastructure(request);
break; break;
default: default:
logger.debug("AccountingService: CurrentScope"); logger.debug("AccountingService: CurrentScope");
@ -97,7 +99,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
return root; return root;
} }
private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request, TreeOptions treeOptions2) private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request)
throws Exception, PortalException, SystemException { throws Exception, PortalException, SystemException {
ScopeDescriptor infra = null; ScopeDescriptor infra = null;
PortalContext portalContext = PortalContext.getConfiguration(); PortalContext portalContext = PortalContext.getConfiguration();
@ -156,51 +158,60 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
if (detachedREs != null && detachedREs.isEnabled()) { if (detachedREs != null && detachedREs.isEnabled()) {
logger.debug("DetachedREs is enabled"); logger.debug("DetachedREs is enabled");
if (detachedREs.getGateways() != null && !detachedREs.getGateways().isEmpty()) { if (detachedREs.getGateways() != null && !detachedREs.getGateways().isEmpty()) {
for (String key : detachedREs.getGateways().keySet()) { ArrayList<Gateway> gatewaysList = new ArrayList<Gateway>(detachedREs.getGateways().values());
Gateway gateway = detachedREs.getGateways().get(key); Collections.sort(gatewaysList);
ScopeDescriptor getewaySD = new ScopeDescriptor(gateway.getName(), key); for (Gateway gateway : gatewaysList) {
LinkedList<ScopeDescriptor> voChildren = retrieveVOChildren(gateway); ScopeDescriptor getewaySD = new ScopeDescriptor(gateway.getName(), gateway.getScope());
LinkedList<ScopeDescriptor> voChildren = retrieveVOChildren(infraNode, gateway);
getewaySD.setChildren(voChildren); getewaySD.setChildren(voChildren);
infraChildren.add(getewaySD); infraChildren.add(getewaySD);
} }
CocktailSort.sort(infraChildren,Order.DESC);
} }
} else { } else {
logger.debug("DetachedREs is disabled"); logger.debug("DetachedREs is disabled");
} }
} }
infra.setChildren(infraChildren); infra.setChildren(infraChildren);
return infra; return infra;
} }
private LinkedList<ScopeDescriptor> retrieveVOChildren(Gateway gateway) { 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()) { if (gateway.getVos() != null && !gateway.getVos().isEmpty()) {
LinkedList<ScopeDescriptor> vos = new LinkedList<>(); ArrayList<VO> vosList = new ArrayList<VO>(gateway.getVos().values());
for (String key : gateway.getVos().keySet()) { Collections.sort(vosList);
VO vo = gateway.getVos().get(key); for (VO vo : vosList) {
ScopeDescriptor voSD = new ScopeDescriptor(vo.getName(), key); ScopeDescriptor voSD = new ScopeDescriptor(vo.getName(), vo.getScope());
LinkedList<ScopeDescriptor> voChildren = retrieveVREChildren(vo); LinkedList<ScopeDescriptor> voChildren = retrieveVREChildren(vo);
voSD.setChildren(voChildren); voSD.setChildren(voChildren);
vos.add(voSD); vos.add(voSD);
} }
return vos;
} else {
return null;
} }
return vos;
} }
private LinkedList<ScopeDescriptor> retrieveVREChildren(VO vo) { private LinkedList<ScopeDescriptor> retrieveVREChildren(VO vo) {
LinkedList<ScopeDescriptor> vres = new LinkedList<>();
if (vo.getVres() != null && !vo.getVres().isEmpty()) { if (vo.getVres() != null && !vo.getVres().isEmpty()) {
LinkedList<ScopeDescriptor> vres = new LinkedList<>(); ArrayList<org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE> vresList = new ArrayList<org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE>(
for (String key : vo.getVres().keySet()) { vo.getVres().values());
org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE vre = vo.getVres().get(key); Collections.sort(vresList);
ScopeDescriptor vreSD = new ScopeDescriptor(vre.getName(), key); for (org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE vre : vresList) {
ScopeDescriptor vreSD = new ScopeDescriptor(vre.getName(), vre.getScope());
vres.add(vreSD); vres.add(vreSD);
} }
return vres;
} else {
return null;
} }
return vres;
} }
private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope) { private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope) {

View File

@ -0,0 +1,71 @@
package org.gcube.portlets.user.accountingdashboard.server.util;
import java.util.List;
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
public class CocktailSort {
public enum Order {
ASC, DESC
}
public static void sort(List<ScopeDescriptor> list, Order order) {
if (list != null && list.size() > 1) {
// `begin` ed `end` first and last index to check
int begin = -1;
int end = list.size() - 1;
boolean swapped;
do {
swapped = false;
// increases `begin` because the elements before `begin` are
// sorted correctly
begin = begin + 1;
for (int i = begin; i < end; i++) {
if (order == Order.ASC) {
if (list.get(i).getName().compareTo(list.get(i + 1).getName()) < 0) {
ScopeDescriptor sd = list.get(i);
list.set(i, list.get(i + 1));
list.set(i + 1, sd);
swapped = true;
}
} else {
if (list.get(i).getName().compareTo(list.get(i + 1).getName()) > 0) {
ScopeDescriptor sd = list.get(i);
list.set(i, list.get(i + 1));
list.set(i + 1, sd);
swapped = true;
}
}
}
if (swapped == false) {
break;
}
swapped = false;
// decreases `end` because the elements after `end` are sorted
// correctly
end = end - 1;
for (int i = end; i > begin; i--) {
if (order == Order.ASC) {
if (list.get(i).getName().compareTo(list.get(i - 1).getName()) > 0) {
ScopeDescriptor sd = list.get(i);
list.set(i, list.get(i - 1));
list.set(i - 1, sd);
swapped = true;
}
} else {
if (list.get(i).getName().compareTo(list.get(i - 1).getName()) < 0) {
ScopeDescriptor sd = list.get(i);
list.set(i, list.get(i - 1));
list.set(i - 1, sd);
swapped = true;
}
}
}
} while (swapped);
}
}
}