Search in sources :

Example 26 with CollectionNode

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

the class CurrentUserController method getCurrentUser.

@RequestMapping
@ResponseBody
public RootNode 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.add(":all");
    }
    CollectionNode collectionNode = fieldFilterService.filter(User.class, Collections.singletonList(currentUser), fields);
    RootNode rootNode = new RootNode(collectionNode.getChildren().get(0));
    rootNode.setDefaultNamespace(DxfNamespaces.DXF_2_0);
    rootNode.setNamespace(DxfNamespaces.DXF_2_0);
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) User(org.hisp.dhis.user.User) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 27 with CollectionNode

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

the class MessageConversationController method modifyMessageConversationRead.

/**
     * Internal handler for setting the read property of MessageConversation.
     *
     * @param readValue true when setting as read, false when setting unread.
     */
private RootNode modifyMessageConversationRead(String userUid, List<String> uids, HttpServletResponse response, boolean readValue) {
    RootNode responseNode = new RootNode("response");
    User currentUser = currentUserService.getCurrentUser();
    User user = userUid != null ? userService.getUser(userUid) : currentUser;
    if (user == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        responseNode.addChild(new SimpleNode("message", "No user with uid: " + userUid));
        return responseNode;
    }
    if (!canModifyUserConversation(currentUser, user)) {
        throw new UpdateAccessDeniedException("Not authorized to modify this object.");
    }
    Collection<org.hisp.dhis.message.MessageConversation> messageConversations = messageService.getMessageConversations(user, uids);
    if (messageConversations.isEmpty()) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        responseNode.addChild(new SimpleNode("message", "No MessageConversations found for the given IDs."));
        return responseNode;
    }
    CollectionNode marked = responseNode.addChild(new CollectionNode(readValue ? "markedRead" : "markedUnread"));
    marked.setWrapping(false);
    for (org.hisp.dhis.message.MessageConversation conversation : messageConversations) {
        boolean success = (readValue ? conversation.markRead(user) : conversation.markUnread(user));
        if (success) {
            messageService.updateMessageConversation(conversation);
            marked.addChild(new SimpleNode("uid", conversation.getUid()));
        }
    }
    response.setStatus(HttpServletResponse.SC_OK);
    return responseNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) User(org.hisp.dhis.user.User) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) MessageConversation(org.hisp.dhis.webapi.webdomain.MessageConversation)

Example 28 with CollectionNode

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

the class MessageConversationController method setMessageStatus.

//--------------------------------------------------------------------------
// Assign status
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/status", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode setMessageStatus(@PathVariable String uid, @RequestParam MessageConversationStatus messageConversationStatus, HttpServletResponse response) {
    RootNode responseNode = new RootNode("response");
    User user = currentUserService.getCurrentUser();
    if (!canModifyUserConversation(user, user) && (messageService.hasAccessToManageFeedbackMessages(user))) {
        throw new UpdateAccessDeniedException("Not authorized to modify this object.");
    }
    org.hisp.dhis.message.MessageConversation messageConversation = messageService.getMessageConversation(uid);
    if (messageConversation == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        responseNode.addChild(new SimpleNode("message", "No MessageConversation found for the given ID."));
        return responseNode;
    }
    CollectionNode marked = responseNode.addChild(new CollectionNode(messageConversationStatus.name()));
    marked.setWrapping(false);
    messageConversation.setStatus(messageConversationStatus);
    messageService.updateMessageConversation(messageConversation);
    marked.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) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) 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 29 with CollectionNode

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

the class MessageConversationController method setMessagePriority.

//--------------------------------------------------------------------------
// Assign priority
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/priority", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode setMessagePriority(@PathVariable String uid, @RequestParam MessageConversationPriority messageConversationPriority, HttpServletResponse response) {
    RootNode responseNode = new RootNode("response");
    User user = currentUserService.getCurrentUser();
    if (!canModifyUserConversation(user, user) && (messageService.hasAccessToManageFeedbackMessages(user))) {
        throw new UpdateAccessDeniedException("Not authorized to modify this object.");
    }
    org.hisp.dhis.message.MessageConversation messageConversation = messageService.getMessageConversation(uid);
    if (messageConversation == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        responseNode.addChild(new SimpleNode("message", "No MessageConversation found for the given ID."));
        return responseNode;
    }
    CollectionNode marked = responseNode.addChild(new CollectionNode(messageConversationPriority.name()));
    marked.setWrapping(false);
    messageConversation.setPriority(messageConversationPriority);
    messageService.updateMessageConversation(messageConversation);
    marked.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) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) 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 30 with CollectionNode

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

the class SystemController method getUid.

// -------------------------------------------------------------------------
// UID Generator
// -------------------------------------------------------------------------
@RequestMapping(value = { "/uid", "/id" }, method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode getUid(@RequestParam(required = false, defaultValue = "1") Integer limit) throws IOException, InvalidTypeException {
    limit = Math.min(limit, 10000);
    RootNode rootNode = new RootNode("codes");
    CollectionNode collectionNode = rootNode.addChild(new CollectionNode("codes"));
    collectionNode.setWrapping(false);
    for (int i = 0; i < limit; i++) {
        collectionNode.addChild(new SimpleNode("code", CodeGenerator.generateUid()));
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) 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)

Aggregations

CollectionNode (org.hisp.dhis.node.types.CollectionNode)30 RootNode (org.hisp.dhis.node.types.RootNode)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)17 SimpleNode (org.hisp.dhis.node.types.SimpleNode)16 ComplexNode (org.hisp.dhis.node.types.ComplexNode)9 User (org.hisp.dhis.user.User)8 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)5 Pager (org.hisp.dhis.common.Pager)4 Node (org.hisp.dhis.node.Node)4 Schema (org.hisp.dhis.schema.Schema)4 MessageConversation (org.hisp.dhis.webapi.webdomain.MessageConversation)4 DataElement (org.hisp.dhis.dataelement.DataElement)3 NotAuthenticatedException (org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException)3 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)2 DeleteAccessDeniedException (org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException)2 AbstractNode (org.hisp.dhis.node.AbstractNode)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Query (org.hisp.dhis.query.Query)2 Property (org.hisp.dhis.schema.Property)2