use of org.hisp.dhis.node.types.ComplexNode in project dhis2-core by dhis2.
the class DefaultFieldFilterServiceTest method defaultClass.
@Test
void defaultClass() {
final CategoryOption co1 = new CategoryOption();
co1.setUid("abc1");
final CategoryOption co2 = new CategoryOption();
co2.setUid("abc2");
co2.setName("default");
final CategoryOption co3 = new CategoryOption();
co3.setUid("abc3");
final Category category = new Category();
category.setUid("def1");
category.getCategoryOptions().add(co1);
category.getCategoryOptions().add(co2);
category.getCategoryOptions().add(co3);
final FieldFilterParams params = new FieldFilterParams(Collections.singletonList(category), Arrays.asList("id", "categoryOptions"));
params.setDefaults(Defaults.EXCLUDE);
final ComplexNode node = service.toComplexNode(params);
Assertions.assertEquals("category", node.getName());
Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "id") instanceof SimpleNode);
Assertions.assertEquals("def1", ((SimpleNode) getNamedNode(node.getUnorderedChildren(), "id")).getValue());
Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "categoryOptions") instanceof CollectionNode);
final CollectionNode collectionNode = (CollectionNode) getNamedNode(node.getUnorderedChildren(), "categoryOptions");
Assertions.assertEquals(2, collectionNode.getUnorderedChildren().size());
final List<String> coIds = new ArrayList<>();
Assertions.assertTrue(collectionNode.getUnorderedChildren().get(0) instanceof ComplexNode);
ComplexNode complexNode = (ComplexNode) collectionNode.getUnorderedChildren().get(0);
Assertions.assertEquals("categoryOption", complexNode.getName());
Assertions.assertEquals(1, complexNode.getUnorderedChildren().size());
Assertions.assertTrue(complexNode.getUnorderedChildren().get(0) instanceof SimpleNode);
SimpleNode simpleNode = (SimpleNode) complexNode.getUnorderedChildren().get(0);
Assertions.assertEquals("id", simpleNode.getName());
coIds.add(String.valueOf(simpleNode.getValue()));
Assertions.assertTrue(collectionNode.getUnorderedChildren().get(1) instanceof ComplexNode);
complexNode = (ComplexNode) collectionNode.getUnorderedChildren().get(1);
Assertions.assertEquals("categoryOption", complexNode.getName());
Assertions.assertEquals(1, complexNode.getUnorderedChildren().size());
Assertions.assertTrue(complexNode.getUnorderedChildren().get(0) instanceof SimpleNode);
simpleNode = (SimpleNode) complexNode.getUnorderedChildren().get(0);
Assertions.assertEquals("id", simpleNode.getName());
coIds.add(String.valueOf(simpleNode.getValue()));
assertThat(coIds, Matchers.containsInAnyOrder("abc1", "abc3"));
}
use of org.hisp.dhis.node.types.ComplexNode 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.ComplexNode in project dhis2-core by dhis2.
the class UserControllerUtils method getUserDataApprovalWorkflows.
/**
* Gets the data approval workflows a user can see, including the workflow
* levels accessible to the user and the actions (if any) they can take at
* those levels to approve (and accept if configured) data.
*
* @param user the user
* @throws Exception if an error occurs
*/
public RootNode getUserDataApprovalWorkflows(User user) throws Exception {
CollectionNode collectionNode = new CollectionNode("dataApprovalWorkflows", true);
for (DataApprovalWorkflow workflow : dataApprovalService.getAllWorkflows()) {
if (!aclService.canRead(user, workflow)) {
continue;
}
ComplexNode workflowNode = new ComplexNode("dataApprovalWorkflow");
workflowNode.addChild(new SimpleNode("name", workflow.getName()));
workflowNode.addChild(new SimpleNode("id", workflow.getUid()));
workflowNode.addChild(getWorkflowLevelNodes(user, workflow));
collectionNode.addChild(workflowNode);
}
collectionNode.getUnorderedChildren().sort(Comparator.comparing(c -> (String) ((SimpleNode) c.getUnorderedChildren().get(0)).getValue()));
RootNode rootNode = NodeUtils.createRootNode("dataApprovalWorkflows");
rootNode.addChild(collectionNode);
return rootNode;
}
Aggregations