use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class MessageConversationController method unmarkMessageConversationFollowup.
//--------------------------------------------------------------------------
// Clear follow up
//--------------------------------------------------------------------------
@RequestMapping(value = "unfollowup", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode unmarkMessageConversationFollowup(@RequestParam(value = "user", required = false) String userUid, @RequestBody List<String> uids, HttpServletResponse response) {
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 UIDs"));
return responseNode;
}
CollectionNode marked = responseNode.addChild(new CollectionNode("unmarkedFollowup"));
marked.setWrapping(false);
for (org.hisp.dhis.message.MessageConversation conversation : messageConversations) {
if (conversation.isFollowUp()) {
conversation.toggleFollowUp(user);
messageService.updateMessageConversation(conversation);
}
marked.addChild(new SimpleNode("uid", conversation.getUid()));
}
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 removeUserAssigned.
//--------------------------------------------------------------------------
// Remove assigned user
//--------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/assign", method = RequestMethod.DELETE, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode removeUserAssigned(@PathVariable String uid, 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;
}
messageConversation.setAssignee(null);
messageService.updateMessageConversation(messageConversation);
responseNode.addChild(new SimpleNode("message", "Message is no longer assigned to user"));
response.setStatus(HttpServletResponse.SC_OK);
return responseNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class IndexController method createRootNode.
private RootNode createRootNode() {
RootNode rootNode = NodeUtils.createMetadata();
CollectionNode collectionNode = rootNode.addChild(new CollectionNode("resources"));
for (Schema schema : schemaService.getSchemas()) {
if (schema.haveApiEndpoint()) {
ComplexNode complexNode = collectionNode.addChild(new ComplexNode("resource"));
// TODO add i18n to this
complexNode.addChild(new SimpleNode("displayName", beautify(schema.getPlural())));
complexNode.addChild(new SimpleNode("singular", schema.getSingular()));
complexNode.addChild(new SimpleNode("plural", schema.getPlural()));
complexNode.addChild(new SimpleNode("href", contextService.getApiPath() + schema.getRelativeApiEndpoint()));
}
}
return rootNode;
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class CsvNodeSerializer method startWriteRootNode.
@Override
protected void startWriteRootNode(RootNode rootNode) throws Exception {
for (Node child : rootNode.getChildren()) {
if (child.isCollection()) {
for (Node node : child.getChildren()) {
csvGenerator.writeStartObject();
for (Node property : node.getChildren()) {
if (property.isSimple()) {
writeSimpleNode((SimpleNode) property);
}
}
csvGenerator.writeEndObject();
}
}
}
}
use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.
the class ExcelNodeSerializer method startWriteRootNode.
@Override
protected void startWriteRootNode(RootNode rootNode) throws Exception {
XSSFCreationHelper creationHelper = workbook.getCreationHelper();
int rowIdx = 1;
for (Node collectionNode : rootNode.getChildren()) {
if (collectionNode.isCollection()) {
for (Node complexNode : collectionNode.getChildren()) {
XSSFRow row = sheet.createRow(rowIdx++);
int cellIdx = 0;
for (Node node : complexNode.getChildren()) {
if (node.isSimple()) {
XSSFCell cell = row.createCell(cellIdx++);
cell.setCellValue(getValue((SimpleNode) node));
if (node.haveProperty() && PropertyType.URL.equals(node.getProperty().getPropertyType())) {
XSSFHyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.URL);
hyperlink.setAddress(getValue((SimpleNode) node));
hyperlink.setLabel(getValue((SimpleNode) node));
cell.setHyperlink(hyperlink);
} else if (node.haveProperty() && PropertyType.EMAIL.equals(node.getProperty().getPropertyType())) {
XSSFHyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.EMAIL);
hyperlink.setAddress(getValue((SimpleNode) node));
hyperlink.setLabel(getValue((SimpleNode) node));
cell.setHyperlink(hyperlink);
}
}
}
}
}
}
}
Aggregations