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