Search in sources :

Example 76 with RootNode

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

the class DefaultMetadataVersionServiceTest method testShouldCreateAValidVersionsNodeTree.

@Test
public void testShouldCreateAValidVersionsNodeTree() throws Exception {
    List<MetadataVersion> versions = new ArrayList<>();
    versions.add(new MetadataVersion("test_version1", VersionType.ATOMIC));
    versions.add(new MetadataVersion("test_version2", VersionType.BEST_EFFORT));
    versions.add(new MetadataVersion("test_version3", VersionType.BEST_EFFORT));
    RootNode root = versionService.getMetadataVersionsAsNode(versions);
    ComplexNode[] versionNodes = getVersionFromNodeTree(root);
    for (int i = 0; i < versionNodes.length; i++) {
        assertEquals(versions.get(i).getName(), ((SimpleNode) versionNodes[i].getChildren().get(0)).getValue());
        assertEquals(versions.get(i).getType(), ((SimpleNode) versionNodes[i].getChildren().get(1)).getValue());
    }
    assertEquals(versions.size(), versionNodes.length);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 77 with RootNode

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

the class DefaultMetadataVersionServiceTest method testShouldCreateNodesWith_Name_Type_CreatedId_ImportDate.

@Test
public void testShouldCreateNodesWith_Name_Type_CreatedId_ImportDate() throws Exception {
    MetadataVersion version = new MetadataVersion("test_version1", VersionType.ATOMIC);
    version.setUid("myId");
    Date date = new Date();
    version.setImportDate(date);
    version.setCreated(date);
    version.setHashCode("2asda2d31asd3ads3dadasd");
    List<MetadataVersion> versions = new ArrayList<>();
    versions.add(version);
    RootNode root = versionService.getMetadataVersionsAsNode(versions);
    ComplexNode[] versionNodes = getVersionFromNodeTree(root);
    assertEquals(version.getName(), ((SimpleNode) versionNodes[0].getChildren().get(0)).getValue());
    assertEquals(version.getType(), ((SimpleNode) versionNodes[0].getChildren().get(1)).getValue());
    assertEquals(version.getCreated(), ((SimpleNode) versionNodes[0].getChildren().get(2)).getValue());
    assertEquals(version.getUid(), ((SimpleNode) versionNodes[0].getChildren().get(3)).getValue());
    assertEquals(version.getImportDate(), ((SimpleNode) versionNodes[0].getChildren().get(4)).getValue());
    assertEquals(version.getHashCode(), ((SimpleNode) versionNodes[0].getChildren().get(5)).getValue());
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 78 with RootNode

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

the class AuditController method getTrackedEntityDataValueAudit.

@RequestMapping(value = "trackedEntityDataValue", method = RequestMethod.GET)
@ResponseBody
public RootNode getTrackedEntityDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> psi, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<DataElement> dataElements = getDataElements(de);
    List<ProgramStageInstance> programStageInstances = getProgramStageInstances(psi);
    List<TrackedEntityDataValueAudit> dataValueAudits;
    Pager pager = null;
    if (skipPaging) {
        dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
    } else {
        int total = trackedEntityDataValueAuditService.countTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
        pager = new Pager(page, total, pageSize);
        dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType, pager.getOffset(), pager.getPageSize());
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityDataValueAudits", true));
    trackedEntityAttributeValueAudits.addChildren(fieldFilterService.filter(TrackedEntityDataValueAudit.class, dataValueAudits, fields).getChildren());
    return rootNode;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) CollectionNode(org.hisp.dhis.node.types.CollectionNode) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 79 with RootNode

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

the class AbstractNodeTest method testRootNodeEquals.

@Test
void testRootNodeEquals() {
    final RootNode rootNode1 = createRootNode(NODE_1, "propName1", "propValue1");
    final RootNode rootNode2 = createRootNode(NODE_1, "propName1", "propValue1");
    assertEquals(rootNode1, rootNode2);
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Test(org.junit.jupiter.api.Test)

Example 80 with RootNode

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

the class UserPropertyTransformerTest method testFieldNodeServiceSerializerPresetStar.

@Test
void testFieldNodeServiceSerializerPresetStar() 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[*],users[*]"));
    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)

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