use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class SystemController method getObjectCounts.
@RequestMapping(value = "/objectCounts", method = RequestMethod.GET)
@ResponseBody
public RootNode getObjectCounts() {
Map<Objects, Integer> objectCounts = statisticsProvider.getObjectCounts();
RootNode rootNode = NodeUtils.createRootNode("objectCounts");
for (Objects objects : objectCounts.keySet()) {
rootNode.addChild(new SimpleNode(objects.getValue(), objectCounts.get(objects)));
}
return rootNode;
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class MessageConversationController method removeUserFromMessageConversation.
//--------------------------------------------------------------------------
// Remove a user from a MessageConversation
// In practice a DELETE on MessageConversation <-> User relationship
//--------------------------------------------------------------------------
@RequestMapping(value = "/{mc-uid}/{user-uid}", method = RequestMethod.DELETE, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode removeUserFromMessageConversation(@PathVariable(value = "mc-uid") String mcUid, @PathVariable(value = "user-uid") String userUid, HttpServletResponse response) throws DeleteAccessDeniedException {
RootNode responseNode = new RootNode("reply");
User user = userService.getUser(userUid);
if (user == null) {
responseNode.addChild(new SimpleNode("message", "No user with uid: " + userUid));
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return responseNode;
}
if (!canModifyUserConversation(currentUserService.getCurrentUser(), user)) {
throw new DeleteAccessDeniedException("Not authorized to modify user: " + user.getUid());
}
org.hisp.dhis.message.MessageConversation messageConversation = messageService.getMessageConversation(mcUid);
if (messageConversation == null) {
responseNode.addChild(new SimpleNode("message", "No messageConversation with uid: " + mcUid));
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return responseNode;
}
CollectionNode removed = responseNode.addChild(new CollectionNode("removed"));
if (messageConversation.remove(user)) {
messageService.updateMessageConversation(messageConversation);
removed.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 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 (CategoryOptionCombo 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().equalsIgnoreCase(ouScheme)) {
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;
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class PluckNodeTransformerTest method withArg.
@Test
void withArg() {
Node result = transformer.transform(collectionNode, Collections.singletonList("name"));
Assertions.assertTrue(result instanceof CollectionNode);
CollectionNode collection = (CollectionNode) result;
Assertions.assertEquals("organisationUnits", collection.getName());
Assertions.assertEquals("testUrn", collection.getNamespace());
Assertions.assertEquals(2, collection.getUnorderedChildren().size());
Assertions.assertEquals("name", collection.getUnorderedChildren().get(0).getName());
Assertions.assertTrue(collection.getUnorderedChildren().get(0) instanceof SimpleNode);
Assertions.assertEquals("OU 1", ((SimpleNode) collection.getUnorderedChildren().get(0)).getValue());
Assertions.assertEquals("name", collection.getUnorderedChildren().get(1).getName());
Assertions.assertTrue(collection.getUnorderedChildren().get(1) instanceof SimpleNode);
Assertions.assertEquals("OU 2", ((SimpleNode) collection.getUnorderedChildren().get(1)).getValue());
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class IsEmptyNodeTransformer method transform.
@Override
public Node transform(Node node, List<String> args) {
checkNotNull(node);
checkNotNull(node.getProperty());
Property property = node.getProperty();
if (property.isCollection()) {
return new SimpleNode(property.getCollectionName(), node.getChildren().isEmpty(), property.isAttribute());
} else if (property.isSimple()) {
return new SimpleNode(property.getName(), ObjectUtils.isEmpty(((SimpleNode) node).getValue()), property.isAttribute());
}
return node;
}
Aggregations