2251: Accounting Manager - Stacked column chart for tops

https://support.d4science.org/issues/2251

Start Stacked Chart on Storage

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@124191 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-02-15 13:35:02 +00:00
parent 09716a490c
commit 9a881615a0
28 changed files with 1942 additions and 207 deletions

View File

@ -4,9 +4,6 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="accounting-manager-theme-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/accounting-manager-theme/accounting-manager-theme">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/accounting-manager/target/accounting-manager-0.0.1-SNAPSHOT/WEB-INF/classes"/> <property name="java-output-path" value="/accounting-manager/target/accounting-manager-0.0.1-SNAPSHOT/WEB-INF/classes"/>
<property name="context-root" value="accounting-manager"/> <property name="context-root" value="accounting-manager"/>
</wb-module> </wb-module>

View File

@ -80,6 +80,11 @@
<artifactId>accounting-lib</artifactId> <artifactId>accounting-lib</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version> <version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
</dependency>
</dependencies> </dependencies>
</profile> </profile>
</profiles> </profiles>
@ -241,7 +246,6 @@
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version> <version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<!-- LOGGING --> <!-- LOGGING -->
<dependency> <dependency>
<groupId>com.allen-sauer.gwt.log</groupId> <groupId>com.allen-sauer.gwt.log</groupId>

View File

@ -1,8 +1,8 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts; package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChart; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.job.JobChart;
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
/** /**
@ -32,12 +32,12 @@ public class AccountingChart4Job extends AccountingChartBuilder {
return; return;
} }
if (!(accountingStateData.getSeriesResponse() instanceof SeriesStorage)) { if (!(accountingStateData.getSeriesResponse() instanceof SeriesJob)) {
accountingChartSpec.setChart(accountingChartPanel); accountingChartSpec.setChart(accountingChartPanel);
return; return;
} }
StorageChart container=new StorageChart(accountingStateData); JobChart container=new JobChart(accountingStateData);
accountingChartPanel = new AccountingChartPanel(container); accountingChartPanel = new AccountingChartPanel(container);

View File

@ -1,6 +1,5 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts; package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChart;
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
@ -37,9 +36,9 @@ public class AccountingChart4Portlet extends AccountingChartBuilder {
return; return;
} }
StorageChart container=new StorageChart(accountingStateData); //StorageChart container=new StorageChart(accountingStateData);
accountingChartPanel = new AccountingChartPanel(container); //accountingChartPanel = new AccountingChartPanel(container);
accountingChartSpec.setChart(accountingChartPanel); accountingChartSpec.setChart(accountingChartPanel);

View File

@ -1,9 +1,15 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts; package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChart; import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChart4Top;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChartBuilder;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChartDirector;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChartPanel;
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerStorageChartDrawException;
import com.allen_sauer.gwt.log.client.Log;
/** /**
* Accounting Chart 4 Storage * Accounting Chart 4 Storage
@ -14,7 +20,6 @@ import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingMan
*/ */
public class AccountingChart4Storage extends AccountingChartBuilder { public class AccountingChart4Storage extends AccountingChartBuilder {
private AccountingStateData accountingStateData; private AccountingStateData accountingStateData;
public AccountingChart4Storage(AccountingStateData accountingStateData) { public AccountingChart4Storage(AccountingStateData accountingStateData) {
@ -37,12 +42,52 @@ public class AccountingChart4Storage extends AccountingChartBuilder {
accountingChartSpec.setChart(accountingChartPanel); accountingChartSpec.setChart(accountingChartPanel);
return; return;
} }
StorageChart container=new StorageChart(accountingStateData); StorageChartPanel container = createStorageChartPanel();
accountingChartPanel = new AccountingChartPanel(container); accountingChartPanel = new AccountingChartPanel(container.getChart());
accountingChartSpec.setChart(accountingChartPanel); accountingChartSpec.setChart(accountingChartPanel);
} }
private StorageChartPanel createStorageChartPanel() throws AccountingManagerStorageChartDrawException {
if (accountingStateData == null
|| accountingStateData.getAccountingType() == null) {
return null;
}
switch (accountingStateData.getAccountingType()) {
case STORAGE:
return createStorageChart(new StorageChart4Top(
accountingStateData));
default:
return null;
}
}
private StorageChartPanel createStorageChart(
StorageChartBuilder chartBuilder) throws AccountingManagerStorageChartDrawException {
try {
StorageChartDirector director = new StorageChartDirector();
director.setStorageChartBuilder(chartBuilder);
director.constructStorageChart();
StorageChartPanel chart = director.getStorageChart();
return chart;
} catch (AccountingManagerStorageChartDrawException e) {
Log.error(e.getLocalizedMessage());
e.printStackTrace();
throw e;
}
}
} }

View File

@ -1,6 +1,5 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts; package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChart;
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData; import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage; import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
@ -37,9 +36,9 @@ public class AccountingChart4Task extends AccountingChartBuilder {
return; return;
} }
StorageChart container=new StorageChart(accountingStateData); //StorageChart container=new StorageChart(accountingStateData);
accountingChartPanel = new AccountingChartPanel(container); //accountingChartPanel = new AccountingChartPanel(container);
accountingChartSpec.setChart(accountingChartPanel); accountingChartSpec.setChart(accountingChartPanel);

View File

