use of org.openmrs.module.reporting.report.ReportDesign in project openmrs-module-mirebalais by PIH.
the class ReportSetup method setupReport.
/**
* This is only public for testing
* @param manager
*/
public static void setupReport(ReportManager manager, ReportService reportService, ReportDefinitionService reportDefinitionService, AdministrationService administrationService, SerializedObjectDAO serializedObjectDAO) {
if (alreadyAtLatestVersion(manager, administrationService)) {
return;
}
ReportDefinition reportDefinition = manager.constructReportDefinition();
log.info("Saving new definition of " + reportDefinition.getName());
ReportDefinition existing = reportDefinitionService.getDefinitionByUuid(reportDefinition.getUuid());
if (existing != null) {
// we need to overwrite the existing, rather than purge-and-recreate, to avoid deleting old ReportRequests
log.debug("overwriting existing ReportDefinition");
reportDefinition.setId(existing.getId());
// Context.evictFromSession(existing);
} else {
// incompatible class changes for a serialized object could mean that getting the definition return null
// and some serialization error gets logged. In that case we want to overwrite the invalid serialized definition
SerializedObject invalidSerializedObject = serializedObjectDAO.getSerializedObjectByUuid(reportDefinition.getUuid());
if (invalidSerializedObject != null) {
reportDefinition.setId(invalidSerializedObject.getId());
// Context.evictFromSession(invalidSerializedObject);
}
// serializedObjectDAO.purgeObject(invalidSerializedObject.getId());
}
reportDefinitionService.saveDefinition(reportDefinition);
// purging a ReportDesign doesn't trigger any extra logic, so we can just purge-and-recreate here
List<ReportDesign> existingDesigns = reportService.getReportDesigns(reportDefinition, null, true);
if (existingDesigns.size() > 0) {
log.debug("Deleting " + existingDesigns.size() + " old designs for " + reportDefinition.getName());
for (ReportDesign design : existingDesigns) {
reportService.purgeReportDesign(design);
}
}
try {
List<ReportDesign> designs = manager.constructReportDesigns(reportDefinition);
for (ReportDesign design : designs) {
reportService.saveReportDesign(design);
}
administrationService.setGlobalProperty(globalPropertyFor(manager), manager.getVersion());
} catch (IOException ex) {
log.error("Error constructing report design for " + reportDefinition.getName(), ex);
}
}
Aggregations