Search in sources :

Example 96 with Property

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

the class DefaultFieldFilterServiceTest method addProperty.

private static Property addProperty(Map<String, Property> propertyMap, Object bean, String property) throws Exception {
    PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(bean, property);
    Property p = new Property(pd.getPropertyType(), pd.getReadMethod(), pd.getWriteMethod());
    p.setName(pd.getName());
    p.setReadable(true);
    propertyMap.put(pd.getName(), p);
    return p;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Property(org.hisp.dhis.schema.Property)

Example 97 with Property

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

the class FieldPathHelper method getSchemaByPath.

private Schema getSchemaByPath(List<String> paths, Class<?> klass) {
    requireNonNull(paths);
    requireNonNull(klass);
    // get root schema
    Schema schema = schemaService.getDynamicSchema(klass);
    Property currentProperty;
    for (String path : paths) {
        currentProperty = schema.getProperty(path);
        if (currentProperty == null) {
            // invalid path
            return null;
        }
        if (currentProperty.isCollection()) {
            schema = schemaService.getDynamicSchema(currentProperty.getItemKlass());
        } else {
            schema = schemaService.getDynamicSchema(currentProperty.getKlass());
        }
    }
    return schema;
}
Also used : Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property)

Example 98 with Property

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

the class FieldPathHelper method expandReference.

private void expandReference(Map<String, FieldPath> fieldPathMap, List<String> paths, Schema schema) {
    Property idProperty = schema.getProperty("id");
    FieldPath fp = new FieldPath(idProperty.isCollection() ? idProperty.getCollectionName() : idProperty.getName(), paths);
    fp.setProperty(idProperty);
    fieldPathMap.put(fp.toFullPath(), fp);
}
Also used : Property(org.hisp.dhis.schema.Property)

Example 99 with Property

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

the class DefaultFieldFilterService method toCollectionNode.

@Override
public CollectionNode toCollectionNode(Class<?> wrapper, FieldFilterParams params) {
    String fields = params.getFields() == null ? "" : Joiner.on(",").join(params.getFields());
    Schema rootSchema = schemaService.getDynamicSchema(wrapper);
    CollectionNode collectionNode = new CollectionNode(rootSchema.getCollectionName());
    collectionNode.setNamespace(rootSchema.getNamespace());
    List<?> objects = params.getObjects();
    if (params.getSkipSharing()) {
        final List<String> fieldList = CollectionUtils.isEmpty(params.getFields()) ? Collections.singletonList("*") : params.getFields();
        // excludes must be preserved (e.g. when field collections like
        // :owner are used, which is not expanded by modify filter)
        fields = Stream.concat(fieldParser.modifyFilter(fieldList, SHARING_FIELDS).stream(), SHARING_FIELDS.stream()).filter(org.apache.commons.lang3.StringUtils::isNotBlank).distinct().collect(Collectors.joining(","));
    }
    if (params.getObjects().isEmpty() || objects.stream().allMatch(Objects::isNull)) {
        return collectionNode;
    }
    FieldMap fieldMap = new FieldMap();
    Schema schema = schemaService.getDynamicSchema(HibernateProxyUtils.getRealClass(objects.get(0)));
    if (StringUtils.isEmpty(fields)) {
        for (Property property : schema.getProperties()) {
            fieldMap.put(property.getName(), new FieldMap());
        }
    } else {
        fieldMap = fieldParser.parse(fields);
    }
    final FieldMap finalFieldMap = fieldMap;
    if (params.getUser() == null) {
        params.setUser(currentUserService.getCurrentUser());
    }
    objects.forEach(object -> {
        AbstractNode node = buildNode(finalFieldMap, wrapper, object, params.getUser(), params.getDefaults());
        if (node != null) {
            collectionNode.addChild(node);
        }
    });
    return collectionNode;
}
Also used : AbstractNode(org.hisp.dhis.node.AbstractNode) Schema(org.hisp.dhis.schema.Schema) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Property(org.hisp.dhis.schema.Property)

Example 100 with Property

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

the class AbstractNodeTest method createSingleChild.

@Test
void createSingleChild() {
    final SimpleNode simpleNode = new SimpleNode("id", "My Test");
    final TestNode testNode = new TestNode("tests", NodeType.COMPLEX, new Property(TestClass.class), simpleNode);
    Assertions.assertEquals("tests", testNode.getName());
    Assertions.assertEquals(NodeType.COMPLEX, testNode.nodeType);
    Assertions.assertEquals(TestClass.class, testNode.getProperty().getKlass());
    Assertions.assertEquals(1, testNode.getUnorderedChildren().size());
    Assertions.assertSame(simpleNode, testNode.getUnorderedChildren().get(0));
}
Also used : Property(org.hisp.dhis.schema.Property) SimpleNode(org.hisp.dhis.node.types.SimpleNode) Test(org.junit.jupiter.api.Test)

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