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;
}
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;
}
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());
}
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;
}
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));
}
Aggregations