Search in sources :

Example 16 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.

the class IsNotEmptyNodeTransformer 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;
}
Also used : Property(org.hisp.dhis.schema.Property) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 17 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.

the class PluckNodeTransformer method transform.

@Override
public Node transform(Node node, List<String> args) {
    checkNotNull(node);
    checkNotNull(node.getProperty());
    Property property = node.getProperty();
    if (property.isCollection()) {
        final String fieldName = (args == null || args.isEmpty()) ? null : StringUtils.defaultIfEmpty(args.get(0), null);
        final CollectionNode collectionNode = new CollectionNode(node.getName(), node.getUnorderedChildren().size());
        collectionNode.setNamespace(node.getNamespace());
        for (final Node objectNode : node.getUnorderedChildren()) {
            for (final Node fieldNode : objectNode.getUnorderedChildren()) {
                if (fieldNode instanceof SimpleNode && (fieldName == null || fieldName.equals(fieldNode.getName()))) {
                    final SimpleNode childNode = new SimpleNode(fieldNode.getName(), ((SimpleNode) fieldNode).getValue());
                    childNode.setProperty(collectionNode.getProperty());
                    collectionNode.addChild(childNode);
                    break;
                }
            }
        }
        return collectionNode;
    }
    return node;
}
Also used : SimpleNode(org.hisp.dhis.node.types.SimpleNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Node(org.hisp.dhis.node.Node) Property(org.hisp.dhis.schema.Property) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 18 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.

the class DefaultFieldFilterServiceTest method baseIdentifiable.

@Test
void baseIdentifiable() {
    final OrganisationUnit ou1 = new OrganisationUnit();
    ou1.setUid("abc1");
    ou1.setName("Test 1");
    final OrganisationUnit ou2 = new OrganisationUnit();
    ou2.setUid("abc2");
    ou2.setName("Test 2");
    final CategoryOption option = new CategoryOption();
    option.setUid("def1");
    option.getOrganisationUnits().add(ou1);
    option.getOrganisationUnits().add(ou2);
    final FieldFilterParams params = new FieldFilterParams(Collections.singletonList(option), Arrays.asList("id", "organisationUnits[id,name]"));
    final ComplexNode node = service.toComplexNode(params);
    Assertions.assertEquals("categoryOption", node.getName());
    Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "id") instanceof SimpleNode);
    Assertions.assertEquals("def1", ((SimpleNode) getNamedNode(node.getUnorderedChildren(), "id")).getValue());
    Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "organisationUnits") instanceof CollectionNode);
    final CollectionNode collectionNode = (CollectionNode) getNamedNode(node.getUnorderedChildren(), "organisationUnits");
    Assertions.assertEquals(2, collectionNode.getUnorderedChildren().size());
    final List<String> ouIds = new ArrayList<>();
    final List<String> ouNames = new ArrayList<>();
    Assertions.assertTrue(collectionNode.getUnorderedChildren().get(0) instanceof ComplexNode);
    ComplexNode complexNode = (ComplexNode) collectionNode.getUnorderedChildren().get(0);
    Assertions.assertEquals("organisationUnit", complexNode.getName());
    Assertions.assertEquals(2, complexNode.getUnorderedChildren().size());
    Assertions.assertTrue(getNamedNode(complexNode.getUnorderedChildren(), "id") instanceof SimpleNode);
    SimpleNode simpleNode = (SimpleNode) getNamedNode(complexNode.getUnorderedChildren(), "id");
    Assertions.assertEquals("id", simpleNode.getName());
    ouIds.add(String.valueOf(simpleNode.getValue()));
    Assertions.assertTrue(getNamedNode(complexNode.getUnorderedChildren(), "name") instanceof SimpleNode);
    simpleNode = (SimpleNode) getNamedNode(complexNode.getUnorderedChildren(), "name");
    Assertions.assertEquals("name", simpleNode.getName());
    ouNames.add(String.valueOf(simpleNode.getValue()));
    Assertions.assertTrue(collectionNode.getUnorderedChildren().get(1) instanceof ComplexNode);
    complexNode = (ComplexNode) collectionNode.getUnorderedChildren().get(1);
    Assertions.assertEquals("organisationUnit", complexNode.getName());
    Assertions.assertEquals(2, complexNode.getUnorderedChildren().size());
    Assertions.assertTrue(getNamedNode(complexNode.getUnorderedChildren(), "id") instanceof SimpleNode);
    simpleNode = (SimpleNode) getNamedNode(complexNode.getUnorderedChildren(), "id");
    Assertions.assertEquals("id", simpleNode.getName());
    ouIds.add(String.valueOf(simpleNode.getValue()));
    Assertions.assertTrue(getNamedNode(complexNode.getUnorderedChildren(), "name") instanceof SimpleNode);
    simpleNode = (SimpleNode) getNamedNode(complexNode.getUnorderedChildren(), "name");
    Assertions.assertEquals("name", simpleNode.getName());
    ouNames.add(String.valueOf(simpleNode.getValue()));
    assertThat(ouIds, Matchers.containsInAnyOrder("abc1", "abc2"));
    assertThat(ouNames, Matchers.containsInAnyOrder("Test 1", "Test 2"));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) 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 19 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.

