Search in sources :

Example 1 with ClassPathUriResolver

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()));
}
Also used : ClassPathUriResolver(org.hisp.dhis.webapi.view.ClassPathUriResolver) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams) DataSet(org.hisp.dhis.dataset.DataSet) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1 DataSet (org.hisp.dhis.dataset.DataSet)1 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)1 MetadataExportParams (org.hisp.dhis.dxf2.metadata.MetadataExportParams)1 ClassPathUriResolver (org.hisp.dhis.webapi.view.ClassPathUriResolver)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1