@ -0,0 +1,614 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.job;
import java.util.Date;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.ChartTimeMeasure;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.DownloadConstants;
import org.gcube.portlets.admin.accountingmanager.client.resource.AccountingManagerResources;
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJobData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesService;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesServiceData;
import com.allen_sauer.gwt.log.client.Log;
import com.github.highcharts4gwt.client.view.widget.HighchartsLayoutPanel;
import com.github.highcharts4gwt.model.array.api.ArrayNumber;
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.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.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
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;
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
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;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class JobChart extends SimpleContainer {
private DateTimeFormat dtf=DateTimeFormat.getFormat(PredefinedFormat.YEAR_MONTH_DAY);
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 JobChart(AccountingStateData accountingStateData) {
this.accountingStateData = accountingStateData;
forceLayoutOnResize = true;
create();
}
private void create() {
ToolBar toolBar = new ToolBar();
toolBar.setSpacing(2);
// Download
final TextButton downloadButton = new TextButton(DownloadConstants.DOWNLOAD,
AccountingManagerResources.INSTANCE
.accountingDownload24());
// downloadButton.setScale(ButtonScale.MEDIUM);
downloadButton.setIconAlign(IconAlign.RIGHT);
downloadButton.setArrowAlign(ButtonArrowAlign.RIGHT);
downloadButton.setMenu(createDownloadMenu());
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 (toggleButton.getValue()) {
createSingleAxisChart();
highchartsLayoutPanel.renderChart(options);
} else {
createMultiAxisChart();
highchartsLayoutPanel.renderChart(options);
}
forceLayout();
}
});
//toolBar.add(toggleButton, new BoxLayoutData(new Margins(0)));
//
createMultiAxisChart();
highchartsLayoutPanel = new HighchartsLayoutPanel();
highchartsLayoutPanel.renderChart(options);
//
VerticalLayoutContainer vert = new VerticalLayoutContainer();
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 Menu createDownloadMenu() {
Menu menuDownload = new Menu();
downloadPNGItem = new MenuItem(DownloadConstants.DOWNLOAD_PNG,
AccountingManagerResources.INSTANCE
.accountingFilePNG24());
downloadPNGItem.setHeight(30);
downloadJPGItem = new MenuItem(DownloadConstants.DOWNLOAD_JPG,
AccountingManagerResources.INSTANCE
.accountingFileJPG24());
downloadJPGItem.setHeight(30);
downloadPDFItem = new MenuItem(DownloadConstants.DOWNLOAD_PDF,
AccountingManagerResources.INSTANCE
.accountingFilePDF24());
downloadPDFItem.setHeight(30);
downloadSVGItem = new MenuItem(DownloadConstants.DOWNLOAD_SVG,
AccountingManagerResources.INSTANCE
.accountingFileSVG24());
downloadSVGItem.setHeight(30);
downloadPNGItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
String id = highchartsLayoutPanel.getElement().getId();
onDownloadPNG(id);
}
});
downloadJPGItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
String id = highchartsLayoutPanel.getElement().getId();
onDownloadJPG(id);
}
});
downloadPDFItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
String id = highchartsLayoutPanel.getElement().getId();
onDownloadPDF(id);
}
});
downloadSVGItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
String id = highchartsLayoutPanel.getElement().getId();
onDownloadSVG(id);
}
});
menuDownload.add(downloadPNGItem);
menuDownload.add(downloadJPGItem);
menuDownload.add(downloadPDFItem);
menuDownload.add(downloadSVGItem);
return menuDownload;
}
// chart.options.exporting.buttons.contextButton.menuItems[0].onclick();
public static native void onDownloadPNG(String id) /*-{
console.log(id);
var chart = $wnd
.jQuery('#' + id)
.highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.service.ServiceChart::options);
console.log(chart);
chart.exportChart();
}-*/;
public static native void onDownloadJPG(String id) /*-{
console.log(id);
var chart = $wnd
.jQuery('#' + id)
.highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.service.ServiceChart::options);
console.log(chart);
chart.exportChart({
type : 'image/jpeg'
});
}-*/;
public static native void onDownloadPDF(String id) /*-{
console.log(id);
var chart = $wnd
.jQuery('#' + id)
.highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.service.ServiceChart::options);
console.log(chart);
chart.exportChart({
type : 'application/pdf'
});
}-*/;
public static native void onDownloadSVG(String id) /*-{
console.log(id);
var chart = $wnd
.jQuery('#' + id)
.highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.service.ServiceChart::options);
console.log(chart);
chart.exportChart({
type : 'image/svg+xml'
});
}-*/;
private void createMultiAxisChart() {
SeriesJob seriesJob = (SeriesJob) accountingStateData
.getSeriesResponse();
double minRange = ChartTimeMeasure
.calculateMinRange(accountingStateData.getSeriesRequest()
.getAccountingPeriod());
double interval = ChartTimeMeasure
.calculateInterval(accountingStateData.getSeriesRequest()
.getAccountingPeriod());
Date dateStart=dtf.parse(accountingStateData.getSeriesRequest()
.getAccountingPeriod().getStartDate());
dateStart.setTime(dateStart.getTime()
+ ChartTimeMeasure.timeZoneOffset() * ChartTimeMeasure.MINUTE);
Log.debug("BuildChart DateStart: "
+ DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_FULL)
.format(dateStart));
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
options = highchartsFactory.createChartOptions();
options.navigation().buttonOptions().enabled(false);
options.exporting().filename("AccountingService");
options.chart().zoomType("xy");
options.title().text("Accounting Job");
/*
* options.subtitle().text("Click and drag in the plot area to zoom in");
*/
ArrayString colors = options.colors();
// colors.setValue(0, "#cc0038");
// colors.setValue(1, "#32cd32");
// xAxis
options.xAxis().type("datetime").minRange(minRange);
// yAxis
String multiAxis = "[{" + " \"id\": \"OperationCount\","
+ " \"labels\": { " + " \"format\": \"{value}\","
+ " \"style\": { " + " \"color\": \""
+ colors.get(1)
+ "\""
+ " }"
+ " },"
+ " \"title\": { "
+ " \"text\": \"Operation Count\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(1)
+ "\""
+ " }"
+ " }"
+ "} , {"
+ " \"id\": \"Duration\", "
+ " \"title\": {"
+ " \"text\": \"Duration\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(0)
+ "\""
+ " }"
+ " },"
+ " \"labels\": {"
+ " \"format\": \"{value} ms\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(0)
+ "\""
+ " }"
+ " },"
+ " \"opposite\": \"true\""
+ ", \"showFirstLabel\": \"false\""
+ "} , {"
+ " \"id\": \"MaxInvocationTime\", "
+ " \"title\": {"
+ " \"text\": \"Max Invocation Time\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(2)
+ "\""
+ " }"
+ " },"
+ " \"labels\": {"
+ " \"format\": \"{value} ms\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(2)
+ "\""
+ " }"
+ " },"
+ " \"opposite\": \"true\""
+ ", \"showFirstLabel\": \"false\""
+ "} , {"
+ " \"id\": \"MinInvocationTime\", "
+ " \"title\": {"
+ " \"text\": \"Min Invocation Time\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(3)
+ "\""
+ " }"
+ " },"
+ " \"labels\": {"
+ " \"format\": \"{value} ms\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(3)
+ "\""
+ " }"
+ " },"
+ " \"opposite\": \"true\""
+ ", \"showFirstLabel\": \"false\"" + "}]"
;
options.setFieldAsJsonObject("yAxis", multiAxis);
// does not seem to be working
String fillcolor = "{" + "\"linearGradient\": {" + "\"x1\": 0,"
+ "\"y1\": 0," + "\"x2\": 0," + "\"y2\": 1" + "},"
+ "\"stops\": [" + "[" + "0, \"#058DC7\"" + "]," + "["
+ "1, \"#FFFFFF\"" + "]" + "]" + "}";
options.plotOptions().area()
.setFieldAsJsonObject("fillColor", fillcolor).marker()
.radius(2).lineWidth(1).states().hover().lineWidth(1);
SeriesColumn seriesOperationCount = highchartsFactory
.createSeriesColumn();
seriesOperationCount.name("Operation Count");
seriesOperationCount.color(colors.get(1));
seriesOperationCount.type("column");
ArrayNumber dataOperationCount = seriesOperationCount
.dataAsArrayNumber();
seriesOperationCount.pointInterval(interval).pointStart(
dateStart.getTime());
SeriesArea seriesDuration = highchartsFactory.createSeriesArea();
seriesDuration.name("Duration");
seriesDuration.color(colors.get(0));
seriesDuration.yAxisAsString("Duration");
ArrayNumber dataDuration = seriesDuration.dataAsArrayNumber();
seriesDuration.pointInterval(interval).pointStart(dateStart.getTime());
SeriesArea seriesMaxInvocationTime = highchartsFactory
.createSeriesArea();
seriesMaxInvocationTime.name("Max Invocation Time");
seriesMaxInvocationTime.color(colors.get(2));
seriesMaxInvocationTime.yAxisAsString("MaxInvocationTime");
ArrayNumber dataMaxInvocationTime = seriesMaxInvocationTime
.dataAsArrayNumber();
seriesMaxInvocationTime.pointInterval(interval).pointStart(
dateStart.getTime());
SeriesArea seriesMinInvocationTime = highchartsFactory
.createSeriesArea();
seriesMinInvocationTime.name("Min Invocation Time");
seriesMinInvocationTime.color(colors.get(3));
seriesMinInvocationTime.yAxisAsString("MinInvocationTime");
ArrayNumber dataMinInvocationTime = seriesMinInvocationTime
.dataAsArrayNumber();
seriesMinInvocationTime.pointInterval(interval).pointStart(
dateStart.getTime());
for (SeriesJobData seriesServiceData : seriesJob.getSeries()) {
dataOperationCount.push(seriesServiceData.getOperationCount());
dataDuration.push(seriesServiceData.getOperationCount());
dataMaxInvocationTime
.push(seriesServiceData.getOperationCount());
dataMinInvocationTime
.push(seriesServiceData.getOperationCount());
//dataDuration.push(seriesServiceData.getDuration());
//dataMaxInvocationTime
// .push(seriesServiceData.getMaxInvocationTime());
//dataMinInvocationTime
// .push(seriesServiceData.getMinInvocationTime());
}
options.series().addToEnd(seriesOperationCount);
options.series().addToEnd(seriesDuration);
options.series().addToEnd(seriesMaxInvocationTime);
options.series().addToEnd(seriesMinInvocationTime);
options.chart().showAxes(true);
options.legend().enabled(true);
// options.legend().layout("vertical");
// options.legend().align("left");
// options.legend().x(120);
// options.legend().verticalAlign("top");
// options.legend().y(100);
// options.legend().floating(true);
// options.legend()
// .backgroundColor(
// "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'white'");
return;
}
private void createSingleAxisChart() {
SeriesService seriesService = (SeriesService) accountingStateData
.getSeriesResponse();
double minRange = ChartTimeMeasure
.calculateMinRange(accountingStateData.getSeriesRequest()
.getAccountingPeriod());
double interval = ChartTimeMeasure
.calculateInterval(accountingStateData.getSeriesRequest()
.getAccountingPeriod());
Date dateStart=dtf.parse(accountingStateData.getSeriesRequest()
.getAccountingPeriod().getStartDate());
dateStart.setTime(dateStart.getTime()
+ ChartTimeMeasure.timeZoneOffset() * ChartTimeMeasure.MINUTE);
Log.debug("BuildChart DateStart: "
+ DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_FULL)
.format(dateStart));
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
options = highchartsFactory.createChartOptions();
options.navigation().buttonOptions().enabled(false);
options.exporting().filename("AccountingService");
options.chart().zoomType("xy");
options.title().text("Accounting Service");
/*
* options.subtitle().text("Click and drag in the plot area to zoom in");
*/
ArrayString colors = options.colors();
// colors.setValue(0, "#cc0038");
// colors.setValue(1, "#32cd32");
// xAxis
options.xAxis().type("datetime").minRange(minRange);
// yAxis
// options.yAxis().title().text("Exchange rate");
// Highcharts.getOptions().colors[0]
String multiAxis = "[{" + " \"id\": \"OperationCount\","
+ " \"labels\": { " + " \"format\": \"{value}\","
+ " \"style\": { " + " \"color\": \""
+ colors.get(1)
+ "\""
+ " }"
+ " },"
+ " \"title\": { "
+ " \"text\": \"Operation Count\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(1)
+ "\""
+ " }"
+ " }"
+ "} , {"
+ " \"id\": \"ServiceData\", "
+ " \"linkedTo\": \"0\","
+ " \"gridLineWidth\": \"0\","
+ " \"title\": {"
+ " \"text\": \"\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(1)
+ "\""
+ " }"
+ " },"
+ " \"labels\": {"
+ " \"format\": \"{value} ms\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(1)
+ "\"" + " }" + " }," + " \"opposite\": \"true\"" + // +
// ", \"showFirstLabel\": \"false\""
// +
"}]";
options.setFieldAsJsonObject("yAxis", multiAxis);
// does not seem to be working
String fillcolor = "{" + "\"linearGradient\": {" + "\"x1\": 0,"
+ "\"y1\": 0," + "\"x2\": 0," + "\"y2\": 1" + "},"
+ "\"stops\": [" + "[" + "0, \"#058DC7\"" + "]," + "["
+ "1, \"#FFFFFF\"" + "]" + "]" + "}";
options.plotOptions().area()
.setFieldAsJsonObject("fillColor", fillcolor).marker()
.radius(2).lineWidth(1).states().hover().lineWidth(1);
SeriesColumn seriesOperationCount = highchartsFactory
.createSeriesColumn();
seriesOperationCount.name("Operation Count");
seriesOperationCount.color(colors.get(1));
seriesOperationCount.type("column");
ArrayNumber dataOperationCount = seriesOperationCount
.dataAsArrayNumber();
seriesOperationCount.pointInterval(interval).pointStart(
dateStart.getTime());
SeriesArea seriesDuration = highchartsFactory.createSeriesArea();
seriesDuration.name("Duration");
seriesDuration.color(colors.get(0));
ArrayNumber dataDuration = seriesDuration.dataAsArrayNumber();
seriesDuration.pointInterval(interval).pointStart(dateStart.getTime());
SeriesArea seriesMaxInvocationTime = highchartsFactory
.createSeriesArea();
seriesMaxInvocationTime.name("Max Invocation Time");
seriesMaxInvocationTime.color(colors.get(2));
ArrayNumber dataMaxInvocationTime = seriesMaxInvocationTime
.dataAsArrayNumber();
seriesMaxInvocationTime.pointInterval(interval).pointStart(
dateStart.getTime());
SeriesArea seriesMinInvocationTime = highchartsFactory
.createSeriesArea();
seriesMinInvocationTime.name("Min Invocation Time");
seriesMinInvocationTime.color(colors.get(3));
// seriesMinInvocationTime.yAxisAsString("MinInvocationTime");
ArrayNumber dataMinInvocationTime = seriesMinInvocationTime
.dataAsArrayNumber();
seriesMinInvocationTime.pointInterval(interval).pointStart(
dateStart.getTime());
for (SeriesServiceData seriesServiceData : seriesService.getSeries()) {
dataOperationCount.push(seriesServiceData.getOperationCount());
dataDuration.push(seriesServiceData.getDuration());
dataMaxInvocationTime
.push(seriesServiceData.getMaxInvocationTime());
dataMinInvocationTime
.push(seriesServiceData.getMinInvocationTime());
}
options.series().addToEnd(seriesOperationCount);
options.series().addToEnd(seriesDuration);
options.series().addToEnd(seriesMaxInvocationTime);
options.series().addToEnd(seriesMinInvocationTime);
options.chart().showAxes(true);
options.legend().enabled(true);
return;
}
}

