use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class CurrentUserController method getCurrentUser.
@RequestMapping
@ResponseBody
public RootNode getCurrentUser(HttpServletResponse response) throws Exception {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
if (fields.isEmpty()) {
fields.add(":all");
}
CollectionNode collectionNode = fieldFilterService.filter(User.class, Collections.singletonList(currentUser), 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.RootNode in project dhis2-core by dhis2.
the class LockExceptionController method getLockExceptions.
// -------------------------------------------------------------------------
// Resources
// -------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getLockExceptions(@RequestParam(required = false) String key, @RequestParam Map<String, String> rpParameters, HttpServletRequest request, HttpServletResponse response) throws IOException, WebMessageException {
List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<LockException> lockExceptions = new ArrayList<>();
if (key != null) {
LockException lockException = dataSetService.getLockException(MathUtils.parseInt(key));
if (lockException == null) {
throw new WebMessageException(WebMessageUtils.notFound("Cannot find LockException with key: " + key));
}
lockExceptions.add(lockException);
} else if (!filters.isEmpty()) {
lockExceptions = dataSetService.filterLockExceptions(filters);
} else {
lockExceptions = dataSetService.getAllLockExceptions();
}
WebOptions options = new WebOptions(rpParameters);
WebMetadata metadata = new WebMetadata();
Pager pager = metadata.getPager();
if (options.hasPaging() && pager == null) {
pager = new Pager(options.getPage(), lockExceptions.size(), options.getPageSize());
lockExceptions = PagerUtils.pageCollection(lockExceptions, pager);
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
rootNode.addChild(fieldFilterService.filter(LockException.class, lockExceptions, fields));
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class MessageConversationController method setUserAssigned.
//--------------------------------------------------------------------------
// Assign user
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/assign", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode setUserAssigned(@PathVariable String uid, @RequestParam(required = false) String userId, 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;
}
User userToAssign;
if ((userToAssign = userService.getUser(userId)) == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "Could not find user to assign"));
return responseNode;
}
if (!configurationService.isUserInFeedbackRecipientUserGroup(userToAssign)) {
response.setStatus(HttpServletResponse.SC_CONFLICT);
responseNode.addChild(new SimpleNode("message", "User provided is not a member of the system's feedback recipient group"));
return responseNode;
}
messageConversation.setAssignee(userToAssign);
messageService.updateMessageConversation(messageConversation);
responseNode.addChild(new SimpleNode("message", "User " + userToAssign.getName() + " was assigned to ticket"));
response.setStatus(HttpServletResponse.SC_OK);
return responseNode;
}
use of org.hisp.dhis.node.types.RootNode 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.RootNode 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;
}
Aggregations