Merge pull request 'Future/18815' (#1) from Future/18815 into master

This commit is contained in:
Giancarlo Panichi 2020-04-09 17:32:10 +02:00
commit 95b009ae60
22 changed files with 599 additions and 80 deletions

View File

@ -1,7 +1,10 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets.user.accounting-dashboard.1-2-0"
date="2019-11-12">
date="2020-04-08">
<Change>Updated export csv support with Firefox and Safari [ticket #18034]</Change>
<Change>Added Core Services support [ticket #18291]</Change>
<Change>Added Detached REs support [ticket #18815]</Change>
<Change>Added the alphabetical sorting of tabs [ticket #18754]</Change>
</Changeset>
<Changeset component="org.gcube.portlets.user.accounting-dashboard.1-1-0"
date="2019-10-01">

10
pom.xml
View File

@ -7,7 +7,7 @@
<groupId>org.gcube.tools</groupId>
<version>1.1.0</version>
<relativePath />
</parent>
</parent>
<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
@ -256,6 +256,14 @@
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- detachedres-library -->
<dependency>
<groupId>org.gcube.infrastructure.detachedres</groupId>
<artifactId>detachedres-library</artifactId>
<version>[0.0.1,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- Portal Service -->
<dependency>
<groupId>com.liferay.portal</groupId>

View File

@ -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<EnvironmentData>() {
@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<ScopeData>() {
service.getScopeData(treeOptions,new AsyncCallback<ScopeData>() {
@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<ReportData>() {
service.getReport(requestReportData,treeOptions, new AsyncCallback<ReportData>() {
@Override
public void onFailure(Throwable caught) {
@ -144,4 +178,5 @@ public class Controller {
}
}

View File

@ -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<EnvironmentEvent.EnvironmentEventHandler> {
private EnvironmentData environmentData;
public interface EnvironmentEventHandler extends EventHandler {
void onInit(EnvironmentEvent event);
}
public static final Type<EnvironmentEventHandler> TYPE = new Type<>();
public EnvironmentEvent(EnvironmentData environmentData) {
this.environmentData = environmentData;
}
public static void fire(HasHandlers source, EnvironmentEvent event) {
source.fireEvent(event);
}
@Override
public Type<EnvironmentEventHandler> 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 + "]";
}
}

View File

@ -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<FilterAreaPresenter.Fil
interface FilterAreaView extends View, HasUiHandlers<FilterAreaPresenter> {
void displayScopeData(ScopeData scopeData);
void setEnvironment(EnvironmentData environmentData);
}
@ -47,7 +52,6 @@ public class FilterAreaPresenter extends PresenterWidget<FilterAreaPresenter.Fil
}
private void addProviders() {
}
@ -62,26 +66,44 @@ public class FilterAreaPresenter extends PresenterWidget<FilterAreaPresenter.Fil
}
});
controller.getEventBus().addHandler(EnvironmentEvent.TYPE, new EnvironmentEvent.EnvironmentEventHandler() {
@Override
public void onInit(EnvironmentEvent event) {
logger.log(Level.FINE, "EnvironmentEvent received");
getView().setEnvironment(event.getEnvironmentData());
}
});
}
@Override
protected void onBind() {
super.onBind();
controller.getEnvironment();
controller.getTree();
}
@Override
public void updateTreeOptions(TreeOptions treeOptions) {
logger.fine("UpdateTreeOption: " + treeOptions);
controller.setTreeOptions(treeOptions);
controller.getTree();
}
@Override
public void getReport(RequestReportData requestReportData) {
if(checkDate(requestReportData.getDateFrom(),requestReportData.getDateTo())){
if (checkDate(requestReportData.getDateFrom(), requestReportData.getDateTo())) {
controller.getReport(requestReportData);
}
}
private boolean checkDate(String dateStart, String dateEnd) {
DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd");
Date dateStartD = null;
try {
logger.fine("DateTemp1: " + dateStart);
@ -92,7 +114,6 @@ public class FilterAreaPresenter extends PresenterWidget<FilterAreaPresenter.Fil
return false;
}
Date dateEndD = null;
try {
logger.fine("DateTemp2: " + dateEnd);

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.accountingdashboard.client.application.mainarea.filter;
import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData;
import org.gcube.portlets.user.accountingdashboard.shared.options.TreeOptions;
import com.gwtplatform.mvp.client.UiHandlers;
@ -12,4 +13,6 @@ import com.gwtplatform.mvp.client.UiHandlers;
public interface FilterAreaUiHandlers extends UiHandlers {
public void getReport(RequestReportData requestReportData);
public void updateTreeOptions(TreeOptions treeOptions);
}

View File

@ -14,11 +14,17 @@ import org.gcube.portlets.user.accountingdashboard.client.resources.AppResources
import org.gcube.portlets.user.accountingdashboard.client.resources.ScopeTreeResources;
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.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.RadioButton;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import com.google.gwt.i18n.client.LocaleInfo;
@ -61,7 +67,16 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
@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<FilterAreaPresenter>
}
});
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<ScopeData>();
RequestReportEventHandler handler = new RequestReportEventHandler() {
@ -177,10 +219,38 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
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<ScopeData> scopeDataList = new ArrayList<>();
scopeDataList.add(scopeData);
this.scopeData = scopeData;
@ -194,6 +264,7 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
}
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<FilterAreaPresenter>
}
}

View File

@ -11,38 +11,47 @@
<g:HTMLPanel styleName="{res.uiDataCss.uiDataFiltersPanel}">
<b:Heading size="5" styleName="{res.uiDataCss.uiDataFiltersTitle}">Filters</b:Heading>
<g:HTMLPanel ui:field="periodPanel"
styleName="{res.uiDataCss.uiDataFiltersPeriodPanel}">
<b:Form type="HORIZONTAL" styleName="{res.uiDataCss.uiDataFiltersFormPanel}">
<b:Fieldset>
<b:ControlGroup>
<b:ControlLabel width="50px" for="fromPeriod">From:</b:ControlLabel>
<b:Controls styleName="{res.uiDataCss.uiDataFiltersControls}">
<b:ListBox ui:field="yearStart" width="104px" b:id="yearStart">
</b:ListBox>
<b:ListBox ui:field="monthStart" width="104px" b:id="monthStart">
</b:ListBox>
<b:HelpBlock>Select the start date</b:HelpBlock>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel width="50px" for="endPeriod">To:</b:ControlLabel>
<b:Controls styleName="{res.uiDataCss.uiDataFiltersControls}">
<b:ListBox ui:field="yearEnd" width="104px" b:id="yearEnd">
</b:ListBox>
<b:ListBox ui:field="monthEnd" width="104px" b:id="monthEnd">
</b:ListBox>
<b:HelpBlock>Select the end date</b:HelpBlock>
</b:Controls>
</b:ControlGroup>
</b:Fieldset>
</b:Form>
</g:HTMLPanel>
<g:HTMLPanel ui:field="explorePanel"
styleName="{res.uiDataCss.uiDataFiltersExplorePanel}">
<c:CellTree addStyleNames="{res.uiDataCss.uiDataExploreTree}"
ui:field='scopeTree' />
</g:HTMLPanel>
<b:Heading size="5" styleName="{res.uiDataCss.uiDataFiltersTitle}">Filters</b:Heading>
<g:HTMLPanel ui:field="periodPanel"
styleName="{res.uiDataCss.uiDataFiltersPeriodPanel}">
<b:Form type="HORIZONTAL" styleName="{res.uiDataCss.uiDataFiltersFormPanel}">
<b:Fieldset>
<b:ControlGroup styleName="{res.uiDataCss.uiDataFiltersControlGroup}">
<b:ControlLabel width="70px" for="fromPeriod">From:</b:ControlLabel>
<b:Controls styleName="{res.uiDataCss.uiDataFiltersControls}">
<b:ListBox ui:field="yearStart" width="104px" b:id="yearStart">
</b:ListBox>
<b:ListBox ui:field="monthStart" width="104px" b:id="monthStart">
</b:ListBox>
<b:HelpBlock>Select the start date</b:HelpBlock>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup styleName="{res.uiDataCss.uiDataFiltersControlGroup}">
<b:ControlLabel width="70px" for="endPeriod">To:</b:ControlLabel>
<b:Controls styleName="{res.uiDataCss.uiDataFiltersControls}">
<b:ListBox ui:field="yearEnd" width="104px" b:id="yearEnd">
</b:ListBox>
<b:ListBox ui:field="monthEnd" width="104px" b:id="monthEnd">
</b:ListBox>
<b:HelpBlock>Select the end date</b:HelpBlock>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="cgDetachedREs" styleName="{res.uiDataCss.uiDataFiltersControlGroup}">
<b:ControlLabel width="70px" for="detachedREs">Detached:</b:ControlLabel>
<b:Controls styleName="{res.uiDataCss.uiDataFiltersControls}">
<b:RadioButton ui:field="btnShowDetachedREs" text="Show" />
<b:RadioButton ui:field="btnHideDetachedREs" text="Hide" />
<b:HelpBlock>Detached REs</b:HelpBlock>
</b:Controls>
</b:ControlGroup>
</b:Fieldset>
</b:Form>
</g:HTMLPanel>
<g:HTMLPanel ui:field="explorePanel"
styleName="{res.uiDataCss.uiDataFiltersExplorePanel}">
<c:CellTree addStyleNames="{res.uiDataCss.uiDataExploreTree}"
ui:field='scopeTree' />
</g:HTMLPanel>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -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<ReportAreaPresenter>
TabPanel tabPanel = new TabPanel();
tabPanel.addStyleName(resources.uiDataCss().uiDataReportTabPanel());
boolean first = true;
for (String category : categories.keySet()) {
ArrayList<String> sortedKeys =
new ArrayList<String>(categories.keySet());
Collections.sort(sortedKeys);
for (String category : sortedKeys) {
Tab tab = new Tab();
tab.setHeading(category);
HTMLPanel tabContent = new HTMLPanel("");

View File

@ -28,6 +28,8 @@ public interface AppResources extends ClientBundle {
String uiDataFiltersTitle();
String uiDataFiltersFormPanel();
String uiDataFiltersControlGroup();
String uiDataFiltersControls();

View File

@ -40,8 +40,12 @@
margin: 0px !important;
}
.uiDataFiltersControlGroup {
margin-bottom: 10px;
}
.uiDataFiltersControls {
margin-left: 60px;
margin-left: 80px;
}
.uiDataExploreTree {

View File

@ -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;
}

View File

@ -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<UserInfo> callback);
void getScopeData(AsyncCallback<ScopeData> callback);
void getEnvironment(AsyncCallback<EnvironmentData> callback);
void getScopeData(TreeOptions treeOptions, AsyncCallback<ScopeData> callback);
void getReport(RequestReportData requestReportdata, AsyncCallback<ReportData> asyncCallback);
void getReport(RequestReportData requestReportdata, TreeOptions treeOptions,
AsyncCallback<ReportData> asyncCallback);
}

View File

@ -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
}
}
}

View File

@ -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");

View File

@ -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<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");
}
}
infra.setChildren(infraChildren);
return infra;
}
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()) {
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;
}
private LinkedList<ScopeDescriptor> retrieveVREChildren(VO vo) {
LinkedList<ScopeDescriptor> vres = new LinkedList<>();
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;
}
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<ScopeDescriptor> rootChildren = null;
rootChildren = retrieveGatewayChildren(request, currentSiteGroupId, currUser);

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);
}
}
}

View File

@ -1,4 +1,4 @@
package org.gcube.portlets.user.accountingdashboard.server.accounting;
package org.gcube.portlets.user.accountingdashboard.shared.env;
/**
*

View File

@ -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 + "]";
}
}

View File

@ -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 + "]";
}
}

View File

@ -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);

View File

@ -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);
}
}
}