View File

@ -0,0 +1,50 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels.StorageChartMultiPanel;
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerStorageChartDrawException;
/**
* Accounting Chart 4 Storage Multi
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class StorageChart4Multi extends StorageChartBuilder {
private AccountingStateData accountingStateData;
public StorageChart4Multi(AccountingStateData accountingStateData) {
this.accountingStateData = accountingStateData;
}
@Override
public void buildChart() throws AccountingManagerStorageChartDrawException {
StorageChartPanel storageChartPanel = null;
if (accountingStateData == null
|| accountingStateData.getAccountingType() == null
|| accountingStateData.getSeriesRequest() == null
|| accountingStateData.getSeriesResponse() == null) {
storageChartSpec.setChart(storageChartPanel);
return;
}
if (!(accountingStateData.getSeriesResponse() instanceof SeriesStorage)) {
storageChartSpec.setChart(storageChartPanel);
return;
}
StorageChartMultiPanel container = new StorageChartMultiPanel(accountingStateData);
storageChartPanel = new StorageChartPanel(container);
storageChartSpec.setChart(storageChartPanel);
}
}

View File

@ -0,0 +1,50 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels.StorageChartTopPanel;
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerStorageChartDrawException;
/**
* Accounting Chart 4 Storage Top
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class StorageChart4Top extends StorageChartBuilder {
private AccountingStateData accountingStateData;
public StorageChart4Top(AccountingStateData accountingStateData) {
this.accountingStateData = accountingStateData;
}
@Override
public void buildChart() throws AccountingManagerStorageChartDrawException {
StorageChartPanel storageChartPanel = null;
if (accountingStateData == null
|| accountingStateData.getAccountingType() == null
|| accountingStateData.getSeriesRequest() == null
|| accountingStateData.getSeriesResponse() == null) {
storageChartSpec.setChart(storageChartPanel);
return;
}
if (!(accountingStateData.getSeriesResponse() instanceof SeriesStorage)) {
storageChartSpec.setChart(storageChartPanel);
return;
}
StorageChartTopPanel container = new StorageChartTopPanel(accountingStateData);
storageChartPanel = new StorageChartPanel(container);
storageChartSpec.setChart(storageChartPanel);
}
}

View File

@ -0,0 +1,26 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerStorageChartDrawException;
/**
* Abstract class for build Accounting Chart
*
* @author "Giancarlo Panichi"
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public abstract class StorageChartBuilder {
protected StorageChartSpec storageChartSpec;
public StorageChartSpec getStorageChartSpec(){
return storageChartSpec;
}
public void createSpec(){
storageChartSpec=new StorageChartSpec();
}
public abstract void buildChart() throws AccountingManagerStorageChartDrawException;
}

View File

@ -0,0 +1,31 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerStorageChartDrawException;
/**
* Storage Chart Director
*
* @author "Giancarlo Panichi"
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class StorageChartDirector {
StorageChartBuilder storageChartBuilder;
public void setStorageChartBuilder(
StorageChartBuilder storageChartBuilder) {
this.storageChartBuilder = storageChartBuilder;
}
public StorageChartPanel getStorageChart() {
return storageChartBuilder.getStorageChartSpec().getChart();
}
public void constructStorageChart() throws AccountingManagerStorageChartDrawException {
storageChartBuilder.createSpec();
storageChartBuilder.buildChart();
}
}

View File

@ -0,0 +1,34 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage;
import com.sencha.gxt.widget.core.client.container.Container;
/**
* Storage Chart Panel
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class StorageChartPanel {
private Container chart;
public StorageChartPanel(Container chart) {
super();
this.chart = chart;
}
public Container getChart() {
return chart;
}
public void setChart(Container chart) {
this.chart = chart;
}
@Override
public String toString() {
return "StorageChartPanel [chart=" + chart + "]";
}
}

View File

@ -0,0 +1,22 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage;
/**
* Storage Chart Specification
*
* @author "Giancarlo Panichi" email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class StorageChartSpec {
private StorageChartPanel chart;
public StorageChartPanel getChart() {
return chart;
}
public void setChart(StorageChartPanel chart) {
this.chart = chart;
}
}

View File

@ -1,4 +1,4 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage; package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels;
import java.util.Date; import java.util.Date;
@ -43,7 +43,7 @@ import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class StorageChart extends SimpleContainer { public class StorageChartMultiPanel extends SimpleContainer {
private static final String DATA_VOLUME_UNIT = "Data Volume Unit"; private static final String DATA_VOLUME_UNIT = "Data Volume Unit";
@ -58,7 +58,7 @@ public class StorageChart extends SimpleContainer {
private MenuItem downloadJPGItem; private MenuItem downloadJPGItem;
private MenuItem downloadPDFItem; private MenuItem downloadPDFItem;
private MenuItem downloadSVGItem; private MenuItem downloadSVGItem;
// Unit Menu // Unit Menu
private MenuItem kBItem; private MenuItem kBItem;
private MenuItem MBItem; private MenuItem MBItem;
@ -71,7 +71,7 @@ public class StorageChart extends SimpleContainer {
private long unitMeasure = ByteUnitMeasure.getMegaByteDimForStorage(); private long unitMeasure = ByteUnitMeasure.getMegaByteDimForStorage();
private String unitMeasureLabel = ByteUnitMeasure.MB; private String unitMeasureLabel = ByteUnitMeasure.MB;
public StorageChart(AccountingStateData accountingStateData) { public StorageChartMultiPanel(AccountingStateData accountingStateData) {
this.accountingStateData = accountingStateData; this.accountingStateData = accountingStateData;
forceLayoutOnResize = true; forceLayoutOnResize = true;
create(); create();
@ -115,6 +115,7 @@ public class StorageChart extends SimpleContainer {
} }
private void updateChart() { private void updateChart() {
vert.remove(highchartsLayoutPanel); vert.remove(highchartsLayoutPanel);
// //
@ -189,6 +190,7 @@ public class StorageChart extends SimpleContainer {
} }
private Menu createUnitMenu() { private Menu createUnitMenu() {
Menu menuUnit = new Menu(); Menu menuUnit = new Menu();
kBItem = new MenuItem(ByteUnitMeasure.KILOBYTE); kBItem = new MenuItem(ByteUnitMeasure.KILOBYTE);
@ -255,7 +257,7 @@ public class StorageChart extends SimpleContainer {
var chart = $wnd var chart = $wnd
.jQuery('#' + id) .jQuery('#' + id)
.highcharts( .highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChart::options); this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels.StorageChartMultiPanel::options);
console.log(chart); console.log(chart);
chart.exportChart(); chart.exportChart();
@ -266,7 +268,7 @@ public class StorageChart extends SimpleContainer {
var chart = $wnd var chart = $wnd
.jQuery('#' + id) .jQuery('#' + id)
.highcharts( .highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChart::options); this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels.StorageChartMultiPanel::options);
console.log(chart); console.log(chart);
chart.exportChart({ chart.exportChart({
type : 'image/jpeg' type : 'image/jpeg'
@ -279,7 +281,7 @@ public class StorageChart extends SimpleContainer {
var chart = $wnd var chart = $wnd
.jQuery('#' + id) .jQuery('#' + id)
.highcharts( .highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChart::options); this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels.StorageChartMultiPanel::options);
console.log(chart); console.log(chart);
chart.exportChart({ chart.exportChart({
type : 'application/pdf' type : 'application/pdf'
@ -292,7 +294,7 @@ public class StorageChart extends SimpleContainer {
var chart = $wnd var chart = $wnd
.jQuery('#' + id) .jQuery('#' + id)
.highcharts( .highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.StorageChart::options); this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels.StorageChartMultiPanel::options);
console.log(chart); console.log(chart);
chart.exportChart({ chart.exportChart({
type : 'image/svg+xml' type : 'image/svg+xml'
@ -437,4 +439,5 @@ public class StorageChart extends SimpleContainer {
return; return;
} }
} }

View File

@ -0,0 +1,501 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels;
import java.util.ArrayList;
import java.util.Date;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.ByteUnitMeasure;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.ChartTimeMeasure;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.DownloadConstants;
import org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils.StorageChartMeasure;
import org.gcube.portlets.admin.accountingmanager.client.resource.AccountingManagerResources;
import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorageData;
import com.allen_sauer.gwt.log.client.Log;
import com.github.highcharts4gwt.client.view.widget.HighchartsLayoutPanel;
import com.github.highcharts4gwt.model.array.api.ArrayNumber;
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.SeriesColumn;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
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.container.BoxLayoutContainer.BoxLayoutData;
import com.sencha.gxt.widget.core.client.container.MarginData;
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
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.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;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class StorageChartTopPanel extends SimpleContainer {
private static final String DATA_VOLUME_UNIT = "Data Volume Unit";
private static final String MEASURE_TYPE = "Measure";
private DateTimeFormat dtf = DateTimeFormat
.getFormat(PredefinedFormat.YEAR_MONTH_DAY);
private AccountingStateData accountingStateData;
private HighchartsLayoutPanel highchartsLayoutPanel;
// Download Menu
private MenuItem downloadPNGItem;
private MenuItem downloadJPGItem;
private MenuItem downloadPDFItem;
private MenuItem downloadSVGItem;
// Measure Menu
private MenuItem dataVolumeItem;
private MenuItem operationCountItem;
// Unit Menu
private MenuItem kBItem;
private MenuItem MBItem;
private MenuItem GBItem;
private MenuItem TBItem;
ChartOptions options;
private VerticalLayoutContainer vert;
private long unitMeasure = ByteUnitMeasure.getMegaByteDimForStorage();
private String unitMeasureLabel = ByteUnitMeasure.MB;
public StorageChartTopPanel(AccountingStateData accountingStateData) {
this.accountingStateData = accountingStateData;
forceLayoutOnResize = true;
create();
}
private void create() {
ToolBar toolBar = new ToolBar();
toolBar.setSpacing(2);
// Download
final TextButton downloadButton = new TextButton(
DownloadConstants.DOWNLOAD,
AccountingManagerResources.INSTANCE.accountingDownload24());
// downloadButton.setScale(ButtonScale.MEDIUM);
downloadButton.setIconAlign(IconAlign.RIGHT);
downloadButton.setArrowAlign(ButtonArrowAlign.RIGHT);
downloadButton.setMenu(createDownloadMenu());
// Measure
final TextButton measureButton = new TextButton(MEASURE_TYPE,
AccountingManagerResources.INSTANCE.accountingByte24());
measureButton.setIconAlign(IconAlign.RIGHT);
measureButton.setArrowAlign(ButtonArrowAlign.RIGHT);
measureButton.setMenu(createMeasureMenu());
// Unit
final TextButton unitButton = new TextButton(DATA_VOLUME_UNIT,
AccountingManagerResources.INSTANCE.accountingByte24());
unitButton.setIconAlign(IconAlign.RIGHT);
unitButton.setArrowAlign(ButtonArrowAlign.RIGHT);
unitButton.setMenu(createUnitMenu());
toolBar.add(downloadButton, new BoxLayoutData(new Margins(0)));
toolBar.add(measureButton, new BoxLayoutData(new Margins(0)));
toolBar.add(unitButton, new BoxLayoutData(new Margins(0)));
//
createChart();
highchartsLayoutPanel = new HighchartsLayoutPanel();
highchartsLayoutPanel.renderChart(options);
//
vert = new VerticalLayoutContainer();
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 void updateChart() {
vert.remove(highchartsLayoutPanel);
//
createChart();
highchartsLayoutPanel = new HighchartsLayoutPanel();
highchartsLayoutPanel.renderChart(options);
vert.add(highchartsLayoutPanel, new VerticalLayoutData(1, 1,
new Margins(0)));
forceLayout();
}
private Menu createDownloadMenu() {
Menu menuDownload = new Menu();
downloadPNGItem = new MenuItem(DownloadConstants.DOWNLOAD_PNG,
AccountingManagerResources.INSTANCE.accountingFilePNG24());
downloadPNGItem.setHeight(30);
downloadJPGItem = new MenuItem(DownloadConstants.DOWNLOAD_JPG,
AccountingManagerResources.INSTANCE.accountingFileJPG24());
downloadJPGItem.setHeight(30);
downloadPDFItem = new MenuItem(DownloadConstants.DOWNLOAD_PDF,
AccountingManagerResources.INSTANCE.accountingFilePDF24());
downloadPDFItem.setHeight(30);
downloadSVGItem = new MenuItem(DownloadConstants.DOWNLOAD_SVG,
AccountingManagerResources.INSTANCE.accountingFileSVG24());
downloadSVGItem.setHeight(30);
downloadPNGItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
String id = highchartsLayoutPanel.getElement().getId();
onDownloadPNG(id);
}
});
downloadJPGItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
String id = highchartsLayoutPanel.getElement().getId();
onDownloadJPG(id);
}
});
downloadPDFItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
String id = highchartsLayoutPanel.getElement().getId();
onDownloadPDF(id);
}
});
downloadSVGItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
String id = highchartsLayoutPanel.getElement().getId();
onDownloadSVG(id);
}
});
menuDownload.add(downloadPNGItem);
menuDownload.add(downloadJPGItem);
menuDownload.add(downloadPDFItem);
menuDownload.add(downloadSVGItem);
return menuDownload;
}
private Menu createMeasureMenu() {
Menu menuMeasure = new Menu();
dataVolumeItem = new MenuItem("Data Volume");
dataVolumeItem.setHeight(30);
operationCountItem = new MenuItem("Operation Count");
operationCountItem.setHeight(30);
dataVolumeItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
// DataVolume
updateChart();
}
});
operationCountItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
// OperationCount
updateChart();
}
});
menuMeasure.add(dataVolumeItem);
menuMeasure.add(operationCountItem);
return menuMeasure;
}
private Menu createUnitMenu() {
Menu menuUnit = new Menu();
kBItem = new MenuItem(ByteUnitMeasure.KILOBYTE);
kBItem.setHeight(30);
MBItem = new MenuItem(ByteUnitMeasure.MEGABYTE);
MBItem.setHeight(30);
GBItem = new MenuItem(ByteUnitMeasure.GIGABYTE);
GBItem.setHeight(30);
TBItem = new MenuItem(ByteUnitMeasure.TERABYTE);
TBItem.setHeight(30);
kBItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
unitMeasure = ByteUnitMeasure.getKiloByteDimForStorage();
unitMeasureLabel = ByteUnitMeasure.kB;
updateChart();
}
});
MBItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
unitMeasure = ByteUnitMeasure.getMegaByteDimForStorage();
unitMeasureLabel = ByteUnitMeasure.MB;
updateChart();
}
});
GBItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
unitMeasure = ByteUnitMeasure.getGigaByteDimForStorage();
unitMeasureLabel = ByteUnitMeasure.GB;
updateChart();
}
});
TBItem.addSelectionHandler(new SelectionHandler<Item>() {
@Override
public void onSelection(SelectionEvent<Item> event) {
unitMeasure = ByteUnitMeasure.getTeraByteDimForStorage();
unitMeasureLabel = ByteUnitMeasure.TB;
updateChart();
}
});
menuUnit.add(kBItem);
menuUnit.add(MBItem);
menuUnit.add(GBItem);
menuUnit.add(TBItem);
return menuUnit;
}
// chart.options.exporting.buttons.contextButton.menuItems[0].onclick();
public static native void onDownloadPNG(String id) /*-{
console.log(id);
var chart = $wnd
.jQuery('#' + id)
.highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels.StorageChartTopPanel::options);
console.log(chart);
chart.exportChart();
}-*/;
public static native void onDownloadJPG(String id) /*-{
console.log(id);
var chart = $wnd
.jQuery('#' + id)
.highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels.StorageChartTopPanel::options);
console.log(chart);
chart.exportChart({
type : 'image/jpeg'
});
}-*/;
public static native void onDownloadPDF(String id) /*-{
console.log(id);
var chart = $wnd
.jQuery('#' + id)
.highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels.StorageChartTopPanel::options);
console.log(chart);
chart.exportChart({
type : 'application/pdf'
});
}-*/;
public static native void onDownloadSVG(String id) /*-{
console.log(id);
var chart = $wnd
.jQuery('#' + id)
.highcharts(
this.@org.gcube.portlets.admin.accountingmanager.client.maindata.charts.storage.panels.StorageChartTopPanel::options);
console.log(chart);
chart.exportChart({
type : 'image/svg+xml'
});
}-*/;
private void createChart() {
SeriesStorage seriesStorage = (SeriesStorage) accountingStateData
.getSeriesResponse();
double minRange = ChartTimeMeasure
.calculateMinRange(accountingStateData.getSeriesRequest()
.getAccountingPeriod());
double interval = ChartTimeMeasure
.calculateInterval(accountingStateData.getSeriesRequest()
.getAccountingPeriod());
Date dateStart = dtf.parse(accountingStateData.getSeriesRequest()
.getAccountingPeriod().getStartDate());
dateStart.setTime(dateStart.getTime()
+ ChartTimeMeasure.timeZoneOffset() * ChartTimeMeasure.MINUTE);
Log.debug("BuildChart DateStart: "
+ DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_FULL)
.format(dateStart));
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
options = highchartsFactory.createChartOptions();
options.chart().zoomType("xy");
options.exporting().buttons().contextButton().enabled(false);
options.exporting().filename("AccountingStorageTop");
options.title().text("Accounting Storage Top");
/*
* options.subtitle().text("Click and drag in the plot area to zoom in");
*/
ArrayString colors = options.colors();
// colors.setValue(0, "#cc0038");
// colors.setValue(1, "#32cd32");
// xAxis
options.xAxis().type("datetime").minRange(minRange);
// yAxis
options.setFieldAsJsonObject("yAxis", retrieveYAxis(colors));
options.plotOptions().setFieldAsJsonObject(
"column",
"{ " + "\"stacking\": \"normal\"," + "\"dataLabels\": { "
+ " \"enabled\": \"true\","
+ " \"color\": \"white\", " + " \"style\": {"
+ " \"textShadow\": \"0 0 3px black\"" + " }"
+ " }" + " }");
ArrayList<SeriesColumn> seriesColumn = new ArrayList<>();
for (int i = 1; i < 6; i++) {
SeriesColumn seriesOperationCount = highchartsFactory
.createSeriesColumn();
seriesOperationCount.name("Operation Count" + i);
seriesOperationCount.color(colors.get(i));
seriesOperationCount.type("column");
ArrayNumber dataOperationCount = seriesOperationCount
.dataAsArrayNumber();
for (SeriesStorageData seriesStorageData : seriesStorage
.getSeries()) {
dataOperationCount.push(seriesStorageData.getOperationCount());
}
seriesOperationCount.pointInterval(interval).pointStart(
dateStart.getTime());
seriesColumn.add(seriesOperationCount);
}
for (SeriesColumn serie : seriesColumn) {
options.series().addToEnd(serie);
}
options.chart().showAxes(true);
options.legend().enabled(true);
return;
}
private String retrieveYAxis(ArrayString colors) {
StorageChartMeasure storageChartMeasure = StorageChartMeasure.DataVolume;
switch (storageChartMeasure) {
case DataVolume:
return "[{" + " \"id\": \"Data Volume\"," + " \"labels\": {"
+ " \"format\": \"{value} "
+ unitMeasureLabel
+ "\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(0)
+ "\""
+ " }"
+ " },"
+ " \"stackLabels\": {"
+ " \"enabled\": \"true\","
+ " \"style\": {"
+ " \"fontWeight\": \"bold\","
+ " \"color\": \"gray\""
+ " } "
+ " },"
+ " \"title\": { "
+ " \"text\": \"Data Volume\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(1) + "\"" + " }" + " }" + "}]";
case OperationCount:
return "[{" + " \"id\": \"OperationCount\"," + " \"labels\": { "
+ " \"format\": \"{value}\"," + " \"style\": { "
+ " \"color\": \"" + colors.get(1) + "\"" + " }"
+ " }," + " \"stackLabels\": {" + " \"enabled\": \"true\","
+ " \"style\": {" + " \"fontWeight\": \"bold\","
+ " \"color\": \"gray\"" + " } " + " },"
+ " \"title\": { " + " \"text\": \"Operation Count\","
+ " \"style\": {" + " \"color\": \""
+ colors.get(1) + "\"" + " }" + " }" + "}]";
default:
return "[{" + " \"id\": \"Data Volume\"," + " \"labels\": {"
+ " \"format\": \"{value} "
+ unitMeasureLabel
+ "\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(0)
+ "\""
+ " }"
+ " },"
+ " \"stackLabels\": {"
+ " \"enabled\": \"true\","
+ " \"style\": {"
+ " \"fontWeight\": \"bold\","
+ " \"color\": \"gray\""
+ " } "
+ " },"
+ " \"title\": { "
+ " \"text\": \"Data Volume\","
+ " \"style\": {"
+ " \"color\": \""
+ colors.get(1) + "\"" + " }" + " }" + "}]";
}
}
}

