69: Create new Accounting Portlet

Task-Url: https://support.d4science.org/issues/69

Updated to fix UTC TimeZone

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@118925 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-09-07 17:11:34 +00:00
parent bd3e856520
commit 0475946c05
12 changed files with 202 additions and 79 deletions

View File

@ -58,7 +58,7 @@ public class AccountingManagerController {
accountingType = AccountingType.STORAGE;
accountingState = new AccountingState();
AccountingStateData accountingStateData = new AccountingStateData(
accountingType, null, null,null);
accountingType, null, null, null);
accountingState.setState(accountingType, accountingStateData);
init();
}
@ -228,31 +228,28 @@ public class AccountingManagerController {
}
}
public void showDefault(){
public void showDefault() {
createDefaultChart(AccountingType.STORAGE);
}
private void createDefaultChart(AccountingType accountingType) {
accountingMonitor = new AccountingMonitor();
Date d=new Date();
Date d = new Date();
CalendarUtil.addMonthsToDate(d, -1);
SeriesRequest seriesRequest=new SeriesRequest(
new AccountingPeriod(d,new Date(),AccountingPeriodMode.DAILY), null);
SeriesRequest seriesRequest = new SeriesRequest(new AccountingPeriod(d,
new Date(), AccountingPeriodMode.DAILY), null);
this.accountingType = accountingType;
AccountingStateData accountingStateData = new AccountingStateData(
accountingType, seriesRequest, null,null);
accountingState.setState(accountingType,
accountingStateData);
accountingType, seriesRequest, null, null);
accountingState.setState(accountingType, accountingStateData);
retrieveFilterKey();
}
private void retrieveFilterKey() {
AccountingManagerServiceAsync.INSTANCE.getFilterKeys(accountingType,
@ -264,7 +261,8 @@ public class AccountingManagerController {
eventBus.fireEvent(new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
Log.error("Error retrieving filter keys for "+accountingType+":"
Log.error("Error retrieving filter keys for "
+ accountingType + ":"
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error retrieving filter keys",
caught.getLocalizedMessage());
@ -275,7 +273,8 @@ public class AccountingManagerController {
@Override
public void onSuccess(ArrayList<FilterKey> result) {
Log.debug("FilterKeys: " + result);
AccountingStateData accountingStateData=accountingState.getState(accountingType);
AccountingStateData accountingStateData = accountingState
.getState(accountingType);
accountingStateData.setAvailableFilterKeys(result);
accountingState.setState(accountingType,
accountingStateData);
@ -284,20 +283,18 @@ public class AccountingManagerController {
});
}
private void callDefaultSeriesRequest() {
AccountingManagerServiceAsync.INSTANCE.getSeries(
accountingType,
AccountingManagerServiceAsync.INSTANCE.getSeries(accountingType,
accountingState.getState(accountingType).getSeriesRequest(),
new AsyncCallback<SeriesResponse>() {
@Override
public void onSuccess(SeriesResponse seriesResponse) {
Log.debug("SeriesResponse: " + seriesResponse);
AccountingStateData accountingStateData=accountingState.getState(accountingType);
Log.debug("SeriesResponse: " + seriesResponse);
AccountingStateData accountingStateData = accountingState
.getState(accountingType);
accountingStateData.setSeriesResponse(seriesResponse);
accountingState.setState(accountingType,
accountingStateData);
@ -319,18 +316,16 @@ public class AccountingManagerController {
UtilsGXT3.alert("Error",
caught.getLocalizedMessage());
StateChangeEvent stateChangeEvent = new StateChangeEvent(
StateChangeType.Restore, accountingState.getState(accountingType));
StateChangeType.Restore, accountingState
.getState(accountingType));
eventBus.fireEvent(stateChangeEvent);
}
}
});
}
private void doFiltersChangeCommand(FiltersChangeEvent event) {
if (event == null || event.getFiltersChangeType() == null) {
@ -357,15 +352,18 @@ public class AccountingManagerController {
}
private void callSeriesRequest() {
AccountingManagerServiceAsync.INSTANCE.getSeries(
accountingType,
Log.debug("Call getSeries on server, params: " + accountingType + ", "
+ accountingState.getState(accountingType).getSeriesRequest());
AccountingManagerServiceAsync.INSTANCE.getSeries(accountingType,
accountingState.getState(accountingType).getSeriesRequest(),
new AsyncCallback<SeriesResponse>() {
@Override
public void onSuccess(SeriesResponse seriesResponse) {
Log.debug("SeriesResponse: " + seriesResponse);
AccountingStateData accountingStateData=accountingState.getState(accountingType);
AccountingStateData accountingStateData = accountingState
.getState(accountingType);
accountingStateData.setSeriesResponse(seriesResponse);
accountingState.setState(accountingType,
accountingStateData);

View File

@ -95,6 +95,8 @@ public class FiltersPanel extends FramedPanel {
if (accountingPeriod != null) {
SeriesRequest seriesRequest = new SeriesRequest(accountingPeriod,activeFilters);
Log.debug("UpdateChart: "+seriesRequest);
FiltersChangeEvent filtersChangeEvent = new FiltersChangeEvent(
FiltersChangeType.Update, seriesRequest);
eventBus.fireEvent(filtersChangeEvent);

View File

@ -13,11 +13,8 @@ import com.github.highcharts4gwt.model.array.api.ArrayString;
import com.github.highcharts4gwt.model.factory.api.HighchartsOptionFactory;
import com.github.highcharts4gwt.model.factory.jso.JsoHighchartsOptionFactory;
import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions;
import com.github.highcharts4gwt.model.highcharts.option.api.GlobalOptions;
import com.github.highcharts4gwt.model.highcharts.option.api.Navigation;
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea;
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn;
import com.github.highcharts4gwt.model.highcharts.option.api.navigation.ButtonOptions;
import com.sencha.gxt.widget.core.client.container.MarginData;
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
@ -67,6 +64,7 @@ public class AccountingChart4Storage extends AccountingChartBuilder {
Date dateStart=accountingStateData.getSeriesRequest().getAccountingPeriod().getStartDate();
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
highchartsFactory.createGlobalOptions().global().useUTC(true);
ChartOptions options = highchartsFactory.createChartOptions();
options.chart().zoomType("xy");
options.exporting().buttons().contextButton().enabled(true);

View File

@ -16,8 +16,12 @@ import com.github.highcharts4gwt.model.factory.jso.JsoHighchartsOptionFactory;
import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions;
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea;
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.sencha.gxt.cell.core.client.ButtonCell.ButtonArrowAlign;
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.button.ToggleButton;
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
import com.sencha.gxt.widget.core.client.container.MarginData;
@ -26,6 +30,9 @@ import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.menu.Item;
import com.sencha.gxt.widget.core.client.menu.Menu;
import com.sencha.gxt.widget.core.client.menu.MenuItem;
import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
/**
@ -36,48 +43,70 @@ import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
*/
public class VariableAxisChart extends SimpleContainer {
private static final String DOWNLOAD = "Download";
private static final String DOWNLOAD_PNG = "Download PNG Image";
private static final String DOWNLOAD_JPG = "Download JPG Image";
private static final String DOWNLOAD_PDF = "Download PDF Document";
private static final String DOWNLOAD_SVG = "Download SVG Vector Image";
private static final String SINGLE_AXIS = "Single Axis";
private AccountingStateData accountingStateData;
private HighchartsLayoutPanel highchartsLayoutPanel;
// Replace Menu
private MenuItem downloadPNGItem;
private MenuItem downloadJPGItem;
private MenuItem downloadPDFItem;
private MenuItem downloadSVGItem;
ChartOptions options;
public VariableAxisChart(AccountingStateData accountingStateData) {
this.accountingStateData = accountingStateData;
forceLayoutOnResize=true;
forceLayoutOnResize = true;
create();
}
}
private void create() {
ToolBar toolBar = new ToolBar();
toolBar.setSpacing(2);
final ToggleButton toggleBtn = new ToggleButton(SINGLE_AXIS);
toggleBtn.setIcon(AccountingManagerResources.INSTANCE.accountingChartVariableAxis24());
toggleBtn.setIconAlign(IconAlign.RIGHT);
toggleBtn.setValue(false);
// Download
final TextButton downloadButton = new TextButton(DOWNLOAD,
AccountingManagerResources.INSTANCE
.accountingChartVariableAxis24());
//downloadButton.setScale(ButtonScale.MEDIUM);
downloadButton.setIconAlign(IconAlign.RIGHT);
downloadButton.setArrowAlign(ButtonArrowAlign.RIGHT);
downloadButton.setMenu(createDownloadMenu());
toggleBtn.addSelectHandler(new SelectHandler() {
//toolBar.add(downloadButton, new BoxLayoutData(new Margins(0)));
// Single Axis
final ToggleButton toggleButton = new ToggleButton(SINGLE_AXIS);
toggleButton.setIcon(AccountingManagerResources.INSTANCE
.accountingChartVariableAxis24());
toggleButton.setIconAlign(IconAlign.RIGHT);
toggleButton.setValue(false);
toggleButton.addSelectHandler(new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
if(toggleBtn.getValue()){
ChartOptions options = createSingleAxisChart();
if (toggleButton.getValue()) {
createSingleAxisChart();
highchartsLayoutPanel.renderChart(options);
} else {
ChartOptions options = createMultiAxisChart();
createMultiAxisChart();
highchartsLayoutPanel.renderChart(options);
}
forceLayout();
}
});
toolBar.add(toggleBtn, new BoxLayoutData(new Margins(0)));
toolBar.add(toggleButton, new BoxLayoutData(new Margins(0)));
//
ChartOptions options = createMultiAxisChart();
createMultiAxisChart();
highchartsLayoutPanel = new HighchartsLayoutPanel();
highchartsLayoutPanel.renderChart(options);
@ -87,13 +116,72 @@ public class VariableAxisChart extends SimpleContainer {
vert.add(toolBar, new VerticalLayoutData(1, -1, new Margins(0)));
vert.add(highchartsLayoutPanel, new VerticalLayoutData(1, 1,
new Margins(0)));
add(vert, new MarginData(0));
}
private ChartOptions createMultiAxisChart() {
private Menu createDownloadMenu() {
Menu menuDownload = new Menu();
downloadPNGItem = new MenuItem(DOWNLOAD_PNG,
AccountingManagerResources.INSTANCE
.accountingChartVariableAxis24());
downloadJPGItem = new MenuItem(DOWNLOAD_JPG,
AccountingManagerResources.INSTANCE
.accountingChartVariableAxis24());
downloadPDFItem = new MenuItem(DOWNLOAD_PDF,
AccountingManagerResources.INSTANCE
.accountingChartVariableAxis24());
downloadSVGItem = new MenuItem(DOWNLOAD_SVG,
AccountingManagerResources.INSTANCE
.accountingChartVariableAxis24());
downloadPNGItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
onDownloadPNG();
}
});
downloadJPGItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
onDownloadPNG();
}
});
downloadPDFItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
options.exporting();
}
});
downloadSVGItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
onDownloadPNG();
}
});
menuDownload.add(downloadPNGItem);
menuDownload.add(downloadJPGItem);
menuDownload.add(downloadPDFItem);
menuDownload.add(downloadSVGItem);
return menuDownload;
}
public static native void onDownloadPNG() /*-{
console.log($wnd.Highcharts.Chart);
}-*/;
private void createMultiAxisChart() {
SeriesService seriesService = (SeriesService) accountingStateData
.getSeriesResponse();
@ -109,12 +197,15 @@ public class VariableAxisChart extends SimpleContainer {
.getAccountingPeriod().getStartDate();
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
ChartOptions options = highchartsFactory.createChartOptions();
options = highchartsFactory.createChartOptions();
options.navigation().buttonOptions().enabled(true);
options.chart().zoomType("xy");
options.title().text("Accounting Service");
/*options.subtitle().text("Click and drag in the plot area to zoom in");*/
/*
* options.subtitle().text("Click and drag in the plot area to zoom in");
*/
ArrayString colors = options.colors();
// colors.setValue(0, "#cc0038");
@ -285,10 +376,10 @@ public class VariableAxisChart extends SimpleContainer {
// options.legend()
// .backgroundColor(
// "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'white'");
return options;
return;
}
private ChartOptions createSingleAxisChart() {
private void createSingleAxisChart() {
SeriesService seriesService = (SeriesService) accountingStateData
.getSeriesResponse();
@ -304,12 +395,15 @@ public class VariableAxisChart extends SimpleContainer {
.getAccountingPeriod().getStartDate();
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
ChartOptions options = highchartsFactory.createChartOptions();
options = highchartsFactory.createChartOptions();
options.navigation().buttonOptions().enabled(true);
options.chart().zoomType("xy");
options.title().text("Accounting Service");
/*options.subtitle().text("Click and drag in the plot area to zoom in");*/
/*
* options.subtitle().text("Click and drag in the plot area to zoom in");
*/
ArrayString colors = options.colors();
// colors.setValue(0, "#cc0038");
@ -386,7 +480,7 @@ public class VariableAxisChart extends SimpleContainer {
SeriesArea seriesDuration = highchartsFactory.createSeriesArea();
seriesDuration.name("Duration");
seriesDuration.color(colors.get(0));
ArrayNumber dataDuration = seriesDuration.dataAsArrayNumber();
seriesDuration.pointInterval(interval).pointStart(dateStart.getTime());
@ -395,7 +489,7 @@ public class VariableAxisChart extends SimpleContainer {
.createSeriesArea();
seriesMaxInvocationTime.name("Max Invocation Time");
seriesMaxInvocationTime.color(colors.get(2));
ArrayNumber dataMaxInvocationTime = seriesMaxInvocationTime
.dataAsArrayNumber();
@ -406,7 +500,7 @@ public class VariableAxisChart extends SimpleContainer {
.createSeriesArea();
seriesMinInvocationTime.name("Min Invocation Time");
seriesMinInvocationTime.color(colors.get(3));
//seriesMinInvocationTime.yAxisAsString("MinInvocationTime");
// seriesMinInvocationTime.yAxisAsString("MinInvocationTime");
ArrayNumber dataMinInvocationTime = seriesMinInvocationTime
.dataAsArrayNumber();
@ -431,7 +525,7 @@ public class VariableAxisChart extends SimpleContainer {
options.chart().showAxes(true);
options.legend().enabled(true);
return options;
return;
}
}

View File

@ -1,9 +1,13 @@
package org.gcube.portlets.admin.accountingmanager.server.amservice;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import org.gcube.accounting.analytics.Info;
import org.gcube.accounting.analytics.ResourceRecordQuery;
import org.gcube.accounting.analytics.TemporalConstraint;
import org.gcube.portlets.admin.accountingmanager.server.amservice.query.AccountingQuery;
import org.gcube.portlets.admin.accountingmanager.server.amservice.query.AccountingQuery4Job;
import org.gcube.portlets.admin.accountingmanager.server.amservice.query.AccountingQuery4Portlet;
@ -46,8 +50,9 @@ public class AccountingCaller {
try {
logger.debug("getSeries(): [AccountingType=" + accountingType
+ " , seriesRequest=" + seriesRequest + "]");
ResourceRecordQuery rrq = new ResourceRecordQuery();
AccountingQueryBuilder queryBuilder = getAccountQueryBuilder(
accountingType, seriesRequest);
@ -61,6 +66,7 @@ public class AccountingCaller {
"Error in invocation: Operation not supported");
}
logger.debug("Query: "+query);
List<Info> infos = rrq.getInfo(query.getType(),
query.getTemporalConstraint(), query.getFilters(), true);
@ -69,6 +75,7 @@ public class AccountingCaller {
"Error retrieving list of info: list is null!");
}
logger.debug("Retrieved Infos");
logger.debug("Infos: "+infos);
SeriesResponseBuilder seriesResponseBuilder = getSeriesResponseBuilder(
accountingType, infos);
@ -102,6 +109,34 @@ public class AccountingCaller {
"Error accounting type is null");
}
Calendar startTempCalendar = new GregorianCalendar();
startTempCalendar.setTime(seriesRequest.getAccountingPeriod()
.getStartDate());
Calendar startCalendar = new GregorianCalendar(
startTempCalendar.get(GregorianCalendar.YEAR),
startTempCalendar.get(GregorianCalendar.MONTH),
startTempCalendar.get(GregorianCalendar.DATE));
startCalendar.setTimeZone(TemporalConstraint.DEFAULT_TIME_ZONE);
Calendar endTempCalendar = new GregorianCalendar();
endTempCalendar.setTime(seriesRequest.getAccountingPeriod()
.getEndDate());
Calendar endCalendar = new GregorianCalendar(
endTempCalendar.get(GregorianCalendar.YEAR),
endTempCalendar.get(GregorianCalendar.MONTH),
endTempCalendar.get(GregorianCalendar.DATE));
endCalendar.setTimeZone(TemporalConstraint.DEFAULT_TIME_ZONE);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
sdf.setTimeZone(TemporalConstraint.DEFAULT_TIME_ZONE);
logger.debug("StartCalendar: " + sdf.format(startCalendar.getTime()));
logger.debug("EndCalendar: " + sdf.format(endCalendar.getTime()));
seriesRequest.getAccountingPeriod().setStartDate(startCalendar.getTime());
seriesRequest.getAccountingPeriod().setEndDate(endCalendar.getTime());
switch (accountingType) {
case JOB:
return new AccountingQuery4Job(seriesRequest);

View File

@ -39,8 +39,8 @@ public class AccountingQuery4Storage extends AccountingQueryBuilder {
ArrayList<AccountingFilter> accountingFilters = seriesRequest
.getFilters();
ArrayList<Filter> filters=null;
ArrayList<Filter> filters = null;
if (accountingFilters != null) {
filters = new ArrayList<Filter>();
for (AccountingFilter accountigFilters : accountingFilters) {

View File

@ -26,7 +26,6 @@ public class SeriesResponse4Job extends SeriesResponseBuilder {
@Override
public void buildSeriesResponse() throws AccountingManagerServiceException {
logger.debug("Infos: "+infos);
if(infos.size()<=0){
logger.error("Error creating series for job accounting: No data available!");
throw new AccountingManagerServiceException("No data available!");

View File

@ -27,7 +27,6 @@ public class SeriesResponse4Portlet extends SeriesResponseBuilder {
@Override
public void buildSeriesResponse() throws AccountingManagerServiceException {
logger.debug("Infos: "+infos);
if(infos.size()<=0){
logger.error("Error creating series for portlet accounting: No data available!");
throw new AccountingManagerServiceException("No data available!");

View File

@ -32,7 +32,6 @@ public class SeriesResponse4Service extends SeriesResponseBuilder {
@Override
public void buildSeriesResponse() throws AccountingManagerServiceException {
try {
logger.debug("Infos: " + infos);
if(infos.size()<=0){
logger.error("Error creating series for service accounting: No data available!");
throw new AccountingManagerServiceException("No data available!");

View File

@ -32,7 +32,6 @@ public class SeriesResponse4Storage extends SeriesResponseBuilder {
@Override
public void buildSeriesResponse() throws AccountingManagerServiceException {
try {
logger.debug("Infos: " + infos);
if(infos.size()<=0){
logger.error("Error creating series for storage accounting: No data available!");
throw new AccountingManagerServiceException("No data available!");

View File

@ -26,7 +26,6 @@ public class SeriesResponse4Task extends SeriesResponseBuilder {
@Override
public void buildSeriesResponse() throws AccountingManagerServiceException {
logger.debug("Infos: "+infos);
if(infos.size()<=0){
logger.error("Error creating series for task accounting: No data available!");
throw new AccountingManagerServiceException("No data available!");

View File

@ -48,14 +48,15 @@
name="locale" values="es" /> <set-property name="locale" value="en, it, es"
/> <set-property-fallback name="locale" value="en" /> -->
<!--
<!--
<set-property name="log_ConsoleLogger" value="ENABLED" />
<set-property name="log_DivLogger" value="ENABLED" />
<set-property name="log_GWTLogger" value="ENABLED" />
<set-property name="log_SystemLogger" value="ENABLED" /> -->
<set-property name="log_SystemLogger" value="ENABLED" /> -->
<!-- Not in GWT 2.6 <set-property name="log_FirebugLogger" value="ENABLED"
/> -->
<set-property name="log_ConsoleLogger" value="DISABLED" />
<set-property name="log_DivLogger" value="DISABLED" />
<set-property name="log_GWTLogger" value="DISABLED" />