use of org.hisp.dhis.node.types.ComplexNode in project dhis2-core by dhis2.
the class MeController method getCurrentUser.
@RequestMapping(value = "", method = RequestMethod.GET)
public void getCurrentUser(HttpServletResponse response) throws Exception {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
CollectionNode collectionNode = fieldFilterService.filter(User.class, Collections.singletonList(currentUser), fields);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
RootNode rootNode = NodeUtils.createRootNode(collectionNode.getChildren().get(0));
if (fieldsContains("settings", fields)) {
rootNode.addChild(new ComplexNode("settings")).addChildren(NodeUtils.createSimples(userSettingService.getUserSettingsWithFallbackByUserAsMap(currentUser, USER_SETTING_NAMES, true)));
}
if (fieldsContains("authorities", fields)) {
rootNode.addChild(new CollectionNode("authorities")).addChildren(NodeUtils.createSimples(currentUser.getUserCredentials().getAllAuthorities()));
}
nodeService.serialize(rootNode, "application/json", response.getOutputStream());
}
use of org.hisp.dhis.node.types.ComplexNode in project dhis2-core by dhis2.
the class AbstractNodeTest method testComplexNodeNotEquals.
@Test
void testComplexNodeNotEquals() {
// Instantiating object 1
ComplexNode complexNode1 = createComplexNode(NODE_1);
// Instantiating object 2
ComplexNode complexNode2 = createComplexNode(NODE_2);
assertNotEquals(complexNode1, complexNode2);
}
use of org.hisp.dhis.node.types.ComplexNode in project dhis2-core by dhis2.
the class AbstractNodeTest method createComplexNode.
private ComplexNode createComplexNode(String node1) {
ComplexNode complexNode1;
List<Node> children1 = new ArrayList<>();
children1.add(new SimpleNode("id", node1));
complexNode1 = new ComplexNode("dataElement");
complexNode1.setMetadata(false);
complexNode1.setChildren(children1);
return complexNode1;
}
use of org.hisp.dhis.node.types.ComplexNode in project dhis2-core by dhis2.
the class AbstractNodeTest method testComplexNodeEquals.
@Test
void testComplexNodeEquals() {
// Instantiating object 1
ComplexNode complexNode1 = createComplexNode(NODE_1);
// Instantiating object 2
ComplexNode complexNode2 = createComplexNode(NODE_1);
assertEquals(complexNode1, complexNode2);
}
use of org.hisp.dhis.node.types.ComplexNode in project dhis2-core by dhis2.
the class DefaultDataValueSetService method getDataValueTemplate.
private CollectionNode getDataValueTemplate(DataElement dataElement, String deScheme, OrganisationUnit organisationUnit, String ouScheme, Period period, boolean comment) {
CollectionNode collectionNode = new CollectionNode("dataValues");
collectionNode.setWrapping(false);
for (CategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
ComplexNode complexNode = collectionNode.addChild(new ComplexNode("dataValue"));
String label = dataElement.getDisplayName();
if (!categoryOptionCombo.isDefault()) {
label += " " + categoryOptionCombo.getDisplayName();
}
if (comment) {
complexNode.setComment("Data element: " + label);
}
if (IdentifiableProperty.CODE.toString().toLowerCase().equals(deScheme.toLowerCase())) {
SimpleNode simpleNode = complexNode.addChild(new SimpleNode("dataElement", dataElement.getCode()));
simpleNode.setAttribute(true);
} else {
SimpleNode simpleNode = complexNode.addChild(new SimpleNode("dataElement", dataElement.getUid()));
simpleNode.setAttribute(true);
}
SimpleNode simpleNode = complexNode.addChild(new SimpleNode("categoryOptionCombo", categoryOptionCombo.getUid()));
simpleNode.setAttribute(true);
simpleNode = complexNode.addChild(new SimpleNode("period", period != null ? period.getIsoDate() : ""));
simpleNode.setAttribute(true);
if (organisationUnit != null) {
if (IdentifiableProperty.CODE.toString().equalsIgnoreCase(ouScheme)) {
simpleNode = complexNode.addChild(new SimpleNode("orgUnit", organisationUnit.getCode() == null ? "" : organisationUnit.getCode()));
simpleNode.setAttribute(true);
} else {
simpleNode = complexNode.addChild(new SimpleNode("orgUnit", organisationUnit.getUid() == null ? "" : organisationUnit.getUid()));
simpleNode.setAttribute(true);
}
}
simpleNode = complexNode.addChild(new SimpleNode("value", ""));
simpleNode.setAttribute(true);
}
return collectionNode;
}
Aggregations