use of org.hisp.dhis.report.Report in project dhis2-core by dhis2.
the class DashboardTest method testGetAvailableItemByType.
@Test
public void testGetAvailableItemByType() {
Dashboard dashboard = new Dashboard();
DashboardItem diA = new DashboardItem();
DashboardItem diB = new DashboardItem();
DashboardItem diC = new DashboardItem();
diA.setUid("A");
diB.setUid("B");
diC.setUid("C");
diA.setChart(new Chart("A"));
diB.getReports().add(new Report("A", null, null, null));
diB.getReports().add(new Report("B", null, null, null));
diC.getResources().add(new Document("A", null, false, null));
diC.getResources().add(new Document("B", null, false, null));
diC.getResources().add(new Document("C", null, false, null));
dashboard.getItems().add(diA);
dashboard.getItems().add(diB);
dashboard.getItems().add(diC);
assertEquals(diB, dashboard.getAvailableItemByType(DashboardItemType.REPORTS));
assertEquals(diC, dashboard.getAvailableItemByType(DashboardItemType.RESOURCES));
assertNull(dashboard.getAvailableItemByType(DashboardItemType.MAP));
}
use of org.hisp.dhis.report.Report in project dhis2-core by dhis2.
the class DefaultReportService method renderReport.
// -------------------------------------------------------------------------
// ReportService implementation
// -------------------------------------------------------------------------
@Override
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 = null;
try {
JasperReport jasperReport = JasperCompileManager.compileReport(IOUtils.toInputStream(report.getDesignContent(), StandardCharsets.UTF_8));
if (// Use JR data source
report.hasReportTable()) {
ReportTable reportTable = report.getReportTable();
Grid grid = reportTableService.getReportTableGrid(reportTable.getUid(), reportDate, organisationUnitUid);
print = JasperFillManager.fillReport(jasperReport, params, grid);
} else // Use JDBC data source
{
if (report.hasRelativePeriods()) {
List<Period> relativePeriods = report.getRelatives().getRelativePeriods(reportDate, null, false);
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().isParamOrganisationUnit() && 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.report.Report in project dhis2-core by dhis2.
the class GetReportParamsAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
if (mode == null || uid == null) {
return SUCCESS;
}
RelativePeriods relatives = null;
if (MODE_REPORT_TABLE.equals(mode)) {
ReportTable reportTable = reportTableService.getReportTable(uid);
if (reportTable != null) {
reportParams = reportTable.getReportParams();
relatives = reportTable.getRelatives();
}
} else if (MODE_REPORT.equals(mode)) {
Report report = reportService.getReport(uid);
if (report != null && report.isTypeReportTable()) {
reportParams = report.getReportTable().getReportParams();
relatives = report.getReportTable().getRelatives();
} else if (report != null && (report.isTypeJdbc() || report.isTypeHtml())) {
reportParams = report.getReportParams();
relatives = report.getRelatives();
}
if (type == null && report != null) {
// Set type based on report
type = report.getType();
}
}
if (reportParams != null && reportParams.isParamReportingMonth() && relatives != null) {
CalendarPeriodType periodType = (CalendarPeriodType) relatives.getPeriodType();
List<Period> periods = periodType.generateLast5Years(new Date());
Collections.reverse(periods);
FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
Calendar calendar = PeriodType.getCalendar();
for (Period period_ : periods) {
BaseIdentifiableObject period = new BaseIdentifiableObject();
if (calendar.isIso8601()) {
period.setUid(period_.getIsoDate());
period.setDisplayName(format.formatPeriod(period_));
} else {
DateTimeUnit dateTimeUnit = calendar.fromIso(period_.getStartDate());
period.setUid(period_.getPeriodType().getIsoDate(dateTimeUnit));
period.setDisplayName(format.formatPeriod(period_));
}
this.periods.add(period);
}
}
return SUCCESS;
}
use of org.hisp.dhis.report.Report in project dhis2-core by dhis2.
the class ReportController method getReportDesign.
@RequestMapping(value = "/{uid}/design", method = RequestMethod.GET)
public void getReportDesign(@PathVariable("uid") String uid, HttpServletResponse response) throws Exception {
Report report = reportService.getReport(uid);
if (report == null) {
throw new WebMessageException(WebMessageUtils.notFound("Report not found for identifier: " + uid));
}
if (report.getDesignContent() == null) {
throw new WebMessageException(WebMessageUtils.conflict("Report has no design content: " + uid));
}
if (report.isTypeHtml()) {
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.NO_CACHE, filenameEncode(report.getName()) + ".html", true);
} else {
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE, filenameEncode(report.getName()) + ".jrxml", true);
}
response.getWriter().write(report.getDesignContent());
}
use of org.hisp.dhis.report.Report in project dhis2-core by dhis2.
the class ReportController method updateReportDesign.
// -------------------------------------------------------------------------
// CRUD
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/design", method = RequestMethod.PUT)
@PreAuthorize("hasRole('ALL')")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateReportDesign(@PathVariable("uid") String uid, @RequestBody String designContent, HttpServletResponse response) throws Exception {
Report report = reportService.getReport(uid);
if (report == null) {
throw new WebMessageException(WebMessageUtils.notFound("Report not found for identifier: " + uid));
}
report.setDesignContent(designContent);
reportService.saveReport(report);
}
Aggregations