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;
}
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());
}
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);
}
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);
}
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()));
}
Aggregations