Search in sources :

Example 6 with MetadataExportParams

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());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with MetadataExportParams

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());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with MetadataExportParams

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;
}
Also used : MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams)

Example 9 with MetadataExportParams

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

Example 10 with MetadataExportParams

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);
}
Also used : TranslateParams(org.hisp.dhis.dxf2.common.TranslateParams) MetadataExportParams(org.hisp.dhis.dxf2.metadata.MetadataExportParams) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

MetadataExportParams (org.hisp.dhis.dxf2.metadata.MetadataExportParams)8 List (java.util.List)6 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)6 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)3 Query (org.hisp.dhis.query.Query)3 User (org.hisp.dhis.user.User)3 HashMap (java.util.HashMap)2 OrderParams (org.hisp.dhis.dxf2.common.OrderParams)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)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 Map (java.util.Map)1 Transformer (javax.xml.transform.Transformer)1