Search in sources :

Example 1 with ExportParams

use of org.hisp.dhis.dxf2.dataset.ExportParams in project dhis2-core by dhis2.

the class DefaultMetadataVersionService method getMetadataExport.

//--------------------------------------------------------------------------
// Private methods
//--------------------------------------------------------------------------
/**
     * Generates the metadata export based on the created date of the current version.
     */
private ByteArrayOutputStream getMetadataExport(Date minDate) {
    ByteArrayOutputStream os = null;
    try {
        MetadataExportParams exportParams = new MetadataExportParams();
        if (minDate != null) {
            List<String> defaultFilterList = new ArrayList<String>();
            defaultFilterList.add("lastUpdated:gte:" + DateUtils.getLongGmtDateString(minDate));
            exportParams.setDefaultFilter(defaultFilterList);
            metadataExportService.validate(exportParams);
        }
        os = new ByteArrayOutputStream(1024);
        RootNode metadata = metadataExportService.getMetadataAsNode(exportParams);
        nodeService.serialize(metadata, "application/json", os);
    } catch (//We have to catch the "Exception" object as no specific exception on the contract.
    Exception ex) {
        String message = "Exception occurred while exporting metadata for capturing a metadata version" + ex.getMessage();
        log.error(message, ex);
        throw new MetadataVersionServiceException(message, ex);
    }
    return os;
}
Also used : MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) RootNode(org.hisp.dhis.node.types.RootNode) MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with ExportParams

use of org.hisp.dhis.dxf2.dataset.ExportParams in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method getCompleteRegistrationsXml.

// -------------------------------------------------------------------------
// GET
// -------------------------------------------------------------------------
@ApiVersion({ DhisApiVersion.DEFAULT, DhisApiVersion.V26, DhisApiVersion.V27 })
@RequestMapping(method = RequestMethod.GET, produces = CONTENT_TYPE_XML)
public void getCompleteRegistrationsXml(@RequestParam Set<String> dataSet, @RequestParam(required = false) Set<String> period, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false, name = "children") boolean includeChildren, @RequestParam(required = false) Set<String> orgUnit, @RequestParam(required = false) Set<String> orgUnitGroup, @RequestParam(required = false) Date created, @RequestParam(required = false) String createdDuration, @RequestParam(required = false) Integer limit, IdSchemes idSchemes, HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType(CONTENT_TYPE_XML);
    ExportParams params = registrationExchangeService.paramsFromUrl(dataSet, orgUnit, orgUnitGroup, period, startDate, endDate, includeChildren, created, createdDuration, limit, idSchemes);
    registrationExchangeService.writeCompleteDataSetRegistrationsXml(params, response.getOutputStream());
}
Also used : ExportParams(org.hisp.dhis.dxf2.dataset.ExportParams) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ExportParams

use of org.hisp.dhis.dxf2.dataset.ExportParams in project dhis2-core by dhis2.

the class JdbcCompleteDataSetRegistrationExchangeStore method writeCompleteDataSetRegistrationsJson.

@Override
public void writeCompleteDataSetRegistrationsJson(ExportParams params, OutputStream outputStream) {
    CompleteDataSetRegistrations cdsr = new StreamingJsonCompleteDataSetRegistrations(outputStream);
    write(params, cdsr);
    IOUtils.closeQuietly(outputStream);
}
Also used : StreamingJsonCompleteDataSetRegistrations(org.hisp.dhis.dxf2.dataset.streaming.StreamingJsonCompleteDataSetRegistrations) StreamingXmlCompleteDataSetRegistrations(org.hisp.dhis.dxf2.dataset.streaming.StreamingXmlCompleteDataSetRegistrations) StreamingJsonCompleteDataSetRegistrations(org.hisp.dhis.dxf2.dataset.streaming.StreamingJsonCompleteDataSetRegistrations)

Example 4 with ExportParams

use of org.hisp.dhis.dxf2.dataset.ExportParams in project dhis2-core by dhis2.

the class JdbcCompleteDataSetRegistrationExchangeStore method writeCompleteDataSetRegistrationsXml.

//--------------------------------------------------------------------------
// CompleteDataSetRegistrationStore implementation
//--------------------------------------------------------------------------
@Override
public void writeCompleteDataSetRegistrationsXml(ExportParams params, OutputStream outputStream) {
    CompleteDataSetRegistrations cdsr = new StreamingXmlCompleteDataSetRegistrations(XMLFactory.getXMLWriter(outputStream));
    write(params, cdsr);
    IOUtils.closeQuietly(outputStream);
}
Also used : StreamingXmlCompleteDataSetRegistrations(org.hisp.dhis.dxf2.dataset.streaming.StreamingXmlCompleteDataSetRegistrations) StreamingJsonCompleteDataSetRegistrations(org.hisp.dhis.dxf2.dataset.streaming.StreamingJsonCompleteDataSetRegistrations) StreamingXmlCompleteDataSetRegistrations(org.hisp.dhis.dxf2.dataset.streaming.StreamingXmlCompleteDataSetRegistrations)

Example 5 with ExportParams

use of org.hisp.dhis.dxf2.dataset.ExportParams 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

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)2 ExportParams (org.hisp.dhis.dxf2.dataset.ExportParams)2 StreamingJsonCompleteDataSetRegistrations (org.hisp.dhis.dxf2.dataset.streaming.StreamingJsonCompleteDataSetRegistrations)2 StreamingXmlCompleteDataSetRegistrations (org.hisp.dhis.dxf2.dataset.streaming.StreamingXmlCompleteDataSetRegistrations)2 MetadataExportParams (org.hisp.dhis.dxf2.metadata.MetadataExportParams)2 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)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