use of org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException in project dhis2-core by dhis2.
the class MetadataVersionController method downloadGZipVersion.
//endpoint to download metadata in gzip format
@PreAuthorize("hasRole('ALL') or hasRole('F_METADATA_MANAGE')")
@RequestMapping(value = MetadataVersionSchemaDescriptor.API_ENDPOINT + "/{versionName}/data.gz", method = RequestMethod.GET, produces = "*/*")
public void downloadGZipVersion(@PathVariable("versionName") String versionName, HttpServletResponse response) throws MetadataVersionException, IOException, BadRequestException {
boolean enabled = isMetadataVersioningEnabled();
try {
if (!enabled) {
throw new BadRequestException("Metadata versioning is not enabled for this instance.");
}
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metadata.json.gz", true);
response.addHeader(ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
String versionData = versionService.getVersionData(versionName);
if (versionData == null) {
throw new MetadataVersionException("No metadata version snapshot found for the given version " + versionName);
}
GZIPOutputStream gos = new GZIPOutputStream(response.getOutputStream());
gos.write(versionData.getBytes(StandardCharsets.UTF_8));
gos.close();
} catch (MetadataVersionServiceException ex) {
throw new MetadataVersionException("Unable to download version from system: " + versionName + ex.getMessage());
}
}
Aggregations