the class DefaultFieldFilterServiceTest method baseIdentifiableIdOnly.

@Test
void baseIdentifiableIdOnly() {
    final OrganisationUnit ou1 = new OrganisationUnit();
    ou1.setUid("abc1");
    final OrganisationUnit ou2 = new OrganisationUnit();
    ou2.setUid("abc2");
    final CategoryOption option = new CategoryOption();
    option.setUid("def1");
    option.getOrganisationUnits().add(ou1);
    option.getOrganisationUnits().add(ou2);
    final FieldFilterParams params = new FieldFilterParams(Collections.singletonList(option), Arrays.asList("id", "organisationUnits"));
    final ComplexNode node = service.toComplexNode(params);
    Assertions.assertEquals("categoryOption", node.getName());
    Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "id") instanceof SimpleNode);
    Assertions.assertEquals("def1", ((SimpleNode) getNamedNode(node.getUnorderedChildren(), "id")).getValue());
    Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "organisationUnits") instanceof CollectionNode);
    final CollectionNode collectionNode = (CollectionNode) getNamedNode(node.getUnorderedChildren(), "organisationUnits");
    Assertions.assertEquals(2, collectionNode.getUnorderedChildren().size());
    final List<String> ouIds = new ArrayList<>();
    Assertions.assertTrue(collectionNode.getUnorderedChildren().get(0) instanceof ComplexNode);
    ComplexNode complexNode = (ComplexNode) collectionNode.getUnorderedChildren().get(0);
    Assertions.assertEquals("organisationUnit", 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());
    ouIds.add(String.valueOf(simpleNode.getValue()));
    Assertions.assertTrue(collectionNode.getUnorderedChildren().get(1) instanceof ComplexNode);
    complexNode = (ComplexNode) collectionNode.getUnorderedChildren().get(1);
    Assertions.assertEquals("organisationUnit", 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());
    ouIds.add(String.valueOf(simpleNode.getValue()));
    assertThat(ouIds, Matchers.containsInAnyOrder("abc1", "abc2"));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) 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 20 with SimpleNode

use of org.hisp.dhis.node.types.SimpleNode in project dhis2-core by dhis2.

the class DataElementOperandControllerTest method buildResponse.

private CollectionNode buildResponse(List<DataElementOperand> dataElementOperands) {
    CollectionNode collectionNode = new CollectionNode("dataElementOperands");
    collectionNode.setWrapping(true);
    collectionNode.setNamespace("http://dhis2.org/schema/dxf/2.0");
    for (DataElementOperand dataElementOperand : dataElementOperands) {
        ComplexNode complexNode = new ComplexNode("dataElementOperand");
        complexNode.setNamespace(collectionNode.getNamespace());
        complexNode.addChild(new SimpleNode("displayName", dataElementOperand.getDisplayName(), false));
        complexNode.addChild(new SimpleNode("id", dataElementOperand.getDimensionItem(), true));
        collectionNode.addChild(complexNode);
    }
    return collectionNode;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Aggregations

SimpleNode (org.hisp.dhis.node.types.SimpleNode)57 CollectionNode (org.hisp.dhis.node.types.CollectionNode)38 RootNode (org.hisp.dhis.node.types.RootNode)36 ComplexNode (org.hisp.dhis.node.types.ComplexNode)26 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)21 User (org.hisp.dhis.user.User)18 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Node (org.hisp.dhis.node.Node)10 Property (org.hisp.dhis.schema.Property)10 MessageConversation (org.hisp.dhis.webapi.webdomain.MessageConversation)8 ArrayList (java.util.ArrayList)7 DeleteAccessDeniedException (org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException)7 CurrentUser (org.hisp.dhis.user.CurrentUser)7 Test (org.junit.jupiter.api.Test)7 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 CategoryOption (org.hisp.dhis.category.CategoryOption)4 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4