Search in sources :

Example 51 with SimpleNode

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

the class MessageConversationController method removeUserAssigned.

// --------------------------------------------------------------------------
// Remove assigned user
// --------------------------------------------------------------------------
@DeleteMapping(value = "/{uid}/assign", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode removeUserAssigned(@PathVariable String uid, @CurrentUser User currentUser, HttpServletResponse response) {
    RootNode responseNode = new RootNode("response");
    if (!canModifyUserConversation(currentUser, currentUser) && (messageService.hasAccessToManageFeedbackMessages(currentUser))) {
        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;
    }
    messageConversation.setAssignee(null);
    messageService.updateMessageConversation(messageConversation);
    responseNode.addChild(new SimpleNode("message", "Message is no longer assigned to user"));
    response.setStatus(HttpServletResponse.SC_OK);
    return responseNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) SimpleNode(org.hisp.dhis.node.types.SimpleNode) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 52 with SimpleNode

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

the class MessageConversationController method markMessageConversationFollowup.

// --------------------------------------------------------------------------
// Mark conversations for follow up
// --------------------------------------------------------------------------
@PostMapping(value = "followup", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode markMessageConversationFollowup(@RequestParam(value = "user", required = false) String userUid, @RequestBody List<String> uids, HttpServletResponse response, @CurrentUser User currentUser) {
    RootNode responseNode = new RootNode("response");
    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 UIDs"));
        return responseNode;
    }
    CollectionNode marked = responseNode.addChild(new CollectionNode("markedFollowup"));
    marked.setWrapping(false);
    for (org.hisp.dhis.message.MessageConversation conversation : messageConversations) {
        if (!conversation.isFollowUp()) {
            conversation.toggleFollowUp(user);
            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) CurrentUser(org.hisp.dhis.user.CurrentUser) User(org.hisp.dhis.user.User) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) MessageConversation(org.hisp.dhis.webapi.webdomain.MessageConversation) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 53 with SimpleNode

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

the class MessageConversationController method setMessagePriority.

// --------------------------------------------------------------------------
// Assign priority
// --------------------------------------------------------------------------
@PostMapping(value = "/{uid}/priority", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode setMessagePriority(@PathVariable String uid, @RequestParam MessageConversationPriority messageConversationPriority, @CurrentUser User currentUser, HttpServletResponse response) {
    RootNode responseNode = new RootNode("response");
    if (!canModifyUserConversation(currentUser, currentUser) && (messageService.hasAccessToManageFeedbackMessages(currentUser))) {
        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) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 54 with SimpleNode

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

the class MessageConversationController method getObject.

@Override
public RootNode getObject(@PathVariable String uid, Map<String, String> rpParameters, @CurrentUser User currentUser, HttpServletRequest request, HttpServletResponse response) throws Exception {
    org.hisp.dhis.message.MessageConversation messageConversation = messageService.getMessageConversation(uid);
    if (messageConversation == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        RootNode responseNode = new RootNode("reply");
        responseNode.addChild(new SimpleNode("message", "No MessageConversation found with UID: " + uid));
        return responseNode;
    }
    if (!canReadMessageConversation(currentUser, messageConversation)) {
        throw new AccessDeniedException("Not authorized to access this conversation.");
    }
    return super.getObject(uid, rpParameters, currentUser, request, response);
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) DeleteAccessDeniedException(org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 55 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode 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, User currentUser) {
    RootNode responseNode = new RootNode("response");
    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) CurrentUser(org.hisp.dhis.user.CurrentUser) 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)

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