Search in sources :

Example 26 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class DefaultDataValueSetService method getDataValueSetTemplate.

// -------------------------------------------------------------------------
// Template
// -------------------------------------------------------------------------
@Override
public RootNode getDataValueSetTemplate(DataSet dataSet, Period period, List<String> orgUnits, boolean writeComments, String ouScheme, String deScheme) {
    RootNode rootNode = new RootNode("dataValueSet");
    rootNode.setNamespace(DxfNamespaces.DXF_2_0);
    rootNode.setComment("Data set: " + dataSet.getDisplayName() + " (" + dataSet.getUid() + ")");
    CollectionNode collectionNode = rootNode.addChild(new CollectionNode("dataValues"));
    collectionNode.setWrapping(false);
    if (orgUnits.isEmpty()) {
        for (DataElement dataElement : dataSet.getDataElements()) {
            CollectionNode collection = getDataValueTemplate(dataElement, deScheme, null, ouScheme, period, writeComments);
            collectionNode.addChildren(collection.getChildren());
        }
    } else {
        for (String orgUnit : orgUnits) {
            OrganisationUnit organisationUnit = identifiableObjectManager.search(OrganisationUnit.class, orgUnit);
            if (organisationUnit == null) {
                continue;
            }
            for (DataElement dataElement : dataSet.getDataElements()) {
                CollectionNode collection = getDataValueTemplate(dataElement, deScheme, organisationUnit, ouScheme, period, writeComments);
                collectionNode.addChildren(collection.getChildren());
            }
        }
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

Example 27 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class UserPropertyTransformerTest method testFieldNodeServiceSerializer.

@Test
void testFieldNodeServiceSerializer() throws JsonProcessingException {
    Simple simple = new Simple(1, "Simple1");
    simple.setUser(createUser('a'));
    simple.getUser().setUuid(uuid);
    simple.getUsers().add(createUser('A'));
    simple.getUsers().add(createUser('B'));
    simple.getUsers().add(createUser('C'));
    simple.getUsers().add(createUser('D'));
    ComplexNode complexNode = nodeService.toNode(simple);
    RootNode rootNode = NodeUtils.createRootNode(complexNode);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    nodeService.serialize(rootNode, "application/json", outputStream);
    String jsonSource = outputStream.toString();
    verifyJsonSource(jsonSource);
    Simple simpleFromJson = jsonMapper.readValue(jsonSource, Simple.class);
    assertEquals(1, simpleFromJson.getId());
    assertEquals("Simple1", simpleFromJson.getName());
    assertNotNull(simple.getUser());
    assertEquals("usernamea", simple.getUser().getUsername());
    assertEquals(uuid, simple.getUser().getUuid());
    assertNotNull(simple.getUsers());
    assertEquals(4, simple.getUsers().size());
    FieldFilterParams params = new FieldFilterParams(Collections.singletonList(simple), Collections.singletonList("id,name,user[id,code],users[id,code]"));
    fieldFilterService.toComplexNode(params);
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 28 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class UserPropertyTransformerTest method testNodeServiceSerializer.

@Test
void testNodeServiceSerializer() throws JsonProcessingException {
    Simple simple = new Simple(1, "Simple1");
    simple.setUser(createUser('a'));
    simple.getUser().setUuid(uuid);
    ComplexNode complexNode = nodeService.toNode(simple);
    RootNode rootNode = NodeUtils.createRootNode(complexNode);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    nodeService.serialize(rootNode, "application/json", outputStream);
    String jsonSource = outputStream.toString();
    verifyJsonSource(jsonSource);
    Simple simpleFromJson = jsonMapper.readValue(jsonSource, Simple.class);
    assertEquals(1, simpleFromJson.getId());
    assertEquals("Simple1", simpleFromJson.getName());
    assertNotNull(simple.getUser());
    assertEquals("usernamea", simple.getUser().getUsername());
    assertEquals(uuid, simple.getUser().getUuid());
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 29 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class NodeUtils method createMetadata.

public static RootNode createMetadata() {
    RootNode rootNode = new RootNode("metadata");
    rootNode.setDefaultNamespace(DxfNamespaces.DXF_2_0);
    rootNode.setNamespace(DxfNamespaces.DXF_2_0);
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode)

Example 30 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class NodeUtils method createEvents.

public static RootNode createEvents() {
    RootNode rootNode = new RootNode("events");
    rootNode.setDefaultNamespace(DxfNamespaces.DXF_2_0);
    rootNode.setNamespace(DxfNamespaces.DXF_2_0);
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode)

Aggregations

RootNode (org.hisp.dhis.node.types.RootNode)112 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)59 CollectionNode (org.hisp.dhis.node.types.CollectionNode)50 SimpleNode (org.hisp.dhis.node.types.SimpleNode)40 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)30 GetMapping (org.springframework.web.bind.annotation.GetMapping)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 Pager (org.hisp.dhis.common.Pager)26 User (org.hisp.dhis.user.User)25 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)24 ComplexNode (org.hisp.dhis.node.types.ComplexNode)20 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)17 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)15 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 Node (org.hisp.dhis.node.Node)11 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)10 List (java.util.List)9 Query (org.hisp.dhis.query.Query)9 DataSet (org.hisp.dhis.dataset.DataSet)7