Search in sources :

Example 6 with ComplexNode

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());
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

Example 7 with ComplexNode

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);
}
Also used : ComplexNode(org.hisp.dhis.node.types.ComplexNode) Test(org.junit.jupiter.api.Test)

Example 8 with ComplexNode

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;
}
Also used : ComplexNode(org.hisp.dhis.node.types.ComplexNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) RootNode(org.hisp.dhis.node.types.RootNode) ArrayList(java.util.ArrayList) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 9 with ComplexNode

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);
}
Also used : ComplexNode(org.hisp.dhis.node.types.ComplexNode) Test(org.junit.jupiter.api.Test)

Example 10 with ComplexNode

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;
}
Also used : ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

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