70 lines
2.4 KiB
Java
70 lines
2.4 KiB
Java
package org.gcube.portlets.user.accountingdashboard.server.accounting;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.gcube.accounting.accounting.summary.access.model.Record;
|
|
import org.gcube.accounting.accounting.summary.access.model.Report;
|
|
import org.gcube.accounting.accounting.summary.access.model.ReportElement;
|
|
import org.gcube.accounting.accounting.summary.access.model.Series;
|
|
import org.gcube.portlets.user.accountingdashboard.shared.data.RecordData;
|
|
import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData;
|
|
import org.gcube.portlets.user.accountingdashboard.shared.data.ReportElementData;
|
|
import org.gcube.portlets.user.accountingdashboard.shared.data.SeriesData;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
*
|
|
* @author Giancarlo Panichi
|
|
*
|
|
*/
|
|
public class ReportDataBuilder {
|
|
private static Logger logger = LoggerFactory.getLogger(ReportDataBuilder.class);
|
|
|
|
private Report report;
|
|
|
|
public ReportDataBuilder(Report report) {
|
|
this.report = report;
|
|
}
|
|
|
|
public ReportData build() {
|
|
if (report == null || report.getElements() == null) {
|
|
logger.error("Invalid report: " + report);
|
|
return null;
|
|
}
|
|
|
|
ArrayList<ReportElementData> elements = new ArrayList<>();
|
|
for (ReportElement reportElement : report.getElements()) {
|
|
if (reportElement.getSerieses() == null) {
|
|
ReportElementData reportElementData = new ReportElementData(reportElement.getLabel(),
|
|
reportElement.getCategory(), reportElement.getXAxis(), reportElement.getYAxis(), null);
|
|
elements.add(reportElementData);
|
|
} else {
|
|
ArrayList<SeriesData> serieses = new ArrayList<>();
|
|
for (Series series : reportElement.getSerieses()) {
|
|
SeriesData seriesData = null;
|
|
if (series.getDataRow() == null) {
|
|
seriesData = new SeriesData(series.getLabel(), null);
|
|
} else {
|
|
ArrayList<RecordData> dataRow = new ArrayList<>();
|
|
for (Record record : series.getDataRow()) {
|
|
RecordData recordData = new RecordData(record.getX(), record.getY());
|
|
dataRow.add(recordData);
|
|
}
|
|
seriesData = new SeriesData(series.getLabel(), dataRow);
|
|
}
|
|
serieses.add(seriesData);
|
|
}
|
|
ReportElementData reportElementData = new ReportElementData(reportElement.getLabel(),
|
|
reportElement.getCategory(), reportElement.getXAxis(), reportElement.getYAxis(), serieses);
|
|
elements.add(reportElementData);
|
|
}
|
|
}
|
|
ReportData reportData = new ReportData(elements);
|
|
logger.debug("ReportData: " + reportData);
|
|
return reportData;
|
|
|
|
}
|
|
|
|
}
|