Search in sources :

Example 21 with CollectionNode

use of org.hisp.dhis.node.types.CollectionNode 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 22 with CollectionNode

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

the class TrackedEntityInstanceController method getTrackedEntityInstanceById.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_INSTANCE_SEARCH')")
@ResponseBody
public RootNode getTrackedEntityInstanceById(@PathVariable("id") String pvId) throws NotFoundException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.add(":all");
    }
    CollectionNode collectionNode = fieldFilterService.filter(TrackedEntityInstance.class, Lists.newArrayList(getTrackedEntityInstance(pvId, fields)), 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) CollectionNode(org.hisp.dhis.node.types.CollectionNode) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 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 24 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 25 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)

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