Search in sources :

Example 31 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class EventVisualizationController method generateChart.

@GetMapping(value = { "/{uid}/data", "/{uid}/data.png" })
void generateChart(@PathVariable("uid") String uid, @RequestParam(value = "date", required = false) Date date, @RequestParam(value = "ou", required = false) String ou, @RequestParam(value = "width", defaultValue = "800", required = false) int width, @RequestParam(value = "height", defaultValue = "500", required = false) int height, @RequestParam(value = "attachment", required = false) boolean attachment, HttpServletResponse response) throws IOException, WebMessageException {
    // TODO no acl?
    final EventVisualization eventVisualization = eventVisualizationService.getEventVisualization(uid);
    if (eventVisualization == null) {
        throw new WebMessageException(notFound("Event visualization does not exist: " + uid));
    }
    doesNotAllowPivotAndReportChart(eventVisualization);
    final OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit(ou) : null;
    final JFreeChart jFreeChart = chartService.getJFreeChart(new PlotData(eventVisualization), date, unit, i18nManager.getI18nFormat());
    final String filename = filenameEncode(eventVisualization.getName()) + ".png";
    contextUtils.configureResponse(response, CONTENT_TYPE_PNG, RESPECT_SYSTEM_SETTING, filename, attachment);
    writeChartAsPNG(response.getOutputStream(), jFreeChart, width, height);
}
Also used : PlotData(org.hisp.dhis.visualization.PlotData) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) JFreeChart(org.jfree.chart.JFreeChart) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)31 Test (org.junit.jupiter.api.Test)20 DhisSpringTest (org.hisp.dhis.DhisSpringTest)11 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)7 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)7 User (org.hisp.dhis.user.User)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Program (org.hisp.dhis.program.Program)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 JpaQueryParameters (org.hisp.dhis.hibernate.JpaQueryParameters)3 Interpretation (org.hisp.dhis.interpretation.Interpretation)3 UserAccess (org.hisp.dhis.user.sharing.UserAccess)3 ArrayList (java.util.ArrayList)2 Function (java.util.function.Function)2 Dashboard (org.hisp.dhis.dashboard.Dashboard)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 EventChart (org.hisp.dhis.eventchart.EventChart)2 EventReport (org.hisp.dhis.eventreport.EventReport)2 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2