diff --git a/changelog.xml b/changelog.xml index e30161e..03d12fb 100644 --- a/changelog.xml +++ b/changelog.xml @@ -1,7 +1,10 @@ + date="2020-04-08"> Updated export csv support with Firefox and Safari [ticket #18034] + Added Core Services support [ticket #18291] + Added Detached REs support [ticket #18815] + Added the alphabetical sorting of tabs [ticket #18754] diff --git a/pom.xml b/pom.xml index b8570ca..5c90dc4 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.gcube.tools 1.1.0 - + 4.0.0 @@ -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..0f6b577 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 @@ -6,6 +6,7 @@ import java.util.logging.Logger; import org.gcube.portlets.user.accountingdashboard.client.application.dialog.error.ErrorPresenter; import org.gcube.portlets.user.accountingdashboard.client.application.dialog.info.InfoPresenter; import org.gcube.portlets.user.accountingdashboard.client.application.dialog.monitor.MonitorPresenter; +import org.gcube.portlets.user.accountingdashboard.client.application.event.EnvironmentEvent; import org.gcube.portlets.user.accountingdashboard.client.application.event.HelloEvent; import org.gcube.portlets.user.accountingdashboard.client.application.event.ReportEvent; import org.gcube.portlets.user.accountingdashboard.client.application.event.ScopeDataEvent; @@ -13,6 +14,8 @@ 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.env.EnvironmentData; +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 +40,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 +51,7 @@ public class Controller { this.errorPresenter = errorPresenter; this.infoPresenter = infoPresenter; //this.cache = new ApplicationCache(); + this.setTreeOptions(new TreeOptions(false)); } @@ -72,6 +77,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()); @@ -100,9 +113,30 @@ public class Controller { }); } + + public void getEnvironment() { + service.getEnvironment(new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + logger.log(Level.FINE, "Error in getEnvironment(): ", caught); + errorPresenter.errorMessage(caught.getLocalizedMessage()); + } + + @Override + public void onSuccess(EnvironmentData environmentData) { + logger.log(Level.FINE, "ScopeData: " + environmentData); + EnvironmentEvent event = new EnvironmentEvent(environmentData); + eventBus.fireEvent(event); + } + + }); + + } + public void getTree() { - service.getScopeData(new AsyncCallback() { + service.getScopeData(treeOptions,new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -123,7 +157,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 +178,5 @@ public class Controller { } + } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/event/EnvironmentEvent.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/event/EnvironmentEvent.java new file mode 100644 index 0000000..beb26bb --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/event/EnvironmentEvent.java @@ -0,0 +1,51 @@ +package org.gcube.portlets.user.accountingdashboard.client.application.event; + +import org.gcube.portlets.user.accountingdashboard.shared.env.EnvironmentData; + +import com.google.gwt.event.shared.EventHandler; +import com.google.gwt.event.shared.GwtEvent; +import com.google.gwt.event.shared.HasHandlers; + +/** + * + * @author Giancarlo Panichi + * + */ +public class EnvironmentEvent extends GwtEvent { + + private EnvironmentData environmentData; + + public interface EnvironmentEventHandler extends EventHandler { + void onInit(EnvironmentEvent event); + } + + public static final Type TYPE = new Type<>(); + + public EnvironmentEvent(EnvironmentData environmentData) { + this.environmentData = environmentData; + } + + public static void fire(HasHandlers source, EnvironmentEvent event) { + source.fireEvent(event); + } + + @Override + public Type getAssociatedType() { + return TYPE; + } + + @Override + protected void dispatch(EnvironmentEventHandler handler) { + handler.onInit(this); + } + + public EnvironmentData getEnvironmentData() { + return environmentData; + } + + @Override + public String toString() { + return "EnvironmentEvent [environmentData=" + environmentData + "]"; + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaPresenter.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaPresenter.java index 17f4782..41b1af6 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaPresenter.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaPresenter.java @@ -5,9 +5,12 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.gcube.portlets.user.accountingdashboard.client.application.controller.Controller; +import org.gcube.portlets.user.accountingdashboard.client.application.event.EnvironmentEvent; import org.gcube.portlets.user.accountingdashboard.client.application.event.ScopeDataEvent; 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.env.EnvironmentData; +import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.inject.Inject; @@ -29,6 +32,8 @@ public class FilterAreaPresenter extends PresenterWidget { void displayScopeData(ScopeData scopeData); + + void setEnvironment(EnvironmentData environmentData); } @@ -47,7 +52,6 @@ public class FilterAreaPresenter extends PresenterWidget @UiField(provided = true) ListBox monthEnd; + + @UiField(provided = false) + ControlGroup cgDetachedREs; + @UiField(provided = true) + RadioButton btnShowDetachedREs; + + @UiField(provided = true) + RadioButton btnHideDetachedREs; + @UiField(provided = true) CellTree scopeTree; @@ -161,6 +176,33 @@ public class FilterAreaView extends ViewWithUiHandlers } }); + + logger.log(Level.FINE, "Configuring buttons DetachedREs"); + //cgDetachedREs=new ControlGroup(); + + btnShowDetachedREs=new RadioButton("radioDetachedREs"); + btnShowDetachedREs.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + TreeOptions treeOptions=new TreeOptions(true); + getUiHandlers().updateTreeOptions(treeOptions); + } + }); + + btnHideDetachedREs=new RadioButton("radioDetachedREs"); + btnHideDetachedREs.setValue(true); + btnHideDetachedREs.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + TreeOptions treeOptions=new TreeOptions(false); + getUiHandlers().updateTreeOptions(treeOptions); + } + }); + + + logger.log(Level.FINE, "Configuring DataProvider"); dataProvider = new ListDataProvider(); RequestReportEventHandler handler = new RequestReportEventHandler() { @@ -177,10 +219,38 @@ public class FilterAreaView extends ViewWithUiHandlers ScopeTreeResources scopeTreeResources = GWT.create(ScopeTreeResources.class); scopeTree = new CellTree(scopeTreeModel, null, scopeTreeResources); scopeTree.setDefaultNodeSize(500); + + logger.log(Level.FINE, "FilterAreaView init end"); } + @Override + public void setEnvironment(EnvironmentData environmentData) { + logger.log(Level.FINE, "displayScopeData()"); + if(environmentData!=null&&environmentData.getAccountingServiceType()!=null){ + switch(environmentData.getAccountingServiceType()){ + case CurrentScope: + cgDetachedREs.setVisible(false); + break; + case Infrastructure: + cgDetachedREs.setVisible(true); + break; + case PortalContex: + cgDetachedREs.setVisible(false); + break; + default: + cgDetachedREs.setVisible(false); + break; + + } + } else { + cgDetachedREs.setVisible(false); + } + } + + @Override public void displayScopeData(ScopeData scopeData) { + logger.log(Level.FINE, "displayScopeData()"); ArrayList scopeDataList = new ArrayList<>(); scopeDataList.add(scopeData); this.scopeData = scopeData; @@ -194,6 +264,7 @@ public class FilterAreaView extends ViewWithUiHandlers } private void requestReport() { + logger.log(Level.FINE, "requestReport()"); String[] months = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsFull(); logger.log(Level.FINE, "Months: " + months.length); @@ -238,4 +309,6 @@ public class FilterAreaView extends ViewWithUiHandlers } + + } diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaView.ui.xml b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaView.ui.xml index 1cace33..5733f6f 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaView.ui.xml +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/filter/FilterAreaView.ui.xml @@ -11,38 +11,47 @@ - Filters - - - - - From: - - - - - - Select the start date - - - - To: - - - - - - Select the end date - - - - - - - - + Filters + + + + + From: + + + + + + Select the start date + + + + To: + + + + + + Select the end date + + + + Detached: + + + + Detached REs + + + + + + + + + diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/ReportAreaView.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/ReportAreaView.java index cc57ad3..42e2d23 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/ReportAreaView.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/ReportAreaView.java @@ -1,6 +1,7 @@ package org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.logging.Logger; @@ -87,7 +88,11 @@ public class ReportAreaView extends ViewWithUiHandlers TabPanel tabPanel = new TabPanel(); tabPanel.addStyleName(resources.uiDataCss().uiDataReportTabPanel()); boolean first = true; - for (String category : categories.keySet()) { + ArrayList sortedKeys = + new ArrayList(categories.keySet()); + Collections.sort(sortedKeys); + + for (String category : sortedKeys) { Tab tab = new Tab(); tab.setHeading(category); HTMLPanel tabContent = new HTMLPanel(""); diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/AppResources.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/AppResources.java index f0db263..5074505 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/AppResources.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/AppResources.java @@ -28,6 +28,8 @@ public interface AppResources extends ClientBundle { String uiDataFiltersTitle(); String uiDataFiltersFormPanel(); + + String uiDataFiltersControlGroup(); String uiDataFiltersControls(); diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/uiData.css b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/uiData.css index bff001c..54511a0 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/uiData.css +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/client/resources/uiData.css @@ -40,8 +40,12 @@ margin: 0px !important; } +.uiDataFiltersControlGroup { + margin-bottom: 10px; +} + .uiDataFiltersControls { - margin-left: 60px; + margin-left: 80px; } .uiDataExploreTree { 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..29497e0 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 @@ -3,7 +3,9 @@ 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.env.EnvironmentData; 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 +28,10 @@ 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; + + public EnvironmentData getEnvironment() 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..228bce6 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,8 @@ 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.env.EnvironmentData; +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 +26,11 @@ public interface AccountingDashboardServiceAsync { void hello(AsyncCallback callback); - void getScopeData(AsyncCallback callback); + void getEnvironment(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..4abba8d 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 @@ -6,12 +6,14 @@ import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.portlets.user.accountingdashboard.client.rpc.AccountingDashboardService; import org.gcube.portlets.user.accountingdashboard.server.accounting.AccountingService; -import org.gcube.portlets.user.accountingdashboard.server.accounting.AccountingServiceType; import org.gcube.portlets.user.accountingdashboard.server.util.ServiceCredentials; 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.env.AccountingServiceType; +import org.gcube.portlets.user.accountingdashboard.shared.env.EnvironmentData; 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; @@ -63,13 +65,30 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme } } + + @Override + public EnvironmentData getEnvironment() throws ServiceException { + try { + logger.debug("AccountingDashboardServiceImpl getEnvironment()"); + ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); + AccountingServiceType accountingServiceType=getAccountingContext(serviceCredentials.getScope()); + EnvironmentData environmentData=new EnvironmentData(accountingServiceType); + return environmentData; + } catch (ServiceException e) { + logger.error(e.getLocalizedMessage(), e); + throw e; + } catch (Throwable e) { + logger.error("GetEnvironment(): " + e.getLocalizedMessage(), e); + throw new ServiceException("Error retrieving environment info: " + e.getLocalizedMessage(), e); + } + } @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 +102,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) { @@ -117,4 +136,6 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme } } + + } \ No newline at end of file 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..704fc3f 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 @@ -16,7 +16,9 @@ import org.gcube.portlets.user.accountingdashboard.shared.data.ReportElementData 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.env.AccountingServiceType; 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 +33,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 +43,7 @@ public class AccountingService { logger.error("Invalid AccountingServiceType requested: null"); } + PortalContextTreeProvider portalContextTreeProvider=null; switch (accountingServiceType) { case CurrentScope: logger.debug("AccountingService: CurrentScope"); @@ -48,11 +51,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..a668c1a 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,16 @@ 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.server.util.CocktailSort; +import org.gcube.portlets.user.accountingdashboard.server.util.CocktailSort.Order; +import org.gcube.portlets.user.accountingdashboard.shared.env.AccountingServiceType; 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 +50,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 { @@ -110,19 +125,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 +153,68 @@ 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()) { + ArrayList gatewaysList = new ArrayList(detachedREs.getGateways().values()); + Collections.sort(gatewaysList); + for (Gateway gateway : gatewaysList) { + ScopeDescriptor getewaySD = new ScopeDescriptor(gateway.getName(), gateway.getScope()); + LinkedList voChildren = retrieveVOChildren(infraNode, gateway); + getewaySD.setChildren(voChildren); + infraChildren.add(getewaySD); + } + CocktailSort.sort(infraChildren,Order.DESC); + } + } else { + logger.debug("DetachedREs is disabled"); + } + } + infra.setChildren(infraChildren); return infra; } + private LinkedList retrieveVOChildren(InfraNode infraNode, Gateway gateway) { + LinkedList vos = new LinkedList<>(); + + if (infraNode != null) { + ScopeDescriptor infraNodeScopeDescriptor = createRelativeInfraNode(infraNode, gateway.getScope()); + vos.add(infraNodeScopeDescriptor); + } + if (gateway.getVos() != null && !gateway.getVos().isEmpty()) { + ArrayList vosList = new ArrayList(gateway.getVos().values()); + Collections.sort(vosList); + for (VO vo : vosList) { + ScopeDescriptor voSD = new ScopeDescriptor(vo.getName(), vo.getScope()); + LinkedList voChildren = retrieveVREChildren(vo); + voSD.setChildren(voChildren); + vos.add(voSD); + } + } + + return vos; + } + + private LinkedList retrieveVREChildren(VO vo) { + LinkedList vres = new LinkedList<>(); + + if (vo.getVres() != null && !vo.getVres().isEmpty()) { + ArrayList vresList = new ArrayList( + 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; + } + private ScopeDescriptor createRelativeInfraNode(InfraNode infraNode, String scope) { StringBuilder absoluteScope = new StringBuilder(); absoluteScope.append(scope); @@ -164,28 +237,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/server/util/CocktailSort.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/util/CocktailSort.java new file mode 100644 index 0000000..b8435e2 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/server/util/CocktailSort.java @@ -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 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); + } + } + +} diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingServiceType.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/env/AccountingServiceType.java similarity index 64% rename from src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingServiceType.java rename to src/main/java/org/gcube/portlets/user/accountingdashboard/shared/env/AccountingServiceType.java index 7570943..e52050d 100644 --- a/src/main/java/org/gcube/portlets/user/accountingdashboard/server/accounting/AccountingServiceType.java +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/env/AccountingServiceType.java @@ -1,4 +1,4 @@ -package org.gcube.portlets.user.accountingdashboard.server.accounting; +package org.gcube.portlets.user.accountingdashboard.shared.env; /** * diff --git a/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/env/EnvironmentData.java b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/env/EnvironmentData.java new file mode 100644 index 0000000..61b1933 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/env/EnvironmentData.java @@ -0,0 +1,38 @@ +package org.gcube.portlets.user.accountingdashboard.shared.env; + +import java.io.Serializable; + +/** + * + * @author Giancarlo Panichi + * + */ +public class EnvironmentData implements Serializable { + + private static final long serialVersionUID = 5817114786613046203L; + + private AccountingServiceType accountingServiceType; + + public EnvironmentData() { + super(); + } + + public EnvironmentData(AccountingServiceType accountingServiceType) { + super(); + this.accountingServiceType = accountingServiceType; + } + + public AccountingServiceType getAccountingServiceType() { + return accountingServiceType; + } + + public void setAccountingServiceType(AccountingServiceType accountingServiceType) { + this.accountingServiceType = accountingServiceType; + } + + @Override + public String toString() { + return "EnvironmentData [accountingServiceType=" + accountingServiceType + "]"; + } + +} 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..5bed26e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/accountingdashboard/shared/options/TreeOptions.java @@ -0,0 +1,38 @@ +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() { + super(); + } + + 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..526e0c7 100644 --- a/src/test/java/org/gcube/portlets/user/accountingdashboard/AccountingServiceTest.java +++ b/src/test/java/org/gcube/portlets/user/accountingdashboard/AccountingServiceTest.java @@ -1,8 +1,8 @@ package org.gcube.portlets.user.accountingdashboard; import org.gcube.portlets.user.accountingdashboard.server.accounting.AccountingService; -import org.gcube.portlets.user.accountingdashboard.server.accounting.AccountingServiceType; import org.gcube.portlets.user.accountingdashboard.shared.Constants; +import org.gcube.portlets.user.accountingdashboard.shared.env.AccountingServiceType; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -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); + } + } + + + +}