Skip to content

Commit

Permalink
Merge pull request #16 from devgateway/OCNANDI-24-25
Browse files Browse the repository at this point in the history
OCNANDI-24 OCNANDI-25
  • Loading branch information
mpostelnicu committed Nov 2, 2023
2 parents f92f8a5 + fe33d3c commit af469b5
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 270 deletions.
13 changes: 13 additions & 0 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<commons-email.version>1.5</commons-email.version>
<json-tools.version>1.2.14</json-tools.version>
<json-patch.version>1.13</json-patch.version>
<ooxml-schemas.version>1.4</ooxml-schemas.version>
</properties>

<parent>
Expand Down Expand Up @@ -84,6 +85,18 @@
<version>2.0</version>
</dependency>

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>${ooxml-schemas.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.github.java-json-tools</groupId>
<artifactId>json-schema-validator</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
*******************************************************************************/
package org.devgateway.ocds.web.rest.controller;

import io.swagger.annotations.ApiOperation;
import org.bson.Document;
import org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

import static org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.CONTRACTS;
import static org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.CONTRACTS_VALUE_AMOUNT;
import static org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.PLANNING_BUDGETB;
Expand All @@ -26,19 +39,6 @@
import static org.springframework.data.mongodb.core.aggregation.Aggregation.sort;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.unwind;

import io.swagger.annotations.ApiOperation;
import org.bson.Document;
import org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* @author mpostelnicu
*/
Expand All @@ -51,13 +51,8 @@ public class BudgetStatsController extends GenericOCDSController {
public List<Document> expenditureToDateVsBudget(
@ModelAttribute @Valid final YearFilterPagingRequest filter) {

YearFilterPagingRequest effectiveFilters = new YearFilterPagingRequest();
effectiveFilters.setBuyerId(filter.getBuyerId());
effectiveFilters.setProcuringEntityId(filter.getProcuringEntityId());
effectiveFilters.setFiscalYear(filter.getFiscalYear());

Aggregation agg = newAggregation(
match(getDefaultFilterCriteria(effectiveFilters)),
match(getYearDefaultFilterCriteria(filter, getTenderDateField())),
facet(
unwind(CONTRACTS, true),
group(PLANNING_FISCAL_YEAR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
import org.apache.poi.ss.usermodel.Chart;
import org.apache.poi.ss.usermodel.charts.ChartAxis;
import org.apache.poi.ss.usermodel.charts.ChartDataSource;
import org.apache.poi.xssf.usermodel.XSSFChart;
import org.apache.xmlbeans.XmlObject;
import org.devgateway.toolkit.web.excelcharts.CustomChartSeries;
import org.devgateway.toolkit.web.excelcharts.util.XSSFChartUtil;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAreaChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAreaSer;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrossBetween;

/**
* @author idobre
Expand All @@ -23,50 +32,50 @@ protected CustomChartSeries createNewSerie(final int id, final int order, final
return new AbstractSeries(id, order, categories, values) {
@Override
public void addToChart(final XmlObject ctChart) {
// final CTAreaChart ctAreaChart = (CTAreaChart) ctChart;
// final CTAreaSer ctAreaSer = ctAreaChart.addNewSer();
//
// ctAreaSer.addNewIdx().setVal(this.id);
// ctAreaSer.addNewOrder().setVal(this.order);
//
// final CTAxDataSource catDS = ctAreaSer.addNewCat();
// XSSFChartUtil.buildAxDataSource(catDS, this.categories);
//
// final CTNumDataSource valueDS = ctAreaSer.addNewVal();
// XSSFChartUtil.buildNumDataSource(valueDS, this.values);
//
// if (isTitleSet()) {
// ctAreaSer.setTx(getCTSerTx());
// }
final CTAreaChart ctAreaChart = (CTAreaChart) ctChart;
final CTAreaSer ctAreaSer = ctAreaChart.addNewSer();

ctAreaSer.addNewIdx().setVal(this.id);
ctAreaSer.addNewOrder().setVal(this.order);

final CTAxDataSource catDS = ctAreaSer.addNewCat();
XSSFChartUtil.buildAxDataSource(catDS, this.categories);

final CTNumDataSource valueDS = ctAreaSer.addNewVal();
XSSFChartUtil.buildNumDataSource(valueDS, this.values);

if (isTitleSet()) {
ctAreaSer.setTx(getCTSerTx());
}
}
};
}

@Override
public void fillChart(final Chart chart, final ChartAxis... axis) {
// if (!(chart instanceof XSSFChart)) {
// throw new IllegalArgumentException("Chart must be instance of XSSFChart");
// }
//
// final XSSFChart xssfChart = (XSSFChart) chart;
// final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
// final CTAreaChart areChart = plotArea.addNewAreaChart();
// areChart.addNewVaryColors().setVal(false);
//
// xssfChart.setTitleText(this.title);
//
// CTValAx[] ctValAx = plotArea.getValAxArray();
// if (ctValAx.length != 0) {
// ctValAx[0].addNewMajorGridlines().addNewSpPr().addNewSolidFill();
// ctValAx[0].getCrossBetween().setVal(STCrossBetween.BETWEEN);
// }
//
// for (CustomChartSeries s : series) {
// s.addToChart(areChart);
// }
//
// for (ChartAxis ax : axis) {
// areChart.addNewAxId().setVal(ax.getId());
// }
if (!(chart instanceof XSSFChart)) {
throw new IllegalArgumentException("Chart must be instance of XSSFChart");
}

final XSSFChart xssfChart = (XSSFChart) chart;
final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
final CTAreaChart areChart = plotArea.addNewAreaChart();
areChart.addNewVaryColors().setVal(false);

xssfChart.setTitleText(this.title);

CTValAx[] ctValAx = plotArea.getValAxArray();
if (ctValAx.length != 0) {
ctValAx[0].addNewMajorGridlines().addNewSpPr().addNewSolidFill();
ctValAx[0].getCrossBetween().setVal(STCrossBetween.BETWEEN);
}

for (CustomChartSeries s : series) {
s.addToChart(areChart);
}

for (ChartAxis ax : axis) {
areChart.addNewAxId().setVal(ax.getId());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
import org.apache.poi.xssf.usermodel.XSSFChart;
import org.apache.xmlbeans.XmlObject;
import org.devgateway.toolkit.web.excelcharts.CustomChartSeries;
import org.devgateway.toolkit.web.excelcharts.util.XSSFChartUtil;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarSer;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
import org.openxmlformats.schemas.drawingml.x2006.chart.STBarDir;
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrossBetween;

/**
* @author idobre
Expand All @@ -14,7 +23,7 @@
* Holds data for a XSSF Bar Chart.
*/
public class XSSFBarChartData extends AbstractXSSFChartData {
//protected STBarDir.Enum barDir = STBarDir.COL;
protected STBarDir.Enum barDir = STBarDir.COL;

public XSSFBarChartData(final String title) {
super(title);
Expand All @@ -26,21 +35,21 @@ protected CustomChartSeries createNewSerie(final int id, final int order, final
return new AbstractSeries(id, order, categories, values) {
@Override
public void addToChart(final XmlObject ctChart) {
// final CTBarChart ctBarChart = (CTBarChart) ctChart;
// final CTBarSer ctBarSer = ctBarChart.addNewSer();
//
// ctBarSer.addNewIdx().setVal(this.id);
// ctBarSer.addNewOrder().setVal(this.order);
//
// final CTAxDataSource catDS = ctBarSer.addNewCat();
// XSSFChartUtil.buildAxDataSource(catDS, this.categories);
//
// final CTNumDataSource valueDS = ctBarSer.addNewVal();
// XSSFChartUtil.buildNumDataSource(valueDS, this.values);
//
// if (isTitleSet()) {
// ctBarSer.setTx(getCTSerTx());
// }
final CTBarChart ctBarChart = (CTBarChart) ctChart;
final CTBarSer ctBarSer = ctBarChart.addNewSer();

ctBarSer.addNewIdx().setVal(this.id);
ctBarSer.addNewOrder().setVal(this.order);

final CTAxDataSource catDS = ctBarSer.addNewCat();
XSSFChartUtil.buildAxDataSource(catDS, this.categories);

final CTNumDataSource valueDS = ctBarSer.addNewVal();
XSSFChartUtil.buildNumDataSource(valueDS, this.values);

if (isTitleSet()) {
ctBarSer.setTx(getCTSerTx());
}
}
};
}
Expand All @@ -50,34 +59,34 @@ public void fillChart(final Chart chart, final ChartAxis... axis) {
if (!(chart instanceof XSSFChart)) {
throw new IllegalArgumentException("Chart must be instance of XSSFChart");
}
//
// final XSSFChart xssfChart = (XSSFChart) chart;
// final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
// final CTBarChart barChart = plotArea.addNewBarChart();
//
// barChart.addNewVaryColors().setVal(false);
//
// // set bars orientation
// barChart.addNewBarDir().setVal(barDir);
//
// xssfChart.setTitleText(this.title);
//
// CTValAx[] ctValAx = plotArea.getValAxArray();
// if (ctValAx.length != 0) {
// ctValAx[0].addNewMajorGridlines().addNewSpPr().addNewSolidFill();
// ctValAx[0].getCrossBetween().setVal(STCrossBetween.BETWEEN);
// }
//
// for (CustomChartSeries s : series) {
// s.addToChart(barChart);
// }
//
// for (ChartAxis ax : axis) {
// barChart.addNewAxId().setVal(ax.getId());
// }

final XSSFChart xssfChart = (XSSFChart) chart;
final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
final CTBarChart barChart = plotArea.addNewBarChart();

barChart.addNewVaryColors().setVal(false);

// set bars orientation
barChart.addNewBarDir().setVal(barDir);

xssfChart.setTitleText(this.title);

CTValAx[] ctValAx = plotArea.getValAxArray();
if (ctValAx.length != 0) {
ctValAx[0].addNewMajorGridlines().addNewSpPr().addNewSolidFill();
ctValAx[0].getCrossBetween().setVal(STCrossBetween.BETWEEN);
}

for (CustomChartSeries s : series) {
s.addToChart(barChart);
}

for (ChartAxis ax : axis) {
barChart.addNewAxId().setVal(ax.getId());
}
}

// public void setBarDir(final STBarDir.Enum barDir) {
// this.barDir = barDir;
// }
public void setBarDir(final STBarDir.Enum barDir) {
this.barDir = barDir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
import org.apache.poi.xssf.usermodel.XSSFChart;
import org.apache.xmlbeans.XmlObject;
import org.devgateway.toolkit.web.excelcharts.CustomChartSeries;
import org.devgateway.toolkit.web.excelcharts.util.XSSFChartUtil;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBubbleChart;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBubbleSer;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;

/**
* @author idobre
Expand All @@ -24,21 +30,21 @@ protected CustomChartSeries createNewSerie(final int id, final int order, final
return new AbstractSeries(id, order, categories, values) {
@Override
public void addToChart(final XmlObject ctChart) {
// final CTBubbleChart ctBubbleChart = (CTBubbleChart) ctChart;
// final CTBubbleSer bubbleSer = ctBubbleChart.addNewSer();
//
// bubbleSer.addNewIdx().setVal(this.id);
// bubbleSer.addNewOrder().setVal(this.order);
//
// final CTAxDataSource catDS = bubbleSer.addNewXVal();
// XSSFChartUtil.buildAxDataSource(catDS, this.categories);
//
// final CTNumDataSource valueDS = bubbleSer.addNewBubbleSize();
// XSSFChartUtil.buildNumDataSource(valueDS, this.values);
//
// if (isTitleSet()) {
// bubbleSer.setTx(getCTSerTx());
// }
final CTBubbleChart ctBubbleChart = (CTBubbleChart) ctChart;
final CTBubbleSer bubbleSer = ctBubbleChart.addNewSer();

bubbleSer.addNewIdx().setVal(this.id);
bubbleSer.addNewOrder().setVal(this.order);

final CTAxDataSource catDS = bubbleSer.addNewXVal();
XSSFChartUtil.buildAxDataSource(catDS, this.categories);

final CTNumDataSource valueDS = bubbleSer.addNewBubbleSize();
XSSFChartUtil.buildNumDataSource(valueDS, this.values);

if (isTitleSet()) {
bubbleSer.setTx(getCTSerTx());
}
}
};
}
Expand All @@ -49,18 +55,18 @@ public void fillChart(final Chart chart, final ChartAxis... axis) {
throw new IllegalArgumentException("Chart must be instance of XSSFChart");
}

// final XSSFChart xssfChart = (XSSFChart) chart;
// final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
// final CTBubbleChart bubbleChart = plotArea.addNewBubbleChart();
//
// for (CustomChartSeries s : series) {
// s.addToChart(bubbleChart);
// }
//
// for (ChartAxis ax : axis) {
// bubbleChart.addNewAxId().setVal(ax.getId());
// }
final XSSFChart xssfChart = (XSSFChart) chart;
final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
final CTBubbleChart bubbleChart = plotArea.addNewBubbleChart();

for (CustomChartSeries s : series) {
s.addToChart(bubbleChart);
}

for (ChartAxis ax : axis) {
bubbleChart.addNewAxId().setVal(ax.getId());
}

// xssfChart.setTitleText(this.title);
xssfChart.setTitleText(this.title);
}
}
Loading

0 comments on commit af469b5

Please sign in to comment.