Search in sources :

Example 26 with ComplexNode

use of org.hisp.dhis.node.types.ComplexNode 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 27 with ComplexNode

use of org.hisp.dhis.node.types.ComplexNode 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)

Example 28 with ComplexNode

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

the class AbstractNodeSerializer method writeComplexNode.

protected void writeComplexNode(ComplexNode complexNode) throws Exception {
    if (!config.getInclusionStrategy().include(complexNode.getChildren())) {
        return;
    }
    startWriteComplexNode(complexNode);
    for (Node node : complexNode.getChildren()) {
        dispatcher(node);
        flushStream();
    }
    endWriteComplexNode(complexNode);
}
Also used : SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RootNode(org.hisp.dhis.node.types.RootNode)

Example 29 with ComplexNode

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

the class PluckNodeTransformerTest method setUp.

@BeforeEach
public void setUp() {
    schemaService = new DefaultSchemaService(new DefaultPropertyIntrospectorService(new JacksonPropertyIntrospector()), sessionFactory);
    collectionNode = new CollectionNode("organisationUnits", 2);
    collectionNode.setNamespace("testUrn");
    collectionNode.setProperty(schemaService.getDynamicSchema(CategoryOption.class).getProperty("organisationUnits"));
    ComplexNode complexNode = new ComplexNode("organisationUnit");
    SimpleNode simpleNode = new SimpleNode("id", schemaService.getDynamicSchema(Category.class).getProperty("id"), "abc1");
    complexNode.addChild(simpleNode);
    simpleNode = new SimpleNode("name", schemaService.getDynamicSchema(Category.class).getProperty("id"), "OU 1");
    complexNode.addChild(simpleNode);
    collectionNode.addChild(complexNode);
    complexNode = new ComplexNode("organisationUnit");
    simpleNode = new SimpleNode("id", schemaService.getDynamicSchema(Category.class).getProperty("id"), "abc2");
    complexNode.addChild(simpleNode);
    simpleNode = new SimpleNode("name", schemaService.getDynamicSchema(Category.class).getProperty("id"), "OU 2");
    complexNode.addChild(simpleNode);
    collectionNode.addChild(complexNode);
}
Also used : Category(org.hisp.dhis.category.Category) ComplexNode(org.hisp.dhis.node.types.ComplexNode) DefaultSchemaService(org.hisp.dhis.schema.DefaultSchemaService) CollectionNode(org.hisp.dhis.node.types.CollectionNode) JacksonPropertyIntrospector(org.hisp.dhis.schema.introspection.JacksonPropertyIntrospector) DefaultPropertyIntrospectorService(org.hisp.dhis.schema.DefaultPropertyIntrospectorService) SimpleNode(org.hisp.dhis.node.types.SimpleNode) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 30 with ComplexNode

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

the class DefaultFieldFilterServiceTest method baseIdentifiableName.

@Test
void baseIdentifiableName() {
    final OrganisationUnit ou1 = new OrganisationUnit();
    ou1.setUid("abc1");
    ou1.setName("OU 1");
    final OrganisationUnit ou2 = new OrganisationUnit();
    ou2.setUid("abc2");
    ou2.setName("OU 2");
    final CategoryOption option = new CategoryOption();
    option.setUid("def1");
    option.getOrganisationUnits().add(ou1);
    option.getOrganisationUnits().add(ou2);
    final FieldFilterParams params = new FieldFilterParams(Collections.singletonList(option), Arrays.asList("id", "organisationUnits~pluck(name)[id,name]"));
    final ComplexNode node = service.toComplexNode(params);
    Assertions.assertEquals("categoryOption", node.getName());
    Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "id") instanceof SimpleNode);
    Assertions.assertEquals("def1", ((SimpleNode) getNamedNode(node.getUnorderedChildren(), "id")).getValue());
    Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "organisationUnits") instanceof CollectionNode);
    final CollectionNode collectionNode = (CollectionNode) getNamedNode(node.getUnorderedChildren(), "organisationUnits");
    Assertions.assertEquals(2, collectionNode.getUnorderedChildren().size());
    final List<String> ouIds = new ArrayList<>();
    Assertions.assertTrue(collectionNode.getUnorderedChildren().get(0) instanceof SimpleNode);
    SimpleNode simpleNode = (SimpleNode) collectionNode.getUnorderedChildren().get(0);
    Assertions.assertEquals("name", simpleNode.getName());
    ouIds.add(String.valueOf(simpleNode.getValue()));
    Assertions.assertTrue(collectionNode.getUnorderedChildren().get(1) instanceof SimpleNode);
    simpleNode = (SimpleNode) collectionNode.getUnorderedChildren().get(1);
    Assertions.assertEquals("name", simpleNode.getName());
    ouIds.add(String.valueOf(simpleNode.getValue()));
    assertThat(ouIds, Matchers.containsInAnyOrder("OU 1", "OU 2"));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) Test(org.junit.jupiter.api.Test)

Aggregations

ComplexNode (org.hisp.dhis.node.types.ComplexNode)33 SimpleNode (org.hisp.dhis.node.types.SimpleNode)23 CollectionNode (org.hisp.dhis.node.types.CollectionNode)21 RootNode (org.hisp.dhis.node.types.RootNode)15 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)5 Node (org.hisp.dhis.node.Node)5 CategoryOption (org.hisp.dhis.category.CategoryOption)4 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Schema (org.hisp.dhis.schema.Schema)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)3 Property (org.hisp.dhis.schema.Property)3 Collection (java.util.Collection)2 Category (org.hisp.dhis.category.Category)2