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