View File

@ -0,0 +1,63 @@
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts.utils;
import java.util.Arrays;
import java.util.List;
/**
* Storage Chart Measure
*
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum StorageChartMeasure {
DataVolume("Data Volume"), OperationCount("Operation Count");
/**
* @param text
*/
private StorageChartMeasure(final String id) {
this.id = id;
}
private final String id;
@Override
public String toString() {
return id;
}
public String getLabel() {
return id;
}
public String getId() {
return id;
}
/**
*
* @param id
* @return
*/
public static StorageChartMeasure getFromId(String id) {
if (id == null || id.isEmpty())
return null;
for (StorageChartMeasure columnDataType : values()) {
if (columnDataType.id.compareToIgnoreCase(id) == 0) {
return columnDataType;
}
}
return null;
}
public static List<StorageChartMeasure> asList() {
List<StorageChartMeasure> list = Arrays.asList(values());
return list;
}
}

View File

@ -63,12 +63,13 @@ public class AccountingManagerMenu extends TabPanel {
taskItemConf.setIcon(AccountingManagerResources.INSTANCE.accountingTask48()); taskItemConf.setIcon(AccountingManagerResources.INSTANCE.accountingTask48());
EmptyPanel taskCategory=new EmptyPanel(AccountingType.TASK.name()); EmptyPanel taskCategory=new EmptyPanel(AccountingType.TASK.name());
add(taskCategory, taskItemConf); add(taskCategory, taskItemConf);
*/
TabItemConfig jobItemConf = new TabItemConfig("Job", false); TabItemConfig jobItemConf = new TabItemConfig("Job", false);
jobItemConf.setIcon(AccountingManagerResources.INSTANCE.accountingJob48()); jobItemConf.setIcon(AccountingManagerResources.INSTANCE.accountingJob48());
EmptyPanel jobCategory=new EmptyPanel(AccountingType.JOB.name()); EmptyPanel jobCategory=new EmptyPanel(AccountingType.JOB.name());
add(jobCategory, jobItemConf); add(jobCategory, jobItemConf);
*/
setActiveWidget(getWidget(0)); setActiveWidget(getWidget(0));

View File

@ -8,6 +8,8 @@ import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerService; import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerService;
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCaller; import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCaller;
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerInterface;
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCallerTester;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType; import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue; import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
@ -87,7 +89,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session); SessionUtil.getAslSession(session);
AccountingCaller accountingCaller = new AccountingCaller(); AccountingCallerInterface accountingCaller = new AccountingCallerTester();
SeriesResponse seriesResponse = accountingCaller.getSeries( SeriesResponse seriesResponse = accountingCaller.getSeries(
accountingType, seriesRequest); accountingType, seriesRequest);
@ -115,7 +117,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session); SessionUtil.getAslSession(session);
AccountingCaller accountingCaller = new AccountingCaller(); AccountingCallerInterface accountingCaller = new AccountingCallerTester();
ArrayList<FilterKey> filterKeys = accountingCaller.getFilterKeys(accountingType); ArrayList<FilterKey> filterKeys = accountingCaller.getFilterKeys(accountingType);
return filterKeys; return filterKeys;
@ -143,7 +145,7 @@ public class AccountingManagerServiceImpl extends RemoteServiceServlet
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session); SessionUtil.getAslSession(session);
AccountingCaller accountingCaller = new AccountingCaller(); AccountingCallerInterface accountingCaller = new AccountingCallerTester();
ArrayList<FilterValue> filterValues = accountingCaller.getFilterValues(filterValuesRequest); ArrayList<FilterValue> filterValues = accountingCaller.getFilterValues(filterValuesRequest);
return filterValues; return filterValues;

