use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class MessageConversationController method removeUserFromMessageConversations.
// --------------------------------------------------------------------------
// Remove a user from one or more MessageConversations (batch operation)
// --------------------------------------------------------------------------
@DeleteMapping(produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode removeUserFromMessageConversations(@RequestParam("mc") List<String> mcUids, @RequestParam(value = "user", required = false) String userUid, HttpServletResponse response, @CurrentUser User currentUser) throws DeleteAccessDeniedException {
RootNode responseNode = new RootNode("response");
User user = userUid == null ? currentUser : userService.getUser(userUid);
if (user == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "User does not exist: " + userUid));
return responseNode;
}
if (!canModifyUserConversation(currentUser, user)) {
throw new DeleteAccessDeniedException("Not authorized to modify user: " + user.getUid());
}
Collection<org.hisp.dhis.message.MessageConversation> messageConversations = messageService.getMessageConversations(user, mcUids);
if (messageConversations.isEmpty()) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "No MessageConversations found for the given UIDs."));
return responseNode;
}
CollectionNode removed = responseNode.addChild(new CollectionNode("removed"));
for (org.hisp.dhis.message.MessageConversation mc : messageConversations) {
if (mc.remove(user)) {
messageService.updateMessageConversation(mc);
removed.addChild(new SimpleNode("uid", mc.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
// --------------------------------------------------------------------------
@PostMapping(value = "/{uid}/status", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode setMessageStatus(@PathVariable String uid, @RequestParam MessageConversationStatus messageConversationStatus, @CurrentUser User currentUser, HttpServletResponse response) {
RootNode responseNode = new RootNode("response");
if (!canModifyUserConversation(currentUser, currentUser) && (messageService.hasAccessToManageFeedbackMessages(currentUser))) {
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 PdfNodeSerializer method startWriteRootNode.
@Override
protected void startWriteRootNode(RootNode rootNode) throws Exception {
for (Node child : rootNode.getChildren()) {
if (child.isCollection()) {
PdfPTable table = PDFUtils.getPdfPTable(true, 0.25f, 0.75f);
boolean haveContent = false;
for (Node node : child.getChildren()) {
for (Node property : node.getChildren()) {
if (property.isSimple()) {
table.addCell(PDFUtils.getItalicCell(property.getName()));
table.addCell(PDFUtils.getTextCell(getValue((SimpleNode) property)));
haveContent = true;
}
}
if (haveContent) {
table.addCell(PDFUtils.getEmptyCell(2, 15));
haveContent = false;
}
}
document.add(table);
}
}
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class AbstractCrudController method getCollectionItem.
//--------------------------------------------------------------------------
// Identifiable object collections add, delete
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/{property}/{itemId}", method = RequestMethod.GET)
@ResponseBody
public RootNode getCollectionItem(@PathVariable("uid") String pvUid, @PathVariable("property") String pvProperty, @PathVariable("itemId") String pvItemId, @RequestParam Map<String, String> parameters, TranslateParams translateParams, HttpServletRequest request, HttpServletResponse response) throws Exception {
User user = currentUserService.getCurrentUser();
setUserContext(user, translateParams);
if (!aclService.canRead(user, getEntityClass())) {
throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
}
RootNode rootNode = getObjectInternal(pvUid, parameters, Lists.newArrayList(), Lists.newArrayList(pvProperty + "[:all]"), user);
// TODO optimize this using field filter (collection filtering)
if (!rootNode.getChildren().isEmpty() && rootNode.getChildren().get(0).isCollection()) {
rootNode.getChildren().get(0).getChildren().stream().filter(Node::isComplex).forEach(node -> {
node.getChildren().stream().filter(child -> child.isSimple() && child.getName().equals("id") && !((SimpleNode) child).getValue().equals(pvItemId)).forEach(child -> rootNode.getChildren().get(0).removeChild(node));
});
}
if (rootNode.getChildren().isEmpty() || rootNode.getChildren().get(0).getChildren().isEmpty()) {
throw new WebMessageException(WebMessageUtils.notFound(pvProperty + " with ID " + pvItemId + " could not be found."));
}
return rootNode;
}
use of org.hisp.dhis.node.types.SimpleNode 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;
}
Aggregations