use of org.hisp.dhis.webapi.webdomain.MessageConversation in project dhis2-core by dhis2.
the class MessageConversationController method postXmlObject.
//--------------------------------------------------------------------------
// POST for new MessageConversation
//--------------------------------------------------------------------------
@Override
public void postXmlObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
MessageConversation messageConversation = renderService.fromXml(request.getInputStream(), MessageConversation.class);
postObject(response, request, messageConversation);
}
use of org.hisp.dhis.webapi.webdomain.MessageConversation in project dhis2-core by dhis2.
the class MessageConversationController method getMessage.
/**
* /* Returns the specified message after making sure the user has access to
* it.
*
* @param mcUid the message conversation UID.
* @param msgUid the message UID.
* @param user the user.
* @return a {@link Message}.
* @throws WebMessageException
*/
private Message getMessage(String mcUid, String msgUid, User user) throws WebMessageException {
org.hisp.dhis.message.MessageConversation conversation = messageService.getMessageConversation(mcUid);
if (conversation == null) {
throw new WebMessageException(notFound(String.format("No message conversation with uid '%s'", mcUid)));
}
if (!canReadMessageConversation(user, conversation)) {
throw new AccessDeniedException("Not authorized to access this conversation.");
}
List<Message> messages = conversation.getMessages().stream().filter(msg -> msg.getUid().equals(msgUid)).collect(Collectors.toList());
if (messages.size() < 1) {
throw new WebMessageException(notFound(String.format("No message with uid '%s' in messageConversation '%s", msgUid, mcUid)));
}
Message message = messages.get(0);
if (message.isInternal() && !configurationService.isUserInFeedbackRecipientUserGroup(user)) {
throw new WebMessageException(conflict("Not authorized to access this message"));
}
return message;
}
use of org.hisp.dhis.webapi.webdomain.MessageConversation 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.webapi.webdomain.MessageConversation in project dhis2-core by dhis2.
the class MessageConversationController method postJsonObject.
@Override
public void postJsonObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
MessageConversation messageConversation = renderService.fromJson(request.getInputStream(), MessageConversation.class);
postObject(response, request, messageConversation);
}
use of org.hisp.dhis.webapi.webdomain.MessageConversation 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;
}
Aggregations