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());
}
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;
}
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());
}
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));
}
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));
}
}
Aggregations