From d5266a0b7c7e737be71400cb593fc682c0a00992 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 14 Feb 2020 15:04:07 +0100 Subject: [PATCH] ref 18291: Modify Accounting Dashboard portlet to support Core Services https://support.d4science.org/issues/18291 Fixed infra nodes scope --- .../accounting/PortalContextTreeProvider.java | 20 +++++++++++++++++-- .../server/is/BuildInfraNode.java | 17 +++++++++------- .../accountingdashboard/shared/Constants.java | 3 ++- .../AccountingServiceTest.java | 4 ++-- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java index 6939a45..d58c2ae 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/PortalContextTreeProvider.java @@ -110,10 +110,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); + } else { + scopeGroup=gCubeGroup.getGroupName(); + } + StringBuilder gatewayScope=new StringBuilder(); gatewayScope.append(infrastructureScope); gatewayScope.append("/"); - gatewayScope.append(gCubeGroup.getGroupName()); + gatewayScope.append(scopeGroup); + ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, gatewayScope.toString()); if (gatewayChildren != null) { gatewayChildren.addFirst(infraNodeScopeDescriptor); @@ -163,10 +172,17 @@ public class PortalContextTreeProvider implements ContextTreeProvider { 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); + } else { + scopeGroup=gatewayName; + } StringBuilder gatewayScope=new StringBuilder(); gatewayScope.append(portalScope); gatewayScope.append("/"); - gatewayScope.append(gatewayName); + gatewayScope.append(scopeGroup); InfraNode infraNode = BuildInfraNode.build(portalScope); diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/is/BuildInfraNode.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/is/BuildInfraNode.java index 84b1394..f8ee0e2 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/is/BuildInfraNode.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/is/BuildInfraNode.java @@ -36,9 +36,9 @@ public class BuildInfraNode { if (accountingDashboardConfigJAXB != null) { logger.info("AccountingDashboard: use configuration in scope: " + scope); if (accountingDashboardConfigJAXB.isEnabledInfraNode()) { - logger.info("Infra Nodes configuration enabled in scope: " + scope); + logger.info("AccountingDashboard: Infra Nodes configuration enabled in scope: " + scope); InfraNodeJAXB infraNodeJAXB = accountingDashboardConfigJAXB.getBaseInfraNode(); - logger.info("Infra Nodes configuration: " + infraNodeJAXB); + logger.info("AccountingDashboard: Base Infra Nodes configuration: " + infraNodeJAXB); if (infraNodeJAXB != null) { infraNode = new InfraNode(infraNodeJAXB.getScope(), infraNodeJAXB.getName(), infraNodeJAXB.getDescription()); @@ -48,15 +48,18 @@ public class BuildInfraNode { } } else { - logger.info("Infra Nodes use default configuration for scope: " + scope); - infraNode = useDefaultConfiguration(); + logger.info( + "AccountingDashboard: Base Infra Nodes is not present in configuration" + + " resource for scope: " + + scope); + //infraNode = useDefaultConfiguration(); } } else { - logger.info("Infra Nodes configuration disabled in scope: " + scope); + logger.info("AccountingDashboard: Infra Nodes configuration disabled for scope: " + scope); } } else { - logger.info("AccountingDashboard: use infra nodes default configuration for scope: " + scope); - infraNode = useDefaultConfiguration(); + logger.info("AccountingDashboard: configuration resource is not present in scope: " + scope); + // infraNode = useDefaultConfiguration(); } } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/Constants.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/Constants.java index 4aa1871..92108f1 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/Constants.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/Constants.java @@ -17,7 +17,8 @@ public class Constants { public static final String CMEMS_IMPORTER_LANG = "AccountingDashBoradLang"; public static final String DEFAULT_USER = "giancarlo.panichi"; - public static final String DEFAULT_SCOPE = "/gcube/devNext/NextNext"; + //public static final String DEFAULT_SCOPE = "/gcube/devNext/NextNext"; + public static final String DEFAULT_SCOPE = "/gcube"; public static final String DEFAULT_TOKEN = ""; public static final String DEFAULT_ROLE = "OrganizationMember"; diff --git a/src/test/java/org/gcube/portlets/user/accountingdashboard/AccountingServiceTest.java b/src/test/java/org/gcube/portlets/user/accountingdashboard/AccountingServiceTest.java index 693567c..fe2fd99 100644 --- a/src/test/java/org/gcube/portlets/user/accountingdashboard/AccountingServiceTest.java +++ b/src/test/java/org/gcube/portlets/user/accountingdashboard/AccountingServiceTest.java @@ -24,8 +24,8 @@ public class AccountingServiceTest extends TestCase { try { AuthTest.setToken(); - AccountingService accountingService = new AccountingService(AccountingServiceType.CurrentScope); - // accountingService.getTree(); + new AccountingService(AccountingServiceType.CurrentScope); + //accountingService.getTree(); assertTrue(true); } catch (Throwable e) {