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