From 82361090f754d59508d7396d79f4bccbf39e5c4f Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 7 Apr 2020 17:34:45 +0200 Subject: [PATCH] ref 18815: Accounting Dashboard Reminiscence https://support.d4science.org/issues/18815 Added detachedres-library --- .classpath | 6 +- .settings/org.eclipse.wst.common.component | 2 +- pom.xml | 12 +- .../application/controller/Controller.java | 16 ++- .../rpc/AccountingDashboardService.java | 5 +- .../rpc/AccountingDashboardServiceAsync.java | 6 +- .../AccountingDashboardServiceImpl.java | 9 +- .../server/accounting/AccountingService.java | 11 +- .../accounting/PortalContextTreeProvider.java | 105 ++++++++++++++---- .../shared/options/TreeOptions.java | 34 ++++++ .../AccountingServiceTest.java | 2 +- .../ISDetachedREsTest.java | 49 ++++++++ 12 files changed, 215 insertions(+), 42 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/accountingdashboard/shared/options/TreeOptions.java create mode 100644 src/test/java/org/gcube/portlets/user/accountingdashboard/ISDetachedREsTest.java diff --git a/.classpath b/.classpath index 5c0febd..38083dc 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -50,5 +50,5 @@ - + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 822ca16..6d41532 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,5 @@ - + diff --git a/pom.xml b/pom.xml index b8570ca..d83ea4b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,13 +7,13 @@ org.gcube.tools 1.1.0 - + 4.0.0 org.gcube.portlets.user accounting-dashboard - 1.2.0 + 1.3.0 war accounting-dashboard @@ -256,6 +256,14 @@ [1.0.0,2.0.0-SNAPSHOT) + + + org.gcube.infrastructure.detachedres + detachedres-library + [0.0.1,2.0.0-SNAPSHOT) + + + com.liferay.portal diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/controller/Controller.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/controller/Controller.java index c67f751..4f8bb58 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/controller/Controller.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/controller/Controller.java @@ -13,6 +13,7 @@ import org.gcube.portlets.user.accountingdashboard.client.rpc.AccountingDashboar import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData; +import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions; import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo; import com.google.gwt.event.shared.EventBus; @@ -37,6 +38,7 @@ public class Controller { private MonitorPresenter monitorPresenter; private ErrorPresenter errorPresenter; private InfoPresenter infoPresenter; + private TreeOptions treeOptions=null; @Inject Controller(@Named("ControllerEventBus") EventBus eventBus, AccountingDashboardServiceAsync service, @@ -47,6 +49,7 @@ public class Controller { this.errorPresenter = errorPresenter; this.infoPresenter = infoPresenter; //this.cache = new ApplicationCache(); + this.setTreeOptions(new TreeOptions(false)); } @@ -72,6 +75,14 @@ public class Controller { infoPresenter.infoMessage(info); } + public TreeOptions getTreeOptions() { + return treeOptions; + } + + public void setTreeOptions(TreeOptions treeOptions) { + this.treeOptions = treeOptions; + } + public void hello() { eventBus.fireEvent(new HelloEvent()); @@ -102,7 +113,7 @@ public class Controller { } public void getTree() { - service.getScopeData(new AsyncCallback() { + service.getScopeData(treeOptions,new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -123,7 +134,7 @@ public class Controller { public void getReport(RequestReportData requestReportData) { monitorPresenter.enable(true); - service.getReport(requestReportData, new AsyncCallback() { + service.getReport(requestReportData,treeOptions, new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -144,4 +155,5 @@ public class Controller { } + } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/rpc/AccountingDashboardService.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/rpc/AccountingDashboardService.java index a44e87f..eeb4d41 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/rpc/AccountingDashboardService.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/rpc/AccountingDashboardService.java @@ -4,6 +4,7 @@ import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData; import org.gcube.portlets.user.accountingdashboard.shared.exception.ServiceException; +import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions; import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo; import com.google.gwt.user.client.rpc.RemoteService; @@ -26,8 +27,8 @@ public interface AccountingDashboardService extends RemoteService { */ public UserInfo hello() throws ServiceException; - public ScopeData getScopeData() throws ServiceException; + public ScopeData getScopeData(TreeOptions treeOptions) throws ServiceException; - public ReportData getReport(RequestReportData requestReportdata) throws ServiceException; + public ReportData getReport(RequestReportData requestReportdata, TreeOptions treeOptions) throws ServiceException; } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/rpc/AccountingDashboardServiceAsync.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/rpc/AccountingDashboardServiceAsync.java index 51858d8..f5739b3 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/rpc/AccountingDashboardServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/rpc/AccountingDashboardServiceAsync.java @@ -6,6 +6,7 @@ package org.gcube.portlets.user.accountingdashboard.client.rpc; import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData; +import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions; import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo; import com.google.gwt.core.client.GWT; @@ -24,8 +25,9 @@ public interface AccountingDashboardServiceAsync { void hello(AsyncCallback callback); - void getScopeData(AsyncCallback callback); + void getScopeData(TreeOptions treeOptions, AsyncCallback callback); - void getReport(RequestReportData requestReportdata, AsyncCallback asyncCallback); + void getReport(RequestReportData requestReportdata, TreeOptions treeOptions, + AsyncCallback asyncCallback); } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java index ef56017..998c4e3 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/AccountingDashboardServiceImpl.java @@ -12,6 +12,7 @@ import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData; import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData; import org.gcube.portlets.user.accountingdashboard.shared.exception.ServiceException; +import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions; import org.gcube.portlets.user.accountingdashboard.shared.session.UserInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,11 +66,11 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme } @Override - public ScopeData getScopeData() throws ServiceException { + public ScopeData getScopeData(TreeOptions treeOptions) throws ServiceException { try { logger.debug("AccountingDashboardServiceImpl getScopeData()"); ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); - AccountingService as = new AccountingService(getAccountingContext(serviceCredentials.getScope())); + AccountingService as = new AccountingService(getAccountingContext(serviceCredentials.getScope()),treeOptions); ScopeData scopeData = as.getTree(this.getThreadLocalRequest()); return scopeData; } catch (ServiceException e) { @@ -83,11 +84,11 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme } @Override - public ReportData getReport(RequestReportData requestReportData) throws ServiceException { + public ReportData getReport(RequestReportData requestReportData,TreeOptions treeOptions) throws ServiceException { try { logger.debug("AccountingDashboardServiceImpl getReport(): " + requestReportData); ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); - AccountingService as = new AccountingService(getAccountingContext(serviceCredentials.getScope())); + AccountingService as = new AccountingService(getAccountingContext(serviceCredentials.getScope()), treeOptions); ReportData reportData = as.getReport(this.getThreadLocalRequest(), requestReportData); return reportData; } catch (ServiceException e) { diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java index a6e07f9..0900edf 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingService.java @@ -17,6 +17,7 @@ import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData; import org.gcube.portlets.user.accountingdashboard.shared.data.SeriesData; import org.gcube.portlets.user.accountingdashboard.shared.exception.ServiceException; +import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +32,7 @@ public class AccountingService { private AccountingDao dao; - public AccountingService(AccountingServiceType accountingServiceType) throws ServiceException { + public AccountingService(AccountingServiceType accountingServiceType, TreeOptions treeOptions) throws ServiceException { try { if (Constants.DEBUG_MODE) { return; @@ -41,6 +42,7 @@ public class AccountingService { logger.error("Invalid AccountingServiceType requested: null"); } + PortalContextTreeProvider portalContextTreeProvider=null; switch (accountingServiceType) { case CurrentScope: logger.debug("AccountingService: CurrentScope"); @@ -48,11 +50,14 @@ public class AccountingService { break; case PortalContex: logger.debug("AccountingService: PortalContext"); - dao = AccountingDao.get(new PortalContextTreeProvider(accountingServiceType)); + portalContextTreeProvider=new PortalContextTreeProvider(accountingServiceType); + dao = AccountingDao.get(portalContextTreeProvider); break; case Infrastructure: logger.debug("AccountingService: Infrastructure"); - dao = AccountingDao.get(new PortalContextTreeProvider(accountingServiceType)); + portalContextTreeProvider=new PortalContextTreeProvider(accountingServiceType); + portalContextTreeProvider.setTreeOptions(treeOptions); + dao = AccountingDao.get(portalContextTreeProvider); break; default: logger.debug("AccountingService: CurrentScope"); 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 d58c2ae..eb85a09 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 @@ -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 voChildren = retrieveVOChildren(gateway); + getewaySD.setChildren(voChildren); + infraChildren.add(getewaySD); + } + } + } else { + logger.debug("DetachedREs is disabled"); + } + } + infra.setChildren(infraChildren); return infra; } + private LinkedList retrieveVOChildren(Gateway gateway) { + if (gateway.getVos() != null && !gateway.getVos().isEmpty()) { + LinkedList vos = new LinkedList<>(); + for (String key : gateway.getVos().keySet()) { + VO vo = gateway.getVos().get(key); + ScopeDescriptor voSD = new ScopeDescriptor(vo.getName(), key); + LinkedList voChildren = retrieveVREChildren(vo); + voSD.setChildren(voChildren); + vos.add(voSD); + } + return vos; + } else { + return null; + } + } + + private LinkedList retrieveVREChildren(VO vo) { + if (vo.getVres() != null && !vo.getVres().isEmpty()) { + LinkedList 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 rootChildren = null; rootChildren = retrieveGatewayChildren(request, currentSiteGroupId, currUser); diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/options/TreeOptions.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/options/TreeOptions.java new file mode 100644 index 0000000..dad03bd --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/options/TreeOptions.java @@ -0,0 +1,34 @@ +package org.gcube.portlets.user.accountingdashboard.shared.options; + +import java.io.Serializable; + +/** + * + * @author Giancarlo Panichi + * + */ +public class TreeOptions implements Serializable { + + private static final long serialVersionUID = 730133583251742872L; + + private boolean showDetachedREs = false; + + public TreeOptions(boolean showDetachedREs) { + super(); + this.showDetachedREs = showDetachedREs; + } + + public boolean isShowDetachedREs() { + return showDetachedREs; + } + + public void setShowDetachedREs(boolean showDetachedREs) { + this.showDetachedREs = showDetachedREs; + } + + @Override + public String toString() { + return "TreeOptions [showDetachedREs=" + showDetachedREs + "]"; + } + +} 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 fe2fd99..96d12d2 100644 --- a/src/test/java/org/gcube/portlets/user/accountingdashboard/AccountingServiceTest.java +++ b/src/test/java/org/gcube/portlets/user/accountingdashboard/AccountingServiceTest.java @@ -24,7 +24,7 @@ public class AccountingServiceTest extends TestCase { try { AuthTest.setToken(); - new AccountingService(AccountingServiceType.CurrentScope); + new AccountingService(AccountingServiceType.CurrentScope,null); //accountingService.getTree(); assertTrue(true); diff --git a/src/test/java/org/gcube/portlets/user/accountingdashboard/ISDetachedREsTest.java b/src/test/java/org/gcube/portlets/user/accountingdashboard/ISDetachedREsTest.java new file mode 100644 index 0000000..bced63a --- /dev/null +++ b/src/test/java/org/gcube/portlets/user/accountingdashboard/ISDetachedREsTest.java @@ -0,0 +1,49 @@ +/** + * + */ +package org.gcube.portlets.user.accountingdashboard; + +import org.gcube.infrastructure.detachedres.detachedreslibrary.server.DetachedREsClient; +import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs; +import org.gcube.portlets.user.accountingdashboard.shared.Constants; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import junit.framework.TestCase; + +/** + * + * @author Giancarlo Panichi + * + * + */ +public class ISDetachedREsTest extends TestCase { + + private static Logger logger = LoggerFactory.getLogger(ISDetachedREsTest.class); + + @Test + public void testAccountingDashboardResource() { + if (Constants.TEST_ENABLE) { + logger.debug("Test Enabled"); + + try { + DetachedREsClient detachedREsClient = new DetachedREsClient(Constants.DEFAULT_TOKEN); + DetachedREs detachedREs = detachedREsClient.getDetachedREsInScope(Constants.DEFAULT_SCOPE); + logger.debug("DetachedREs: " + detachedREs); + assertTrue(true); + + } catch (Exception e) { + logger.error(e.getLocalizedMessage(), e); + assertTrue("Error searching the resource!", false); + } + + } else { + logger.debug("Test Disabled"); + assertTrue(true); + } + } + + + +}