Search in sources :

Example 31 with ComplexNode

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"));
}
Also used : Category(org.hisp.dhis.category.Category) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) Test(org.junit.jupiter.api.Test)

Example 32 with ComplexNode

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;
}
Also used : ComplexNode(org.hisp.dhis.node.types.ComplexNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 33 with ComplexNode

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;
}
Also used : DataApprovalLevelService(org.hisp.dhis.dataapproval.DataApprovalLevelService) AUTH_APPROVE(org.hisp.dhis.dataapproval.DataApproval.AUTH_APPROVE) AUTH_ACCEPT_LOWER_LEVELS(org.hisp.dhis.dataapproval.DataApproval.AUTH_ACCEPT_LOWER_LEVELS) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataApprovalService(org.hisp.dhis.dataapproval.DataApprovalService) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) SimpleNode(org.hisp.dhis.node.types.SimpleNode) AUTHORITY_ALL(org.hisp.dhis.user.UserAuthorityGroup.AUTHORITY_ALL) NodeUtils(org.hisp.dhis.node.NodeUtils) Component(org.springframework.stereotype.Component) ComplexNode(org.hisp.dhis.node.types.ComplexNode) AUTH_APPROVE_LOWER_LEVELS(org.hisp.dhis.dataapproval.DataApproval.AUTH_APPROVE_LOWER_LEVELS) AclService(org.hisp.dhis.security.acl.AclService) User(org.hisp.dhis.user.User) SettingKey(org.hisp.dhis.setting.SettingKey) Comparator(java.util.Comparator) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) RootNode(org.hisp.dhis.node.types.RootNode) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Aggregations

ComplexNode (org.hisp.dhis.node.types.ComplexNode)33 SimpleNode (org.hisp.dhis.node.types.SimpleNode)23 CollectionNode (org.hisp.dhis.node.types.CollectionNode)21 RootNode (org.hisp.dhis.node.types.RootNode)15 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)5 Node (org.hisp.dhis.node.Node)5 CategoryOption (org.hisp.dhis.category.CategoryOption)4 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Schema (org.hisp.dhis.schema.Schema)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)3 Property (org.hisp.dhis.schema.Property)3 Collection (java.util.Collection)2 Category (org.hisp.dhis.category.Category)2