use of org.hisp.dhis.webapi.view.ClassPathUriResolver in project dhis2-core by dhis2.
the class DataSetController method getStructureDefinition.
// -------------------------------------------------------------------------
// Controller
// -------------------------------------------------------------------------
@SuppressWarnings("unchecked")
@RequestMapping(produces = "application/dsd+xml")
public void getStructureDefinition(@RequestParam Map<String, String> parameters, HttpServletResponse response) throws IOException, TransformerException {
MetadataExportParams exportParams = filterMetadataOptions();
Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadataMap = exportService.getMetadata(exportParams);
Metadata metadata = new Metadata();
metadata.setDataElements((List<DataElement>) metadataMap.get(DataElement.class));
metadata.setDataSets((List<DataSet>) metadataMap.get(DataSet.class));
metadata.setCategoryOptionCombos((List<DataElementCategoryOptionCombo>) metadataMap.get(DataElementCategoryOptionCombo.class));
InputStream input = new ByteArrayInputStream(DefaultRenderService.getXmlMapper().writeValueAsString(metadata).getBytes("UTF-8"));
TransformerFactory tf = TransformerFactory.newInstance();
tf.setURIResolver(new ClassPathUriResolver());
Transformer transformer = tf.newTransformer(new StreamSource(new ClassPathResource(DSD_TRANSFORM).getInputStream()));
transformer.transform(new StreamSource(input), new StreamResult(response.getOutputStream()));
}
Aggregations