use of org.hisp.dhis.node.types.CollectionNode 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.CollectionNode 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.CollectionNode 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);
}
}
}
}
}
}
}
use of org.hisp.dhis.node.types.CollectionNode in project dhis2-core by dhis2.
the class AbstractNodeSerializer method writeCollectionNode.
protected void writeCollectionNode(CollectionNode collectionNode) throws Exception {
if (!config.getInclusionStrategy().include(collectionNode.getChildren())) {
return;
}
startWriteCollectionNode(collectionNode);
for (Node node : collectionNode.getChildren()) {
dispatcher(node);
flushStream();
}
endWriteCollectionNode(collectionNode);
}
use of org.hisp.dhis.node.types.CollectionNode in project dhis2-core by dhis2.
the class DefaultDataValueSetService method getDataValueTemplate.
private CollectionNode getDataValueTemplate(DataElement dataElement, String deScheme, OrganisationUnit organisationUnit, String ouScheme, Period period, boolean comment) {
CollectionNode collectionNode = new CollectionNode("dataValues");
collectionNode.setWrapping(false);
for (DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
ComplexNode complexNode = collectionNode.addChild(new ComplexNode("dataValue"));
String label = dataElement.getDisplayName();
if (!categoryOptionCombo.isDefault()) {
label += " " + categoryOptionCombo.getDisplayName();
}
if (comment) {
complexNode.setComment("Data element: " + label);
}
if (IdentifiableProperty.CODE.toString().toLowerCase().equals(deScheme.toLowerCase())) {
SimpleNode simpleNode = complexNode.addChild(new SimpleNode("dataElement", dataElement.getCode()));
simpleNode.setAttribute(true);
} else {
SimpleNode simpleNode = complexNode.addChild(new SimpleNode("dataElement", dataElement.getUid()));
simpleNode.setAttribute(true);
}
SimpleNode simpleNode = complexNode.addChild(new SimpleNode("categoryOptionCombo", categoryOptionCombo.getUid()));
simpleNode.setAttribute(true);
simpleNode = complexNode.addChild(new SimpleNode("period", period != null ? period.getIsoDate() : ""));
simpleNode.setAttribute(true);
if (organisationUnit != null) {
if (IdentifiableProperty.CODE.toString().toLowerCase().equals(ouScheme.toLowerCase())) {
simpleNode = complexNode.addChild(new SimpleNode("orgUnit", organisationUnit.getCode() == null ? "" : organisationUnit.getCode()));
simpleNode.setAttribute(true);
} else {
simpleNode = complexNode.addChild(new SimpleNode("orgUnit", organisationUnit.getUid() == null ? "" : organisationUnit.getUid()));
simpleNode.setAttribute(true);
}
}
simpleNode = complexNode.addChild(new SimpleNode("value", ""));
simpleNode.setAttribute(true);
}
return collectionNode;
}
Aggregations