use of org.hisp.dhis.dxf2.metadata.MetadataExportParams in project dhis2-core by dhis2.
the class MetadataExportServiceTest method testMetadataExportWithCustomClasses.
@Test
public void testMetadataExportWithCustomClasses() {
DataElementGroup deg1 = createDataElementGroup('A');
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
manager.save(de1);
manager.save(de2);
manager.save(de3);
User user = createUser('A');
manager.save(user);
deg1.addDataElement(de1);
deg1.addDataElement(de2);
deg1.addDataElement(de3);
deg1.setUser(user);
manager.save(deg1);
MetadataExportParams params = new MetadataExportParams();
params.addClass(DataElement.class);
Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = metadataExportService.getMetadata(params);
assertFalse(metadata.containsKey(User.class));
assertFalse(metadata.containsKey(DataElementGroup.class));
assertTrue(metadata.containsKey(DataElement.class));
assertEquals(3, metadata.get(DataElement.class).size());
}
use of org.hisp.dhis.dxf2.metadata.MetadataExportParams in project dhis2-core by dhis2.
the class MetadataExportServiceTest method testMetadataExport.
@Test
public void testMetadataExport() {
DataElementGroup deg1 = createDataElementGroup('A');
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
manager.save(de1);
manager.save(de2);
manager.save(de3);
User user = createUser('A');
manager.save(user);
deg1.addDataElement(de1);
deg1.addDataElement(de2);
deg1.addDataElement(de3);
deg1.setUser(user);
manager.save(deg1);
MetadataExportParams params = new MetadataExportParams();
Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = metadataExportService.getMetadata(params);
assertEquals(1, metadata.get(User.class).size());
assertEquals(1, metadata.get(DataElementGroup.class).size());
assertEquals(3, metadata.get(DataElement.class).size());
}
use of org.hisp.dhis.dxf2.metadata.MetadataExportParams in project dhis2-core by dhis2.
the class DataSetController method filterMetadataOptions.
/**
* Select only the meta-data required to describe form definitions.
*
* @return the filtered options.
*/
private MetadataExportParams filterMetadataOptions() {
MetadataExportParams params = new MetadataExportParams();
params.addQuery(Query.from(schemaService.getSchema(DataElement.class)));
params.addQuery(Query.from(schemaService.getSchema(DataSet.class)));
params.addQuery(Query.from(schemaService.getSchema(DataElementCategoryOptionCombo.class)));
return params;
}
use of org.hisp.dhis.dxf2.metadata.MetadataExportParams 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()));
}
use of org.hisp.dhis.dxf2.metadata.MetadataExportParams in project dhis2-core by dhis2.
the class MetadataExportController method getMetadata.
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public RootNode getMetadata(@RequestParam(required = false, defaultValue = "false") boolean translate, @RequestParam(required = false) String locale) {
if (translate) {
TranslateParams translateParams = new TranslateParams(true, locale);
setUserContext(currentUserService.getCurrentUser(), translateParams);
}
MetadataExportParams params = metadataExportService.getParamsFromMap(contextService.getParameterValuesMap());
metadataExportService.validate(params);
return metadataExportService.getMetadataAsNode(params);
}
Aggregations