use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class AbstractNodeTest method createSingleChild.
@Test
void createSingleChild() {
final SimpleNode simpleNode = new SimpleNode("id", "My Test");
final TestNode testNode = new TestNode("tests", NodeType.COMPLEX, new Property(TestClass.class), simpleNode);
Assertions.assertEquals("tests", testNode.getName());
Assertions.assertEquals(NodeType.COMPLEX, testNode.nodeType);
Assertions.assertEquals(TestClass.class, testNode.getProperty().getKlass());
Assertions.assertEquals(1, testNode.getUnorderedChildren().size());
Assertions.assertSame(simpleNode, testNode.getUnorderedChildren().get(0));
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class SizeNodeTransformer 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().size(), property.isAttribute());
} else if (property.is(PropertyType.TEXT)) {
return new SimpleNode(property.getName(), ((String) ((SimpleNode) node).getValue()).length(), property.isAttribute());
} else if (property.is(PropertyType.INTEGER, PropertyType.NUMBER)) {
return new SimpleNode(property.getName(), ((SimpleNode) node).getValue(), property.isAttribute());
}
return node;
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class NodeUtils method createSlimPager.
public static Node createSlimPager(final SlimPager pager) {
final ComplexNode pagerNode = new ComplexNode("pager");
pagerNode.setMetadata(true);
pagerNode.addChild(new SimpleNode("page", pager.getPage()));
pagerNode.addChild(new SimpleNode("pageSize", pager.getPageSize()));
pagerNode.addChild(new SimpleNode("isLastPage", pager.isLastPage()));
return pagerNode;
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class AbstractFullReadOnlyController method getCollectionItem.
@GetMapping("/{uid}/{property}/{itemId}")
@ResponseBody
public RootNode getCollectionItem(@PathVariable("uid") String pvUid, @PathVariable("property") String pvProperty, @PathVariable("itemId") String pvItemId, @RequestParam Map<String, String> parameters, TranslateParams translateParams, HttpServletResponse response, @CurrentUser User currentUser) throws Exception {
setUserContext(currentUser, translateParams);
try {
if (!aclService.canRead(currentUser, 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]"), currentUser);
// 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(notFound(pvProperty + " with ID " + pvItemId + " could not be found."));
}
cachePrivate(response);
return rootNode;
} finally {
UserContext.reset();
}
}
use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.
the class MessageConversationController method setUserAssigned.
// --------------------------------------------------------------------------
// Assign user
// --------------------------------------------------------------------------
@PostMapping(value = "/{uid}/assign", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode setUserAssigned(@PathVariable String uid, @RequestParam(required = false) String userId, @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;
}
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 (messageConversation.getMessageType() == MessageType.TICKET && !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 successfully"));
response.setStatus(HttpServletResponse.SC_OK);
return responseNode;
}
Aggregations