Search in sources :

Example 11 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.

the class SystemController method getObjectCounts.

@RequestMapping(value = "/objectCounts", method = RequestMethod.GET)
@ResponseBody
public RootNode getObjectCounts() {
    Map<Objects, Integer> objectCounts = statisticsProvider.getObjectCounts();
    RootNode rootNode = NodeUtils.createRootNode("objectCounts");
    for (Objects objects : objectCounts.keySet()) {
        rootNode.addChild(new SimpleNode(objects.getValue(), objectCounts.get(objects)));
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Objects(org.hisp.dhis.common.Objects) SimpleNode(org.hisp.dhis.node.types.SimpleNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.

the class MessageConversationController method removeUserFromMessageConversation.

//--------------------------------------------------------------------------
// Remove a user from a MessageConversation
// In practice a DELETE on MessageConversation <-> User relationship
//--------------------------------------------------------------------------
@RequestMapping(value = "/{mc-uid}/{user-uid}", method = RequestMethod.DELETE, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode removeUserFromMessageConversation(@PathVariable(value = "mc-uid") String mcUid, @PathVariable(value = "user-uid") String userUid, HttpServletResponse response) throws DeleteAccessDeniedException {
    RootNode responseNode = new RootNode("reply");
    User user = userService.getUser(userUid);
    if (user == null) {
        responseNode.addChild(new SimpleNode("message", "No user with uid: " + userUid));
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return responseNode;
    }
    if (!canModifyUserConversation(currentUserService.getCurrentUser(), user)) {
        throw new DeleteAccessDeniedException("Not authorized to modify user: " + user.getUid());
    }
    org.hisp.dhis.message.MessageConversation messageConversation = messageService.getMessageConversation(mcUid);
    if (messageConversation == null) {
        responseNode.addChild(new SimpleNode("message", "No messageConversation with uid: " + mcUid));
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return responseNode;
    }
    CollectionNode removed = responseNode.addChild(new CollectionNode("removed"));
    if (messageConversation.remove(user)) {
        messageService.updateMessageConversation(messageConversation);
        removed.addChild(new SimpleNode("uid", messageConversation.getUid()));
    }
    response.setStatus(HttpServletResponse.SC_OK);
    return responseNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) User(org.hisp.dhis.user.User) DeleteAccessDeniedException(org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode 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)

Example 14 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.

the class PluckNodeTransformerTest method withArg.

@Test
void withArg() {
    Node result = transformer.transform(collectionNode, Collections.singletonList("name"));
    Assertions.assertTrue(result instanceof CollectionNode);
    CollectionNode collection = (CollectionNode) result;
    Assertions.assertEquals("organisationUnits", collection.getName());
    Assertions.assertEquals("testUrn", collection.getNamespace());
    Assertions.assertEquals(2, collection.getUnorderedChildren().size());
    Assertions.assertEquals("name", collection.getUnorderedChildren().get(0).getName());
    Assertions.assertTrue(collection.getUnorderedChildren().get(0) instanceof SimpleNode);
    Assertions.assertEquals("OU 1", ((SimpleNode) collection.getUnorderedChildren().get(0)).getValue());
    Assertions.assertEquals("name", collection.getUnorderedChildren().get(1).getName());
    Assertions.assertTrue(collection.getUnorderedChildren().get(1) instanceof SimpleNode);
    Assertions.assertEquals("OU 2", ((SimpleNode) collection.getUnorderedChildren().get(1)).getValue());
}
Also used : CollectionNode(org.hisp.dhis.node.types.CollectionNode) Node(org.hisp.dhis.node.Node) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) Test(org.junit.jupiter.api.Test)

Example 15 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.

the class IsEmptyNodeTransformer method transform.

@Override
public Node transform(Node node, List<String> args) {
    checkNotNull(node);
    checkNotNull(node.getProperty());
    Property property = node.getProperty();
    if (property.isCollection()) {
        return new SimpleNode(property.getCollectionName(), node.getChildren().isEmpty(), property.isAttribute());
    } else if (property.isSimple()) {
        return new SimpleNode(property.getName(), ObjectUtils.isEmpty(((SimpleNode) node).getValue()), property.isAttribute());
    }
    return node;
}
Also used : Property(org.hisp.dhis.schema.Property) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Aggregations

SimpleNode (org.hisp.dhis.node.types.SimpleNode)57 CollectionNode (org.hisp.dhis.node.types.CollectionNode)38 RootNode (org.hisp.dhis.node.types.RootNode)36 ComplexNode (org.hisp.dhis.node.types.ComplexNode)26 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)21 User (org.hisp.dhis.user.User)18 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Node (org.hisp.dhis.node.Node)10 Property (org.hisp.dhis.schema.Property)10 MessageConversation (org.hisp.dhis.webapi.webdomain.MessageConversation)8 ArrayList (java.util.ArrayList)7 DeleteAccessDeniedException (org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException)7 CurrentUser (org.hisp.dhis.user.CurrentUser)7 Test (org.junit.jupiter.api.Test)7 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 CategoryOption (org.hisp.dhis.category.CategoryOption)4 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4