ref 18815: Accounting Dashboard Reminiscence
https://support.d4science.org/issues/18815 Updated detached REs support
This commit is contained in:
parent
e368c174dd
commit
2081513f2f
|
@ -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.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.is.InfraNode;
|
||||
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
|
||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||
|
@ -86,7 +88,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|||
break;
|
||||
case Infrastructure:
|
||||
logger.debug("AccountingService: Infrastructure");
|
||||
root = recreateTreeForInfrastructure(request, treeOptions);
|
||||
root = recreateTreeForInfrastructure(request);
|
||||
break;
|
||||
default:
|
||||
logger.debug("AccountingService: CurrentScope");
|
||||
|
@ -97,7 +99,7 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|||
return root;
|
||||
}
|
||||
|
||||
private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request, TreeOptions treeOptions2)
|
||||
private ScopeDescriptor recreateTreeForInfrastructure(HttpServletRequest request)
|
||||
throws Exception, PortalException, SystemException {
|
||||
ScopeDescriptor infra = null;
|
||||
PortalContext portalContext = PortalContext.getConfiguration();
|
||||
|
@ -156,13 +158,15 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|||
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);
|
||||
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");
|
||||
|
@ -173,34 +177,41 @@ public class PortalContextTreeProvider implements ContextTreeProvider {
|
|||
return infra;
|
||||
}
|
||||
|
||||
private LinkedList<ScopeDescriptor> retrieveVOChildren(Gateway gateway) {
|
||||
if (gateway.getVos() != null && !gateway.getVos().isEmpty()) {
|
||||
private LinkedList<ScopeDescriptor> retrieveVOChildren(InfraNode infraNode, Gateway gateway) {
|
||||
LinkedList<ScopeDescriptor> vos = new LinkedList<>();
|
||||
for (String key : gateway.getVos().keySet()) {
|
||||
VO vo = gateway.getVos().get(key);
|
||||
ScopeDescriptor voSD = new ScopeDescriptor(vo.getName(), key);
|
||||
|
||||
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;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return vos;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
}
|
||||
return vres;
|
||||
}
|
||||
|
||||
private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue