Search in sources :

Example 21 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class AclServiceTest method testResetSharingPropsPublic.

@Test
void testResetSharingPropsPublic() {
    User user = createAdminUser("F_VISUALIZATION_PUBLIC_ADD");
    Visualization visualization = new Visualization();
    visualization.setAutoFields();
    visualization.setPublicAccess(AccessStringHelper.DEFAULT);
    visualization.setExternalAccess(true);
    visualization.setType(VisualizationType.COLUMN);
    assertFalse(aclService.verifySharing(visualization, user).isEmpty());
    aclService.resetSharing(visualization, user);
    assertTrue(AccessStringHelper.READ_WRITE.equals(visualization.getPublicAccess()));
    assertFalse(visualization.getExternalAccess());
    assertTrue(visualization.getUserAccesses().isEmpty());
    assertTrue(visualization.getUserGroupAccesses().isEmpty());
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) User(org.hisp.dhis.user.User) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 22 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class DefaultReportService method renderReport.

// -------------------------------------------------------------------------
// ReportService implementation
// -------------------------------------------------------------------------
@Override
@Transactional(readOnly = true)
public JasperPrint renderReport(OutputStream out, String reportUid, Period period, String organisationUnitUid, String type) {
    I18nFormat format = i18nManager.getI18nFormat();
    Report report = getReport(reportUid);
    Map<String, Object> params = new HashMap<>();
    params.putAll(constantService.getConstantParameterMap());
    Date reportDate = new Date();
    if (period != null) {
        params.put(PARAM_PERIOD_NAME, format.formatPeriod(period));
        reportDate = period.getStartDate();
    }
    OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(organisationUnitUid);
    if (orgUnit != null) {
        int level = orgUnit.getLevel();
        params.put(PARAM_ORGANISATIONUNIT_COLUMN_NAME, orgUnit.getName());
        params.put(PARAM_ORGANISATIONUNIT_LEVEL, level);
        params.put(PARAM_ORGANISATIONUNIT_LEVEL_COLUMN, ORGUNIT_LEVEL_COLUMN_PREFIX + level);
        params.put(PARAM_ORGANISATIONUNIT_UID_LEVEL_COLUMN, ORGUNIT_UID_LEVEL_COLUMN_PREFIX + level);
    }
    JasperPrint print;
    log.debug(String.format("Get report for report date: '%s', org unit: '%s'", DateUtils.getMediumDateString(reportDate), organisationUnitUid));
    try {
        JasperReport jasperReport = JasperCompileManager.compileReport(IOUtils.toInputStream(report.getDesignContent(), StandardCharsets.UTF_8));
        if (// Use JR data source
        report.hasVisualization()) {
            Visualization visualization = report.getVisualization();
            Grid grid = visualizationService.getVisualizationGrid(visualization.getUid(), reportDate, organisationUnitUid);
            print = JasperFillManager.fillReport(jasperReport, params, grid);
        } else // Use JDBC data source
        {
            if (report.hasRelativePeriods()) {
                AnalyticsFinancialYearStartKey financialYearStart = systemSettingManager.getSystemSetting(SettingKey.ANALYTICS_FINANCIAL_YEAR_START, AnalyticsFinancialYearStartKey.class);
                List<Period> relativePeriods = report.getRelatives().getRelativePeriods(reportDate, null, false, financialYearStart);
                String periodString = getCommaDelimitedString(getIdentifiers(periodService.reloadPeriods(relativePeriods)));
                String isoPeriodString = getCommaDelimitedString(IdentifiableObjectUtils.getUids(relativePeriods));
                params.put(PARAM_RELATIVE_PERIODS, periodString);
                params.put(PARAM_RELATIVE_ISO_PERIODS, isoPeriodString);
            }
            if (report.hasReportParams() && report.getReportParams().isOrganisationUnit() && orgUnit != null) {
                params.put(PARAM_ORG_UNITS, String.valueOf(orgUnit.getId()));
                params.put(PARAM_ORG_UNITS_UID, String.valueOf(orgUnit.getUid()));
            }
            Connection connection = DataSourceUtils.getConnection(dataSource);
            try {
                print = JasperFillManager.fillReport(jasperReport, params, connection);
            } finally {
                DataSourceUtils.releaseConnection(connection, dataSource);
            }
        }
        if (print != null) {
            JRExportUtils.export(type, out, print);
        }
    } catch (Exception ex) {
        throw new RuntimeException("Failed to render report", ex);
    }
    return print;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Visualization(org.hisp.dhis.visualization.Visualization) AnalyticsFinancialYearStartKey(org.hisp.dhis.analytics.AnalyticsFinancialYearStartKey) JasperReport(net.sf.jasperreports.engine.JasperReport) Report(org.hisp.dhis.report.Report) HashMap(java.util.HashMap) JasperPrint(net.sf.jasperreports.engine.JasperPrint) Grid(org.hisp.dhis.common.Grid) Connection(java.sql.Connection) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat) TextUtils.getCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString) JasperReport(net.sf.jasperreports.engine.JasperReport) Date(java.util.Date) JasperPrint(net.sf.jasperreports.engine.JasperPrint) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class DashboardItemDeletionHandlerTest method testDeleteVisualization.

@Test
void testDeleteVisualization() {
    Visualization visualization = createVisualization('A');
    visualizationService.save(visualization);
    dashboardItem.setVisualization(visualization);
    dashboardService.saveDashboard(dashboard);
    assertEquals(1, dashboardService.getVisualizationDashboardItems(visualization).size());
    assertEquals(1, dashboard.getItemCount());
    visualizationService.delete(visualization);
    assertEquals(0, dashboardService.getVisualizationDashboardItems(visualization).size());
    assertEquals(0, dashboard.getItemCount());
}
Also used : EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Visualization(org.hisp.dhis.visualization.Visualization) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 24 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class DashboardServiceTest method testSearchDashboardWithMaxCount.

@Test
void testSearchDashboardWithMaxCount() {
    Program prA = createProgram('A', null, null);
    objectManager.save(prA);
    IntStream.range(1, 30).forEach(i -> {
        Visualization visualization = createVisualization('A');
        visualization.setName(RandomStringUtils.randomAlphabetic(5));
        visualizationService.save(visualization);
    });
    IntStream.range(1, 30).forEach(i -> {
        EventVisualization eventVisualization = createEventVisualization("A", prA);
        eventVisualization.setName(RandomStringUtils.randomAlphabetic(5));
        eventVisualizationService.save(eventVisualization);
    });
    IntStream.range(1, 30).forEach(i -> eventChartService.saveEventChart(createEventChart(prA)));
    DashboardSearchResult result = dashboardService.search(Sets.newHashSet(DashboardItemType.VISUALIZATION));
    assertThat(result.getVisualizationCount(), is(25));
    assertThat(result.getEventChartCount(), is(6));
    result = dashboardService.search(Sets.newHashSet(DashboardItemType.VISUALIZATION), 3, null);
    assertThat(result.getVisualizationCount(), is(25));
    assertThat(result.getEventChartCount(), is(3));
    result = dashboardService.search(Sets.newHashSet(DashboardItemType.VISUALIZATION), 3, 29);
    assertThat(result.getVisualizationCount(), is(29));
    assertThat(result.getEventChartCount(), is(3));
    result = dashboardService.search(Sets.newHashSet(DashboardItemType.EVENT_VISUALIZATION), 3, 29);
    assertThat(result.getEventVisualizationCount(), is(29));
    assertThat(result.getEventReportCount(), is(0));
    result = dashboardService.search(Sets.newHashSet(DashboardItemType.EVENT_VISUALIZATION), 3, 30);
    assertThat(result.getEventVisualizationCount(), is(30));
    assertThat(result.getEventChartCount(), is(3));
}
Also used : EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Visualization(org.hisp.dhis.visualization.Visualization) Program(org.hisp.dhis.program.Program) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 25 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class VisualizationDataController method getVisualizationData.

@GetMapping(value = { "/visualizations/{uid}/data", "/visualizations/{uid}/data.png" })
public void getVisualizationData(@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 {
    final Visualization visualization = visualizationService.getVisualizationNoAcl(uid);
    if (visualization == null) {
        throw new WebMessageException(notFound("Visualization does not exist: " + uid));
    }
    if (visualization.isChart() && isChartSupported(visualization.getType())) {
        OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit(ou) : null;
        JFreeChart jFreeChart = chartService.getJFreeChart(new PlotData(visualization), date, unit, i18nManager.getI18nFormat(), currentUserService.getCurrentUser());
        String filename = CodecUtils.filenameEncode(visualization.getName()) + ".png";
        contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, attachment);
        ChartUtils.writeChartAsPNG(response.getOutputStream(), jFreeChart, width, height);
    } else {
        response.setContentType(CONTENT_TYPE_JSON);
        renderService.toJson(response.getOutputStream(), getReportTableGrid(uid, ou, date));
    }
}
Also used : PlotData(org.hisp.dhis.visualization.PlotData) Visualization(org.hisp.dhis.visualization.Visualization) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) JFreeChart(org.jfree.chart.JFreeChart) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Visualization (org.hisp.dhis.visualization.Visualization)48 Test (org.junit.jupiter.api.Test)36 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)26 DhisSpringTest (org.hisp.dhis.DhisSpringTest)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)14 User (org.hisp.dhis.user.User)13 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)7 DataElement (org.hisp.dhis.dataelement.DataElement)6 List (java.util.List)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 Period (org.hisp.dhis.period.Period)4 Date (java.util.Date)3 Dashboard (org.hisp.dhis.dashboard.Dashboard)3 DataSet (org.hisp.dhis.dataset.DataSet)3 ErrorReport (org.hisp.dhis.feedback.ErrorReport)3 UserAccess (org.hisp.dhis.user.sharing.UserAccess)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 ArrayList (java.util.ArrayList)2