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, 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(currentUserService.getCurrentUser(), messageConversation)) {
throw new AccessDeniedException("Not authorized to access this conversation.");
}
return super.getObject(uid, rpParameters, request, response);
}
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) {
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.SimpleNode 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.SimpleNode 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;
}
use of org.hisp.dhis.node.types.SimpleNode 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;
}
Aggregations