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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations