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