Search in sources :

Example 61 with Property

use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.

the class PagingNodeTransformer method transform.

@Override
public Node transform(Node node, List<String> args) {
    checkNotNull(node);
    checkArgument(!args.isEmpty(), "paging requires at least one parameter, .e.g: property|paging(page, pageSize)");
    checkNotNull(node.getProperty());
    int page;
    int pageSize = Pager.DEFAULT_PAGE_SIZE;
    try {
        page = Integer.parseInt(args.get(0));
        if (args.size() > 1) {
            pageSize = Integer.parseInt(args.get(1));
        }
    } catch (NumberFormatException ex) {
        return node;
    }
    Property property = node.getProperty();
    if (property.isCollection()) {
        Pager pager = new Pager(page, node.getChildren().size(), pageSize);
        ((AbstractNode) node).setChildren(PagerUtils.pageCollection(node.getChildren(), pager));
        return node;
    }
    return node;
}
Also used : AbstractNode(org.hisp.dhis.node.AbstractNode) Pager(org.hisp.dhis.common.Pager) Property(org.hisp.dhis.schema.Property)

Example 62 with Property

use of org.hisp.dhis.schema.Property 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 63 with Property

use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.

the class SimpleNodeTest method createWithProperty.

@Test
void createWithProperty() {
    final Property property = new Property(AbstractNodeTest.TestClass.class);
    property.setName("test");
    property.setNamespace("testUri");
    property.setAttribute(true);
    final SimpleNode simpleNode = new SimpleNode("id", property, "My Test");
    Assertions.assertEquals("id", simpleNode.getName());
    Assertions.assertEquals("testUri", simpleNode.getNamespace());
    Assertions.assertTrue(simpleNode.isAttribute());
    Assertions.assertEquals("My Test", simpleNode.getValue());
}
Also used : AbstractNodeTest(org.hisp.dhis.node.AbstractNodeTest) Property(org.hisp.dhis.schema.Property) Test(org.junit.jupiter.api.Test) AbstractNodeTest(org.hisp.dhis.node.AbstractNodeTest)

Example 64 with Property

use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.

the class TranslationUtils method getObjectPropertyValues.

public static Map<String, String> getObjectPropertyValues(Schema schema, Object object) {
    if (object == null) {
        return null;
    }
    List<Property> properties = schema.getTranslatableProperties();
    Map<String, String> translations = new HashMap<>();
    for (Property property : properties) {
        translations.put(property.getName(), getProperty(object, property.getName()));
    }
    return translations;
}
Also used : HashMap(java.util.HashMap) ReflectionUtils.getProperty(org.hisp.dhis.system.util.ReflectionUtils.getProperty) Property(org.hisp.dhis.schema.Property)

Example 65 with Property

use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.

the class ComplexNodeTest method createSingleChild.

@Test
void createSingleChild() {
    final Property property = new Property(AbstractNodeTest.TestClass.class);
    property.setName("tests");
    property.setNamespace("testUri");
    final SimpleNode simpleNode = new SimpleNode("id", "My Test");
    final ComplexNode testNode = new ComplexNode(property, simpleNode);
    Assertions.assertEquals("tests", testNode.getName());
    Assertions.assertEquals("testUri", testNode.getNamespace());
    Assertions.assertEquals(AbstractNodeTest.TestClass.class, testNode.getProperty().getKlass());
    Assertions.assertEquals(1, testNode.getUnorderedChildren().size());
    Assertions.assertSame(simpleNode, testNode.getUnorderedChildren().get(0));
}
Also used : AbstractNodeTest(org.hisp.dhis.node.AbstractNodeTest) Property(org.hisp.dhis.schema.Property) Test(org.junit.jupiter.api.Test) AbstractNodeTest(org.hisp.dhis.node.AbstractNodeTest)

Aggregations

Property (org.hisp.dhis.schema.Property)126 Schema (org.hisp.dhis.schema.Schema)69 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)36 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)26 Collection (java.util.Collection)21 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)21 List (java.util.List)20 Map (java.util.Map)16 Test (org.junit.jupiter.api.Test)16 Attribute (org.hisp.dhis.attribute.Attribute)14 ReflectionUtils (org.hisp.dhis.system.util.ReflectionUtils)14 Collectors (java.util.stream.Collectors)13 User (org.hisp.dhis.user.User)13 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)12 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)12 SimpleNode (org.hisp.dhis.node.types.SimpleNode)12 Query (org.hisp.dhis.query.Query)12 SchemaService (org.hisp.dhis.schema.SchemaService)12 Transactional (org.springframework.transaction.annotation.Transactional)12