View File

@ -8,6 +8,7 @@ import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager; import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.admin.accountingmanager.shared.Constants;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerSessionExpiredException; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerSessionExpiredException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -29,9 +30,9 @@ public class SessionUtil {
ASLSession session; ASLSession session;
if (username == null) { if (username == null) {
logger.warn("no user found in session, use test user"); logger.warn("no user found in session, use test user");
throw new AccountingManagerSessionExpiredException("Session Expired!"); /*throw new AccountingManagerSessionExpiredException("Session Expired!");*/
/*
// Remove comment for Test // Remove comment for Test
username = Constants.DEFAULT_USER; username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE; String scope = Constants.DEFAULT_SCOPE;
@ -40,7 +41,7 @@ public class SessionUtil {
session = SessionManager.getInstance().getASLSession( session = SessionManager.getInstance().getASLSession(
httpSession.getId(), username); httpSession.getId(), username);
session.setScope(scope); session.setScope(scope);
*/
} else { } else {
session = SessionManager.getInstance().getASLSession( session = SessionManager.getInstance().getASLSession(
httpSession.getId(), username); httpSession.getId(), username);

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.gcube.accounting.analytics.Info; import org.gcube.accounting.analytics.Info;
import org.gcube.accounting.analytics.ResourceRecordQuery; import org.gcube.accounting.analytics.ResourceRecordQuery;
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
import org.gcube.portlets.admin.accountingmanager.server.amservice.query.AccountingQuery; import org.gcube.portlets.admin.accountingmanager.server.amservice.query.AccountingQuery;
@ -38,180 +39,178 @@ import org.slf4j.LoggerFactory;
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class AccountingCaller { public class AccountingCaller implements AccountingCallerInterface {
private static Logger logger = LoggerFactory static Logger logger = LoggerFactory
.getLogger(AccountingCaller.class); .getLogger(AccountingCaller.class);
public AccountingCaller() { public AccountingCaller() {
super();
} }
public ArrayList<FilterKey> getFilterKeys(AccountingType accountingType) public ArrayList<FilterKey> getFilterKeys(AccountingType accountingType)
throws AccountingManagerServiceException { throws AccountingManagerServiceException {
try { try {
logger.debug("getFilterKeys(): [AccountingType=" + accountingType logger.debug("getFilterKeys(): [AccountingType=" + accountingType
+ "]"); + "]");
if (accountingType == null) { if (accountingType == null) {
return new ArrayList<FilterKey>(); return new ArrayList<FilterKey>();
} }
ArrayList<FilterKey> filterKeys = new ArrayList<FilterKey>(); ArrayList<FilterKey> filterKeys = new ArrayList<FilterKey>();
List<String> keys; List<String> keys;
ResourceRecordQuery rrq = new ResourceRecordQuery(); ResourceRecordQuery rrq = new ResourceRecordQuery();
switch (accountingType) { switch (accountingType) {
case JOB: case JOB:
// keys=rrq.getKeys(AggregatedJobUsageRecord.class); keys=rrq.getKeys(AggregatedJobUsageRecord.class);
return filterKeys; break;
case PORTLET: case PORTLET:
// keys=rrq.getKeys(AggregatedPortletUsageRecord.class); // keys=rrq.getKeys(AggregatedPortletUsageRecord.class);
return filterKeys; return filterKeys;
case SERVICE: case SERVICE:
keys = rrq.getKeys(AggregatedServiceUsageRecord.class); keys = rrq.getKeys(AggregatedServiceUsageRecord.class);
break; break;
case STORAGE: case STORAGE:
keys = rrq.getKeys(AggregatedStorageUsageRecord.class); keys = rrq.getKeys(AggregatedStorageUsageRecord.class);
break; break;
case TASK: case TASK:
// keys=rrq.getKeys(AggregatedTaskUsageRecord.class); // keys=rrq.getKeys(AggregatedTaskUsageRecord.class);
return filterKeys; return filterKeys;
default: default:
return filterKeys; return filterKeys;
} }
for (String key : keys) { for (String key : keys) {
if (key != null && !key.isEmpty()) { if (key != null && !key.isEmpty()) {
filterKeys.add(new FilterKey(key)); filterKeys.add(new FilterKey(key));
}
}
logger.debug("List FilterKeys:"+filterKeys);
return filterKeys;
} catch (Throwable e) {
logger.error("Error in getFilterKeys(): " + e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("No keys available!");
} }
} }
return filterKeys; public ArrayList<FilterValue> getFilterValues(FilterValuesRequest filterValuesRequest)
} catch (Throwable e) {
logger.error("Error in getFilterKeys(): " + e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("No keys available!");
}
}
public ArrayList<FilterValue> getFilterValues(
FilterValuesRequest filterValuesRequest)
throws AccountingManagerServiceException { throws AccountingManagerServiceException {
try { try {
logger.debug("getFilterValue(): [FilterValueRequest=" logger.debug("getFilterValue(): [FilterValueRequest="
+ filterValuesRequest + "]"); + filterValuesRequest + "]");
if (filterValuesRequest == null if (filterValuesRequest == null
|| filterValuesRequest.getAccountingType() == null || filterValuesRequest.getAccountingType() == null
|| filterValuesRequest.getFilterKey() == null) { || filterValuesRequest.getFilterKey() == null) {
return new ArrayList<FilterValue>(); return new ArrayList<FilterValue>();
} }
ArrayList<FilterValue> filteValues = new ArrayList<FilterValue>(); ArrayList<FilterValue> filteValues = new ArrayList<FilterValue>();
List<String> values; List<String> values;
ResourceRecordQuery rrq = new ResourceRecordQuery(); ResourceRecordQuery rrq = new ResourceRecordQuery();
switch (filterValuesRequest.getAccountingType()) { switch (filterValuesRequest.getAccountingType()) {
case JOB: case JOB:
// values = values =
// rrq.getPossibleValuesForKey(AggregatedJobUsageRecord.class, rrq.getPossibleValuesForKey(AggregatedJobUsageRecord.class,
// filterValuesRequest filterValuesRequest.getFilterKey().getKey());
// .getFilterKey().getKey()); return filteValues;
return filteValues; case PORTLET:
case PORTLET: // values = rrq.getPossibleValuesForKey(
// values = rrq.getPossibleValuesForKey( // AggregatedPortletUsageRecord.class, filterValuesRequest
// AggregatedPortletUsageRecord.class, filterValuesRequest // .getFilterKey().getKey());
// .getFilterKey().getKey()); return filteValues;
return filteValues; case SERVICE:
case SERVICE: values = rrq.getPossibleValuesForKey(
values = rrq.getPossibleValuesForKey( AggregatedServiceUsageRecord.class, filterValuesRequest
AggregatedServiceUsageRecord.class, filterValuesRequest .getFilterKey().getKey());
.getFilterKey().getKey()); break;
break; case STORAGE:
case STORAGE: values = rrq.getPossibleValuesForKey(
values = rrq.getPossibleValuesForKey( AggregatedStorageUsageRecord.class, filterValuesRequest
AggregatedStorageUsageRecord.class, filterValuesRequest .getFilterKey().getKey());
.getFilterKey().getKey()); break;
break; case TASK:
case TASK: // values = rrq.getPossibleValuesForKey(
// values = rrq.getPossibleValuesForKey( // AggregatedTaskUsageRecord.class, filterValuesRequest
// AggregatedTaskUsageRecord.class, filterValuesRequest // .getFilterKey().getKey());
// .getFilterKey().getKey()); return filteValues;
return filteValues; default:
default: return filteValues;
return filteValues; }
} for (String value : values) {
for (String value : values) { if (value != null && !value.isEmpty()) {
if (value != null && !value.isEmpty()) { filteValues.add(new FilterValue(value));
filteValues.add(new FilterValue(value)); }
}
return filteValues;
} catch (Throwable e) {
logger.error("Error in getFilterValues(): "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("No values available!");
} }
} }
return filteValues; public SeriesResponse getSeries(AccountingType accountingType, SeriesRequest seriesRequest)
} catch (Throwable e) {
logger.error("Error in getFilterValues(): "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("No values available!");
}
}
public SeriesResponse getSeries(AccountingType accountingType,
SeriesRequest seriesRequest)
throws AccountingManagerServiceException { throws AccountingManagerServiceException {
try { try {
logger.debug("getSeries(): [AccountingType=" + accountingType logger.debug("getSeries(): [AccountingType=" + accountingType
+ " , seriesRequest=" + seriesRequest + "]"); + " , seriesRequest=" + seriesRequest + "]");
ResourceRecordQuery rrq = new ResourceRecordQuery(); ResourceRecordQuery rrq = new ResourceRecordQuery();
AccountingQueryBuilder queryBuilder = getAccountQueryBuilder( AccountingQueryBuilder queryBuilder = getAccountQueryBuilder(
accountingType, seriesRequest); accountingType, seriesRequest);
AccountingQueryDirector director = new AccountingQueryDirector(); AccountingQueryDirector director = new AccountingQueryDirector();
director.setAccountingQueryBuilder(queryBuilder); director.setAccountingQueryBuilder(queryBuilder);
director.constructAccountingQuery(); director.constructAccountingQuery();
AccountingQuery query = director.getAccountingQuery(); AccountingQuery query = director.getAccountingQuery();
if (query == null) { if (query == null) {
throw new AccountingManagerServiceException( throw new AccountingManagerServiceException(
"Error in invocation: Operation not supported"); "Error in invocation: Operation not supported");
}
logger.debug("Query: " + query);
List<Info> infos = rrq.getInfo(query.getType(),
query.getTemporalConstraint(), query.getFilters(), true);
if (infos == null) {
throw new AccountingManagerServiceException(
"Error retrieving list of info: list is null!");
}
logger.debug("Retrieved Infos");
logger.debug("Infos: " + infos);
SeriesResponseBuilder seriesResponseBuilder = getSeriesResponseBuilder(
accountingType, infos);
SeriesResponseDirector seriesResponseDirector = new SeriesResponseDirector();
seriesResponseDirector
.setSeriesResponseBuilder(seriesResponseBuilder);
seriesResponseDirector.constructSeriesResponse();
SeriesResponse seriesResponse = seriesResponseDirector
.getSeriesResponse();
if (seriesResponse == null) {
throw new AccountingManagerServiceException(
"Error creating series response!");
}
logger.debug("SeriesResponse Created: " + seriesResponse);
return seriesResponse;
} catch (Throwable e) {
logger.error("Error in GetSeries(): " + e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("No data available!");
}
} }
logger.debug("Query: " + query);
List<Info> infos = rrq.getInfo(query.getType(),
query.getTemporalConstraint(), query.getFilters(), true);
if (infos == null) {
throw new AccountingManagerServiceException(
"Error retrieving list of info: list is null!");
}
logger.debug("Retrieved Infos");
logger.debug("Infos: " + infos);
SeriesResponseBuilder seriesResponseBuilder = getSeriesResponseBuilder(
accountingType, infos);
SeriesResponseDirector seriesResponseDirector = new SeriesResponseDirector();
seriesResponseDirector
.setSeriesResponseBuilder(seriesResponseBuilder);
seriesResponseDirector.constructSeriesResponse();
SeriesResponse seriesResponse = seriesResponseDirector
.getSeriesResponse();
if (seriesResponse == null) {
throw new AccountingManagerServiceException(
"Error creating series response!");
}
logger.debug("SeriesResponse Created: " + seriesResponse);
return seriesResponse;
} catch (Throwable e) {
logger.error("Error in GetSeries(): " + e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("No data available!");
}
}
private AccountingQueryBuilder getAccountQueryBuilder( private AccountingQueryBuilder getAccountQueryBuilder(
AccountingType accountingType, SeriesRequest seriesRequest) AccountingType accountingType, SeriesRequest seriesRequest)

View File

@ -0,0 +1,32 @@
package org.gcube.portlets.admin.accountingmanager.server.amservice;
import java.util.ArrayList;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface AccountingCallerInterface {
public ArrayList<FilterKey> getFilterKeys(AccountingType accountingType)
throws AccountingManagerServiceException;
public ArrayList<FilterValue> getFilterValues(
FilterValuesRequest filterValuesRequest)
throws AccountingManagerServiceException;
public SeriesResponse getSeries(AccountingType accountingType,
SeriesRequest seriesRequest)
throws AccountingManagerServiceException;
}

View File

@ -0,0 +1,153 @@
package org.gcube.portlets.admin.accountingmanager.server.amservice;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorageData;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class AccountingCallerTester implements AccountingCallerInterface {
static Logger logger = LoggerFactory
.getLogger(AccountingCallerTester.class);
public AccountingCallerTester() {
super();
}
public ArrayList<FilterKey> getFilterKeys(AccountingType accountingType)
throws AccountingManagerServiceException {
try {
logger.debug("getFilterKeys(): [AccountingType=" + accountingType
+ "]");
if (accountingType == null) {
return new ArrayList<FilterKey>();
}
ArrayList<FilterKey> filterKeys = new ArrayList<FilterKey>();
FilterKey key=new FilterKey("ConsumerId");
FilterKey key1=new FilterKey("ClassName");
filterKeys.add(key);
filterKeys.add(key1);
logger.debug("List FilterKeys:"+filterKeys);
return filterKeys;
} catch (Throwable e) {
logger.error("Error in getFilterKeys(): " + e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("No keys available!");
}
}
public ArrayList<FilterValue> getFilterValues(FilterValuesRequest filterValuesRequest)
throws AccountingManagerServiceException {
try {
logger.debug("getFilterValue(): [FilterValueRequest="
+ filterValuesRequest + "]");
if (filterValuesRequest == null
|| filterValuesRequest.getAccountingType() == null
|| filterValuesRequest.getFilterKey() == null) {
return new ArrayList<FilterValue>();
}
ArrayList<FilterValue> filteValues = new ArrayList<FilterValue>();
List<String> values;
String[] vals={"giancarlo.panichi","gianpaolo.coro"};
switch (filterValuesRequest.getAccountingType()) {
case JOB:
values = Arrays.asList(vals);
case PORTLET:
values = Arrays.asList(vals);
case SERVICE:
values = Arrays.asList(vals);
case STORAGE:
values = Arrays.asList(vals);
case TASK:
values = Arrays.asList(vals);
default:
values = Arrays.asList(vals);
}
for (String value : values) {
if (value != null && !value.isEmpty()) {
filteValues.add(new FilterValue(value));
}
}
return filteValues;
} catch (Throwable e) {
logger.error("Error in getFilterValues(): "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("No values available!");
}
}
public SeriesResponse getSeries(AccountingType accountingType, SeriesRequest seriesRequest)
throws AccountingManagerServiceException {
try {
logger.debug("getSeries(): [AccountingType=" + accountingType
+ " , seriesRequest=" + seriesRequest + "]");
SeriesResponse seriesResponse=null;
switch(accountingType){
case JOB:
break;
case PORTLET:
break;
case SERVICE:
break;
case STORAGE:
ArrayList<SeriesStorageData> seriesStorageData=new ArrayList<>();
for(int i=0;i<30;i++){
SeriesStorageData data=new SeriesStorageData(new Date(), new Double(10*Math.random()).longValue(),new Double(100*Math.random()).longValue());
seriesStorageData.add(data);
}
seriesResponse=new SeriesStorage(seriesStorageData);
break;
case TASK:
break;
default:
break;
}
if (seriesResponse == null) {
throw new AccountingManagerServiceException(
"Error creating series response!");
}
logger.debug("SeriesResponse Created: " + seriesResponse);
return seriesResponse;
} catch (Throwable e) {
logger.error("Error in GetSeries(): " + e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("No data available!");
}
}
}

View File

@ -1,12 +1,15 @@
package org.gcube.portlets.admin.accountingmanager.server.amservice.query; package org.gcube.portlets.admin.accountingmanager.server.amservice.query;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.gcube.accounting.analytics.Filter;
import org.gcube.accounting.analytics.TemporalConstraint; import org.gcube.accounting.analytics.TemporalConstraint;
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
import org.gcube.portlets.admin.accountingmanager.server.amservice.PeriodModeMap; import org.gcube.portlets.admin.accountingmanager.server.amservice.PeriodModeMap;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilter;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -52,15 +55,27 @@ public class AccountingQuery4Job extends AccountingQueryBuilder {
endCalendar.set(GregorianCalendar.SECOND, 59); endCalendar.set(GregorianCalendar.SECOND, 59);
endCalendar.set(GregorianCalendar.MILLISECOND, 999); endCalendar.set(GregorianCalendar.MILLISECOND, 999);
TemporalConstraint temporalConstraint = new TemporalConstraint( TemporalConstraint temporalConstraint = new TemporalConstraint(
startCalendar.getTimeInMillis(), startCalendar.getTimeInMillis(),
endCalendar.getTimeInMillis(), endCalendar.getTimeInMillis(),
PeriodModeMap.getMode(seriesRequest.getAccountingPeriod() PeriodModeMap.getMode(seriesRequest.getAccountingPeriod()
.getPeriod())); .getPeriod()));
ArrayList<AccountingFilter> accountingFilters = seriesRequest
.getFilters();
ArrayList<Filter> filters = null;
if (accountingFilters != null) {
filters = new ArrayList<Filter>();
for (AccountingFilter accountigFilters : accountingFilters) {
Filter filter = new Filter(accountigFilters.getFilterKey()
.getKey(), accountigFilters.getFilterValue());
filters.add(filter);
}
}
AccountingQuery invocation = new AccountingQuery( AccountingQuery invocation = new AccountingQuery(
AggregatedJobUsageRecord.class, temporalConstraint,null); AggregatedJobUsageRecord.class, temporalConstraint, filters);
accountingQuerySpec.setOp(invocation); accountingQuerySpec.setOp(invocation);

View File

@ -1,12 +1,15 @@
package org.gcube.portlets.admin.accountingmanager.server.amservice.query; package org.gcube.portlets.admin.accountingmanager.server.amservice.query;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.gcube.accounting.analytics.Filter;
import org.gcube.accounting.analytics.TemporalConstraint; import org.gcube.accounting.analytics.TemporalConstraint;
import org.gcube.accounting.datamodel.aggregation.AggregatedPortletUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedPortletUsageRecord;
import org.gcube.portlets.admin.accountingmanager.server.amservice.PeriodModeMap; import org.gcube.portlets.admin.accountingmanager.server.amservice.PeriodModeMap;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilter;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -51,15 +54,27 @@ public class AccountingQuery4Portlet extends AccountingQueryBuilder {
endCalendar.set(GregorianCalendar.SECOND, 59); endCalendar.set(GregorianCalendar.SECOND, 59);
endCalendar.set(GregorianCalendar.MILLISECOND, 999); endCalendar.set(GregorianCalendar.MILLISECOND, 999);
TemporalConstraint temporalConstraint = new TemporalConstraint( TemporalConstraint temporalConstraint = new TemporalConstraint(
startCalendar.getTimeInMillis(), startCalendar.getTimeInMillis(),
endCalendar.getTimeInMillis(), endCalendar.getTimeInMillis(),
PeriodModeMap.getMode(seriesRequest.getAccountingPeriod() PeriodModeMap.getMode(seriesRequest.getAccountingPeriod()
.getPeriod())); .getPeriod()));
ArrayList<AccountingFilter> accountingFilters = seriesRequest
.getFilters();
ArrayList<Filter> filters = null;
if (accountingFilters != null) {
filters = new ArrayList<Filter>();
for (AccountingFilter accountigFilters : accountingFilters) {
Filter filter = new Filter(accountigFilters.getFilterKey()
.getKey(), accountigFilters.getFilterValue());
filters.add(filter);
}
}
AccountingQuery invocation = new AccountingQuery( AccountingQuery invocation = new AccountingQuery(
AggregatedPortletUsageRecord.class, temporalConstraint,null); AggregatedPortletUsageRecord.class, temporalConstraint,filters);
accountingQuerySpec.setOp(invocation); accountingQuerySpec.setOp(invocation);

View File

@ -1,12 +1,15 @@
package org.gcube.portlets.admin.accountingmanager.server.amservice.query; package org.gcube.portlets.admin.accountingmanager.server.amservice.query;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.gcube.accounting.analytics.Filter;
import org.gcube.accounting.analytics.TemporalConstraint; import org.gcube.accounting.analytics.TemporalConstraint;
import org.gcube.accounting.datamodel.aggregation.AggregatedTaskUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedTaskUsageRecord;
import org.gcube.portlets.admin.accountingmanager.server.amservice.PeriodModeMap; import org.gcube.portlets.admin.accountingmanager.server.amservice.PeriodModeMap;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingFilter;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest; import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -58,8 +61,20 @@ public class AccountingQuery4Task extends AccountingQueryBuilder {
PeriodModeMap.getMode(seriesRequest.getAccountingPeriod() PeriodModeMap.getMode(seriesRequest.getAccountingPeriod()
.getPeriod())); .getPeriod()));
ArrayList<AccountingFilter> accountingFilters = seriesRequest
.getFilters();
ArrayList<Filter> filters = null;
if (accountingFilters != null) {
filters = new ArrayList<Filter>();
for (AccountingFilter accountigFilters : accountingFilters) {
Filter filter = new Filter(accountigFilters.getFilterKey()
.getKey(), accountigFilters.getFilterValue());
filters.add(filter);
}
}
AccountingQuery invocation = new AccountingQuery( AccountingQuery invocation = new AccountingQuery(
AggregatedTaskUsageRecord.class, temporalConstraint,null); AggregatedTaskUsageRecord.class, temporalConstraint,filters);
accountingQuerySpec.setOp(invocation); accountingQuerySpec.setOp(invocation);

View File

@ -1,10 +1,14 @@
package org.gcube.portlets.admin.accountingmanager.server.amservice.response; package org.gcube.portlets.admin.accountingmanager.server.amservice.response;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.gcube.accounting.analytics.Info; import org.gcube.accounting.analytics.Info;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse; import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJobData;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException; import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -26,14 +30,33 @@ public class SeriesResponse4Job extends SeriesResponseBuilder {
@Override @Override
public void buildSeriesResponse() throws AccountingManagerServiceException { public void buildSeriesResponse() throws AccountingManagerServiceException {
if(infos.size()<=0){ try {
logger.error("Error creating series for job accounting: No data available!"); if(infos.size()<=0){
throw new AccountingManagerServiceException("No data available!"); logger.error("Error creating series for job accounting: No data available!");
throw new AccountingManagerServiceException("No data available!");
}
ArrayList<SeriesJobData> series=new ArrayList<SeriesJobData>();
for (Info info : infos) {
JSONObject jso = info.getValue();
//Long duration = jso.getLong(AggregatedJobUsageRecord.DURATION);
Long operationCount = jso
.getLong(AggregatedJobUsageRecord.OPERATION_COUNT);
//Long maxInvocationTime = jso.getLong(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME);
//Long minInvocationTime = jso.getLong(AggregatedServiceUsageRecord.MIN_INVOCATION_TIME);
series.add(new SeriesJobData(info.getCalendar().getTime(), operationCount));
}
SeriesJob seriesService = new SeriesJob(series);
seriesResponseSpec.setSr(seriesService);
} catch (Throwable e) {
logger.error("Error creating series for job accounting: "+e.getLocalizedMessage());
e.printStackTrace();
throw new AccountingManagerServiceException("Error creating series for job accounting: "+e.getLocalizedMessage());
} }
SeriesResponse seriesResponse = new SeriesResponse();
seriesResponseSpec.setSr(seriesResponse);
} }
} }

View File

@ -16,6 +16,9 @@ public class Constants {
//public final static String DEFAULT_USER = "test.user"; //public final static String DEFAULT_USER = "test.user";
//public final static String DEFAULT_SCOPE = "/gcube/devNext"; //public final static String DEFAULT_SCOPE = "/gcube/devNext";
//public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE"; //public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
//public final static String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
public final static String DEFAULT_SCOPE = "/gcube"; public final static String DEFAULT_SCOPE = "/gcube";

View File

@ -0,0 +1,38 @@
/**
*
*/
package org.gcube.portlets.admin.accountingmanager.shared.exception;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class AccountingManagerStorageChartDrawException extends AccountingManagerChartDrawException {
private static final long serialVersionUID = -8737011216478988776L;
/**
*
*/
public AccountingManagerStorageChartDrawException() {
super();
}
/**
* @param message
*/
public AccountingManagerStorageChartDrawException(String message) {
super(message);
}
public AccountingManagerStorageChartDrawException(String message,Throwable t) {
super(message,t);
}
}